设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8335|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
# H: ]$ Q7 s, Q& E" E8 P$ b" [" ^4 c* Y( g" x8 a8 E
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。7 f1 T. [5 m% ]8 D! R% @

' u8 K# i# J! J' Uturtles-own [a b c d k f g h
- z3 Y2 b' P) q3 c8 m% x% W& Y. `6 Q  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ( q$ T" O) Q0 f( G& O- c/ }
]; i( J7 j) F  A* r
to new* h8 C  A, i) a  I: X
  ca9 w7 q; n  l4 @+ @8 r2 {8 V0 f
  crt 5 * num_of_building
/ v( @" y) K  f$ Z  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
( |9 `& ^* E6 k2 _3 d  scatter     ;;keep center-turtle random positions # C/ _$ O9 q* X# T3 T- i1 u/ U' U3 O; _
  unit_plan   ;;make up the building plan
7 E& c0 H% x- L4 nend5 O* v5 g1 H. U2 O' Y4 W4 g
to scatter, w1 W2 C# z) O/ g4 Z
ask turtles with [remainder who 5 = 0]
6 ~: \' e" r9 R* H[, ?7 P) G' J& }7 I4 S0 [
set xcor xcor - 6 + random-float 15
# k: F3 [; Q. G- f! gset ycor ycor - 6 + random-float 15
) p5 ]" Y; W& `]
1 I$ J+ j1 \. O2 m$ D: kend
# a* s8 K: F+ i5 B3 I4 G, L! ~to unit_plan . _+ h' \0 }; L! P& |" `
ask turtles [
8 ^7 x9 S0 P! H) u0 }9 P, F, w- kif (remainder who 5 = 1) [set a who
. f. _" O2 |& s  v                          set x ( 0 - Wid / 2 ) , m* G. e( r3 x- x) q, U/ W
                          set y  Dep / 2 ]1 a- F' r: v% x3 s
           set b  int (a / 5) * 58 e0 O' B5 w& q: B
    setxy ( xcor-of turtle b + x )
- i$ z" ]8 w- Y          ( ycor-of turtle b + y )( b8 g3 e4 Y4 C8 S; k0 E/ N2 m
if (remainder who 5 = 2) [set c who
; ]) R0 o' h( c  O  \                          set x ( 0 - Wid / 2 )
- S4 ~2 s0 f4 H& A) }8 n) j                          set y (0 - Dep / 2 )  ]
) a: G9 P6 r: o, t1 _, b                          set d int (c / 5) * 5
! T5 O/ l3 H5 S! P   setxy   ( xcor-of turtle d + x )( O) S! w' R4 y7 t" t
           (ycor-of turtle d + y ) ( o+ A# q6 }! R0 K1 p8 N  [
          % ]- f2 }. `/ P& N& {' H$ h) L) \' M
            
5 D5 c$ ?/ Y  Q" G/ |  q9 pif (remainder who 5 = 3) [set k who3 @& [$ r. x1 C5 K
                          set x( Wid / 2)  % T( E2 Y- D8 x7 |
                          set y (0 - Dep / 2 ) ]/ e. P2 n. ^& L1 Z1 ~8 d$ K- E
                          set f int (k / 5) * 5& W& B8 X! h) L$ l  c6 ?, r# B
  setxy   ( xcor-of turtle f + x )
/ w! G: N  v$ t1 I+ b+ _! D1 O           (ycor-of turtle f + y )
6 r% A5 n$ L5 {) x7 x/ y6 b           & N. N7 s6 {" o) C2 v& \
           
; V2 M. ?! F) o7 V/ dif (remainder who 5 = 4) [set g who9 s9 Q3 D1 j& W8 V; C! n
                          set x Wid / 2 & j$ `, b% E* F: F" x3 U
                          set y  Dep / 2 ]% Q; u: b  V9 l( v' R5 q3 A/ Q
                          set h  int (g / 5) * 5
! S1 w  O. u* P7 a+ Y; J/ F  setxy   ( xcor-of turtle h + x )1 x! u$ {) ~) {; o# V% O9 \7 E
           (ycor-of turtle h + y ) 4 V; Q; w0 H: r' n1 q: Q) _' B
                          
9 o7 J" d9 J- L/ F9 R                          " |  M' P6 m, x5 U+ O4 z) m
                          ]
. ~3 w2 E. z. I) |  kend
- L( r  E9 L3 ~( H/ O
+ Y- p+ Z% G' d' u[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,+ f6 f/ i- b" M
应该是( D) q- Y! B7 j$ B( `1 O
ask turtles [- C& K" s  n6 r! o9 v
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
/ g3 {3 [) c$ @' \! U, w                          set y  Dep / 2 2 O9 r/ E8 g( G( A, c. q9 Z
           set b  int (who / 5) * 5
' I- a1 j4 p: ~  S% X: c    setxy ( xcor-of turtle b + x ). T3 Z; \, s4 q6 W' [
          ( ycor-of turtle b + y )]]! F4 J) x, I4 O) {, p
end6 u* \' q( F" e) [
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-9 17:31 , Processed in 0.017081 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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