设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7727|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
; q2 N7 P. o  o+ Y% b- Z: F" u
8 j/ z6 [7 N5 @. @( ^但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
8 ?0 X5 u1 V) {0 c4 ]" l2 Q
) Z1 i8 }3 \0 \/ V3 h) H* v+ tturtles-own [a b c d k f g h, G1 L! ?( r# H  W
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
5 J  m5 f; ~. g]2 {* u$ k" z* A/ Y) |# c: F9 g
to new
7 Y! T* N, C5 Y  E  ca6 _9 b/ k$ x7 w, @
  crt 5 * num_of_building9 |  @- I& C: `+ E& M
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
1 F! R- W6 _2 j1 X0 [; q0 M: D  scatter     ;;keep center-turtle random positions # y! f, y' T6 {; z# \
  unit_plan   ;;make up the building plan
" N: R+ W1 U  N$ {2 Uend
3 T# y9 u3 y3 }to scatter9 V) P! T( r! q, h
ask turtles with [remainder who 5 = 0]7 N9 f) a' m) G) V& j
[
" |9 @$ Y; o6 X& o( Xset xcor xcor - 6 + random-float 15
# M9 p2 g" J6 s/ w6 i6 {set ycor ycor - 6 + random-float 15/ `2 ~  T5 K, E6 k# {% Y& R; E
]
4 E- A/ z. G7 F5 e- i8 nend; y9 H  H+ G4 ?5 V+ M
to unit_plan 0 t& H8 J- [4 b4 @
ask turtles [& y" Z3 i8 I, N' c/ K- j
if (remainder who 5 = 1) [set a who & c* f. ^8 E+ W/ b/ n! U
                          set x ( 0 - Wid / 2 ) . Z( D& U' L3 p% t
                          set y  Dep / 2 ]
$ ?* Q5 G: B# W           set b  int (a / 5) * 5
' a# y% k3 u9 ^# Y' B8 n    setxy ( xcor-of turtle b + x )
) v2 \! p+ |( }: c) V3 u6 d; t8 x5 u          ( ycor-of turtle b + y )9 n& L) a8 `/ A9 A" N& E
if (remainder who 5 = 2) [set c who/ c! N6 c: f  _! |- H
                          set x ( 0 - Wid / 2 )
, H" m1 e6 \2 U4 F* `                          set y (0 - Dep / 2 )  ]
. G4 n; Q' @* }' n5 s: t                          set d int (c / 5) * 58 y; A- o: [& W. Z9 p$ X8 t
   setxy   ( xcor-of turtle d + x )  H/ J, r+ _/ Q5 P2 f( x
           (ycor-of turtle d + y ) 8 ~% |: c( @! u" S
         
9 d7 l2 u; @* n9 f6 L            2 y+ f" y. Z: W, T! ?' N6 ~
if (remainder who 5 = 3) [set k who
8 a  V/ B% z5 G                          set x( Wid / 2)  
8 D; ?7 X: E5 y" [                          set y (0 - Dep / 2 ) ]6 q1 a- T( w( L0 C. ^
                          set f int (k / 5) * 58 U7 ~2 J* \1 V
  setxy   ( xcor-of turtle f + x )" j. ]* ]8 V, Q# [' b% R: d/ u
           (ycor-of turtle f + y ) 8 r8 N* r; K" r6 c+ l' x9 ?
           " D) m1 U0 _; {& ^- x
           ( a$ w; [6 Q& C/ c/ F# H
if (remainder who 5 = 4) [set g who6 L( B- ?1 l6 ^1 z; K+ ~; n5 @
                          set x Wid / 2 9 H2 P3 A0 q! x  S( A7 C0 M2 t1 z, w
                          set y  Dep / 2 ]
! L/ B" {- d$ D; ]                          set h  int (g / 5) * 5
4 L; W( t" j% s) C1 H  setxy   ( xcor-of turtle h + x )1 D2 d4 q" H# Y! y- M
           (ycor-of turtle h + y )
  p0 `- f# D3 a* p. z) G                          $ f7 G0 s% A# E( h. y5 |" g  v: x
                          2 G$ P+ G5 U% o
                          ]
& @; V3 U7 D- l; ]# E6 pend
; c: }! n! e  E/ V! W' }, }3 G
) {  B8 ?( K1 L/ U2 s2 g[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,* o. Y& r2 r, H' x1 C- V  M
应该是% U& @6 k  o4 W: |$ k* ?: p
ask turtles [
  j- r1 f$ ]: @: R- iif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 4 f* i5 m* @3 k: c- A2 I2 P7 L
                          set y  Dep / 2
; Q0 S9 R7 @- \" n# K           set b  int (who / 5) * 5
6 p7 m0 @/ s5 h1 |6 D    setxy ( xcor-of turtle b + x )/ R+ V& L3 b' R1 ?/ P
          ( ycor-of turtle b + y )]]
9 M$ B4 l! t# _* uend3 {7 N, l8 Z" k8 k! W6 |( n
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-20 05:03 , Processed in 0.015850 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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