设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8593|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。; ^( J) `6 G& s$ |  r6 K

2 K! `0 _* U( K) ?: m: ~' R( M# G但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
3 i. @8 z$ E3 l+ j3 g6 O# S8 E: H0 L4 a+ X  g1 p7 A
turtles-own [a b c d k f g h
" P9 P, K# _, T0 F  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
4 k6 a4 O- ]& a5 l- Y]+ a& K2 B; m, W" e0 n4 v. Z9 Z
to new
# Z8 k! h) y1 R$ T. n# ^  ca7 m( o( e: W! ]3 G* p  |# y
  crt 5 * num_of_building
* A5 h' m3 `" j) T2 x4 q6 Z  Z  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
7 A# u% }0 i8 W/ Z  scatter     ;;keep center-turtle random positions
4 s: D6 d, L$ y% \  unit_plan   ;;make up the building plan  Z" T( _$ ~# r% |9 }# A  R) Q
end
8 D9 a3 d  O! ], ^3 Eto scatter
) r  v' W1 C; ]% T3 N3 A6 Yask turtles with [remainder who 5 = 0], y/ O- B( v4 g; l+ I6 U
[
5 ^6 b0 t* K1 l, J0 V5 q3 Bset xcor xcor - 6 + random-float 15
4 C3 O& R/ N9 d* h1 @" dset ycor ycor - 6 + random-float 15
6 R3 w( X, x- c0 C/ }6 U1 U; O]
( j0 ?& H5 g7 I1 w' O: T* a' p0 f0 |end: U2 C9 \! G; z
to unit_plan
7 z8 t, N5 T3 V/ A. \" Rask turtles [5 j8 @4 L2 N- X$ |% l$ \0 N
if (remainder who 5 = 1) [set a who 7 U+ o- I* L1 m
                          set x ( 0 - Wid / 2 )
7 c' L$ b/ u/ {                          set y  Dep / 2 ]% Q$ `# W3 T5 Z. K5 e$ H9 D
           set b  int (a / 5) * 5
% I, _! ~( y( t9 N    setxy ( xcor-of turtle b + x )/ d0 y/ _6 J# _: X4 o- p: P
          ( ycor-of turtle b + y )
- |3 T4 h. L3 W4 Y2 [9 b- xif (remainder who 5 = 2) [set c who
9 x5 v# b- e& Q/ C' R                          set x ( 0 - Wid / 2 ) ( a( r$ `6 u' C' w
                          set y (0 - Dep / 2 )  ]7 c6 \( u$ F5 R4 a0 ~
                          set d int (c / 5) * 5, n! V( _+ l6 u" i3 [
   setxy   ( xcor-of turtle d + x )/ i( e' J1 M: }' ^' Q7 G+ H
           (ycor-of turtle d + y )
( |% R- o9 ?. i5 V) i7 Q( X         
) n: a* D; K- t1 D- a! X; T            ; ?- U1 Z; D- m- s
if (remainder who 5 = 3) [set k who
5 S* Y1 g$ I! k! Y3 x) ?3 w" A                          set x( Wid / 2)  7 B% z' R/ f" c* q
                          set y (0 - Dep / 2 ) ]/ r: o7 q& }; ~8 N8 \
                          set f int (k / 5) * 59 p: c, Y7 c7 ~$ x% Z
  setxy   ( xcor-of turtle f + x )' v' g3 d: e$ `% Y2 f( x
           (ycor-of turtle f + y ) 9 h  m0 O+ n. s' _/ R2 Q
           ! V! ?, R* F$ i  I' K/ V
           
$ Q) {+ t0 @% j/ m7 qif (remainder who 5 = 4) [set g who
8 j' W5 b0 f# V                          set x Wid / 2 5 a  l& q/ k, u! _; ~4 m# a; N7 U
                          set y  Dep / 2 ]" _+ `$ Q1 G8 ~3 g
                          set h  int (g / 5) * 5
4 V  G  b" Q) Q4 o& s( Z  e- w+ q  setxy   ( xcor-of turtle h + x )
! r2 S2 m) u8 A           (ycor-of turtle h + y ) 8 g  r" O/ ^4 ^" l8 u9 H
                          * A  `" c. o0 B6 N) H
                          ' V' j+ s, G" _5 u
                          ]+ X; ], J( k7 e3 y+ f
end7 n  i. u* R! z" N" B( d! [/ J; }

8 w& K% L# Q! N( p0 K% P[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
! W4 J: A) z) c% o( w$ D应该是
5 w1 ?% B8 E0 oask turtles [
+ y/ r7 j& K; G2 q: gif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
: @/ w5 z/ g6 ^% t" t                          set y  Dep / 2 " P# J' g, t' d. T
           set b  int (who / 5) * 5. N; O0 i" B3 U8 b. `
    setxy ( xcor-of turtle b + x )
" {. u% @0 T/ L9 U8 d2 b          ( ycor-of turtle b + y )]]) V2 S1 n& s+ q9 q% |. Q
end
# q: S5 ]* S3 d, P4 a之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-15 14:41 , Processed in 0.017199 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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