设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9153|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
+ N+ \. Y0 P$ h3 X% R0 f9 r
$ s# i2 T; Y3 |/ C( r3 E但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
" p) Y- S6 x4 T# m4 m) m4 D+ @/ ^- b$ ^7 S
turtles-own [a b c d k f g h- W7 n) z1 n/ C
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
8 y; Z" G; g) V]5 o5 s- D  r) d7 y
to new5 J1 J1 F, J; t4 M9 u1 K2 D* P
  ca
' k- ^  |' l, A- g- T3 y3 {" y( F5 B  crt 5 * num_of_building; c: J# w* P7 Y3 s4 p& H
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]" B( k6 N; k* d! ]' g, i
  scatter     ;;keep center-turtle random positions
' q0 J1 t+ o; r( t3 ^  unit_plan   ;;make up the building plan! D0 I3 W% N* |7 p$ t6 X; Y
end% ]/ h, ?4 p& n; `9 t3 \3 p
to scatter
6 R& d" d" S. ^0 |0 Qask turtles with [remainder who 5 = 0]" ~, t  U: f5 |
[4 H4 _2 [5 Z6 t# e
set xcor xcor - 6 + random-float 15) ?# e1 E+ `0 I3 X4 g/ w$ q
set ycor ycor - 6 + random-float 157 B* W, `2 ^/ x+ a5 H
]7 Z6 i6 L2 K4 x: D$ d& v! U
end
# J4 O; |: O: _to unit_plan
3 ?. Q% O, a7 i2 d3 Pask turtles [
- t% f8 F! S% M) b7 Yif (remainder who 5 = 1) [set a who   Y  E% H5 h7 X# i. P
                          set x ( 0 - Wid / 2 )
, |1 @8 p) A5 C8 q0 ^3 v                          set y  Dep / 2 ]# B! y4 A* m5 W3 K5 i/ K% j
           set b  int (a / 5) * 5
( W& u  l" k" V    setxy ( xcor-of turtle b + x )
; P4 N/ Z* Y" Q: Q5 B          ( ycor-of turtle b + y )3 w1 _1 b" C0 \& D! x
if (remainder who 5 = 2) [set c who  e, c+ f* I6 k) b" @7 v
                          set x ( 0 - Wid / 2 ) * b/ |- Z0 i) y9 M2 m1 F7 c
                          set y (0 - Dep / 2 )  ]
$ ^( _- a( F3 B5 h                          set d int (c / 5) * 5
7 h3 u* i# s7 Z2 l* K   setxy   ( xcor-of turtle d + x )6 G8 Z/ ?* s6 u- g; d  q& F( ?
           (ycor-of turtle d + y )
' s  O6 [8 E0 U; j6 Q         
- S$ U8 a- b" v/ D% r" Z% ]# z: n            
& s. |/ e  r3 ~if (remainder who 5 = 3) [set k who
1 p2 r- K, j0 R( H+ X                          set x( Wid / 2)  
6 e' j. H9 F3 f                          set y (0 - Dep / 2 ) ]
; g% y  b! e& Q$ b/ K0 M  P) K                          set f int (k / 5) * 52 p3 B( F( q5 ~: l) f" G
  setxy   ( xcor-of turtle f + x )$ E  |) l+ v+ G! H
           (ycor-of turtle f + y ) & X* _% i7 S$ e; b8 M. w
           ) s7 c/ Q" W& i. K. {8 `+ @
           
& n% u# ]  E. Fif (remainder who 5 = 4) [set g who
: Q+ R" v* m/ E4 L& m; E+ f! q9 n                          set x Wid / 2
# r8 Z( I+ y: O. F. s                          set y  Dep / 2 ]! H5 H4 O: z5 B) k8 D
                          set h  int (g / 5) * 5
. M7 o' D  M& `8 }8 g7 r  setxy   ( xcor-of turtle h + x )0 g+ q  Y9 p" I9 e5 A
           (ycor-of turtle h + y )
5 ]7 d9 U- ^: b  X                          , R/ [4 w1 e: I
                          0 B) |% _- H2 _$ I+ M3 G# _* V
                          ]
1 K$ q1 U9 c# O! s' `: w" Lend& p" d6 N, y$ y8 N; Z8 P6 O

9 @" N! u( f0 y6 w[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
( B6 v; Q9 e, I7 W' X5 j- q' h0 n应该是4 V  F! }; A' ?4 P9 e
ask turtles [; M5 o0 F2 ~$ D: k% L0 t% C
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) % v5 j  f6 b/ Z, ^  q
                          set y  Dep / 2
$ g/ ~3 ^: I, D           set b  int (who / 5) * 5
( G# p3 ?: }1 U$ V1 D' K    setxy ( xcor-of turtle b + x )7 k4 u. H! q2 \% q. M
          ( ycor-of turtle b + y )]]
, C( a9 ]6 @; W: |8 {; G0 v6 Gend8 o2 E* @! O% C& ]
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-23 08:16 , Processed in 0.015195 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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