设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8313|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。! T' M  ^: U9 |  p2 r# _

: `6 E  `  Q" b+ _0 e. X2 Y但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
- A0 {% g9 U/ @. e' }2 T- ~
, J: }0 b2 |" P7 \turtles-own [a b c d k f g h
5 T+ A, ]6 p% X9 @7 F  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ! k. z" Y2 v; F, a7 t
]
6 P7 j% c0 t" ?. u/ {3 z, Bto new
. v; Z; A8 X- u- r  ca
6 k: a' \$ C. O5 ~  crt 5 * num_of_building
1 z( H/ Q3 v  x8 o% L, W3 h  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
0 b  I+ Q+ L/ c# k1 s* N  scatter     ;;keep center-turtle random positions + |# m, ], l0 L; s9 H: R
  unit_plan   ;;make up the building plan
0 [( T! F0 T, e9 R6 Q0 @  B- J/ ]end
' c: \% f1 s8 L5 ^4 E' k' Mto scatter/ a- e1 B6 _* O
ask turtles with [remainder who 5 = 0]
5 R0 [! `" A4 T+ u8 z+ P" r[. h0 j) C1 b# r2 E! V/ ^
set xcor xcor - 6 + random-float 15
+ J, _* O4 k! lset ycor ycor - 6 + random-float 15! [. Q7 t; ?+ P! ?- j$ p8 q
]8 B7 x3 d# S  L' O
end
& S2 S( E3 p' V- _3 u1 Gto unit_plan
: Z% x; ~, k, R9 Q0 pask turtles [
+ p/ N: T8 r0 d9 gif (remainder who 5 = 1) [set a who
) ^$ ?9 j  c6 n0 _/ D6 R                          set x ( 0 - Wid / 2 ) ) f5 K2 W. L! Y/ I" }1 A& ]
                          set y  Dep / 2 ]" D* M/ {- V# n
           set b  int (a / 5) * 5% S( X: Z5 V. b- p* @' M
    setxy ( xcor-of turtle b + x )( q: h# _' e& e- U
          ( ycor-of turtle b + y )
. Z  o+ V& }: Y1 H- h9 {4 ?+ uif (remainder who 5 = 2) [set c who0 Z7 q2 ]3 S2 S5 D& j$ L
                          set x ( 0 - Wid / 2 )
3 |7 `  }5 K8 L                          set y (0 - Dep / 2 )  ]+ R/ ]/ `% G; |* R
                          set d int (c / 5) * 5
4 B9 x* A, k: O6 ?   setxy   ( xcor-of turtle d + x )
5 S: H1 p  Z; ]- T$ }7 ]6 q7 @           (ycor-of turtle d + y ) " E; R( x9 [* `& b8 g3 P4 i
         
: C0 k1 `2 c9 r5 }8 e" D              P2 n( i0 M* @  u
if (remainder who 5 = 3) [set k who+ \/ E1 S3 W, }$ K- `
                          set x( Wid / 2)  ! e: t. I2 {, F! z; L" M6 W0 S3 B
                          set y (0 - Dep / 2 ) ]  d" `/ ^& p' j: J  v9 R/ B5 R
                          set f int (k / 5) * 5
: i" C* |' z2 R  x0 v  setxy   ( xcor-of turtle f + x )
/ V; K! `7 d, j5 l) Y, a; c) |) C           (ycor-of turtle f + y ) ! G/ v4 m; a. z- Y! y" @
           
3 m5 S: B3 p" d/ v6 U% R, ?           
( I3 K  W6 h# L( S3 q6 cif (remainder who 5 = 4) [set g who
- a! H: I" v9 A7 ~3 j7 s+ \                          set x Wid / 2
. J' K7 N- p  r6 y% ^& N                          set y  Dep / 2 ]
- \4 e) p8 [) n" x; [" W4 e                          set h  int (g / 5) * 5
  S% @3 v) X, y& l$ V: d2 _. R9 n4 J  setxy   ( xcor-of turtle h + x )
2 x- O, x! p3 q8 u: {           (ycor-of turtle h + y ) 1 j) F, G: P- r4 \' y- \6 L5 i3 D: Y
                          ) M4 U7 ]9 O3 T. F) _
                          
, x7 t, c6 Y/ X# t. M                          ]
) N; L/ g; w7 ^6 ]% ?end
% Q1 Q$ j8 \7 Z3 v! l. ^6 _5 w4 T) }' a: e3 N: G
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
* h7 B! a, I) W7 G* K1 v应该是
& q  D0 U, M0 |8 m4 D! Qask turtles [; I; i/ _+ S, Q2 ?/ @
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) , G% Y' y% M2 E* T. p3 \
                          set y  Dep / 2
- |, }+ ~, }( Z; z/ D; F$ o           set b  int (who / 5) * 5
$ J& w7 r; h& j9 ?! H    setxy ( xcor-of turtle b + x )0 d0 s6 z4 s2 k
          ( ycor-of turtle b + y )]]- s$ l# C3 x) @3 o2 A/ l% X
end
+ W, B" M0 H$ |之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-5 10:22 , Processed in 0.015449 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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