设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7142|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。5 ^6 m9 y$ |3 g9 A( p6 u6 t

. p! i* R% a% c8 W但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
5 ~  P4 t% U$ U6 Y) u2 i! q; ?8 b" L7 Z* v% G( Z; U! V/ S0 C
turtles-own [a b c d k f g h
) B6 j5 j' v8 }  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 6 ~0 Y  E& @0 q
]; Z) C9 B9 N! X6 M# V7 j
to new7 x) Z1 |  h$ z' I6 U( `, H3 s; m
  ca1 i) B2 n/ @/ r. F
  crt 5 * num_of_building- ~8 ]2 Q7 _# T; `6 m/ Y: Q
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
# N- o% ~9 _, k3 d5 A  scatter     ;;keep center-turtle random positions ' n# q+ \4 I/ Z0 o3 b* D
  unit_plan   ;;make up the building plan# I6 y: R1 x1 _$ W* |0 C9 ?2 K8 |
end
$ x# n. p9 |9 }0 U. L  oto scatter
! A6 F  D1 w! b* [" w. F0 eask turtles with [remainder who 5 = 0]. f* n6 C% n$ ]- ~5 s7 v5 K5 K
[
9 C8 A) n% K4 m4 W( x# W) vset xcor xcor - 6 + random-float 15
- s* l( ?" `+ p' M& i- m8 iset ycor ycor - 6 + random-float 15  _  [' d& s, h, `+ _4 R
]7 }* q6 j7 z5 k% q  E3 _  i
end/ G+ }5 U) n: X* L1 i6 K
to unit_plan 5 ~2 V# z2 g; k' i/ [& J- S
ask turtles [; Q$ {1 E6 u2 C! ?1 h) S
if (remainder who 5 = 1) [set a who % M" I) y1 O7 m, w+ Q) T
                          set x ( 0 - Wid / 2 ) ! P+ P5 @$ a6 f% \" w
                          set y  Dep / 2 ]7 x5 k2 B; T1 h! u% B) f
           set b  int (a / 5) * 58 U) S' J  O$ B% g2 |
    setxy ( xcor-of turtle b + x )3 |  c: ^* y; k/ r) u
          ( ycor-of turtle b + y )& V& O- ?  h1 F2 v+ D: K% Q' K
if (remainder who 5 = 2) [set c who) i+ B4 v! }+ L5 t; n) O5 r# T
                          set x ( 0 - Wid / 2 )
3 g* _% S8 C3 F4 G$ H  L( C7 J6 {: Q                          set y (0 - Dep / 2 )  ]
3 Y. i* x2 N9 U. g% ^$ k" j$ @2 }                          set d int (c / 5) * 5
1 G5 v! O+ A0 y   setxy   ( xcor-of turtle d + x )
$ M9 a) p" W7 M0 y* b( R+ S           (ycor-of turtle d + y ) , n+ S+ e4 B3 {, ]4 p5 i* ?( ?
          5 G9 S5 a; A5 {
            * W8 D# V( u7 B) [3 p' j
if (remainder who 5 = 3) [set k who
5 h. q& I: H4 {7 b8 `* T8 M                          set x( Wid / 2)  % R5 E% c2 q; I$ L/ c8 @
                          set y (0 - Dep / 2 ) ]% Y) G& Y  B+ _) R+ h% R2 `
                          set f int (k / 5) * 5
2 K" O5 ~2 v( P# d' m& ]/ g! C% U  setxy   ( xcor-of turtle f + x ), l4 I2 t4 v4 d( _9 K' V
           (ycor-of turtle f + y )
+ A; ^8 B. g; K! s" [3 p           ' e5 }# n+ O% K
           
, J8 m3 W& `0 p7 G2 P9 U1 D  Pif (remainder who 5 = 4) [set g who
: `& j0 I( f+ Z3 c1 C, l& j                          set x Wid / 2
2 d3 u2 U" s! {2 a                          set y  Dep / 2 ]7 h3 L4 u; Z% U; r8 L9 S
                          set h  int (g / 5) * 5
3 R* n. [/ _5 H. z( V  setxy   ( xcor-of turtle h + x )
% k+ h  B6 j6 g4 d           (ycor-of turtle h + y ) . L  g$ A* u+ L  I3 v7 c- E; `
                          
9 E: V6 G. J, `( I1 `5 m                          # E  R; i1 J+ Z
                          ]
+ t5 w% n+ W' F% L8 s5 mend
( \) a+ g8 Q, a) Q) o
8 d8 Q; a# H9 M! t4 e[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
$ d/ y3 N& X/ j2 ~; \应该是
0 Q  \# ~% U& C( Zask turtles [
% t+ `3 i% o# g5 Jif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
9 m  P) |# e8 ~5 o! H  B. @                          set y  Dep / 2
# y, e7 L" H  x% J% f           set b  int (who / 5) * 5$ p+ H/ k3 |" L( O
    setxy ( xcor-of turtle b + x )
$ C9 m7 S; G2 L" Y3 _  B, z: h  e* Q          ( ycor-of turtle b + y )]]
+ z' U0 s( u* n# r9 Zend
1 Z1 V) W& v! o6 |2 {) K3 u" x之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-5 10:56 , Processed in 0.016869 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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