设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7396|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
: a/ ]/ |/ k0 i/ _) L; Y* A
% T/ v" Z4 O8 |0 ]但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。% e( ?& F3 z! ?; B1 t  r
% l5 z) E- j7 R, V9 G! j
turtles-own [a b c d k f g h
; w- L6 E! h& l. E' G  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
" Y, `2 J$ d- r" q, [% ?# w( M]8 k# a8 g. p3 C$ D' w
to new
8 B: m) s8 }& z$ S- e% q6 }) a  ca1 Z: j, K* l# G# z
  crt 5 * num_of_building
+ }0 |. N5 _% R1 G  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
. k) J! c1 a0 V( I! e' F5 `. N  scatter     ;;keep center-turtle random positions % O7 P; d/ O3 Q, M3 F4 d8 @) j
  unit_plan   ;;make up the building plan( e- Z, c: ~) G1 G. N
end
: r# i6 j# e; {to scatter: i! w4 {- F; @, g7 i
ask turtles with [remainder who 5 = 0]
6 z! ]1 B+ m( I& E: D+ |[! G; Q, K7 m: k% |  S
set xcor xcor - 6 + random-float 15) ?5 t& c4 X' t* D2 E7 G1 W
set ycor ycor - 6 + random-float 15
) l7 Y: P4 ]  j. J]* u' C3 [0 c* @9 C+ Q: H' d
end
  ^5 c3 C8 B- A1 r3 {8 P( Kto unit_plan
- G) p  l5 w# K1 N  Fask turtles [
7 a7 ]4 M3 @3 y) `1 S5 t  z! }if (remainder who 5 = 1) [set a who
$ i9 p. Q- J, y# j8 _  P7 \( c( [: K                          set x ( 0 - Wid / 2 ) 8 |3 m7 P. D' \
                          set y  Dep / 2 ]
0 P6 h5 ~+ R2 O( ^8 ]: F0 f2 f. B           set b  int (a / 5) * 5$ [- T, l3 s4 [3 {5 d6 `
    setxy ( xcor-of turtle b + x )1 Q" O" _: ]+ t3 ^- M
          ( ycor-of turtle b + y )
+ t) @) U3 D' u- G' t" I2 Eif (remainder who 5 = 2) [set c who
2 i0 T- B  c* S* C( o3 P                          set x ( 0 - Wid / 2 ) - r5 V3 ?& H2 c: B2 B  l& q# ]
                          set y (0 - Dep / 2 )  ]
: R: a/ u4 I9 K) {/ x                          set d int (c / 5) * 5
3 Z6 |) T+ H6 x0 l! p   setxy   ( xcor-of turtle d + x )
/ j" c! K5 a% w5 ~& o           (ycor-of turtle d + y )
# K5 V: f5 D& g! l          9 L! H% q+ y3 |
            
& j6 H6 l6 t2 x& qif (remainder who 5 = 3) [set k who
) U' G6 F3 J/ _, L                          set x( Wid / 2)  2 K6 ~, O& A! s: I* O6 G9 h
                          set y (0 - Dep / 2 ) ]
6 ~; r6 h. ~4 Q7 b( ~                          set f int (k / 5) * 5+ H* `" V- H( \4 p
  setxy   ( xcor-of turtle f + x )& c0 c3 O  [% S/ }
           (ycor-of turtle f + y )
1 F% U, r' d. R; f           , c9 i& j8 ?( H/ t! I7 S! b
           
( y0 I6 q% T4 ^* {if (remainder who 5 = 4) [set g who
- N$ \4 F% [$ [; r7 {: g                          set x Wid / 2 % J% \$ n* e0 b1 y3 ~: o; w
                          set y  Dep / 2 ]* m2 P' K' m3 r5 T) O% I7 U
                          set h  int (g / 5) * 5' k3 y( b9 D5 M. A( f
  setxy   ( xcor-of turtle h + x )7 |* L; Z2 t# d9 t$ \9 h( F
           (ycor-of turtle h + y )
4 P$ h6 {% C3 o6 o+ D0 O                          $ G$ K7 ^+ F% A' o  a  @
                          
0 P  g1 v. R$ s, v9 O5 o                          ]* u% W3 `' Q. E7 l2 m
end5 @  ^; _, M, L6 a; T

0 l2 Y7 W% H7 T$ j0 B8 Q' B0 r* s[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,7 |2 \$ ?/ ?5 d0 ~+ z% z
应该是2 p+ Z# \$ m% O# W. W/ t
ask turtles [8 @7 F9 R! d! d5 U" n3 a
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) - d2 ^( |: ~! C
                          set y  Dep / 2 + W2 {! |* o$ K; z
           set b  int (who / 5) * 5
) \- G) m6 d3 a; L% B    setxy ( xcor-of turtle b + x )% H: l) j/ {9 E4 q. K
          ( ycor-of turtle b + y )]]3 i; O5 n+ ], z( Q" j
end$ S4 ~1 t5 _* z7 E- k
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-8 00:37 , Processed in 0.015289 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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