设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7231|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。4 Y- i/ E4 Q. Y7 g: h8 n
/ t4 v0 R' f' V3 H  ?* _
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。3 \/ D* w/ c5 T  y( b
; c' M2 v; i0 H! ]0 E
turtles-own [a b c d k f g h
( O' t$ ^  q; e% h0 e5 s) F  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
9 j; E# M; I' T7 F]
7 V8 V1 L0 R/ |9 Oto new, Y6 f' ~$ l9 d
  ca+ p9 a. J7 J% q, |
  crt 5 * num_of_building
6 \4 H' q2 X/ |2 F  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]: H: d3 Y% m; }) ?( s
  scatter     ;;keep center-turtle random positions
- M4 V* L- h, o1 K  unit_plan   ;;make up the building plan( a9 V' E; X5 q
end. X2 ]4 N3 I' `+ h3 g# q9 O
to scatter
( i1 D# _: m  h1 N/ M, @# T# Gask turtles with [remainder who 5 = 0]- m3 N3 }! w) y: b: ]" z9 ?. [# W/ `
[
: x9 L& K3 c: H! |set xcor xcor - 6 + random-float 15( y6 V( ]: Q5 K7 C7 l5 S. n- f0 w
set ycor ycor - 6 + random-float 156 r" M1 E( B- q2 @. v
]
7 H$ [  `* w1 B, M1 qend
; k/ s3 Z7 S+ w3 B  k7 Wto unit_plan
) N3 {- u+ v; Xask turtles [5 B/ B+ V- _2 [
if (remainder who 5 = 1) [set a who 2 Z( h8 E" p. U
                          set x ( 0 - Wid / 2 ) ( W+ h) [) R. l& \1 z
                          set y  Dep / 2 ]
9 U  a) E! k- i0 G           set b  int (a / 5) * 5, ?8 F1 H# X7 W$ }0 ^
    setxy ( xcor-of turtle b + x )
7 |" q5 U: [) I7 b$ s          ( ycor-of turtle b + y )% ]. c: L4 a; T8 A; N
if (remainder who 5 = 2) [set c who2 c( u  F3 m* w- [/ k& M
                          set x ( 0 - Wid / 2 ) $ l' P7 h# D7 T: I
                          set y (0 - Dep / 2 )  ]6 _  `5 [& k8 @; I
                          set d int (c / 5) * 5  L- p' L; f3 s3 A
   setxy   ( xcor-of turtle d + x )  Q  {3 B& E  B& j/ L1 F+ W; b
           (ycor-of turtle d + y ) " v' B" M" t) ~: L6 T; M
          6 S5 ], p9 q8 s  o4 A" {8 u
            ( O& ~% H* a! C# J
if (remainder who 5 = 3) [set k who
* g2 V) @) \6 f3 N, h' K! f7 L$ j                          set x( Wid / 2)  
' |* c0 p9 H: X. U1 p  S" B                          set y (0 - Dep / 2 ) ]
# ?: H2 g. v5 u9 u* G                          set f int (k / 5) * 5; Y/ I. I0 F" `& T* y( Y6 X
  setxy   ( xcor-of turtle f + x )
- ~" ?9 _) Q6 j! M' z. X2 ]           (ycor-of turtle f + y ) ; f( @$ @  L) ^' c. y' {2 F
           1 c: D/ F5 H! c- v
           & t* d8 w5 R2 ~# g4 T
if (remainder who 5 = 4) [set g who" u, T/ K& h8 Q- R
                          set x Wid / 2
6 ~' Y/ `% b( \9 P/ E7 X                          set y  Dep / 2 ]5 T6 C! Y; A# x
                          set h  int (g / 5) * 5
8 j1 S7 g9 M. k9 X- w: k) @7 s  e  setxy   ( xcor-of turtle h + x )
. q2 b9 ?( k, J) E* n3 U3 S- H           (ycor-of turtle h + y )
+ X9 G6 R0 c" o( }                          
7 ~* h" j0 n5 s- \+ N; \; s  T) P                          
# m7 \. B. z! J3 {+ |/ D8 x) p                          ]8 o- G2 n  Z& f
end
. L, W) U! W* V( ]" N. \# X& W( e" D6 s: a! G3 I+ p( e" k: t: `
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,. ^, Q6 }6 ]- r4 M% b
应该是
0 s' I4 j: l* T9 b/ i6 b6 w9 V0 ~: B. S9 hask turtles [6 i1 \, R5 B  X3 x
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
+ R3 s1 n) a' j$ z8 O+ E                          set y  Dep / 2 - y9 l4 j. E9 E9 _
           set b  int (who / 5) * 5
+ z! j- U4 g" N+ q& y5 L    setxy ( xcor-of turtle b + x )
: C0 w0 x( D4 A) e  h0 I# i- p          ( ycor-of turtle b + y )]]7 E! X7 N# k+ r# @% H5 Q
end. b7 I- [' @( z! ?2 x' g* \* Q
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-19 12:12 , Processed in 0.020248 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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