设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7535|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。0 C. _, ?1 b0 O1 ], Z

' R5 ~) ~- w: ~4 i但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。4 t5 e' i. T) M- \, J+ ~5 u" J6 U# V

* c- O* i( g+ ~- [8 {" ~9 }turtles-own [a b c d k f g h
9 a6 |3 t6 ?* F7 ?) L  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ! t8 x/ l0 b- r& c8 B0 X
]6 a% @( ~3 F# ?5 G* `
to new% q7 w, E( A9 |7 d0 g+ d0 ~# o
  ca
  z0 @( K7 n& C$ ~+ h  crt 5 * num_of_building9 ]& ?8 B2 @1 U6 j. y4 l# ]
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]/ Y" I( Q  n7 K% J
  scatter     ;;keep center-turtle random positions
9 R2 L& Z( |; ?0 P6 p0 G  unit_plan   ;;make up the building plan, y, z4 o+ c  q1 F) b
end0 t! U1 E  i3 z1 l: F7 O/ n3 ?* D
to scatter( s" v2 U8 t/ l& q. v! i
ask turtles with [remainder who 5 = 0]$ V* Q0 l, v% ~$ ]$ e- @( V
[, o0 D! a( a- d
set xcor xcor - 6 + random-float 157 O. q4 C0 z. P. A, E
set ycor ycor - 6 + random-float 15
! ~" I  P5 V* o+ W1 ~, e]3 M( s/ t$ v8 a7 w! A3 f- D
end7 ~1 D9 O3 M" B1 w, i& Y# H1 g0 K
to unit_plan
' T( Q* x7 b. O1 h. e. P, n0 ?ask turtles [
2 G/ a! C; l# s6 a5 Qif (remainder who 5 = 1) [set a who 3 i6 C, e2 O$ h9 V* i
                          set x ( 0 - Wid / 2 ) 4 ?/ R5 E: O* R2 g& c  ?7 a
                          set y  Dep / 2 ]* v1 N  y. R: ~* C2 R) m+ `" m" J
           set b  int (a / 5) * 5
0 {* `# j) e, M4 B4 s/ C4 X    setxy ( xcor-of turtle b + x )* q, c; F" ?/ s2 w1 ]7 q% Y7 a
          ( ycor-of turtle b + y )  _5 F6 q) U9 [6 g! v
if (remainder who 5 = 2) [set c who$ C8 d5 L# o9 i  T; j3 {# N: t3 r
                          set x ( 0 - Wid / 2 )
: T& A$ m5 a; p8 U; Z5 C: M                          set y (0 - Dep / 2 )  ]7 ?+ {' X, M& F; g
                          set d int (c / 5) * 5
, {2 L5 _. x' S' D! s! I# s. F# k& a   setxy   ( xcor-of turtle d + x )
0 I4 j) G! }8 t% _           (ycor-of turtle d + y )
* Z2 O8 A9 k  [& s; b         
8 n8 c$ s1 h8 m- J            & O+ s7 |& H9 b6 D
if (remainder who 5 = 3) [set k who
0 H9 a( i4 M7 I  u                          set x( Wid / 2)  8 }9 v+ N; m/ i1 H8 Q& A
                          set y (0 - Dep / 2 ) ]/ {5 f9 @) A# _. N0 G9 O
                          set f int (k / 5) * 50 t) M/ c: L+ S+ H  i; J' g
  setxy   ( xcor-of turtle f + x )
& [/ y5 [" j. |/ G8 P5 }9 T5 f* m           (ycor-of turtle f + y )
: b) O  T/ i# |) X! q! G           
! e) z" C$ A! I           ( H- J+ \# y% r5 L
if (remainder who 5 = 4) [set g who
8 }4 a8 B2 w* N& Y+ C8 d* U                          set x Wid / 2
: J; c6 O8 Q7 {( e2 \- v, }                          set y  Dep / 2 ]. Z! J5 U0 W( o4 U- j
                          set h  int (g / 5) * 5
$ x. v2 w7 a. D- f# _+ \; {  setxy   ( xcor-of turtle h + x )
* ?, a, Z2 B8 B1 K- N( p           (ycor-of turtle h + y )
9 H0 i  e+ [. u                          
- j. ?: E7 E0 {0 ^3 v0 E& ~( t9 ]                          
( S% |7 M6 p) G5 s" a                          ]/ B/ T& w7 [. {. i
end
9 _% d! }! V: C$ L4 K8 e$ K  |; ^% H
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
- l8 X; e: Q: t, l# `" K/ Y, t2 a) c应该是1 Q' S  G4 o5 k& a+ j; }& ^* V
ask turtles [- a' R* h# i" C2 \" d2 ^4 Y
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
4 a. B, {( |! S/ U" h                          set y  Dep / 2 $ `7 U4 b5 G! R5 z6 P4 `
           set b  int (who / 5) * 5. y3 S1 u5 [8 G+ I- R4 F
    setxy ( xcor-of turtle b + x )
0 G8 D- R' Q0 E1 E3 {          ( ycor-of turtle b + y )]]
" l; K' ?5 }. ]8 qend, Z# }' z( k1 l4 Q+ B$ _
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-23 05:35 , Processed in 0.021742 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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