设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9168|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
  q/ Z+ N& f( G8 Q8 i0 u, Z8 K! y" R7 {" o  y
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
! C- t7 Z" j3 K, m4 k* Q: C' i* `/ u( ~4 l/ O3 Z
turtles-own [a b c d k f g h9 \6 k+ Y% K# j7 Y7 d; ?0 H
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
# e( B9 J) @$ `" S3 O/ m/ o]/ @% c6 L; W# I& O- A
to new
. M" E% p- X) |  ca" b" y2 y0 J( W1 K! q# j
  crt 5 * num_of_building, a, }% I8 p2 D4 T- v: P$ S" D5 g
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
0 T- `5 d' N) H; q+ c) T" @/ T  scatter     ;;keep center-turtle random positions , g! s4 y5 f$ b, k' |( {* j4 d  J7 O
  unit_plan   ;;make up the building plan
: O1 N7 w. ^+ S, ^9 g. A( P! Qend
2 n9 L4 P; l. l& I  Ito scatter
7 q* Y* L& ~. dask turtles with [remainder who 5 = 0]2 _! U! @* @  @$ n
[) \3 ~; f) C& C& h
set xcor xcor - 6 + random-float 15
+ k6 ?) {+ P* o( ~# V. f5 a+ k! O) uset ycor ycor - 6 + random-float 15
/ c/ V$ ~8 c9 V]2 ?7 W# V6 Q4 ]$ I3 H& @
end+ k4 m: d4 a( R4 V# d! |
to unit_plan
% @" ~; u8 U! Uask turtles [
; A8 Y! p, c- b! p2 }' B5 _if (remainder who 5 = 1) [set a who 4 C0 `( h3 `9 y
                          set x ( 0 - Wid / 2 )
  x. s6 z$ B( I2 @# H: d4 m                          set y  Dep / 2 ]! y3 k, M$ o7 t) |
           set b  int (a / 5) * 5$ V1 ^3 y* c# i* }  ?7 N
    setxy ( xcor-of turtle b + x )( u) F& r' P+ [6 ]! O
          ( ycor-of turtle b + y )# F' a/ w, R* }2 V/ E" }9 E4 n9 ]
if (remainder who 5 = 2) [set c who6 o! {- Z* x3 C, i( |0 p. A  v: ?
                          set x ( 0 - Wid / 2 )   a4 j7 ?" d' }- [* r
                          set y (0 - Dep / 2 )  ]2 k& F8 Z; b& k. \  s
                          set d int (c / 5) * 51 ?; z" f" s' A( G2 b: u& n- C* s& V+ `
   setxy   ( xcor-of turtle d + x )
, r; y' R% ?2 S& J% S' I           (ycor-of turtle d + y )
" x/ P3 `5 t9 ]; T          5 C2 i  m/ r) O
            
( Z: j0 F) Q' b4 E( I- \if (remainder who 5 = 3) [set k who; ?; S! @; N1 _3 \
                          set x( Wid / 2)  
% w! h9 H2 @% e6 \- N- v: p, d                          set y (0 - Dep / 2 ) ]
6 G/ n# ?+ k) m) h6 s' ]                          set f int (k / 5) * 5
4 ~1 {3 R7 b7 c6 U  setxy   ( xcor-of turtle f + x )
" d+ e) [. m% y1 D4 q           (ycor-of turtle f + y )
6 l! f9 j& S4 Z. |           
+ o  o. z6 J& n' {; b           
) p8 m/ j, G/ }; z  B! D& A$ S7 Dif (remainder who 5 = 4) [set g who
" j7 _7 U# Z/ f! \2 P+ a                          set x Wid / 2
: N( s5 M$ `: W: r( h: W# e                          set y  Dep / 2 ]- P* U# x! E6 R
                          set h  int (g / 5) * 5
+ I6 i* v% K, e8 s% c  setxy   ( xcor-of turtle h + x )
) M( }- D+ B- K# B1 ]( h           (ycor-of turtle h + y ) 3 e) y- a, w* o  Y9 D6 w  a
                          6 W% U. g. }3 q+ G( C& W
                          
! ~8 b9 c( j' W0 j" Z; k* s/ P* Q' `5 h- b# H                          ]
: }4 H2 J3 P/ L! [+ b8 k! qend: A+ K' E5 m4 y5 x

6 i' S9 N1 ~' o. M. ]2 Z8 f  T: h[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,: ^- e0 n" h; z* Y5 P
应该是0 k1 S$ L6 y- U3 _! |" U8 F
ask turtles [
6 s( T/ A  Q" Z4 b" D* ~8 G+ V* Z8 d$ uif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ; n4 H- T3 L3 E$ s' e" j, s
                          set y  Dep / 2
& p1 j& s8 L! h6 E- f" L           set b  int (who / 5) * 5
4 p5 `0 ?$ q2 {: ~6 i    setxy ( xcor-of turtle b + x )( m8 @# \% L) ?. I$ ~/ d$ q
          ( ycor-of turtle b + y )]]
$ t  Q. y; i; i: }0 Q' n& m$ Bend
8 c% T/ }5 v0 E$ B2 l之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-24 12:06 , Processed in 0.020616 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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