设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6654|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
9 F/ b* `2 k* S* G9 F5 g. ?
; M3 }# ~+ s  |4 {+ c但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
! m7 T, ]' G# I+ ?* q1 h! b8 l8 `8 P, t% [# D6 e
turtles-own [a b c d k f g h
$ r3 p6 k* u1 z( @& R2 t% j# R3 Q4 s- K  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
  T0 I( d' w0 ]]5 o$ q. m" D: b/ m9 E6 |
to new
7 B; R6 R. W& V$ R' q  ca! T, i2 P( E1 c! w/ Y! ~% L: x  U$ l: f
  crt 5 * num_of_building
+ p- u! ?3 O2 m2 O0 t& X6 y( V5 m  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
% X3 b& p" J$ I$ M  j  scatter     ;;keep center-turtle random positions
. h  x3 u, y& ^8 r: C2 H- h/ `" h  unit_plan   ;;make up the building plan$ [/ n- [  T9 y
end
- j% K; l# s7 Ato scatter+ W( v5 n1 [0 J
ask turtles with [remainder who 5 = 0]8 p3 m: K6 J. R4 ^  c! I& j( ]: d
[
( a" I. }6 D, i# e, S% C$ Iset xcor xcor - 6 + random-float 15
) ]( W. K! v9 P1 D7 P" Vset ycor ycor - 6 + random-float 15. H# H: |# J, Y
]
9 p0 @. z- a9 x/ N9 Z/ Mend
) V, r" n2 z" |to unit_plan
8 V9 a' l. J9 b% z: u& fask turtles [, `/ p$ A7 f( b) m/ m
if (remainder who 5 = 1) [set a who
# e& h# W8 A9 w& E% v% M7 g/ N                          set x ( 0 - Wid / 2 ) 2 v" j: U( f' J
                          set y  Dep / 2 ]
5 Y* t9 g7 Q" x! y3 X# H* T( q           set b  int (a / 5) * 5
/ b( [2 d9 A2 F; Q0 f0 `& K6 i    setxy ( xcor-of turtle b + x )+ g4 B1 T! S& M5 W$ M8 A
          ( ycor-of turtle b + y )6 t  x& q6 N, s5 c: T. A
if (remainder who 5 = 2) [set c who
% h. G+ @: k3 c( ?4 \. I* j                          set x ( 0 - Wid / 2 ) ( _) Q8 B, d: k7 }& B- q+ U, {4 L
                          set y (0 - Dep / 2 )  ]0 J. U4 S" p+ l1 E/ C% A
                          set d int (c / 5) * 5# w, \5 N4 o! t
   setxy   ( xcor-of turtle d + x )% {. P: ~( W$ _% s0 C$ i
           (ycor-of turtle d + y )
* x  q0 e6 A+ x! _- O! ~" H          % M, h6 j+ x. \5 T
            * o# }6 k3 h# ^  v9 I2 z  C
if (remainder who 5 = 3) [set k who& `& [" k+ U3 j3 c: I2 ?* O% V
                          set x( Wid / 2)  
1 j1 f% r  \8 |8 K2 j5 b                          set y (0 - Dep / 2 ) ]" |; Z) {1 o. |; K: N* a8 Y; M: }
                          set f int (k / 5) * 5
" k! O" ~  `$ H$ P4 S  setxy   ( xcor-of turtle f + x )
. q+ L8 v/ l; ?  I6 W) c/ M           (ycor-of turtle f + y ) : {, C7 S5 q) r! W9 t( c0 v
           / m$ F/ P3 X# S7 F  }) V, d
           $ @3 D, R9 A( |* c2 C" {
if (remainder who 5 = 4) [set g who/ \2 o5 Q( X( h" a
                          set x Wid / 2
+ z; G! ^! ]# {! I) C# v1 d" [                          set y  Dep / 2 ]
7 U& Z" W: G: p! k( |% _                          set h  int (g / 5) * 5. o2 E) b2 L; B8 t0 f! T
  setxy   ( xcor-of turtle h + x )
5 l: m3 D; |5 E# Y2 H3 K7 I           (ycor-of turtle h + y ) * ^7 Z" B) g6 r4 d- t  {4 _* @
                          4 x4 n9 h$ Z/ E4 G! c% |+ V3 n3 o
                          
. D/ V- C: e( q: ~4 s1 X+ U- d, x                          ]. l" B; T  M+ u: d
end
0 n7 C- O  S2 H7 H4 X- _: R( N: l4 c2 ~7 j, @+ s  H' k
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
. p8 N" _& _6 `4 h. U. a应该是, t% [, |( i- k* a
ask turtles [
5 s1 F1 b# e- a! S$ Nif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
7 b  z) y( d% W; C                          set y  Dep / 2 * B2 w' k7 D9 W: L5 c2 r
           set b  int (who / 5) * 5
! ~  K5 f1 }7 g: S    setxy ( xcor-of turtle b + x )- I- N1 H  S" e) T6 m
          ( ycor-of turtle b + y )]]
% {9 k- W; V% |: D5 X( {end% G7 r: Q. c- r; J! O9 k1 E  x
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-8 10:34 , Processed in 0.013650 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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