设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7823|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。7 p' O* u  y& z) r
9 {; V. g  D8 K' s+ Y
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。5 m' X% Q& v: l" @* I1 l* z9 M

4 E) g1 g8 n. Vturtles-own [a b c d k f g h
4 g2 f, A. T0 d  A; D3 ]+ g  x y     ;; these are the leaf-turtle's offsets relative to center-turtle , \$ j$ H* M2 l0 E* a$ T" ]% W
]
0 I) L7 n0 X3 N. l$ V. Wto new
5 y6 a+ w( @, e& E0 x9 S% l  ca
- C9 \# k$ }, W; j  crt 5 * num_of_building$ M8 v+ T( E* o; n; \
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
* B1 o9 G( ?0 j  j  scatter     ;;keep center-turtle random positions 0 @! X1 b6 L# o) n. j
  unit_plan   ;;make up the building plan. k9 h; ]( ]3 J
end
" P* U0 {8 H, M6 d/ b( u0 Ato scatter
4 R4 r: S! I' x' B7 j9 j0 Xask turtles with [remainder who 5 = 0]5 R6 f1 g  f6 c, v1 L  I
[
5 L# C' m# s/ I. {6 ?set xcor xcor - 6 + random-float 15! a8 X3 N+ F7 \) b1 o( `% Y5 ]
set ycor ycor - 6 + random-float 15
7 O: K) K" w" M+ K]* v$ V5 o% P. r, A4 K4 U7 H8 |
end
3 o: ^. d9 [* Z: Gto unit_plan
$ l) l) q9 _5 M8 Y, }7 i, }# l+ bask turtles [* Z% G" W& ]; c, N  M5 ?' c
if (remainder who 5 = 1) [set a who 3 Z% m  B5 f' W3 i3 B/ V, e( r4 a
                          set x ( 0 - Wid / 2 ) + ~2 Z( n( N* {
                          set y  Dep / 2 ]
+ ]' p6 Q) a! G& }7 E' y2 L4 N           set b  int (a / 5) * 5# r9 A7 s. m/ G
    setxy ( xcor-of turtle b + x )6 d/ W* I# j! t" l8 ]7 B2 i
          ( ycor-of turtle b + y )1 |- @5 q& ]7 K# i7 i; V" V
if (remainder who 5 = 2) [set c who
$ \: N" Z6 a( T7 c                          set x ( 0 - Wid / 2 ) # o5 V  I8 M8 n7 f, R$ E3 E
                          set y (0 - Dep / 2 )  ]6 A. i) ~; j- O3 n
                          set d int (c / 5) * 5
" M( ?  k5 F0 ^1 r/ d1 |. L/ I, Z   setxy   ( xcor-of turtle d + x )' @0 y' k3 n3 G  G1 v! r( ]* B
           (ycor-of turtle d + y )
8 B/ W1 D; h4 ^9 x, [' @- J6 T         
; n# q& y/ o7 m# ^            
3 l2 L  l8 t* H) T  T/ Bif (remainder who 5 = 3) [set k who
, d( \9 C) d7 z" a) t/ Q                          set x( Wid / 2)  4 n$ q/ I% l, X" c
                          set y (0 - Dep / 2 ) ]
. c9 R% e* o7 L: p5 A                          set f int (k / 5) * 5! ?' |0 O2 x2 @) w: R' \# m
  setxy   ( xcor-of turtle f + x )
' _; }' J2 D1 j9 q; n           (ycor-of turtle f + y )
) x6 H  `. w4 ^7 f           
) P9 k3 V/ h6 Z, v) B# n2 e; p           
4 k6 G8 O9 E7 M: `8 @! }0 h! U) H$ \if (remainder who 5 = 4) [set g who0 K* I2 _0 y, P) j5 x
                          set x Wid / 2
* @/ N5 V4 e& }6 A& [                          set y  Dep / 2 ]
3 j; F0 z0 j; ?; f                          set h  int (g / 5) * 5
. A7 f! x" |4 F, V5 A7 Q  setxy   ( xcor-of turtle h + x )6 m0 V' F9 c  Y: ?5 z
           (ycor-of turtle h + y )
6 [' m( F. K2 l9 V) @# F                          
+ ]( ]! s; V" F! ~! k, a                          ; }" H4 w2 s3 M/ j. Z2 t' X! c7 f
                          ]
& o% W' Y/ N; L( o9 Nend
' y, t' W) u1 r; K9 u" p, W) [6 G5 F3 q3 r$ F- Q
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,) [- j& j" F8 R5 @
应该是; Z/ W. R5 B0 v2 }
ask turtles [
6 I8 V" \, }4 ?9 Kif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
, _) [7 y" M) L% @! I                          set y  Dep / 2 ; F) p, _6 c6 a1 Y  Q; I
           set b  int (who / 5) * 5
' c7 V- S; X6 `7 S3 i) V    setxy ( xcor-of turtle b + x ), z; k" |" q3 ^4 q( @8 C8 C
          ( ycor-of turtle b + y )]]
' [( ^' g/ E& Aend6 X3 u- h0 Z1 L8 i! o/ m
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-5 23:16 , Processed in 0.019891 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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