设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6934|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
& Q, G6 P( w" Z: N, M0 c! a3 G& G( i- U4 u
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
. ]6 Z: o, u6 U! I) u
: ^* C. g/ X9 P1 {: C4 S9 nturtles-own [a b c d k f g h% Y( r4 O5 O' ?. u
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ; F# V( n) F, v, j# h4 }9 v% P
]  ^( Y( c. G1 _: e1 @, X+ B
to new
& E7 u$ _1 P/ [6 N+ s  ca
  t: U" Q# `1 X' P+ [0 ?" M; |6 A0 C& K  crt 5 * num_of_building
0 y" x) u/ b9 K  [; `. Z3 \, d  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]9 ?+ E+ j2 K! B
  scatter     ;;keep center-turtle random positions
: x* w3 L; h% K9 C& ^4 D7 D  unit_plan   ;;make up the building plan
! i; t+ s5 J! kend8 p3 `: f/ h. n" {6 ~* S/ f
to scatter! w  ?( w/ Z0 I; h: u) A
ask turtles with [remainder who 5 = 0]
0 t9 G2 e: P: N[
0 n0 i  `1 \- D1 l! [2 T% cset xcor xcor - 6 + random-float 15
) ]4 G2 v; R8 N: q! V& Vset ycor ycor - 6 + random-float 15
' Y: f1 n& M% L+ m% m3 f% Y]
* i8 w) C. G8 oend
" Z% o! G- U. F( cto unit_plan
8 W% M% m0 w/ K* V3 b" i( wask turtles [
5 E. D9 u" n6 r: h- ~3 ~5 [# p# fif (remainder who 5 = 1) [set a who
' B, k. p- C) a! \% \% _9 Y2 S* h                          set x ( 0 - Wid / 2 ) ; s, K( I" f8 h' w
                          set y  Dep / 2 ]3 L5 J# O  t7 y/ ~2 u! o) ?
           set b  int (a / 5) * 51 l  z9 s+ v" K" g" M& ]
    setxy ( xcor-of turtle b + x )$ R1 R% [. O% G# }
          ( ycor-of turtle b + y )( @  m' v- V. Y: `1 L. j
if (remainder who 5 = 2) [set c who
% ~; Z; i7 O" @- n1 j8 t7 S2 s! A$ l                          set x ( 0 - Wid / 2 ) 3 ?' C+ y7 }1 L( N, Z  P/ M
                          set y (0 - Dep / 2 )  ]
( }6 T) A+ G/ S- i  A* ~) e                          set d int (c / 5) * 5
% H6 l* m3 c( {/ [( p7 F7 o. @   setxy   ( xcor-of turtle d + x )" o+ X' r0 X2 I) }; k! ~( u( F- w
           (ycor-of turtle d + y ) 2 N% m0 r& M, u3 N; ^
          , ~0 t4 |& ^# c0 }& e
            * o$ V" J' I$ V: ~9 s2 A5 L
if (remainder who 5 = 3) [set k who9 V9 @- f* k1 ]! ~) A6 F
                          set x( Wid / 2)  
% V  v4 H& K" O, m6 i- ?5 E1 P                          set y (0 - Dep / 2 ) ]
/ ^* @! x6 F, P3 |0 ~& d                          set f int (k / 5) * 5
% @( F$ q% A5 a, z! C$ w  setxy   ( xcor-of turtle f + x )  h$ y1 u! ~. R- b9 @% y* Q( t
           (ycor-of turtle f + y ) % c/ `1 {4 C: h  o6 x* z  x9 y9 V
           
' b# B" s' t& k" g3 O6 f0 Q) n6 F           ( v. o. B& N' d
if (remainder who 5 = 4) [set g who, w8 U' R$ A( Q
                          set x Wid / 2
' Z5 A) N% ?2 k. I7 V: p                          set y  Dep / 2 ]
* r4 |& y7 h" ]# A9 f/ z                          set h  int (g / 5) * 5
( T. Q8 D7 w0 t  u& G6 Q; j  setxy   ( xcor-of turtle h + x )
0 x; ?; N3 A1 {           (ycor-of turtle h + y )
7 n, p- u0 Y- f7 _                          4 T/ W( _* I0 @' u3 \& T/ G
                          
2 N) X  `2 c5 T/ C* Z                          ]
2 e9 o- B- e! }! kend* q% u2 l& T: p2 c- L# {2 ]

" H3 X+ ~6 f( m+ l( i3 j[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
2 v5 d0 s/ p) J9 v! Q; c应该是9 L# N* U( W, n4 f
ask turtles [
, `2 }. V/ X5 P* u$ M* b" Dif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 4 f( W( L2 }3 T' k; }' b
                          set y  Dep / 2
* G: l. z) O# c* k0 i( i           set b  int (who / 5) * 59 V1 {' E# E9 n  a( c1 H) S% U5 l$ ~
    setxy ( xcor-of turtle b + x )
, }  R) ^! t7 a' N: B* z! L5 _          ( ycor-of turtle b + y )]]. ]  B9 k# u  Y4 X' l& N/ P
end7 a  u: P- [( ]9 ~
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-11 08:01 , Processed in 0.020754 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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