设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8836|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。2 o, ^/ o  ~9 x2 k! c$ `3 r$ P

; C9 y7 {1 w- g但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。8 y9 ]6 f" A. B( y* h( t- V4 j
3 d" J2 O9 }/ C" |9 A0 {* d5 X( m5 w
turtles-own [a b c d k f g h6 I% x; a% o& p2 x! o+ h
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 4 ?0 Z# D' r; M& `* @: m+ \
]
8 S* e6 l" s* I9 y2 c$ hto new9 u, r0 z& N: e5 ?) ^9 Q( L
  ca
% \- ~; [, ?0 Z1 T# w! n  crt 5 * num_of_building! }: T: U" @: ?
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]3 \9 {) Z9 Z; V% q& v( U9 P
  scatter     ;;keep center-turtle random positions
3 d# v  Z! P/ @- Z3 I; U  g; B% [0 J  unit_plan   ;;make up the building plan
! j( {8 W, E& \- g* Uend. J9 E5 O" ]. X: H% F7 i/ e
to scatter
8 P; a/ O+ c+ O" h  [ask turtles with [remainder who 5 = 0]
: j/ a' \( W8 C2 m8 S) }9 v7 X[
" Z8 @7 g+ J5 W) D0 c5 P6 kset xcor xcor - 6 + random-float 15
! ?; C6 [. ?) uset ycor ycor - 6 + random-float 15) t7 w6 C7 ?( Y: U; J1 ?+ r4 y, N  L
]
& i! u" Y% g3 _9 B+ B! send* f" V" `4 [* o, \, E
to unit_plan
& P& L6 y" ?! S4 T( V# Hask turtles [" b9 V' J- j+ X# C8 x* w, W
if (remainder who 5 = 1) [set a who 0 r5 o" m- f! A$ W6 V
                          set x ( 0 - Wid / 2 )
8 b) O2 t# b7 D2 M, `                          set y  Dep / 2 ]
9 H4 _3 c8 ]; T           set b  int (a / 5) * 57 H8 H, n7 @" Y
    setxy ( xcor-of turtle b + x )
# Z" P5 O- c1 P8 g8 M" C          ( ycor-of turtle b + y )/ p! w9 W8 m( J
if (remainder who 5 = 2) [set c who
4 e& w0 P' G* U* _: @( P5 j                          set x ( 0 - Wid / 2 ) 5 `$ S+ R3 S+ X
                          set y (0 - Dep / 2 )  ]
4 [/ f3 K6 G8 j; P! C8 s                          set d int (c / 5) * 5
. o7 S3 O& H' g. ~9 X8 b$ |" p   setxy   ( xcor-of turtle d + x )- m! q7 \; B' c: p
           (ycor-of turtle d + y )
: _% Z% \% p" m$ M; w* x         
! J3 b& G4 O" L6 _% `$ p            
$ E2 j, q' b' t8 J' V3 aif (remainder who 5 = 3) [set k who
- z) L4 z% `: J' ]' D% j                          set x( Wid / 2)  
( ^  Z* [% ]) r$ G& g& p# C# ?$ J                          set y (0 - Dep / 2 ) ]  n+ x( r* d4 y5 o& U" o
                          set f int (k / 5) * 5
; Q/ |( R8 k) \3 F8 W  setxy   ( xcor-of turtle f + x )
8 g2 g: Z9 z5 o; J& o' N1 i           (ycor-of turtle f + y )
- Z6 y4 l  e  M6 `* k9 B           - ~5 \4 q5 Q! V  n. @5 u  O" z
           
  j: y0 r: m* l, o/ s1 a2 B3 K: K, w) wif (remainder who 5 = 4) [set g who
$ s& C* f, u9 g' C; B$ e                          set x Wid / 2 . s4 [& T& k$ H* t" t& Y
                          set y  Dep / 2 ]
& u8 s" P& q0 ?, W                          set h  int (g / 5) * 5& d" y. w5 k" W$ ]5 O- K' j6 t
  setxy   ( xcor-of turtle h + x )8 ^. m) K$ y1 A6 F8 C. K8 t
           (ycor-of turtle h + y )
7 d, t* z0 }; t" S# o                          
2 H# J' q2 C4 H                          
) W5 F9 q5 F3 [, s! t                          ]$ y- `# ~% U" i6 X" \2 T
end4 @8 W( y! m3 X/ A" b4 d# v

+ c, e2 C, V  }$ z[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
' H$ J# h) v7 c" T: G8 |应该是4 o/ ~9 p! i2 m  Z& p
ask turtles [- H$ C, _+ l, G, |
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) , U5 _$ w2 L# z+ n  y
                          set y  Dep / 2 ! j+ @' ~- F. Y
           set b  int (who / 5) * 5
5 ?1 i' P2 i. X+ k0 @# _    setxy ( xcor-of turtle b + x )* P& J0 J) j$ ^9 L& ^6 B) f. C
          ( ycor-of turtle b + y )]]! m8 x1 K2 _4 f
end! T" V# ~: ]7 C5 t0 P, y
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-10 09:18 , Processed in 0.016847 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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