设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7430|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
& Q# l% F4 d! R3 t- b) j5 h. ~  V: ^* V9 T- Z5 i
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。9 e: L  ]4 |+ o' f* Y, Y

% r& ~$ Y- q# q0 x3 Hturtles-own [a b c d k f g h& D" h* f' c! n
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ! g) T& g3 {( ~& Y+ e2 j1 J8 s
]' l" l; ~8 W% Q$ K6 o2 ?2 e/ W0 V
to new
. P2 p5 m, q. I- k, b6 D- T  ca0 M0 ]  }9 F6 L7 B' l5 \+ ^
  crt 5 * num_of_building
( r" j) a1 L& I  T& x7 K  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
9 {6 d2 m) W2 B) d* }7 n% A+ |: |  scatter     ;;keep center-turtle random positions 4 ?/ Q3 e7 `/ q# C5 }# [4 _
  unit_plan   ;;make up the building plan4 J7 `8 u" J- U% c/ i' ?* R
end4 }5 h" k+ p8 r7 ]# ~# W/ ^
to scatter  V9 A' s& n+ B! a+ W) u) P, g
ask turtles with [remainder who 5 = 0]
/ |/ b; J" p: J  t3 E/ L[
6 e4 ~+ ~' ^$ V0 y8 [set xcor xcor - 6 + random-float 15
! w# @! [) n. ?1 H3 z+ ~' Mset ycor ycor - 6 + random-float 15
& T* _5 ^4 F: H5 G* X0 Y]
/ J1 j3 ?% m( l3 i6 d5 \end( s1 c) p( s' K- l; f2 ~& `! z+ g. D6 q
to unit_plan 0 [. g  @# z4 B( Y; V
ask turtles [
: y) u4 k) O: I  P: V& pif (remainder who 5 = 1) [set a who + Q$ Z- k' H8 |$ v" Q& E: I& C
                          set x ( 0 - Wid / 2 )   o) `) B) B5 S1 ~- f5 i) t, v1 L
                          set y  Dep / 2 ]- a3 J, Y2 |! C9 \# J8 [$ u5 G
           set b  int (a / 5) * 5
) @- Z: q& Q9 I7 l# v1 k* B    setxy ( xcor-of turtle b + x )
- @/ E2 W. E. \6 b! ^          ( ycor-of turtle b + y )
; H4 }' v( k4 M9 ~, Sif (remainder who 5 = 2) [set c who( ]; X8 u! p  H/ B$ f* ?! J  r
                          set x ( 0 - Wid / 2 )
5 X6 [3 @- i3 H7 k                          set y (0 - Dep / 2 )  ]
" s) U0 g) Q) L5 a1 {8 e' k/ `                          set d int (c / 5) * 56 G) F0 M+ y5 d; Q
   setxy   ( xcor-of turtle d + x )7 ^3 p5 C, S9 p5 O+ {' Z
           (ycor-of turtle d + y ) 1 m+ m" C3 N( M' e- L! o( a
          2 Q0 `( V, i8 p1 ]7 q3 O7 F
            6 T( I& x0 W$ l0 B
if (remainder who 5 = 3) [set k who7 o; n  N: O2 v4 v2 n6 W
                          set x( Wid / 2)  - ]- y" c- ?. B( G% B0 a+ f$ T/ f, W" k
                          set y (0 - Dep / 2 ) ]
$ h6 Y* [- \, p# B$ b7 ~                          set f int (k / 5) * 55 Z: c& M; ^5 I) ^5 Y
  setxy   ( xcor-of turtle f + x )- {% A3 m! x! r+ Q
           (ycor-of turtle f + y ) / O. a7 Q* I8 E4 {! }- u/ o8 d5 e
           
0 o+ m: F# a  R3 K/ A           
' r6 j4 N* I/ _& b' P- X4 d# g  Z8 Gif (remainder who 5 = 4) [set g who
5 p& v1 o7 v0 b. @0 m                          set x Wid / 2
  Z0 F! j' Z) d$ z& J( F4 _3 B                          set y  Dep / 2 ], N1 @8 D4 f$ q( D6 v6 ?
                          set h  int (g / 5) * 58 T6 P, J3 l/ c# n" C! C
  setxy   ( xcor-of turtle h + x )7 v& E% e; t5 R8 n% P
           (ycor-of turtle h + y ) : X! P( ^+ j5 o( q
                          0 w& N& ^% r& O4 m
                          
( g' z8 F# j4 S3 j& i- \( }                          ]
$ D' I" Q" Y% J. Q, S/ b& kend
8 Z8 \4 d( ]6 A% t9 O0 [; t+ q/ X. K; y. G
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
! f3 p6 Y: c% F9 P# W% p应该是6 K/ V+ ]0 c6 j, k2 f
ask turtles [0 z; P2 ~! n4 h8 O
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
; [. o. W; g, p; S' ^) r2 Q7 T                          set y  Dep / 2 ! @* B1 t9 \" F! w, G# d) \) t
           set b  int (who / 5) * 56 O' Y* m# l) V" W8 E
    setxy ( xcor-of turtle b + x )
3 x8 N1 m% O! a4 ?6 t* W          ( ycor-of turtle b + y )]]
' X% g, ~8 s3 fend: v" N$ j/ U9 f5 g. F
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-10 11:35 , Processed in 0.016545 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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