设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7674|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
  c* [& d  h: S* ^! `5 O
# ^& K: u* Z0 P. z: w$ s但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。4 S- o+ Z; D0 x/ u7 p
+ h& t; M. C& E# Z3 c" c0 g9 y
turtles-own [a b c d k f g h$ |1 n8 E& P& e
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 4 U" X) H4 X: ?/ G/ x$ S
]* S' V$ O, N$ y1 d4 k
to new  M0 _# B6 b+ H/ x3 `8 `
  ca3 k# j3 d2 W* f) m! u  R
  crt 5 * num_of_building- U; |  l& p0 D$ e
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
0 P4 l7 O& s7 Z! Z3 ~2 C. h" w  scatter     ;;keep center-turtle random positions ) U7 u. j  T$ i/ M8 m* D) l
  unit_plan   ;;make up the building plan  }8 E% }, W; q  o9 ~) X  j
end
, t4 j/ u" x/ z, W/ J8 [6 C  fto scatter
8 j" A! T' z9 I0 Rask turtles with [remainder who 5 = 0]/ f$ Y" t4 A, w# Q: b
[- U+ o5 k$ m) k, C, P" W8 `
set xcor xcor - 6 + random-float 15
% }( Y. L. q' x- P5 J& ^set ycor ycor - 6 + random-float 15; \' F4 l7 a  {; v! ]8 ]% }# \
]0 e8 M! X. z- Z
end8 w, O- r3 [( i$ c7 ]
to unit_plan
  G5 Z  D3 U1 K7 r3 Z0 Dask turtles [
: k/ f; l; U; i0 J4 D+ iif (remainder who 5 = 1) [set a who
6 [3 @# ~( p' s9 {; B3 r& f6 g; A                          set x ( 0 - Wid / 2 )
+ d* `" s" y  ^9 {/ @( y                          set y  Dep / 2 ]
0 o3 R& w+ i) H8 z0 J+ U* `' M' |5 C           set b  int (a / 5) * 5
9 i7 H0 h; Y1 J" n- e2 m! R1 y: N    setxy ( xcor-of turtle b + x )
- y9 S0 u3 l, B6 ^/ ?          ( ycor-of turtle b + y )  M  n3 A0 T/ k1 L& c% C
if (remainder who 5 = 2) [set c who; {# M" i; f+ Y
                          set x ( 0 - Wid / 2 )
2 G# S. Y, N3 X2 y) P                          set y (0 - Dep / 2 )  ]
0 B6 U7 Y9 P- L4 K; Z: h2 v                          set d int (c / 5) * 5/ x$ o$ A+ b' }7 v
   setxy   ( xcor-of turtle d + x )
5 |1 {) X# K: s! I& V           (ycor-of turtle d + y ) 2 ?0 D; n9 X. W  P) `7 Y, C8 J
            L4 r0 T' |' a) _9 C% D6 r' R
            3 `' r# h' g, n% H" r3 g& {' T/ Z$ X
if (remainder who 5 = 3) [set k who* x3 Z: N7 [+ n! p: I
                          set x( Wid / 2)  9 ^' V' ]3 V4 V
                          set y (0 - Dep / 2 ) ]
& {! b$ e! O, t4 @                          set f int (k / 5) * 5
4 L; ]7 a' w5 D/ ]0 S, }  setxy   ( xcor-of turtle f + x )
/ k! a& a* ~8 Z; b5 e9 Q, y4 O           (ycor-of turtle f + y ) 7 R; `2 b$ d$ o$ N) Q& }
           
+ b7 `) g4 a' s  t# h           & b' U, N" `4 P- V2 O( F3 {
if (remainder who 5 = 4) [set g who2 S" ?. D& I" @3 V- {% j4 l; o
                          set x Wid / 2 0 F! z3 ^+ y) ~& ^6 J5 b
                          set y  Dep / 2 ]  c& ]! a+ F4 O; g
                          set h  int (g / 5) * 5: D& n5 j$ E) T) ]$ H
  setxy   ( xcor-of turtle h + x )! H1 b" Z7 ]. m+ \
           (ycor-of turtle h + y )
+ x( p) O. m- \, _  i0 r. z                          
" d; |) p* u4 v4 A/ o5 }9 I                          4 K- {  ~1 x+ X5 M0 H7 h
                          ]7 v2 ~* X* U' B3 x
end; S1 _, G& k  U% A, E9 F! e* }
2 q: i8 S& ?) c$ M
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,3 _6 Q; q" s# X& _. M: R
应该是3 g4 X% s5 y( g' _
ask turtles [1 y1 l( c9 P! T5 z" U
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 0 B/ a/ @+ r5 ~8 \% u& p0 I6 X8 |8 }
                          set y  Dep / 2 ( G7 o7 I2 H! V5 O4 `# ^
           set b  int (who / 5) * 5% K  {( Q3 u1 s& A! r5 l& L
    setxy ( xcor-of turtle b + x )" f3 p% A6 |- c* A9 L6 p# y! V
          ( ycor-of turtle b + y )]]# y& {- x3 W4 W: Y! E
end* g. ^# [! E( D" Z  q( _; E2 W
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-13 10:46 , Processed in 0.019832 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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