设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7838|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。3 {# w) a3 W  C5 J! s

0 J& |' B/ E8 |" W# y但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
- Q4 ~- F3 J) Z, I4 l8 z
$ y' s" E. y- Qturtles-own [a b c d k f g h
( P6 S5 C+ Q0 L" L. @2 q5 G  x y     ;; these are the leaf-turtle's offsets relative to center-turtle / X6 [6 G- U5 q" f" O- h' i
]2 `3 O9 g% D; T+ o9 Z
to new/ \* X  H7 q% U2 _' |* R
  ca
* c" P& o2 t0 X+ v) ?/ t" R  B  crt 5 * num_of_building; J( Y& @; \0 a* R1 s( M) a8 ~
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]: F% u; K  Z; T! L; F
  scatter     ;;keep center-turtle random positions
* [( q! A9 W" V! i  unit_plan   ;;make up the building plan8 B: U2 [. T; w
end% k+ B! s- x8 L4 l) Y; n5 |
to scatter$ c# q7 J* Q/ n# f  n2 F3 L
ask turtles with [remainder who 5 = 0]. l" k9 C+ ]$ Z+ e% j7 |
[
# g% X" B6 N% Q/ Z2 L3 i. v5 lset xcor xcor - 6 + random-float 15
* i4 o' V  e2 y' T/ i1 {set ycor ycor - 6 + random-float 15; Q$ q5 l% }0 c4 T4 [( h+ M
]3 i5 l% u6 w% Q( L1 F" J
end
1 R' P& `+ }: i5 L( Zto unit_plan
$ r3 {# B" r- N; L/ j' {4 zask turtles [  i3 [9 _, \" L# g- f- p
if (remainder who 5 = 1) [set a who
& D/ g+ ~- Z9 R( Q; C( }                          set x ( 0 - Wid / 2 )
3 W! `  S3 |, ^0 l. C                          set y  Dep / 2 ]+ l. U2 A6 k& ]# E; Z7 {5 \
           set b  int (a / 5) * 52 k- |5 \% y4 ^) t% J, q1 E
    setxy ( xcor-of turtle b + x )
4 o! V" U- ^7 b) f  E          ( ycor-of turtle b + y )
9 j8 {9 X8 Z( t1 F  X9 oif (remainder who 5 = 2) [set c who
: Y0 J) K$ I0 C0 a                          set x ( 0 - Wid / 2 )
" q- g/ z$ k, C4 l; b  v& ~                          set y (0 - Dep / 2 )  ]
1 A5 M2 ]& Z* c4 U5 m6 \                          set d int (c / 5) * 5$ z# s9 C6 j$ P+ F
   setxy   ( xcor-of turtle d + x )
/ L/ P' U2 M8 R6 t) M: [7 I           (ycor-of turtle d + y ) # K: n1 e! H3 \6 f/ a7 k+ B
         
% A5 b2 n7 e9 }0 h% f* b5 k            ! ]; G" X" X! Q, @! K! N
if (remainder who 5 = 3) [set k who+ d: I2 J( m7 t; ~/ _' s
                          set x( Wid / 2)  + }  l6 h- F7 \) V" D* W
                          set y (0 - Dep / 2 ) ]' j+ R* p$ S6 G; L
                          set f int (k / 5) * 5
. B( _! j- J: ]& f) X4 k  setxy   ( xcor-of turtle f + x )
- j' O" o" d$ P/ @! X: E           (ycor-of turtle f + y )
, `1 P: m: @. K: |  y0 c           
$ j" [) K# v/ Q" _( X9 J0 t' M           : ^. z2 H# w8 M2 R
if (remainder who 5 = 4) [set g who
# y! h7 W# N6 `                          set x Wid / 2 7 a/ \7 c& m7 s9 [+ }6 \
                          set y  Dep / 2 ]
2 A9 y. ?% ?) t. m' U0 h  F                          set h  int (g / 5) * 5
) y( z% T5 ?: K! t) ^# r" b  setxy   ( xcor-of turtle h + x )
# A& P- Q1 s% q* b& p! O6 v/ V' O           (ycor-of turtle h + y ) 9 I9 p5 ?5 _, @
                          
0 |  D5 D2 @+ O. ]                          $ h4 O! B8 S* k+ H0 E
                          ]
- }& D! K3 R' S$ \  d" |6 b" zend
4 J7 j" W3 ^+ {6 d6 F/ H& G
4 L( b" ]5 _$ O# E8 \  b9 N[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,1 t. n! `* f! K$ k9 \3 h  ^5 J2 p
应该是
  f6 F) q6 V- }  b9 qask turtles [
  x6 h. Y7 G+ d8 I! ]$ E. ^8 c* Lif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
7 ]2 X, z: ]) K9 l% U; g& w& S                          set y  Dep / 2
  _7 _- ]# F- \0 N           set b  int (who / 5) * 5
. A8 S: Y/ z5 J( o    setxy ( xcor-of turtle b + x ). r9 Q; e* D' C1 u' b% y- ]
          ( ycor-of turtle b + y )]]
& I; N$ H$ d0 s4 z3 L  x- uend5 ]$ f! w5 N; ]/ q# K
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-7 17:45 , Processed in 0.021646 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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