设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7731|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
) i) s+ J8 r& i/ z  x3 ^2 t; ~( {$ d. A" U! |, x/ J1 b
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。. e- G* R/ ~% t! i. S. Q
3 F% V- F+ ?% [. t! P2 F- j* G4 I4 z
turtles-own [a b c d k f g h5 B' k6 a9 l2 Q' R0 r% c6 }! l8 Z
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
3 x! y0 P9 _0 {: W! I+ W: j' B]
7 C4 w# V7 O2 U% qto new
# e) h2 L+ |% u" Q  ca
# `0 [) U; k$ F  crt 5 * num_of_building
' [0 b4 Q6 X3 P) b/ t2 J0 y  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
9 K3 h7 j0 U2 I3 Y2 N5 x# q  scatter     ;;keep center-turtle random positions ; n2 ~. s, R9 Y( M" q; j1 A8 f% q
  unit_plan   ;;make up the building plan& f/ L. ~) d$ F, k3 V$ h
end4 u( e/ ]3 I; u+ k
to scatter
8 B2 m! v. M) m% V7 o  bask turtles with [remainder who 5 = 0]4 C6 Z: l! _2 Z6 n9 q9 ^9 @
[
# e+ _7 p# _8 Wset xcor xcor - 6 + random-float 150 H1 j2 j1 r& J& I" p1 h% E
set ycor ycor - 6 + random-float 15
8 B) A1 P1 X. [! `' l2 b! Y: K]
( w. b0 C3 C- g& h5 M! @end1 i- N5 C7 S4 N2 U" w6 o/ c  X
to unit_plan ; b* P# K+ ]$ P$ }+ T! C8 S' ~+ h" W
ask turtles [
/ x- p) z8 m, E, G/ U+ Lif (remainder who 5 = 1) [set a who
0 E" z" d* i  o' ]+ _                          set x ( 0 - Wid / 2 ) 1 l8 N  X8 P2 T/ G; h) G
                          set y  Dep / 2 ]
! H& _/ G* ^8 e0 [8 d           set b  int (a / 5) * 51 d4 o$ z- ?) T" H" b, ?
    setxy ( xcor-of turtle b + x )
* Y3 P6 X- |: P' u" J3 Z          ( ycor-of turtle b + y )& q' w* p- y- ]2 O5 W
if (remainder who 5 = 2) [set c who
  d0 O7 z+ t2 Z( \. Y" k" }                          set x ( 0 - Wid / 2 )
' D! |6 |+ A8 {$ R$ A% k6 Q# z8 ~                          set y (0 - Dep / 2 )  ]
' @" M1 K5 x1 y( t% a4 V                          set d int (c / 5) * 5  \* p5 |7 Z- r
   setxy   ( xcor-of turtle d + x )
1 ?/ j6 f& X9 ~, A$ a& y           (ycor-of turtle d + y ) * C* W- m7 z8 M; p: X0 f* g: B! `
         
' R# ]4 j# F3 S% X+ V1 T/ I% `% `! W            # _4 h3 ~- Y$ z, a1 G5 |
if (remainder who 5 = 3) [set k who
: `3 |9 {: D6 O$ w8 T6 [9 I                          set x( Wid / 2)  2 Y6 m  I9 m2 P* x2 @
                          set y (0 - Dep / 2 ) ], T% Z& A7 k2 i3 T/ f( i
                          set f int (k / 5) * 54 u- q9 \  P  Y8 c5 O! K! T
  setxy   ( xcor-of turtle f + x )
, I% g. P! }( S& |& s. b& k6 l" q7 U           (ycor-of turtle f + y )
" l/ ^6 }, y9 ]) x           
( c5 ?) ~; `% ?           . H% n, P' N8 M, \8 J# P# V3 G: k" M
if (remainder who 5 = 4) [set g who/ F! i. v5 ?3 P6 q6 V& e+ I5 O
                          set x Wid / 2
; f& q$ Q- I$ G7 _# d                          set y  Dep / 2 ]" H9 q2 u  I8 ?* y
                          set h  int (g / 5) * 5
; {0 j5 _& V# G4 j  ^% z' I  setxy   ( xcor-of turtle h + x )
, Z$ A4 M) k- O& ~  E           (ycor-of turtle h + y )
5 `2 \- {3 o2 D5 D                          / ~7 U0 H7 @- m! {
                          # w& z9 k+ _/ u. S
                          ]7 \" B( }8 _4 U
end
) r0 D9 ~' i' {0 C% u9 ^- K# c
# q5 T+ k+ {# _[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,% u9 A, h" a$ n8 {
应该是
: h, ^4 w+ g8 V, T* U2 A/ x1 _, Task turtles [: H1 x- u$ H! \
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 8 e0 t7 j# X& j! X6 Y) h/ z
                          set y  Dep / 2 . F, `/ ~& j' Z- c4 Y6 ?3 ], E( f7 a" x
           set b  int (who / 5) * 5/ R& ~7 i# \  w; X9 ?8 y6 j* G( _
    setxy ( xcor-of turtle b + x )
- i5 |0 r  \6 D, M4 M          ( ycor-of turtle b + y )]]1 e% h( q. ?7 H% u7 O
end
! v- O( g# ^2 X. q3 L; r; R之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-20 18:51 , Processed in 0.017147 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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