设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9161|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
/ H# y& n. p8 J3 D7 t6 c# h( l
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。- I1 L+ u4 e! n* S2 D* _9 {5 i

% d' s7 ?& q! x. I" \3 Vturtles-own [a b c d k f g h
' L1 Y" ]8 q; G; ]  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
' k" ~: V" U8 P8 _" Z$ p  e]
* R* z3 J# w7 W; a+ }to new* Z1 d9 z$ J0 L$ x* D# J- k  q5 s
  ca
9 ^  V7 [- N% j" d4 f  crt 5 * num_of_building
6 z: z; [; a/ p2 q' V  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
- q8 j" R0 e+ N( O9 I" v9 f. w7 ?, n  scatter     ;;keep center-turtle random positions # Z' `) k: A5 n) I9 I
  unit_plan   ;;make up the building plan; g$ ^7 R% z6 C# f5 G/ }: O
end% c! X2 a7 T% d3 B6 H4 w9 b8 b
to scatter( o& J7 B6 F4 F& k2 U! y0 X
ask turtles with [remainder who 5 = 0]
3 _! T& [( W! g) \4 i7 ?* Q+ e; }[& e4 T0 H3 a# x! Z! F8 j
set xcor xcor - 6 + random-float 153 `, I1 @/ l. G8 Y
set ycor ycor - 6 + random-float 15
2 e! D- c. D/ N, }; A" j]& S4 s6 z7 L' o* T# U6 |
end8 B  d% X& q" t. g: I
to unit_plan
( L; v0 @( ~) n7 L/ M3 @ask turtles [
# y7 ^$ J; h0 Q% I* lif (remainder who 5 = 1) [set a who 6 }: H' |0 d+ Z! d$ }
                          set x ( 0 - Wid / 2 ) * e3 A7 z3 b2 o3 f1 R
                          set y  Dep / 2 ]
: a( u$ }# l  e( p% j. {4 a/ w           set b  int (a / 5) * 59 z; D0 I7 Q! ]
    setxy ( xcor-of turtle b + x )
6 R8 H5 z( m# J" [, I% ]          ( ycor-of turtle b + y )
# t; q% d2 J0 I( V5 j' zif (remainder who 5 = 2) [set c who
0 c9 d9 |9 U. v6 `9 P9 C4 _4 C                          set x ( 0 - Wid / 2 )
: z0 R  `3 X. @" M" D. j2 t. v5 [                          set y (0 - Dep / 2 )  ]2 b# X/ c  k! n6 K1 f
                          set d int (c / 5) * 5
" [4 G: r7 J: c5 @  T7 k( {6 v) ~   setxy   ( xcor-of turtle d + x )
" L4 I" }! @# M6 K! w           (ycor-of turtle d + y ) 3 t+ r: \6 g, Q# S. `
         
" [5 w7 g, k, R            
' x! o$ I3 h& Y; T6 mif (remainder who 5 = 3) [set k who3 M; e" r! i) I. v% W1 W: Z6 G1 w
                          set x( Wid / 2)  0 }! A$ S( s" z! f- X+ ]
                          set y (0 - Dep / 2 ) ]' O5 w6 m* ?9 i
                          set f int (k / 5) * 5
" h, c, I4 p# I8 j. ]% [7 O4 @, ]  G  setxy   ( xcor-of turtle f + x )
% }! o" J: Y7 M0 t! }           (ycor-of turtle f + y ) . W) ]" r( t$ J# C8 `( _0 o1 u# C( P4 n
             B4 \% O  {/ l' n) i
           7 u8 m! E: W0 x4 S. h. {; V& w( m  ~
if (remainder who 5 = 4) [set g who7 w6 ^% @; ^3 h9 v8 a- P
                          set x Wid / 2 8 n8 d- ^8 |) L4 F, E" w  b3 R* p6 S
                          set y  Dep / 2 ]) M$ \( O  N6 u! C
                          set h  int (g / 5) * 5/ S7 _; I) S" s3 `
  setxy   ( xcor-of turtle h + x )
' ^4 A- A8 h3 `( I+ F- h4 y! l           (ycor-of turtle h + y ) 5 I5 ^' }, c4 X$ q  p
                          * u% Z  C1 m8 b) @2 t
                            ?5 R8 {2 t) E: L
                          ]4 X6 L6 }! ?" x: K' s9 q
end
* Z/ T" E( V- L% t# l+ Y- d' Y3 y" \/ t
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
" X: D4 ]/ }, F4 U应该是; C2 r% v7 r6 Q: O
ask turtles [- D# b. |9 k) U/ p
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 3 T# c# _! A) h1 k& Q$ d
                          set y  Dep / 2
: L; M% T; l5 C: v           set b  int (who / 5) * 5
9 P; N  ^; J% Q9 p- h    setxy ( xcor-of turtle b + x )
5 [4 Z2 k; l, d/ Z& ^1 u          ( ycor-of turtle b + y )]]
+ `7 O( Q, G3 x9 d4 g0 w1 a: Aend
3 D( d$ {/ V7 X, Y' v( e6 K+ A之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-23 23:15 , Processed in 0.025216 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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