设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7102|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。# z9 u, s% i% O6 `% L  t- `

+ E' v+ O* Q# s% V* o6 Q9 c6 x, l1 Z3 J但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
, ?( b2 y+ B2 M/ l) E( a
5 L5 M; {" F- R5 X( W' dturtles-own [a b c d k f g h
: _& X4 Y3 J( [4 C  @! P  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ' T( E6 g3 y; v9 d
]5 n9 p+ @6 B! h* s* U0 D: m. A  b
to new4 y* m: c# w% I/ S* v
  ca
1 C4 e1 f0 @) W+ n( M  crt 5 * num_of_building
: |: |" ^* {9 ^  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
. v0 C' q/ {* D) _6 G3 q' m; m. p  scatter     ;;keep center-turtle random positions
/ n6 M5 h: L. j7 p  unit_plan   ;;make up the building plan5 h' ^4 G; Z/ K/ W3 g
end; V6 V) M' Y8 {' h& i" O; m+ Q3 I* Q
to scatter3 I! W, k' S0 w) @
ask turtles with [remainder who 5 = 0]3 S0 ?: l% @# \& e  _
[
2 v1 t3 s- W) y  Y! l  N9 Nset xcor xcor - 6 + random-float 15+ k- m2 i' b. L, O7 g2 Y
set ycor ycor - 6 + random-float 15
2 A9 c3 j7 L2 L9 e4 p]
9 Y; I$ z% }  t2 l' u. H1 s5 P" c* @end5 y3 G% J$ I, _/ `7 }: n0 M
to unit_plan
5 @4 t9 R. u/ Kask turtles [
4 y7 m9 n$ Z. Bif (remainder who 5 = 1) [set a who . v' o: G' ?. p3 {3 x9 H
                          set x ( 0 - Wid / 2 ) ) D( s  }  `) s: ?, ^
                          set y  Dep / 2 ]- W& l8 G5 u7 M+ B
           set b  int (a / 5) * 5% L$ ]5 S' o; x* M3 _: I
    setxy ( xcor-of turtle b + x )) l! R7 D  v3 f, R, M. h* R2 a* b
          ( ycor-of turtle b + y ). l8 z& n4 b6 M3 e3 I
if (remainder who 5 = 2) [set c who
! c( t% F$ S# ]% S' g                          set x ( 0 - Wid / 2 ) 4 Y* d5 V4 R5 }/ Z- C: Q# x! [
                          set y (0 - Dep / 2 )  ]) L3 t7 t9 G  c& w' ^: f+ R
                          set d int (c / 5) * 5
3 n. o6 c/ |/ d  I' s   setxy   ( xcor-of turtle d + x )% C# a; t- X+ w# T
           (ycor-of turtle d + y ) + Y( N, ^2 R% r' y
         
2 L: j( t" I! D, I0 Z+ V( p            + t  o8 P( {# }$ n
if (remainder who 5 = 3) [set k who$ M; D. Y$ I) w* N; d& Z+ Q$ P
                          set x( Wid / 2)  
% `$ o) D5 }! E) g. j% {                          set y (0 - Dep / 2 ) ]
. b' n4 g1 A+ y0 n* ?- @                          set f int (k / 5) * 5
5 y5 i+ \% o* R) G/ I  setxy   ( xcor-of turtle f + x )
5 f8 Q! R. H1 A- ~1 j, B           (ycor-of turtle f + y )
% P* f0 ]1 T8 ^1 S, F' g           
) k. [0 S" o0 k4 D  d           
2 g2 D* ^& ]/ l7 [if (remainder who 5 = 4) [set g who
) p- g+ z, L; A) l. Z# j- F6 W! j                          set x Wid / 2
0 Z' _& L, s. z- l4 U# |                          set y  Dep / 2 ]
4 [7 M; B  _; ?) n$ m- e                          set h  int (g / 5) * 5% w) i) g& x" ?$ f: r
  setxy   ( xcor-of turtle h + x )
# {1 Z/ {4 N8 y. {: x0 n4 \$ C           (ycor-of turtle h + y ) 9 _$ L2 k) ?9 Q" ^; F( @/ I
                          - Z9 P" ?' }) m7 P- E- o
                          # w1 A5 `) s) }) N  j; K! k$ s1 Y
                          ]
0 i% r$ j8 w2 u+ \end9 \5 {4 @7 `* V+ f$ n# ^" o( Q5 H1 q
8 \$ T" }2 {' s+ a* s
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
6 t7 b9 ]$ E: a, n应该是. r/ W! U5 G; }- A1 q
ask turtles [. J6 @& c( \$ c, t8 D! I' P
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
% c+ V5 j, P+ l" G* D                          set y  Dep / 2
/ l$ [* D# T3 P- U3 `& ~$ I' G           set b  int (who / 5) * 5  _/ c$ g/ ^9 u7 u
    setxy ( xcor-of turtle b + x )
. J6 I/ n  V0 l3 w$ z$ M0 E          ( ycor-of turtle b + y )]]3 ?; x) h7 c5 _4 \
end
+ w$ X" `5 F8 J) x# Q: T0 W) [( [之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-30 18:40 , Processed in 0.014446 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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