设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6223|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
7 w$ _0 J0 r* q" j) p. n
. e+ {( Z1 x! _, p( x- L+ b但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
; w/ ^" k4 U1 S5 f! r: h& u9 s* G9 E& `7 H+ q  Y1 \: }. ~9 i
turtles-own [a b c d k f g h
/ i- F) P9 z9 X1 Z1 v8 U! c5 ]  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ; G* v. `" A& }3 r/ S5 I) d
]
' c7 j5 X  B" e7 \to new
7 g+ m6 _1 G( V9 Y4 `2 R0 ^  p* O; m  ca. x* }4 F+ u7 s) {! d
  crt 5 * num_of_building
0 c2 L$ [0 o- U( A8 f  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
$ @6 l; z; y4 |; U' m" o  scatter     ;;keep center-turtle random positions ! D  b* l2 {0 k- K9 S) l/ I! f
  unit_plan   ;;make up the building plan
! |* u* Y$ ]4 B. o& vend3 N- J3 e/ I' @1 |
to scatter: a, R, l6 B- P
ask turtles with [remainder who 5 = 0]3 `; T& s" I' j
[* v  |$ s/ {0 r8 {2 ]8 s8 ~
set xcor xcor - 6 + random-float 157 @4 o+ B$ l8 H
set ycor ycor - 6 + random-float 15
* U6 [! y' \( V; Z8 H]
! l# F0 P! @& D% ~9 A. L1 G  z- I) _! Wend
! k4 B$ B. E5 b% a( `+ V7 x6 X6 wto unit_plan
/ d6 M, [& F) ^ask turtles [+ c6 q7 f0 q! O' Y9 k) c
if (remainder who 5 = 1) [set a who : e3 R- ~7 }' @0 X! N
                          set x ( 0 - Wid / 2 ) 7 Q' ^7 X9 B" O8 b4 ^  a3 F/ {  k
                          set y  Dep / 2 ]! ~  c0 a6 U; [4 ?( b8 P
           set b  int (a / 5) * 5" K5 d/ ^* z: e% l; b& P
    setxy ( xcor-of turtle b + x )$ B  A0 o% u6 T: @8 j' ^3 X9 M
          ( ycor-of turtle b + y )
% w9 T6 g! F# g6 K9 E8 q8 a" m9 Tif (remainder who 5 = 2) [set c who
0 n2 _5 X2 E2 f, [2 A                          set x ( 0 - Wid / 2 )
3 @+ i7 f* N' Z" C                          set y (0 - Dep / 2 )  ]6 k3 t2 t) W3 W* [+ C( u
                          set d int (c / 5) * 5
( _; x) `# T" _, @: K   setxy   ( xcor-of turtle d + x )
) ~2 e/ w. y  p* h0 f           (ycor-of turtle d + y ) % M3 {$ j  ~  u
         
# k3 e* `+ h% Q  C, d+ Q            : A1 z( q- s% ~7 i5 K
if (remainder who 5 = 3) [set k who( |6 d6 A8 u# ?* U, K% s& @6 a
                          set x( Wid / 2)  
( ~) {& j0 p  c& r) R) p' s                          set y (0 - Dep / 2 ) ]
2 b- ?7 i& ]0 v5 P. W  p  r                          set f int (k / 5) * 5
2 ~" Y; f2 ^3 S1 w  setxy   ( xcor-of turtle f + x )
3 U$ a; j; @" Z& {8 T7 s           (ycor-of turtle f + y )
  r" X" w: V* M; f& v           9 X& `/ b# ?$ A
           . s- {  t- h( e0 Z
if (remainder who 5 = 4) [set g who
. m9 Y) f1 k2 |                          set x Wid / 2 # [$ R8 z; D, E8 w$ Q
                          set y  Dep / 2 ]  m8 A# h% q* J: {. ~
                          set h  int (g / 5) * 5% q) ]$ v% a# x. V8 Q0 B; `
  setxy   ( xcor-of turtle h + x ): C$ u( ^2 A: \+ }8 w
           (ycor-of turtle h + y ) : i3 z; y% N3 a4 q
                          , G5 b% H' P. ]) O$ d; ]0 ?, Y
                          ' H+ d9 s, D  B5 [# Y: |8 h
                          ]6 s: t) j5 G! z# m
end
% E& U. P6 `+ b8 y6 `9 r
: P% e% s& Z9 v; Z) A" g$ {[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
) m; D' T" Y) M$ s  M/ F; g应该是
+ P2 [* o/ ?6 J8 |/ ?. aask turtles [
2 {5 ]  @% F# _% \# i2 A" bif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) , A$ S7 J" g" D6 t
                          set y  Dep / 2 . w2 I) V- ?4 j" h  x7 q6 i
           set b  int (who / 5) * 50 c) L" g/ U  j4 X. b8 o
    setxy ( xcor-of turtle b + x )/ u2 q. U/ q6 `) g/ f0 I5 e
          ( ycor-of turtle b + y )]]  c# Z/ k& m7 q& w! }
end
8 G! {" O4 L' p- u/ Q' j, s之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-9-2 10:27 , Processed in 0.013474 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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