设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6961|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。+ M% i+ m( j+ q  P4 F2 ^! z+ d; T
, U- \% C+ |9 a' N
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
1 {/ D( _& x4 u2 r
, F- f& U* c! n" tturtles-own [a b c d k f g h
1 [4 w9 S: |3 s* `# f5 P1 h! S1 U  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
7 a, F; v' U+ x4 j, l$ P! A]$ m& ?) A6 N( s- a. Q8 y- u
to new5 g( t. `# c7 \" f
  ca/ i: n  F# I$ _2 a
  crt 5 * num_of_building
2 O' K& o4 `9 h/ H' X  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
* ]& D; U# b' T0 I  scatter     ;;keep center-turtle random positions
# E9 [4 M6 g/ Y' u( |  unit_plan   ;;make up the building plan# T# {0 ]( q. j
end6 m  C" }8 L( T5 N8 R
to scatter, l+ }+ X; W/ i
ask turtles with [remainder who 5 = 0]  A+ N! ~! w7 [- C% l- T
[
! I! g$ d3 P' pset xcor xcor - 6 + random-float 15& y* C1 [5 U' E- ?
set ycor ycor - 6 + random-float 15+ h3 z5 S  x: N( B: h7 L
]
1 S' p+ h5 p* L: Q0 O' ?3 nend; m; l2 T1 x8 j/ R9 |( Q+ W
to unit_plan
7 e& T; f# ]/ @ask turtles [9 Z: g. V" W/ C# B% T3 X- R
if (remainder who 5 = 1) [set a who
8 r+ L0 X& c: z9 N" g& d6 J                          set x ( 0 - Wid / 2 ) & c) r+ y$ e# U8 b2 E" f/ P
                          set y  Dep / 2 ]2 D) s- l- v$ I$ i
           set b  int (a / 5) * 50 ]( e+ ~5 a' H7 J" Z5 a0 q' w
    setxy ( xcor-of turtle b + x )/ `5 _$ {" H( Z3 I. g$ P( j: t$ Z
          ( ycor-of turtle b + y )
! B! I  F' {1 l5 c  d9 P. Yif (remainder who 5 = 2) [set c who0 ?: g3 h3 C2 F, l
                          set x ( 0 - Wid / 2 )
! Y1 k5 C' h# q8 q                          set y (0 - Dep / 2 )  ]9 G6 u9 N8 S) W; |
                          set d int (c / 5) * 57 Z2 }$ o( K7 W/ B5 n7 D- z
   setxy   ( xcor-of turtle d + x ): e4 n2 a3 w2 \) E$ Y2 ~/ F
           (ycor-of turtle d + y )
2 u* |* P7 n" j+ P( L7 t0 I         
, l8 F" \' |7 z+ v  A5 R            
( e/ R- q: \3 T: ?- V. Jif (remainder who 5 = 3) [set k who
) m& n1 D! V0 n3 H$ o2 q* e                          set x( Wid / 2)  & i9 j! \( W+ N7 P1 L8 G& o" o
                          set y (0 - Dep / 2 ) ]
8 b. b1 B4 y$ ]3 |+ `2 s                          set f int (k / 5) * 52 z0 B7 x1 J: j& a, H6 \
  setxy   ( xcor-of turtle f + x )3 f( l$ k' x& `  \/ A; Z
           (ycor-of turtle f + y ) ' H# d% ~' K; P( v" g: v
           : h7 r4 i1 p, g" i1 y4 p; m
           & p) G1 T% ~4 P3 B: ]
if (remainder who 5 = 4) [set g who* O0 @2 O; h. ~3 g; l4 X
                          set x Wid / 2
$ T0 ], C0 |* F5 ?* q                          set y  Dep / 2 ]
: N1 O3 N, o' ?6 d+ Y& t9 U) K                          set h  int (g / 5) * 55 `% E4 j$ Q' H, ~7 N
  setxy   ( xcor-of turtle h + x )) ~& ?, v, e9 D: A
           (ycor-of turtle h + y ) 9 ^/ L: S5 F  i" r0 M- S
                          . m9 X3 s+ h. [  V
                          
" J, _$ R1 S# A1 a9 b                          ]" E& F/ Q* q' C; X4 r
end2 q5 }7 }0 [: b  J
6 g2 z. c4 q4 S5 p; e2 u6 R. Z$ k
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
8 g2 `. P; ]7 I* D; u/ R$ |4 h应该是' W  Q1 g0 M( R5 r5 i% G7 i8 Z
ask turtles [
7 i3 j) f+ p% e  Z) @! ?& a' P! q, dif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ( o! M0 z$ r+ ^2 I; }- d5 x: g$ o+ o
                          set y  Dep / 2 ) A- n4 x1 T' n4 a+ V/ @
           set b  int (who / 5) * 5
' d2 Z9 _9 ^& m    setxy ( xcor-of turtle b + x )2 X% g. @) A3 `( }& m1 ~
          ( ycor-of turtle b + y )]]
2 {' f2 }' H* Dend" T+ H  s3 R  {* C+ ]0 H. w/ N" n0 Z
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-14 12:14 , Processed in 0.019488 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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