设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7491|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。& ^; L3 |2 d0 K' x

, P& `2 J9 d) p( ?- t6 I$ E但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
/ k4 x4 C/ F( i( Y. M7 N( u, z3 X: z$ Q+ I3 l) R
turtles-own [a b c d k f g h% G! F$ k) I7 g0 r0 y
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle   ^4 }" Y9 r9 \0 a$ e4 I6 }8 x2 |
]
( \9 J: t6 e5 T+ o  l* x" Ato new: [" d- @5 Q: [% ?! S- ~# x) H
  ca( x7 P) B+ e7 w: t4 V
  crt 5 * num_of_building
) ?8 I" y" Y% d  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]( p! \; w' c6 w0 R3 ]
  scatter     ;;keep center-turtle random positions " U. u  b: h: h  z/ G
  unit_plan   ;;make up the building plan
3 o3 R8 e% m. f- [end
/ |% w( c$ o! e, c- ^$ p5 j  Mto scatter
) k* J  t& w" o$ P$ T2 M2 Jask turtles with [remainder who 5 = 0]; {. G7 O% q& ]
[8 P0 N& I& k, j% p
set xcor xcor - 6 + random-float 15+ C9 g5 h% Q% p8 _+ N
set ycor ycor - 6 + random-float 15  M* H& @  u9 `5 U; ?
]( t8 y! _2 T" p9 y1 h+ L% ^! s
end3 T2 d/ b( Q5 H6 _8 n' I
to unit_plan " q- v1 H6 F: g2 b* e9 {
ask turtles [
; \; ~) S' I* L! p) hif (remainder who 5 = 1) [set a who
4 j* H/ l# {; s4 \2 l! R9 Q                          set x ( 0 - Wid / 2 ) * {- y: l( z  R. i* c9 {9 Z9 }3 k
                          set y  Dep / 2 ]+ E9 v$ A8 Q* r: _" y  @; n! m& U
           set b  int (a / 5) * 5
9 r0 W0 N, F$ F# k    setxy ( xcor-of turtle b + x )
* K9 _! _7 U' K* a) C          ( ycor-of turtle b + y )
$ M% g0 \/ O! r. s' z: bif (remainder who 5 = 2) [set c who
8 X% M3 }/ y7 g" q2 B                          set x ( 0 - Wid / 2 ) 4 v9 U) ^4 x- r4 g8 C0 s. L8 i. A
                          set y (0 - Dep / 2 )  ]( V4 H" i/ ]8 P
                          set d int (c / 5) * 54 z+ _9 C! o& v  b) q1 R
   setxy   ( xcor-of turtle d + x ); k% S! b% E: F
           (ycor-of turtle d + y )
) w8 j) e9 x; h          - \: }  m( }5 O( J5 k
            % n  |# g6 o& x. n* @; v
if (remainder who 5 = 3) [set k who0 i3 q2 A! t, X) _9 N; J* U* P
                          set x( Wid / 2)  ( V, V6 e" U5 L) @  s. Y
                          set y (0 - Dep / 2 ) ]8 P1 U* M6 V2 u2 r/ f, B. ^
                          set f int (k / 5) * 5. ?4 \" X$ g4 O5 ?
  setxy   ( xcor-of turtle f + x )
2 Z8 @/ p- }$ _/ ]5 a' x# K           (ycor-of turtle f + y ) + S! v$ F3 b. K/ [/ W3 n& }
           
  {9 W5 P% U/ s) ?+ k5 k           - q! d1 D5 x! \$ D
if (remainder who 5 = 4) [set g who2 u( C& c( o4 I+ F+ g6 b2 |6 f, i
                          set x Wid / 2 : q, V2 t2 W5 W. O$ @; Z! q
                          set y  Dep / 2 ]. ~1 ~) Z( o  \  M( s
                          set h  int (g / 5) * 5# m& Z0 g& N  G1 H$ R0 r, d
  setxy   ( xcor-of turtle h + x )# e- y. h; I: h6 g6 B# F
           (ycor-of turtle h + y )
, }8 [5 f( ^" y. i/ D                          
7 o8 l/ G3 S# @9 r; q" f. U5 g                          
9 }& H; `3 X$ y; o3 F. L7 Z                          ]9 b# k3 Y: C0 A2 ]" D. A( o+ b
end
) G- S, p/ _9 }2 J) b; C
4 [4 }) q, B4 |) k& e& v[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
' A8 n: [+ l- s" Y3 g应该是2 A# M# _2 R6 Y: h
ask turtles [3 B; _8 r# p. Y- b, _8 ~2 a
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ) ~% j) M0 I3 _, S
                          set y  Dep / 2
$ f" g, G! p, e           set b  int (who / 5) * 5
1 G, y$ t' b5 d7 z/ X    setxy ( xcor-of turtle b + x )
, \  ^* r1 F  W3 d. X! N8 G          ( ycor-of turtle b + y )]]* Q! ^3 k, p% g" @+ T
end1 ?/ L1 b% R, p7 }/ V" h. z* V
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-17 23:02 , Processed in 0.014845 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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