设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6948|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
; w* p; p% U3 c* s0 {
+ R* G1 N3 C- n) b但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
# B- J. U7 g. x- @* {
4 e" g! t# z0 |turtles-own [a b c d k f g h
# g! T! M4 U, N7 T4 O/ g  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ! ^4 r; c, E6 J5 j( \- D& u  Q
]
, a" C' \+ Z4 Z2 G- i. Z6 Eto new
  ^4 O/ O/ D# n* U  s1 F9 l  ca
$ Q% Z! j& }( |8 F5 q/ Z2 L  crt 5 * num_of_building
, i. n: A# T# c/ Q) U( Z( m  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
' P' y0 G: g. M0 j  scatter     ;;keep center-turtle random positions
9 h0 h" |' p9 q6 M$ A1 T. p5 _2 t$ r  unit_plan   ;;make up the building plan
4 X  h" F; C$ B: M( hend5 e$ ]2 r: }0 V
to scatter, G- ?" m! y. h( S! ^# H2 ]
ask turtles with [remainder who 5 = 0]
( i$ i6 z. T" v! j* F[
3 \) a1 e8 [) @/ {2 h' ~set xcor xcor - 6 + random-float 15
5 G! F+ [: B3 W& \1 z4 lset ycor ycor - 6 + random-float 15
9 U% {4 l, f  M1 x* `' Y2 |]
- }. H( s0 D6 x: f1 Pend
  Z* J- l8 U6 t. Lto unit_plan ' z+ y, K) X( Y+ t( ~; V
ask turtles [
2 a1 o. ]* K; |& y6 I! Gif (remainder who 5 = 1) [set a who & C8 N$ d6 s2 d( o/ X% Q
                          set x ( 0 - Wid / 2 ) # r8 j0 J, z& b$ U3 j% l2 w
                          set y  Dep / 2 ]
* g# q$ v/ f  Q& `           set b  int (a / 5) * 5
1 e$ j1 h$ X( L9 g2 {5 |4 X- [    setxy ( xcor-of turtle b + x )
2 x: T  _- {4 @. ?          ( ycor-of turtle b + y )
; x: \- q3 l+ c% J7 y7 M1 R' kif (remainder who 5 = 2) [set c who: h/ z* a1 Q# H. U. x
                          set x ( 0 - Wid / 2 )
; Y# ]' W( R1 ~) b8 Y$ c/ ]6 O                          set y (0 - Dep / 2 )  ]! a, u6 k$ u- M6 R( ^; D7 t7 {  P
                          set d int (c / 5) * 5
) Z2 S  i  @! z( c- o4 g   setxy   ( xcor-of turtle d + x )# e, f; K; `8 m& y3 c
           (ycor-of turtle d + y ) : }) a) t0 f2 W. s& g. ~! L
         
' s; o5 H& R# A5 I            
1 ^. I: Y- {- I5 H1 {  rif (remainder who 5 = 3) [set k who8 I. j6 |% z# I/ B! X  X% ~7 W
                          set x( Wid / 2)  
1 |0 K' C* M: {2 ^; s5 f                          set y (0 - Dep / 2 ) ]# J" k' j$ I" Y) |5 r$ H9 {0 H
                          set f int (k / 5) * 5
7 r+ b" d7 M! W+ r  setxy   ( xcor-of turtle f + x )
( ]* z9 J# T3 g  N7 E. \) N           (ycor-of turtle f + y )
8 J* d3 K* o# u! M# t           # c0 ^$ g  t" f
           4 h* |& N. W8 T: J
if (remainder who 5 = 4) [set g who0 d* S" h8 B5 K' t1 C# g0 _; Q
                          set x Wid / 2 , S4 X: m% z9 R" J
                          set y  Dep / 2 ]
" o/ y) y2 S" P. X* c" n0 F                          set h  int (g / 5) * 5: F. I/ h  f5 Q. A# s0 a
  setxy   ( xcor-of turtle h + x )% g! N2 S" _6 i, T4 D
           (ycor-of turtle h + y ) : y+ l& o7 ~6 }3 ]
                          
0 \$ A. u2 t8 r) `1 p6 `                          
$ k) a% G/ ?1 ]2 H' {8 l, v2 u                          ]; L' X0 x. t5 F, \$ w0 |$ |
end
7 I* \0 U& K1 S& w- M
3 W' _. K) D7 o  X7 D" x3 d[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,# o% \0 l$ y; `, @# H' A8 B
应该是
+ j7 I* `, A. s$ oask turtles [, h/ o( A5 e0 ^1 u. a) K5 B% P4 f
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
' q' t9 J" m/ u5 F6 X$ N/ [2 \                          set y  Dep / 2 * m, h9 E/ O( l. L' f$ V
           set b  int (who / 5) * 5) ]/ u; c' B( r" s& e9 Z, o) L
    setxy ( xcor-of turtle b + x )
1 t. K+ }  x/ M: M0 `          ( ycor-of turtle b + y )]], S! `% ~; {4 w4 Z
end
8 G0 z' Y# R6 O. n6 E& C之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-13 06:12 , Processed in 0.018124 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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