设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7194|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。& W+ o; h0 P4 ^
+ c: W. K" ~  X- g$ m. d5 ?
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。$ V1 Q5 b# o/ N9 n
/ k6 r; n* h5 A6 {# f. P
turtles-own [a b c d k f g h4 c, }2 m3 @6 t) Y1 t: k( T9 ~
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
5 R6 j, X1 L; w) i0 `/ \' J]& v5 P# f4 p; `2 r7 J4 l% N
to new3 h* N+ s( I6 s- p
  ca
/ o+ [) @9 ?& n/ ?  crt 5 * num_of_building7 N- [! z8 p( K  a
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]. b, \, i; g. i3 C+ O5 ^
  scatter     ;;keep center-turtle random positions
6 _' F  I& l' l, s  unit_plan   ;;make up the building plan
5 h  o  Y; f$ K$ C% l1 M# nend
, }, c/ O4 Z3 F9 `7 O- dto scatter- u" a/ w4 b( F' C0 M& N
ask turtles with [remainder who 5 = 0]
% h/ q2 f3 g5 J- a; Z[
9 ^* W0 S# L1 c% k' }set xcor xcor - 6 + random-float 15
" }9 a( A3 u9 g: U9 G. [set ycor ycor - 6 + random-float 15" X8 [* ?0 P" p$ ~4 N, Z% v! G2 q- R7 C
]" V; }" d6 |7 J) Q0 L8 o
end
) Y1 h7 D; e1 Y. i6 Oto unit_plan
7 A, T+ d3 G" g" t1 s( v; r2 Task turtles [" f, M  j, q2 f, T& @, f
if (remainder who 5 = 1) [set a who " f7 c) Y( O9 G* t3 [* r
                          set x ( 0 - Wid / 2 ) 3 n7 @1 j0 q) K) o5 K, w
                          set y  Dep / 2 ]; c* t. e& D8 T; a, S. a
           set b  int (a / 5) * 5
2 ]0 @6 m: q3 b7 c% o3 _  k6 N% B    setxy ( xcor-of turtle b + x ): u3 M* m2 x- r1 y8 ]( N6 ]4 H
          ( ycor-of turtle b + y )% l% g7 ?% [6 F% g
if (remainder who 5 = 2) [set c who
4 z- g. u5 b. w6 v$ n" H6 n                          set x ( 0 - Wid / 2 )
" y: \3 X, K( J9 B$ X                          set y (0 - Dep / 2 )  ]8 \  ~0 O  x1 x, t# W
                          set d int (c / 5) * 5
' |, `$ Q" f5 \( H& \5 h  ^; Q   setxy   ( xcor-of turtle d + x )
& Z# W, x3 U3 F           (ycor-of turtle d + y ) 6 _, O$ D& V, Y/ @! D3 H9 H
          3 j0 Z8 Q8 x& N, A
            
; L0 N; d- ]- V( }# n8 p+ Lif (remainder who 5 = 3) [set k who6 s$ |6 k5 x) K7 w7 g$ ?
                          set x( Wid / 2)  
( E1 `/ F6 d0 B                          set y (0 - Dep / 2 ) ]
0 E# d/ \  r8 W- \  z8 ]                          set f int (k / 5) * 5% O( J2 F) ]3 c2 `* x7 Y
  setxy   ( xcor-of turtle f + x )
9 C, j1 r6 L  c; O5 c2 I. J" q. M           (ycor-of turtle f + y ) ! u3 V% G; f, P2 L
           
4 `$ [  a8 I" R           
+ h+ Y( H, A1 E, qif (remainder who 5 = 4) [set g who: w- O0 ?. K. z
                          set x Wid / 2
4 C  f' g6 U! G                          set y  Dep / 2 ]
- @- w3 D% m0 p" g7 P6 l                          set h  int (g / 5) * 53 p1 n! @" F  _; t
  setxy   ( xcor-of turtle h + x )* f# g  _# U$ \3 V
           (ycor-of turtle h + y ) ) C' x6 v5 m( _/ \, M* E( K
                          
/ M" N% q0 I" k# S' t6 R- `1 E1 P; L                          4 H% A% [- [+ k, S( x
                          ]# e0 j+ n# U4 T. _# j8 a. g
end
- C: ^* D- S; s) C# t5 V7 e; _% k# s# d
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,/ F; v+ L, a+ v, F
应该是' y6 P  ~) B5 t# F+ H6 Z3 O
ask turtles [: a4 J; b$ `" u
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
; ~) i& |0 U  W                          set y  Dep / 2
: N8 t: }% g& I. c           set b  int (who / 5) * 5. F2 ^$ n( o0 V
    setxy ( xcor-of turtle b + x )
9 L- h( v# S+ F0 q2 E4 o          ( ycor-of turtle b + y )]]
" H3 Q3 b1 O% a1 q& _- T. Yend
- x  p6 y) l# \: s2 E之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-15 04:33 , Processed in 0.015625 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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