设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9069|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
2 W; a! ?- p8 ^' t4 L: j# x
9 @7 ]0 @7 L, [: P7 ^但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
+ }( u1 P% M  i( Y- Z8 R
! r6 g. x. m8 ]3 Hturtles-own [a b c d k f g h
' M4 p9 v7 o% k% ?6 h- W  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 5 o" o2 K6 h# A" M' ^: D' U' [2 v; U
]
- R8 t+ Q) V  y% |& oto new9 `7 K% }* k$ y0 a" K; ^. a% E9 g
  ca
) z. m+ H) J% T! m  crt 5 * num_of_building& X6 w. `# z2 O. d4 ^* Z
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
* H! m/ Z5 V* n2 l  scatter     ;;keep center-turtle random positions   U0 Y" G# F8 p; y+ R; I% s
  unit_plan   ;;make up the building plan8 v! w" ?+ p0 }1 B
end
' S9 m* W2 q) U  Q1 gto scatter
! G* ]3 i9 n* V& d. Vask turtles with [remainder who 5 = 0]
+ Q( S/ \# I5 J[
( R' b$ O0 f! X% ?! x; R* @set xcor xcor - 6 + random-float 15. W3 T4 L9 O5 Y
set ycor ycor - 6 + random-float 15$ R) [* Y- y3 t: K& ?& _
]- f$ ?  f) k" F  t; T( r& L2 M. l
end0 J' C: W( ~) J# K2 h
to unit_plan
0 Z2 Z/ X, U+ task turtles [5 i- k( Y" U8 \  o1 M* j
if (remainder who 5 = 1) [set a who % E' Q  `5 N4 W4 y& V, m
                          set x ( 0 - Wid / 2 ) * t5 s; e; j+ f
                          set y  Dep / 2 ]
" U. G0 z: k, S$ v2 F           set b  int (a / 5) * 5! e$ `6 a; B9 G4 ?- ~, V9 C
    setxy ( xcor-of turtle b + x )
5 h% F4 q; B) y3 E1 u          ( ycor-of turtle b + y )
5 v, i. q' S5 k! e/ kif (remainder who 5 = 2) [set c who
! v6 i$ P* j8 A$ }0 S- k$ j                          set x ( 0 - Wid / 2 ) ( r% \4 h( u" M6 W; ^
                          set y (0 - Dep / 2 )  ]
. \0 s- p# _# _# ?$ i: o7 b                          set d int (c / 5) * 5, A$ @! ?7 V: b0 y4 ]
   setxy   ( xcor-of turtle d + x )
0 T3 {( S! z8 Q8 M0 U2 F, `           (ycor-of turtle d + y ) : a' }( f$ e$ f' X
          : u% a9 e- B2 I- }
            # Q6 |4 a  w) n- c8 r2 S
if (remainder who 5 = 3) [set k who. |0 N. y; Q; M( }7 P
                          set x( Wid / 2)  7 s8 W4 p/ U6 h: c, H
                          set y (0 - Dep / 2 ) ]
. r2 f: ^6 w3 ?9 r6 j$ b4 q& [7 @& i                          set f int (k / 5) * 5
) f, r# |( s& e; Z) k: N  setxy   ( xcor-of turtle f + x )& [, W( v* d4 M  W( s1 }  y8 S
           (ycor-of turtle f + y )
5 f% u9 G9 H# [" Q  L1 t8 f$ F           
% P9 T) E: \. c( P           
" E( W5 i! ?8 f7 ~+ ?: Pif (remainder who 5 = 4) [set g who$ C0 B8 z( o; o8 A$ K! p
                          set x Wid / 2 " K3 }1 y; J) K  Y
                          set y  Dep / 2 ]& p. N- ~  W8 ?( P+ m$ Y3 X: V5 a
                          set h  int (g / 5) * 5: _5 h% N9 M  A1 R* S+ M+ m
  setxy   ( xcor-of turtle h + x )
. {0 r2 d. r( ?; y+ N% S           (ycor-of turtle h + y ) 7 z- ?3 B+ |8 c; b# c7 n
                          
. W' Y; N4 ]5 B4 i  X                          ) U5 `' O6 r+ o3 x3 ~
                          ]
) y7 i$ X9 F; X- o9 N9 Q) {end
! d7 H1 \8 g/ E; j' e# r: b, x+ E8 }! s: f: O+ g5 k, K
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,- w9 r' I+ R% ~  N, J$ P8 D1 {
应该是
2 N. x8 u8 w6 |- D# ]ask turtles [
2 g) R# [9 d1 {, l" ~! @, oif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
4 U' D% _) v) f4 f                          set y  Dep / 2 0 y' J5 N# U0 m" r
           set b  int (who / 5) * 51 P6 D! N* {( }
    setxy ( xcor-of turtle b + x )1 _! M+ x4 H% P1 g& v* [4 k: e. m
          ( ycor-of turtle b + y )]]6 Q- `6 M1 s+ y$ A  ^
end
+ A! d; B7 }/ q! N; R; l& B& l之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-13 20:53 , Processed in 0.019762 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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