设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7271|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。9 h; a5 u8 W1 D- V9 t* O
" n7 y: n0 \1 L) R" a, N) k, h
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
4 I$ D; I% a  N. V5 S! S2 Z/ n: b
turtles-own [a b c d k f g h, C, c* k2 e4 S6 c/ T8 F3 z( P
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 4 y. U/ d- E/ c+ V
]
' y! z/ x  ~; H5 X: Dto new+ a% j$ |: u: p
  ca( C5 a6 G8 R* S& U
  crt 5 * num_of_building, N; P5 B; h& x% g: [
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]! V# b. [4 i! l! D1 N, c  t
  scatter     ;;keep center-turtle random positions * [. ~; d! _& l, C3 ?- L
  unit_plan   ;;make up the building plan- s! |8 T  w; B4 l* C1 S; c: E, ?" _8 Q
end& I, d, g7 X0 o7 t7 x
to scatter
2 Q7 `$ \1 c7 I- e$ b! g" w9 @ask turtles with [remainder who 5 = 0]
( |& _, S# T. r1 B6 Y[: n' w2 L3 g' D
set xcor xcor - 6 + random-float 15
" D, Z) ?" S% n0 ]/ _# H" B9 X* y8 f0 Mset ycor ycor - 6 + random-float 15
% u: v; s# L3 G4 O2 Z4 j# W]3 w+ H1 ^) ~' Q
end
: ^; g: _) M# i- F. \to unit_plan 6 @8 L# e% q# G1 e
ask turtles [
1 s8 J/ q, A& I4 N9 l9 [' qif (remainder who 5 = 1) [set a who + o4 a0 w9 Y/ l7 L0 b5 J
                          set x ( 0 - Wid / 2 ) 4 a5 }. d( x% C5 _/ a% z& o
                          set y  Dep / 2 ]: y0 m' O# N# D8 P
           set b  int (a / 5) * 5
4 x9 H3 f4 C% H" F% Z! i+ o0 X    setxy ( xcor-of turtle b + x )
! Y1 J- v8 x% T8 s          ( ycor-of turtle b + y ). a. W! K0 ~( \
if (remainder who 5 = 2) [set c who
+ y1 y8 F; p7 x% \                          set x ( 0 - Wid / 2 )
) @! g3 A% Z9 I1 M4 P4 q2 Q* @; Y                          set y (0 - Dep / 2 )  ]& c; J( Y* L3 S/ h3 w" X( j# l
                          set d int (c / 5) * 5
' w2 v: D6 t# \( d5 u   setxy   ( xcor-of turtle d + x )
7 M6 G, p- p% e- d1 ^           (ycor-of turtle d + y ) $ K: g: G( E  n9 b- P) Z* G, y
         
" k/ X0 Z1 ]1 \) W            
# J9 ^3 a8 u* t) V5 G& s  iif (remainder who 5 = 3) [set k who
! ]2 r2 K$ [( a7 y- I; f! x3 e                          set x( Wid / 2)  
/ Y/ |0 d; _' R. K- I                          set y (0 - Dep / 2 ) ]
, C: a- t* a+ p. n- r                          set f int (k / 5) * 5
" Y' X  R5 t0 m8 `3 v" u  setxy   ( xcor-of turtle f + x )
! b$ l& h* x. @           (ycor-of turtle f + y ) 3 M/ h- k3 J- G; Q! z* ~
           1 x* y7 e& |- c) G9 [1 L1 S( q3 ^
           2 w2 N% }! o( \7 Y# |+ a
if (remainder who 5 = 4) [set g who- s( Y0 E7 T8 I! U% @
                          set x Wid / 2 9 I" H, t" b% a3 Z
                          set y  Dep / 2 ]
# v- }* q' d: V$ x) r( t                          set h  int (g / 5) * 5
8 ^* I9 S' ~( b" i/ t  setxy   ( xcor-of turtle h + x )3 @  I/ s2 ~$ J
           (ycor-of turtle h + y ) $ B. Q8 k5 d2 ]1 l7 y' {2 f" L7 W: q
                          ( `7 G6 t0 ]; k( A7 o
                          ! }% F0 ^7 E" L
                          ]# D4 B/ P! r7 u7 |; c4 B9 ~7 Y
end
; h: E: L7 u6 k) M
; D: v  s* O( C1 I9 ^. Q[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
, R9 {' Y+ P. y( W9 q4 f应该是
9 k( l9 c6 _! ^, {; s1 mask turtles [
2 x. S1 Y( f2 Q/ _) cif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
1 p  Q3 B6 v# M9 f) [                          set y  Dep / 2 9 c9 d# j) B0 p: K" f9 L
           set b  int (who / 5) * 5/ n- ?6 |  w! K7 a
    setxy ( xcor-of turtle b + x )/ n% {& b) w7 e8 d6 g$ p
          ( ycor-of turtle b + y )]]
9 Z' ]: ~5 e' X; Z1 K* `end
0 G/ |" I% J7 ?# Q' m之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-23 13:07 , Processed in 0.018259 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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