设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7571|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
9 m& C  }9 }2 p; X& `( j# ?
& A) |9 E- F( K: B/ ~3 k但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
4 O5 r& h9 r2 Y  J/ F/ n4 r
( b3 `/ U" Q* b% `9 t3 A& k! cturtles-own [a b c d k f g h' E" Y/ x/ }+ V+ I0 Y9 Z5 j; }
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
6 l: H, ?6 _' y]
4 V) i2 {! r# Zto new
; V+ B1 k( V" _* W* r/ c  ca0 W6 ]2 Z4 u3 c  b
  crt 5 * num_of_building' a6 a& B2 V& X9 a% z0 k+ F/ z' p
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]# G3 O- U1 U1 F, _
  scatter     ;;keep center-turtle random positions ; w. I6 @7 c, m3 i4 g
  unit_plan   ;;make up the building plan
- w: C$ d( h& j2 vend3 j9 y8 H9 ^/ j$ B4 e
to scatter5 x/ Y" F' ~1 |! Y
ask turtles with [remainder who 5 = 0]! W6 ?. f5 I8 e" v! W0 t
[+ j# M. |9 o* z
set xcor xcor - 6 + random-float 15
% {! ^8 z6 U! l1 s2 F- m' b8 Tset ycor ycor - 6 + random-float 155 h$ Y6 n5 k% l9 K$ u  `" x$ r
]
. n) \& g0 k) `0 gend- Y% s" w$ Z; I% }4 C& M  B7 g, f
to unit_plan
' X* g. r' u6 V3 g, q4 L+ [3 N/ _7 hask turtles [
! F8 ~8 D- D( f! h. x) m2 eif (remainder who 5 = 1) [set a who ) E& B. f  b" C- s+ o
                          set x ( 0 - Wid / 2 )
7 b) @8 Z, C' L. r4 }                          set y  Dep / 2 ]. v1 b- O8 [. Z
           set b  int (a / 5) * 5
5 V% u0 ]2 H; E1 g5 }  i    setxy ( xcor-of turtle b + x )
4 N, K6 K. m  @- P4 r, I& H          ( ycor-of turtle b + y )" @9 i& v, O4 I4 D) M+ {: {, g) j
if (remainder who 5 = 2) [set c who6 \0 m" W! P( R) T) H9 q" a
                          set x ( 0 - Wid / 2 )
( G, v8 u1 a4 D/ t4 i/ \                          set y (0 - Dep / 2 )  ]
' d) q& v: p3 y* @3 \8 _! ^1 f                          set d int (c / 5) * 5" |, }1 D1 \4 ]9 [0 o" b$ J! }. R
   setxy   ( xcor-of turtle d + x )
% j1 o: @% U9 a7 n5 U& r$ I           (ycor-of turtle d + y ) 4 f6 `* J" T: P' J0 Y2 h
         
: O4 Y0 h+ X1 a6 Z5 R3 {              I- z+ Y# {* d* _% F! D0 u
if (remainder who 5 = 3) [set k who
; h& j# R3 o4 N  V1 ^; ~$ d# _' L                          set x( Wid / 2)  
# _8 v& q$ a1 d/ J                          set y (0 - Dep / 2 ) ]6 ~/ I7 c5 }+ g
                          set f int (k / 5) * 5: m3 D" @1 _, A
  setxy   ( xcor-of turtle f + x )0 `0 t8 M/ j7 n$ ]% k- F
           (ycor-of turtle f + y ) 9 ?& c1 S+ G9 s) `$ N
           
0 @3 D: \( w6 s+ e) I5 U0 R$ S           
5 h3 V6 G1 {2 K6 V2 Q# g4 g- Aif (remainder who 5 = 4) [set g who1 Z. f* r% ^4 p# F+ a
                          set x Wid / 2 7 B4 _. x  T# E$ T  a' {
                          set y  Dep / 2 ]8 L1 Z8 {1 q  B
                          set h  int (g / 5) * 5
# H3 Q- s0 I1 U' a# g, U4 o  setxy   ( xcor-of turtle h + x )4 G2 C. \, O( D! }
           (ycor-of turtle h + y )
, q/ a) ]4 ]8 U' s5 B                          7 [( L+ E& W0 _
                          
; X* B9 F* K6 G/ B. v* n                          ]
2 h" A( S) }/ z& ~$ Uend! _& Z7 u0 n, M/ S# B
5 @. g- F2 B+ _) z) W2 R: p$ P
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
  }  w" e9 J3 ^8 j" l应该是  U4 b1 h( H9 a: z. l( e
ask turtles [1 n0 A& k  k; R
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )   B* W' X& @: @; T8 r$ ^" X
                          set y  Dep / 2
1 z6 U% ?1 j1 i           set b  int (who / 5) * 5
; t+ r; f" Z6 x0 K    setxy ( xcor-of turtle b + x )
9 I2 Z2 I: H2 ^: r          ( ycor-of turtle b + y )]]! \1 ^1 l2 B- P
end3 Q, l* d) r  w% h& _! @4 B; K& F' V
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-28 03:38 , Processed in 0.016701 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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