设为首页收藏本站

最大的系统仿真与系统优化公益交流社区

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8373|回复: 1

[交流] 看看这段代码的问题

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
' ^1 d8 g6 T$ S; Y9 u4 d0 \+ I/ t' a5 }6 F0 y1 p- z
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。: q, K! Y# l' H& Q) d# X0 b
; c5 h( ?5 Z% E7 k! l
turtles-own [a b c d k f g h8 o- ]' E- t! f' v! L/ p% k
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 1 _0 m& G' m0 a; u) o( J
]
/ N4 A4 S# X! G7 U& bto new! V/ _5 j* i" ]* e* q
  ca
7 s. H6 ^, S9 m' v  crt 5 * num_of_building
9 b' \3 C$ D# D/ j  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]  @: A2 d$ ?4 D6 ^) x
  scatter     ;;keep center-turtle random positions
8 Z, b' B# H; T9 B0 m0 S  unit_plan   ;;make up the building plan
6 x+ k& L  u0 Q( G+ x$ Eend
( \9 f$ O. f3 Pto scatter
# c  ^1 B3 |) c1 `6 R/ x+ B" X6 vask turtles with [remainder who 5 = 0]
3 m7 e9 g9 b4 R1 k[0 u: m& g. s/ ~% }
set xcor xcor - 6 + random-float 150 k2 P5 z5 U- \* r* e; J! c
set ycor ycor - 6 + random-float 15% n) h9 \. n2 ?
]
2 M/ }8 @# i0 w' o" Dend
+ _8 t9 {6 ?! Y% u& m+ Fto unit_plan 6 b" \  E4 {; I) Z! B
ask turtles [+ K. ]- A; s, J, \, D
if (remainder who 5 = 1) [set a who
5 Y2 Z  I: }6 l( P! X. p5 H+ \                          set x ( 0 - Wid / 2 ) 3 i9 ]+ W  n- ?1 o
                          set y  Dep / 2 ]
& m3 {/ _+ t$ q& C# R           set b  int (a / 5) * 5  q6 {1 ~8 v+ M+ p
    setxy ( xcor-of turtle b + x )
$ [" ^( h, E; m2 e9 ^          ( ycor-of turtle b + y ). P, w7 Z0 d% h$ L
if (remainder who 5 = 2) [set c who8 `( ~7 O; T; G. ]1 k5 I
                          set x ( 0 - Wid / 2 )
' S, |; H- H" z' v                          set y (0 - Dep / 2 )  ]
0 f' d% c/ `8 |1 v- l- x( ]( ?/ `) a                          set d int (c / 5) * 5
3 S. i( Q- P' B   setxy   ( xcor-of turtle d + x )! w- E$ G& a& r' L2 i! _: ^! h
           (ycor-of turtle d + y ) ! {$ {  z; z2 {2 i$ C9 p3 G5 r1 [
         
9 c% f$ G, q; L            
* o) t6 R& ?- i" c! [. R+ Pif (remainder who 5 = 3) [set k who9 s/ U; _" h3 J: H' ?" w( E+ ?
                          set x( Wid / 2)  
$ ~7 z  d* D' {7 J0 E                          set y (0 - Dep / 2 ) ]4 w& Q! g" b% `8 b9 Z0 n
                          set f int (k / 5) * 5
6 u/ [" J- P0 w9 q4 H. C7 [1 u* [  setxy   ( xcor-of turtle f + x ): T' X' J! Q* m
           (ycor-of turtle f + y ) 0 a: ^0 {! H+ Z4 h
           - G# x  k. |1 Z3 \9 \
           ( r& f" S- E. r1 l9 ?
if (remainder who 5 = 4) [set g who
; B/ t4 G4 M6 e& }/ N. E( U. t                          set x Wid / 2
' a2 B6 T! C# O# c/ y9 B                          set y  Dep / 2 ]: B- D6 B, u3 M) `! C+ X
                          set h  int (g / 5) * 5$ E& [1 E0 X4 @2 G- o: e$ ]- ]
  setxy   ( xcor-of turtle h + x )
3 b6 h8 {7 `, Q! ]3 w           (ycor-of turtle h + y ) + U2 G; w6 J0 b% T' U, Y
                          
- d2 p" T4 C0 Q                          
! J7 T$ Z/ w( d; c- d                          ]( N$ o7 s/ r8 b
end
& F0 U; c2 }0 s* I: y( F5 B6 ], z4 S' Z+ C) Y2 J
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,; i, R5 Z$ o! H9 Y) l, u
应该是# |; X: L# V) R5 x+ U. j4 u$ u  b5 H
ask turtles [7 q! S1 u6 p, h' h* s( ^- ?
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) . ]5 U% H2 B2 e2 K- s
                          set y  Dep / 2 ) s# c' B; q* j2 D  E
           set b  int (who / 5) * 5
! s1 B6 d3 S! Z% R( Z- u    setxy ( xcor-of turtle b + x )
' r' I( F: F# y9 S: \# `          ( ycor-of turtle b + y )]]
" Y2 n6 E8 j4 _- Y9 w! n1 n$ }' rend
0 g9 J5 D  J" R( V6 k' Q/ S之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|SimulWay 道于仿真   

GMT+8, 2026-6-16 18:26 , Processed in 0.014085 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表