设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7725|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
* i6 q' h) B. @+ L/ d3 S
/ U" W  L9 c' x8 d# L/ q2 x: i但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。/ B  @8 i% D6 |: c

) n; [3 \, m# K& ~( ]' [turtles-own [a b c d k f g h
2 d8 [% D1 b. l% R2 j: X+ R  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
5 F! ~- Y8 ~/ m' e" G]
1 k- i1 j2 n, N( yto new
: A1 U" d3 S4 u1 N6 a  ca
7 I0 V4 l% h* [  crt 5 * num_of_building! A0 U# a5 `) y. I2 r! n6 i
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
6 g3 p, ?/ D2 a3 c1 L  scatter     ;;keep center-turtle random positions
: T' B( u5 m) B/ P: ^  unit_plan   ;;make up the building plan
8 ]2 X7 \2 E# F- \( Eend6 J  {4 v4 L. k, G  y
to scatter
: `& c2 V' g3 H9 J- @ask turtles with [remainder who 5 = 0], e& P6 Q/ F7 g- i& m5 o3 R. I
[
- V2 r8 @" X. e/ a; Bset xcor xcor - 6 + random-float 15( [6 x& [: J9 U# D1 H4 ^& |
set ycor ycor - 6 + random-float 15
' k) a  A( |& v, X: d% a]
- B) }5 W; b) K9 a$ i' M9 ~) Bend: z# \( }) F9 k& s) H# U5 R- `* J
to unit_plan 1 D, b, E. v: g5 q. C
ask turtles [
+ G* T# h; b$ T0 mif (remainder who 5 = 1) [set a who
1 |, b) a# F! t; L                          set x ( 0 - Wid / 2 )
8 n- l% {, b  o2 ~                          set y  Dep / 2 ]+ X- E5 A5 M  f$ C
           set b  int (a / 5) * 5
3 a2 i0 N- O0 P3 T8 s    setxy ( xcor-of turtle b + x )
% H% k* B3 y5 R' @" I3 q          ( ycor-of turtle b + y )
9 V3 R8 n$ D" d& I0 Iif (remainder who 5 = 2) [set c who8 H4 Z7 x5 }& \- ?
                          set x ( 0 - Wid / 2 )   G4 @# m3 Z1 [9 N0 q/ G
                          set y (0 - Dep / 2 )  ]7 i7 {2 k9 b) [" L8 {
                          set d int (c / 5) * 5
5 [$ s, \. v4 }2 T  E   setxy   ( xcor-of turtle d + x )
) _3 Q( G( g: T+ |$ j           (ycor-of turtle d + y ) " ~6 p- U! q! C  K
          ! i3 @) m7 y7 n: \% j4 |
            
& }0 O1 C  p; _& jif (remainder who 5 = 3) [set k who
5 U! A7 a1 ]: |6 F1 `# O: R                          set x( Wid / 2)  
/ i, z7 K8 f( P+ u* L7 @2 s( e' _: G                          set y (0 - Dep / 2 ) ]
1 O) B  z  j6 u; e8 [7 a                          set f int (k / 5) * 5
( i4 h5 ?0 Y6 l* Z& o9 S. N3 Y  setxy   ( xcor-of turtle f + x )6 c& k+ Z6 S7 z. T/ B, Q) I
           (ycor-of turtle f + y ) 2 V, J" i0 z4 j7 z4 \
           7 |0 e6 O% I# a. j2 u
           
0 ~" d6 }% m1 a5 Yif (remainder who 5 = 4) [set g who
! Y% M) c7 A7 B; p% F$ D; S                          set x Wid / 2
' t3 X* k+ [1 A5 N" U                          set y  Dep / 2 ]7 L- H- J* Q( L; M
                          set h  int (g / 5) * 5! n0 W7 O, d4 f. \0 V) c; n' y
  setxy   ( xcor-of turtle h + x )
8 ?0 K# W* B7 v" y           (ycor-of turtle h + y ) - J. f) \2 K$ _+ |
                          
) s3 O) K, T- Q! |8 B* F                          / T! t9 [* v7 T1 L4 z
                          ]* \. |1 N9 }- n! {  ?& D
end4 s8 t3 G$ F; k' Y  k* a

& [1 O% C/ ?. S( a" M/ e[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,7 o" D. K1 b# {; t! j! w
应该是: q( _  g' F6 w9 O: o! E
ask turtles [5 C! Z- m# _& O" m0 C: q
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
1 \; t' r( W) j3 o: j. _                          set y  Dep / 2 " |  }* Z# }+ u0 g1 e; _6 [
           set b  int (who / 5) * 5
9 {6 o( q# T1 c, N    setxy ( xcor-of turtle b + x )9 _( i6 i5 g: {- ^. f( D8 W  O
          ( ycor-of turtle b + y )]]% |& y8 f" s6 B
end# x' p8 }8 g1 C5 I
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-20 01:37 , Processed in 0.028517 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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