设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8497|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。; O9 r4 z: D0 o- i0 q) Q

& B* K3 h2 w. {( M但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
3 g. g; k1 |! P3 C/ [* X1 Q, {: {7 O1 Y4 z1 ?  f5 m
turtles-own [a b c d k f g h0 t) e" ]$ q5 [4 K
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
4 F# V  A# t# ^4 K1 C6 E; o0 ?]& I; L( z& k0 Z3 I1 l5 Y5 R- `5 Y3 _
to new5 G1 ], M( Y4 q4 w. H
  ca
, |- H! s3 B9 |9 i$ l! S  crt 5 * num_of_building( N& U  U# p, U7 d
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]% i/ R0 N1 w3 j" l/ ]2 \
  scatter     ;;keep center-turtle random positions # B3 ]3 N& Q3 Z$ A! s8 h
  unit_plan   ;;make up the building plan
; X, T& `3 N' Y" T- Wend
! }4 X& d9 S* e+ @* `# Y" s3 L: Gto scatter1 Z5 e% W& @0 Q1 Z3 e
ask turtles with [remainder who 5 = 0]
; t# P9 ^- u) b3 M' E- k[3 y5 q$ Z" }1 C3 y0 a
set xcor xcor - 6 + random-float 154 t$ w1 N- M# C' s- W: W+ {5 e
set ycor ycor - 6 + random-float 15# J; P% j3 R$ i: y2 T, l
]
  R( l0 [* t' X; g* Jend- w1 _3 k: K( A8 L& v# o* L
to unit_plan
" I+ g. ]0 m( v0 q/ ^4 e5 O* Dask turtles [
/ w' X3 I2 x, y9 uif (remainder who 5 = 1) [set a who 6 d: [( B  ^* o5 C" n: f6 o
                          set x ( 0 - Wid / 2 ) + I8 u7 W( t. i# m
                          set y  Dep / 2 ]
! i9 ]9 U2 D. a% L7 ^/ Z           set b  int (a / 5) * 5
0 x9 `) H5 ^+ `" |8 L    setxy ( xcor-of turtle b + x )
: _5 _8 n! j% T- i! Z% x          ( ycor-of turtle b + y )0 ]8 P* N; V0 Q* |
if (remainder who 5 = 2) [set c who( _" g4 U! M& T6 }9 Y2 x) z
                          set x ( 0 - Wid / 2 )
7 ~$ ]( z7 w8 c' x2 `                          set y (0 - Dep / 2 )  ]% ]  K/ Q# [: V! j( k
                          set d int (c / 5) * 51 R1 N+ t4 d; |9 v" G# T' H
   setxy   ( xcor-of turtle d + x )
" e4 N- L$ _, z           (ycor-of turtle d + y ) 0 `  C- K! a, k  i) K& F3 L) O. Z
         
2 R0 v5 b. o  ]  j. z% c  M            
5 o, D8 Y" l+ q. Dif (remainder who 5 = 3) [set k who
  [: Z$ J3 m1 e2 f8 S& j4 l  y                          set x( Wid / 2)  6 b3 o+ Z% I; ~! W, n. r  ^' S4 C
                          set y (0 - Dep / 2 ) ]
6 `3 j) p, S2 n                          set f int (k / 5) * 5
8 n$ H% f3 n+ X& O  setxy   ( xcor-of turtle f + x )# F* P, a9 }  G6 E- n# N/ g$ @: i
           (ycor-of turtle f + y )
+ f" n1 w/ f$ S1 ]( p$ A1 e5 q3 b* A           
# \6 j0 |7 E" C3 I           ( q; {  F$ J; x! h# X* I
if (remainder who 5 = 4) [set g who/ g" F/ ~4 V" t( T% X5 W& J
                          set x Wid / 2
# y* n9 A4 [- J/ h+ }. z) q                          set y  Dep / 2 ]8 j- n; u1 c6 f3 E" k
                          set h  int (g / 5) * 5& m9 D' f. U! A4 P0 U. y+ ?
  setxy   ( xcor-of turtle h + x )
; z) M8 s3 T6 @% ~! l1 ^           (ycor-of turtle h + y )
+ n" @) j) X" d% a1 ?; A( n% e: u                          5 a/ B0 l: b2 {0 J5 b- Z( u
                          # z4 W& u: j- @/ D5 w7 N4 `
                          ]
. y% S" B" U. {/ J) z9 ?6 y& @5 N# send8 i) f# [7 y8 z) h' K9 Q: N

8 J6 ~5 B9 I: _0 B[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
! v3 R2 S" R7 u  }) N% H2 O应该是
1 I, z' L# m9 n& w8 [. Kask turtles [+ W! b! j& U9 c$ a' I4 f6 K
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ' c. e* }% C3 k  }& K% V% R
                          set y  Dep / 2
# h- L1 `. g0 H- x% x  s& w           set b  int (who / 5) * 56 @$ N# p! k4 Y* Y2 Q6 X
    setxy ( xcor-of turtle b + x )
. M5 h9 A# p: a: g& X* O! x          ( ycor-of turtle b + y )]]
+ U( Z- P# Q% N! send( Q6 E% w4 I) c5 p7 m2 p- h
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-5 03:55 , Processed in 0.014818 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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