设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7851|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
4 K$ ]: g# c8 t) j/ ?* o7 f
/ L6 j6 l- s, _0 R# y" Z但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
' n* g6 M2 G9 L5 e; W  A* c# F
6 Y' H7 d1 @7 N, g/ z5 Dturtles-own [a b c d k f g h
  Q0 T) A% ~% U0 w  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
$ P6 ]4 g# i' \, B' ^" e( D]: P) A" F* d4 e. I
to new5 `2 y' c* o( \4 G, b6 v% w
  ca" O4 I/ B8 A2 \$ `% N# a
  crt 5 * num_of_building
( S0 B, b( `! Q/ a: V' O' t  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
) S2 ^. U( V" K9 f! o$ Q3 V" m  scatter     ;;keep center-turtle random positions 0 G* J# z" }* M& v( R
  unit_plan   ;;make up the building plan
" K  e/ S  l( `/ R. {end  H0 S! I1 q! y8 x8 W
to scatter
( @- u. {( o5 nask turtles with [remainder who 5 = 0]' K+ F2 U2 G! M; ~6 f! y1 P
[& k9 c5 h2 U& w0 `) p- ?: R; ]
set xcor xcor - 6 + random-float 15
& z: I" ^8 e: r- q- o4 yset ycor ycor - 6 + random-float 15# b0 b0 i" ]4 L7 P" W8 {, h
]6 p6 h, d" G8 s8 S( y0 u' S. S' B8 V& T
end
# w9 {) W/ ]7 z- I( d/ a5 Hto unit_plan ! S2 d. g5 v- l: s% B) s
ask turtles [3 f9 h1 ?4 v, g
if (remainder who 5 = 1) [set a who / o8 y3 J* `# P2 k' R& ~3 s8 I# J
                          set x ( 0 - Wid / 2 ) ( L9 q9 k3 E% d$ p. B
                          set y  Dep / 2 ]
! G+ r& s+ I5 E* h  g           set b  int (a / 5) * 58 z2 y3 r' B8 m, _# I
    setxy ( xcor-of turtle b + x )
  T% H7 t% H$ R8 _5 `/ T7 u          ( ycor-of turtle b + y ); ]) w- D- `' ]0 O. [' S4 I/ b1 [
if (remainder who 5 = 2) [set c who& p+ z& v4 N+ E" X+ n: b& V; {, `
                          set x ( 0 - Wid / 2 )
, ?" c  o7 E4 k3 Q                          set y (0 - Dep / 2 )  ]/ p, R7 J% b1 {9 Z# J
                          set d int (c / 5) * 5" V7 p9 G% L: A# u' S0 g8 e: K
   setxy   ( xcor-of turtle d + x )
. L- W8 u# s" u2 @* d  v           (ycor-of turtle d + y )
4 V7 x  S3 j9 }+ i          8 P/ S: Z2 m* U  S6 [
            ; l: D- J( q" n- ?* v' X( S
if (remainder who 5 = 3) [set k who
& e3 }1 ^0 ?" i9 ^  W3 l$ G                          set x( Wid / 2)  
- T4 n6 ^! i2 o% l; u* g                          set y (0 - Dep / 2 ) ]$ q$ h  D% D9 w0 ^
                          set f int (k / 5) * 5
6 }8 s. O/ K2 y; n# \! E  setxy   ( xcor-of turtle f + x )
2 \3 q; ^* S! E  i+ |           (ycor-of turtle f + y ) ' q) k- A! M9 s
           
0 \* t- j; ^# K& U$ p# H5 g           
. H2 _5 L/ h8 p5 h9 S: Y1 x1 N4 wif (remainder who 5 = 4) [set g who1 m( r% C2 C: x$ w3 ~2 P  U
                          set x Wid / 2
% w! }- b8 i1 g* T6 O. e                          set y  Dep / 2 ]- h7 D8 D' E& s, B7 Q, o
                          set h  int (g / 5) * 5. l: d1 ]0 d/ j* a
  setxy   ( xcor-of turtle h + x )
! h+ T. z8 G! {8 i  C' S* E* r; W           (ycor-of turtle h + y )
+ |2 |" Z& v- q3 S3 m                          
! h6 \# v% Z& g, ^7 Z                          & o( h, o4 {+ O
                          ]  W. `) M: ^! v; V: }2 N' ]5 Z
end( E. k8 E' _% [3 n" R
) K; O; n& z& S* A4 a
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,( N" }% q0 X( u% T. G
应该是: y4 D" t. h2 \, w2 v
ask turtles [
9 ^7 H( r/ }; C0 E$ k' R3 Qif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
" e2 l% Y0 z. Y* H$ y6 Y7 U                          set y  Dep / 2
% j1 g  b9 s7 G4 j. m% I# E           set b  int (who / 5) * 5
1 p7 U5 C- A7 C# j2 ?) Y/ p    setxy ( xcor-of turtle b + x )
$ a0 M. _1 N% k& m# Q          ( ycor-of turtle b + y )]]8 c* v5 r+ N# _6 j- g" x4 l
end0 K5 V5 m+ w0 {: f9 B3 h" V
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-9 20:45 , Processed in 0.026742 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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