设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7636|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。: ]! Y2 q  h" F. ^5 ~; E/ |* R

5 U% E! |! `1 y: x* B但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。4 N$ _% |, w/ b9 b

+ h! O$ B2 ]# a2 xturtles-own [a b c d k f g h
2 n6 q7 |  A' R/ _  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
: V/ y, z) D( i& F]1 G. k' a% q, g5 R+ z4 \
to new5 j* \0 K! T' E' x7 Z& N. H4 C2 d
  ca# ~" p$ S5 Z4 q( ~* ^& ]
  crt 5 * num_of_building5 ~1 \3 g' s( B! R# K
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
4 W0 b" F, U% K7 C* C& O/ _  scatter     ;;keep center-turtle random positions / f4 {$ ~* W  Y. W
  unit_plan   ;;make up the building plan
+ w) a4 e+ x/ {) B( `* Uend
/ T% h0 _5 ^9 B9 m) q! |; Kto scatter
! p4 J  n: Z/ y7 e2 p# Vask turtles with [remainder who 5 = 0]" S# z# x3 t5 U
[  z' g8 [# g5 H/ _- e
set xcor xcor - 6 + random-float 15
# h; Y& x0 p; Q% H2 @4 _set ycor ycor - 6 + random-float 150 L, ]: V" M. F' f, [
]5 J. n# v. b! [# q0 y+ ~7 j: P4 P
end
9 y8 u2 ]# f; G, ^5 sto unit_plan
2 b, Y3 O+ V* X! {ask turtles [; _7 N! |# p% y$ D5 n) I7 ]! ~% Q
if (remainder who 5 = 1) [set a who / t# Y3 U! j$ v0 z9 [+ c
                          set x ( 0 - Wid / 2 )
& Y9 d/ J) u. N1 t! f2 O. z2 T                          set y  Dep / 2 ]: F, _; n5 D( m$ \8 K0 ?
           set b  int (a / 5) * 5
" W; |1 e- S& B; H. d  T    setxy ( xcor-of turtle b + x )
: F% l7 {' S7 Y* Q" T. s          ( ycor-of turtle b + y )& }; q! U+ Z3 d- g
if (remainder who 5 = 2) [set c who
7 S: ~% P, w$ U' Z- q/ h5 d' ?; W                          set x ( 0 - Wid / 2 ) 3 }6 }5 `; Y4 I9 {" n; q) |9 ?
                          set y (0 - Dep / 2 )  ]3 D* M3 M. L) c2 C6 {
                          set d int (c / 5) * 5
& H; u* z  s1 k- s: G   setxy   ( xcor-of turtle d + x )
3 i4 \2 s* n( C$ ?           (ycor-of turtle d + y ) " |$ h6 V8 H# F' M2 l( G0 C
         
: A" g, G/ {' Z& H            5 o  n, D- m- Q& Z, ~
if (remainder who 5 = 3) [set k who
0 F0 w" ~) `' C6 X% t% i                          set x( Wid / 2)  
5 Z/ }5 z3 z% B$ u& O7 D  {                          set y (0 - Dep / 2 ) ]
5 d* f2 I& ~- R3 g4 }: R                          set f int (k / 5) * 5
0 E. n( Q( @' v8 V  w  setxy   ( xcor-of turtle f + x )
# g1 _- m! w8 X- R2 X& `           (ycor-of turtle f + y )
7 m+ @7 u. X& N; N6 n) ^5 z2 m           
& e! w' w7 ?. ~0 ^+ B; R           5 f" V  Q, }1 h' h
if (remainder who 5 = 4) [set g who2 a; U* c' E- g3 o* G
                          set x Wid / 2
) h+ {  X3 A0 ^9 H  B% u                          set y  Dep / 2 ]7 i$ j9 S7 U1 ?$ Q! x
                          set h  int (g / 5) * 5
2 D# A# g- [' N9 m: g% {' T  setxy   ( xcor-of turtle h + x )
# e2 M6 b$ U+ J0 c5 |8 u, v           (ycor-of turtle h + y )
( Y  ]) _8 k: m* y5 _4 I" n                          
/ M/ h6 [( S/ }! Q                          9 {' b% g: a# e. z$ B  n
                          ]) S7 \5 o# i2 S- T$ b1 ~  P+ S9 _% Q9 ^
end
. s, t0 m; X, K2 }: Z
3 }0 Q2 S" ]( G2 H5 B. a[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
1 }1 y0 `5 X! i1 b1 o5 w! S" M应该是: C+ @: N4 u0 b$ r- ]0 {2 ]3 x
ask turtles [  U4 |7 z( E" N3 b2 U) P8 f
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
) M4 j$ D+ t. i, N+ t3 Y& A# C1 O                          set y  Dep / 2
6 L9 t4 B' x, Z           set b  int (who / 5) * 5
4 o8 n8 B1 F3 g    setxy ( xcor-of turtle b + x )/ ^9 W% A- c3 C1 V) I4 a7 T& p
          ( ycor-of turtle b + y )]]5 }$ U( o2 u" g
end
' X2 Y' A1 e! N! a4 b之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-9 18:47 , Processed in 0.017058 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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