设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7697|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
- \$ P. ^/ `4 f3 S' l$ M0 p: K- q% V: S" d
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
# C" t% J/ Q& Q* i& ]
3 v( ]6 H/ h% W  `" ?6 o  bturtles-own [a b c d k f g h
- Y/ K2 h+ T6 e, |; H3 B, d  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 0 h/ `$ O: p* ?4 L
]( J: n" B0 o( b# j6 b
to new
' X& h* ~/ x% e! B  ca" c: O0 t! S- U0 l( p: X
  crt 5 * num_of_building4 l1 N! c5 r) s1 [
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]% G( z) Q3 E. N' `/ g
  scatter     ;;keep center-turtle random positions
1 E5 d' D8 S3 Z: L5 w7 {  unit_plan   ;;make up the building plan
* |1 a5 J% F: [6 R3 Nend
. p- Y; A0 e+ C- Y/ C$ @8 Rto scatter
$ [  w# c$ G8 P5 U/ jask turtles with [remainder who 5 = 0]1 v! a' y" m! I* l3 S0 J  k
[
+ p8 l5 n! M. ?. D" t7 sset xcor xcor - 6 + random-float 15
1 Q/ U+ C# }+ L/ q3 s0 g7 p4 a5 Kset ycor ycor - 6 + random-float 15
1 Q3 b+ T( U. l. K! H]: ^' V3 _0 x- b- Q8 F7 U3 A
end/ y. S3 P6 Y: Z3 U2 v& ]
to unit_plan 4 Z9 N& P9 n& I$ L% R, u
ask turtles [
6 d& M& z: C  K) Cif (remainder who 5 = 1) [set a who
0 p5 K" r5 ?6 G                          set x ( 0 - Wid / 2 )
/ j8 O# p4 Z2 Q                          set y  Dep / 2 ]
# ^& ]" p, _" Z3 ]           set b  int (a / 5) * 5: m/ h! ]' C& G  O# H) A
    setxy ( xcor-of turtle b + x ): M' M- X! u1 m1 F
          ( ycor-of turtle b + y )& V" z3 ?/ V6 X: q% O# z# \
if (remainder who 5 = 2) [set c who9 p8 R9 F% A- F! |6 t# Q
                          set x ( 0 - Wid / 2 )
7 \8 f, W7 ^8 y# {& K7 z                          set y (0 - Dep / 2 )  ]
, d6 a- ?/ D1 [" ?5 [. k                          set d int (c / 5) * 5  A) o1 E( _6 k9 d9 m1 ~
   setxy   ( xcor-of turtle d + x )1 D( w9 J! o( s% Y" b
           (ycor-of turtle d + y )
& I. M  q8 D4 f2 g6 Y6 P8 X- h         
: B2 r/ h% a( ^            
! S2 P0 G1 ^3 n) E5 T4 Vif (remainder who 5 = 3) [set k who7 E! U9 v. @4 ?2 A$ m
                          set x( Wid / 2)  8 H2 H: b6 P0 E0 O
                          set y (0 - Dep / 2 ) ]
3 ~, g+ `' j, g; F. k4 D                          set f int (k / 5) * 59 N+ x5 p4 ?) |! J7 n0 v) L7 Z0 D$ @
  setxy   ( xcor-of turtle f + x )
) I% k: N2 V8 Y           (ycor-of turtle f + y ) : C4 X- a3 S% Q  P5 r
           " ~" U9 c" c7 c. S  P
           
1 H( [1 J( {8 A: Hif (remainder who 5 = 4) [set g who
/ f& Q# m: J* z5 j1 z                          set x Wid / 2
% V  j2 g- h! e! a  t2 N                          set y  Dep / 2 ]8 Y: A/ l1 D+ m3 N
                          set h  int (g / 5) * 5+ p& |1 M9 @, n: D+ W
  setxy   ( xcor-of turtle h + x )
/ O. `& S) l& o& P0 m           (ycor-of turtle h + y ) 7 C- q5 |3 F  W2 k9 }( Z5 K
                          3 p7 F: e4 x, n/ S9 g7 p
                          
$ f; {7 h; j% R7 }                          ]
8 k' b: m/ K2 m7 D4 hend6 N  O# I: t) }9 H

- B3 J  u& D/ z. z[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
9 B% S2 o5 C* J1 k8 Y, K' k  g  h应该是
& Z* _2 ]% n  n* @ask turtles [1 Z# Q4 ?7 a5 x6 L9 g. X1 V5 {1 h0 _
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 7 ~0 n. M8 b& H$ {
                          set y  Dep / 2 ' N5 I$ m9 w- J# M8 R& C
           set b  int (who / 5) * 5
# u2 n4 o. }. s+ ?- _  L* n7 L    setxy ( xcor-of turtle b + x )
1 p) c% n5 ]' p' x7 ^7 W6 \          ( ycor-of turtle b + y )]]6 _1 G8 s  A# s2 \: C
end
8 n( @2 W/ w* ^5 `' X1 j之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-17 00:07 , Processed in 0.018616 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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