设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7772|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。9 ^. Z' G2 `5 T3 U% O/ p7 K0 H
9 i$ v6 j( M& I' v4 k5 |0 \
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。9 K* x. c7 l* b& F8 k5 Y) q
2 ]! \8 g- l6 ]; i; n) W; d
turtles-own [a b c d k f g h& C8 t. E. a# y% [
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 7 K! Z* {7 i, W2 ?0 k
]
& B1 ?) F5 c5 `; N' E, Cto new$ P5 B5 Y3 Q" ]) @
  ca6 `6 P# Q: j$ r7 v
  crt 5 * num_of_building! v2 ]% M$ h6 @2 ~' M
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]+ y; V. T: ^9 B; E+ l+ e
  scatter     ;;keep center-turtle random positions 3 b0 G& j/ O1 I- A
  unit_plan   ;;make up the building plan
3 E+ y) |1 H1 C% q! [' yend, j% C" I. v, X8 g
to scatter
. S7 c  L( E$ |ask turtles with [remainder who 5 = 0]9 T/ M  H2 Q$ n% F! F8 n
[' ?+ n' i% a2 q& U2 a: e$ U; F
set xcor xcor - 6 + random-float 15
8 Y8 t* B. Z8 y$ @set ycor ycor - 6 + random-float 15+ p1 [- a8 Q$ E' [7 _
]" m7 d6 Z. D5 @% `% q
end
( o7 T# P) F2 g5 d6 G- {- d( Oto unit_plan # r" }% _0 m! C
ask turtles [; |- c' y1 B" K
if (remainder who 5 = 1) [set a who / D2 i9 j/ g7 d, f# t# t% ?+ }3 n8 F
                          set x ( 0 - Wid / 2 ) 5 a5 u# Y5 U7 L( V7 p; Q
                          set y  Dep / 2 ]
4 r6 j4 U/ f; v           set b  int (a / 5) * 5
* a% `. t- ~  u, E$ I7 e" o0 ^6 _    setxy ( xcor-of turtle b + x )3 Z* l1 n% l0 I" B3 r
          ( ycor-of turtle b + y )& k4 S, w6 _5 [
if (remainder who 5 = 2) [set c who+ i9 i- \  N% h: M* t
                          set x ( 0 - Wid / 2 )
# \  {; j( y0 C% h& T. m: v4 z                          set y (0 - Dep / 2 )  ]
0 B& z/ }8 J& e# b: E- P+ p                          set d int (c / 5) * 5/ r9 {& Y/ z- v4 M! n$ g
   setxy   ( xcor-of turtle d + x )
" L' h; z4 i/ z6 T( g4 k3 \           (ycor-of turtle d + y ) 9 J4 z6 g, b" w4 C9 I/ _8 y0 t4 O
          * ^* F6 Z1 k" V" }/ G
            
- {; h; K: K6 U1 E, kif (remainder who 5 = 3) [set k who+ `5 l3 @& E/ [; k( l
                          set x( Wid / 2)  
) \. j- n. n9 L& M# @                          set y (0 - Dep / 2 ) ]3 O) q& \7 f+ O7 M+ d+ O* K8 w8 G
                          set f int (k / 5) * 5
7 {/ t+ x8 q" K1 w7 w2 p! J, X  setxy   ( xcor-of turtle f + x )
! |9 A7 ~/ b  ~           (ycor-of turtle f + y )
8 f0 q8 n# Y0 G6 z           4 d9 W( s: G2 j
           * p7 A! m9 ^5 T0 c
if (remainder who 5 = 4) [set g who8 K; M; \6 O: |" a, {
                          set x Wid / 2
1 F' G2 M2 g  S, p' T; h                          set y  Dep / 2 ]
5 m. Y% \5 |0 R* W                          set h  int (g / 5) * 5
$ G/ H% \& [( P1 [# f9 {5 ?  setxy   ( xcor-of turtle h + x )
- A( g8 h. M# e7 N6 d3 ^           (ycor-of turtle h + y ) + k  ^% `5 n+ B: z2 f2 c
                          + N& j3 g! ]% O1 T" K
                          
: ^- d$ t# z0 h+ {, a* J                          ]
+ l! z2 V. n0 P7 q# n( L! wend
2 ]. Z7 w! k. O# v8 |; Q% ~; L0 N; l3 k5 L) W3 U+ d: T5 W/ {
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,, k9 q4 @$ l" S8 j5 X  R
应该是
4 z5 d* U- g! B. e* ~5 G* sask turtles [
' r& T7 ~/ \1 f$ r( o' ^if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
8 K$ u* s4 l) d+ D                          set y  Dep / 2 3 q: v% O. d( N6 p8 ^
           set b  int (who / 5) * 5* H/ ?! x+ g0 @9 k* F8 v  K
    setxy ( xcor-of turtle b + x )% c. E3 H. D. o4 u4 g
          ( ycor-of turtle b + y )]]: f5 d  w. [6 [3 K
end
6 [2 y* C, G' ?, G4 w3 ~之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-29 06:44 , Processed in 0.019397 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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