设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7700|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。# o$ U0 B$ W& A+ v# J

& x' |0 T$ j* H: Y0 d  `3 ~  ]但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。0 p: l. S" Q' v3 b" Y1 |; f0 L: K

, f$ N" G' B, q2 `% Bturtles-own [a b c d k f g h
+ e, g, k$ o9 F* f& y  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 3 j" J& Z. Q" ?+ m+ s
]
8 o, \2 ]( y  O! U  eto new4 `; `* L8 E2 ?
  ca
1 o& {9 P4 m; b! k; Y( n) @  crt 5 * num_of_building* O$ ~5 ^3 \( ^$ ^; h8 P/ |- C
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
: l% L+ g* H( a# d4 z  scatter     ;;keep center-turtle random positions
* \/ a9 R, H* T1 `# o8 |8 V, V  unit_plan   ;;make up the building plan' B8 k5 b  e& x8 P' V% i7 {1 D) ]
end8 g% X+ r; s5 n* p: Q) `: I0 V
to scatter) H; B4 S0 j" u
ask turtles with [remainder who 5 = 0]. E  ^+ g( ^  s2 E
[: q' ^2 d: \8 z& C+ W4 ]3 f
set xcor xcor - 6 + random-float 15
9 a) a( H/ `; Z' Yset ycor ycor - 6 + random-float 15# x0 E* Y* A9 [: E# j0 P4 z
]7 }0 z1 X; V" h' a
end
2 ?+ x: D6 ^" X  D& Y. ?to unit_plan
9 P9 Y! m. k( y3 n7 Fask turtles [7 _$ R1 `. B& s6 M, X0 ?. I
if (remainder who 5 = 1) [set a who
# \* p3 \0 C& T% Q6 s3 B                          set x ( 0 - Wid / 2 ) . [+ W& ]* p( V
                          set y  Dep / 2 ]
0 ~& I, h4 Z5 O+ d           set b  int (a / 5) * 5
  n4 a2 r6 v+ M$ x5 @8 X& X    setxy ( xcor-of turtle b + x )2 K2 b3 x. m1 O& b0 v! |5 U
          ( ycor-of turtle b + y )3 D& X/ F* M0 ~& {5 r3 q% K
if (remainder who 5 = 2) [set c who
6 D$ W' u1 H3 h* [& t                          set x ( 0 - Wid / 2 )
0 J9 M" Q' I& \+ [' a                          set y (0 - Dep / 2 )  ]8 G* i5 a3 M" D1 M5 d# X) C
                          set d int (c / 5) * 5- W& I3 l) e' f1 Z" x5 J+ P
   setxy   ( xcor-of turtle d + x )% v4 ~6 S+ V' r; w2 \, {# Z
           (ycor-of turtle d + y )
& [3 t, ^: U( M2 o          : b( C' @, c) }7 U+ i: F  u( u# v
            
' @0 n$ }" C, k3 Z/ q/ f+ eif (remainder who 5 = 3) [set k who
( @1 T" V  L2 j9 a; _0 r; `                          set x( Wid / 2)  
2 P3 A: s3 X2 R( Q9 {                          set y (0 - Dep / 2 ) ]
$ e$ }" Y9 T8 s$ n                          set f int (k / 5) * 52 E' Y" U  [9 g# n0 T3 C
  setxy   ( xcor-of turtle f + x )
( _+ \8 R8 [' p9 T           (ycor-of turtle f + y )
, R( T4 A0 J4 h" q           
( ?9 p* z5 p3 M! N2 L           
" `. u( B7 a( A" O% a. t6 oif (remainder who 5 = 4) [set g who# J# ]1 Z3 z1 w" X% |% [
                          set x Wid / 2 % r* F" ]2 m/ M7 X) k: a
                          set y  Dep / 2 ]8 r! l. s. {# i# n% H6 @
                          set h  int (g / 5) * 5
3 Y0 _# e! i2 f. ^  setxy   ( xcor-of turtle h + x )$ A( t7 s$ S- Y$ ]  L
           (ycor-of turtle h + y ) 9 Q1 u( V( H! |
                          2 g% [. C+ c/ d6 w" k3 r
                          9 D" f5 ~" N1 z$ l: \. M, \( r
                          ]# ^! e8 S- w; p6 O9 Z# Y! B& H1 Z; R
end
9 K/ m6 _* H' x* ~$ r3 n! t7 u
2 F* a2 `  r- M, E& T[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,# Q+ i- t9 Q9 J0 ]
应该是  V- l$ \) |3 ~( ^( X3 ~" W9 k7 ~, ?$ q
ask turtles [% Y2 d, ^# S, C  ^8 J4 N
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) & X" _$ X- b' ~$ r5 G- g: n
                          set y  Dep / 2
7 X' d' C) c3 s6 m7 f           set b  int (who / 5) * 5( P; T; U6 f# |0 ^
    setxy ( xcor-of turtle b + x )
' m- b/ c: J- c3 @; C! M* _          ( ycor-of turtle b + y )]]+ s/ q4 ~- t# {
end
# L  f0 `2 i6 |7 i$ f% z之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-17 16:20 , Processed in 0.025103 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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