设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7373|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
$ Q' y8 B: Q4 @2 x; K; e& e7 e& _2 ^
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。) X% H: [) p5 d0 x9 o2 X

, O& Z/ {% e( U( v; `8 dturtles-own [a b c d k f g h
2 F( [. m& M. O  W& [" y  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
! @  g9 _6 k7 v9 ?& ]" e]
& D/ g; i1 _( ?8 _7 F8 L+ l7 M; Yto new2 z7 [# R" d& t
  ca! ^' R* h8 B. F; J6 u! k
  crt 5 * num_of_building% X& D% e5 Z9 @4 I; w' ?
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]/ X) X* e$ ?# w
  scatter     ;;keep center-turtle random positions
4 V* q8 o7 C0 v( v1 I3 s  unit_plan   ;;make up the building plan
3 K+ Z. p8 B: ]end
+ v) w/ e) q3 y% e% G* `to scatter, y2 {+ r4 A9 I, s- A8 M2 i8 T$ q) d
ask turtles with [remainder who 5 = 0]
- e/ M0 H  Y! A# k[& @" g7 |" }+ g! K1 M/ a' [1 a
set xcor xcor - 6 + random-float 15
  S- A0 H" U" T+ @set ycor ycor - 6 + random-float 151 h; R) Z" G. ?
]8 U" g2 c% j' o, ^
end
7 n: m) ^2 W0 J! b- zto unit_plan 0 Y, r" m$ B3 w) v( n) X: }
ask turtles [
( ]: z+ ^% ~& _. `# M0 B2 Fif (remainder who 5 = 1) [set a who + W- j  T4 a0 |. X$ M
                          set x ( 0 - Wid / 2 ) " r- ]0 ?8 d2 j' ]
                          set y  Dep / 2 ]% \  e' ?5 p8 @( _! M$ A1 R
           set b  int (a / 5) * 5
- L9 \  g! s9 V. ~. @    setxy ( xcor-of turtle b + x ). ^5 q8 q$ J/ M. {% b( ~
          ( ycor-of turtle b + y ), M! W" Q5 K+ r" W  s- u8 r
if (remainder who 5 = 2) [set c who
9 L6 W) [: y  V                          set x ( 0 - Wid / 2 )
( P4 B0 T+ i) b5 Y8 r; `                          set y (0 - Dep / 2 )  ]" D0 q9 ~) P" U2 k, R& D$ \
                          set d int (c / 5) * 5
8 o" d+ U4 u! ~) w   setxy   ( xcor-of turtle d + x )8 m/ \/ h" V! F2 t& f
           (ycor-of turtle d + y ) 1 \8 a) `$ y, y) N7 ?5 E
          / x3 }* D3 g0 I
            
9 e' Q# R6 d  D& m% G0 {5 p3 M( ^if (remainder who 5 = 3) [set k who
, i( f) x+ y  h3 U3 E                          set x( Wid / 2)  * T) H2 W+ L+ i! x$ N& j
                          set y (0 - Dep / 2 ) ]# @$ L* ]# M) E2 o2 U
                          set f int (k / 5) * 5
9 c% W) l' ~) t+ z$ f1 y  setxy   ( xcor-of turtle f + x )
6 x7 C  \4 p7 p$ B  E           (ycor-of turtle f + y ) ; n) |) Q4 S5 [7 E
           1 }6 [- s" M& Z% E
           ' ^# G" ~- W* f+ v
if (remainder who 5 = 4) [set g who: d1 Z2 ?/ T2 \8 o5 I/ Z. L* u8 ~
                          set x Wid / 2 8 x# u$ ?9 e; Y$ }9 O! T8 P
                          set y  Dep / 2 ]
+ L& t, a: n7 q6 r" A                          set h  int (g / 5) * 58 M5 y( z! P5 ~' D4 C/ K
  setxy   ( xcor-of turtle h + x )
- g+ y0 G! ]' F2 ^5 b           (ycor-of turtle h + y )
% I: m. A  d5 F4 e5 C+ P( }                          + h8 K) s4 U4 [: `
                          
" g8 M& Z& |+ ?1 o8 }: ~                          ]
& [1 R* `( n: o" ~4 Yend
' P' e- p) D1 T
# t% V; K, G! e  y[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
# y- E- o$ c0 ^- |. i# Z应该是1 v& j5 G$ ^! g( _$ {
ask turtles [
+ s/ t: c7 s- uif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) , Z# D) l1 F8 e8 Q+ A
                          set y  Dep / 2
' B, L$ v/ L* y           set b  int (who / 5) * 56 L1 h5 p9 G# \' i* N
    setxy ( xcor-of turtle b + x )
- R5 R8 A- Y* o          ( ycor-of turtle b + y )]]
8 `2 v: e* W- m( |end) M3 W0 K6 b3 L5 t& V
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-4 22:49 , Processed in 0.016517 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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