设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7980|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
5 w8 x4 }( _. m  ]# J1 a
8 x" S" C: W, S4 j. F4 g但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。) K+ i/ b% ?  L1 b" O& `$ ]
7 Z4 i- ?0 |% E
turtles-own [a b c d k f g h
5 E3 ?6 U2 w3 c/ }, d% A  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
: r( h0 L2 u. w* e]/ i! O+ `* }4 a. f$ f. s! s$ n/ k: e
to new- R% `1 b) Y4 e; T4 F2 ~4 u0 f& A
  ca
6 `! a6 K/ k1 h( t- A* L  crt 5 * num_of_building4 m6 Q* K3 {0 R: c: Y
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]! s- x) ?5 `, t
  scatter     ;;keep center-turtle random positions
; n  h" @. d/ E* V+ \  unit_plan   ;;make up the building plan  q- ]& A- ], ^8 C& k0 s  g
end+ v; q7 D! ?1 q8 V( \# G
to scatter' w7 N4 g$ `  k0 ~! F! W
ask turtles with [remainder who 5 = 0]
' o5 A- j6 h( `: C2 r! I/ v) @[9 _; }, ?* p& i1 Q" y
set xcor xcor - 6 + random-float 15/ A) \: b( ~! l7 ~, D3 X( G- J& f
set ycor ycor - 6 + random-float 15, w" C, G( x" U
]  c& {1 W! t' q# w, D7 @
end+ U* s( S) X" \0 ~9 R- z8 K
to unit_plan
7 [" F" _6 X: {. ^+ w$ @% L& Task turtles [. b7 \) @9 d# w9 G6 ~
if (remainder who 5 = 1) [set a who   t, P( L$ `1 k/ c+ z' t& w
                          set x ( 0 - Wid / 2 ) % |7 m( p4 ]6 u2 f2 M: k* R
                          set y  Dep / 2 ]
7 L% Z* w7 A  {3 g1 Q% l: o" i: [           set b  int (a / 5) * 5# k2 ?& o( B' X: ~- b
    setxy ( xcor-of turtle b + x )
  m2 ^  L8 X5 c( N( u5 _" ?          ( ycor-of turtle b + y )
' J& U# J' F3 V* }+ Z: Oif (remainder who 5 = 2) [set c who
  n& V8 ~9 I1 G- D; z; l' h/ l3 g                          set x ( 0 - Wid / 2 )
$ w! g6 h. x: [                          set y (0 - Dep / 2 )  ]
; M$ |# H/ G* w$ S* j2 X7 R                          set d int (c / 5) * 5
0 K9 J. J  H$ Z4 X  R2 w- z; w   setxy   ( xcor-of turtle d + x )5 X0 d* C' M: N. w6 G
           (ycor-of turtle d + y )
2 J1 R7 p, Y. e) Q8 z          ; f7 K! J( \9 H  b% M0 k
            
- o! ?& V+ C, U- Iif (remainder who 5 = 3) [set k who- b' E) ?" U; d
                          set x( Wid / 2)  
8 n" Q4 d8 X7 l' s  h# R8 F- w3 s/ w                          set y (0 - Dep / 2 ) ]' e$ w9 q; H( s4 b
                          set f int (k / 5) * 5
: L7 Y9 p$ z4 A' [$ e3 I) ]4 N  setxy   ( xcor-of turtle f + x )
& `% K3 q% k3 C2 e8 h0 d           (ycor-of turtle f + y )
, v0 `6 ~  ?7 O1 u           
1 S9 y' H! K( q. Y           
. P  `4 M% v7 Lif (remainder who 5 = 4) [set g who+ F0 U$ V: B0 U% _8 A
                          set x Wid / 2 , h0 L; w9 d: @4 n5 K: o0 [) P
                          set y  Dep / 2 ]
6 Y* E0 k0 {4 z/ y                          set h  int (g / 5) * 5
0 F. j* r# ?# ~3 h9 k  setxy   ( xcor-of turtle h + x )
' E: R% A# m/ ?! X0 `0 e           (ycor-of turtle h + y ) / R7 P* l, d+ S" L! I0 R! h& p
                          
+ F4 k6 W( _  G. _: ?                          
; P( x7 {  @$ k" c                          ]
0 d8 s; ]4 A3 ?: v6 Qend
8 L, I  V; B8 }5 g# U; u2 N5 v5 L& Y# _6 J- J
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,7 w& {2 k1 W3 k, e( R2 ^6 R, K3 v
应该是4 A1 n( r: [6 g" j# g
ask turtles [
" F- V$ t5 d$ @1 L4 ]if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
2 d6 {, [( k% b& H0 h. p" h7 C! Q* s                          set y  Dep / 2 9 U2 Q$ x3 h6 S* j: o! q5 t- X3 v3 |  k
           set b  int (who / 5) * 5
: l0 w5 e( L. p  R- ~    setxy ( xcor-of turtle b + x )# ~# j% ]2 V2 p/ c, S
          ( ycor-of turtle b + y )]]
8 M1 D6 C+ [4 v/ N" Q2 Mend
  z& F1 e/ [% c之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-24 11:39 , Processed in 0.014212 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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