设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7451|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。5 O/ K6 M2 b8 u4 N5 \; ^$ [
# J8 W' r2 _# Y0 @' M6 \7 }
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。7 c/ F6 e& U9 Z" H4 p
0 r( d+ U1 I: b& u5 z
turtles-own [a b c d k f g h
  t% |/ ]; k/ R$ A6 f  x y     ;; these are the leaf-turtle's offsets relative to center-turtle $ ~6 K- N! m: Q: h8 h" o
]; [5 R1 d2 ?/ \! O  ~* f" ]  H- w
to new4 C& a( j' q" [6 i+ g
  ca
) |0 {7 E. T+ C9 k5 [  u1 R  crt 5 * num_of_building
% E! N6 [& r2 V. B' [' i7 y) N: y  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
$ ^( B/ H. N" K! A, Q  scatter     ;;keep center-turtle random positions ; U1 J, [7 `' V! ~: N: e
  unit_plan   ;;make up the building plan+ ^( Q2 f, V/ q: m, V( F$ j6 O+ V
end, K9 @  ?, a5 J6 V0 C* H
to scatter
! x. h) @/ j) b- M4 uask turtles with [remainder who 5 = 0]
/ l0 G( k' w1 t/ i3 d  l8 H6 f[8 r+ s: p7 }) g+ r! U9 I; m2 D
set xcor xcor - 6 + random-float 15
# ~. j( v* W3 V1 {set ycor ycor - 6 + random-float 15+ _/ Y" r" x% J0 G
]
' @) M" T5 x9 _end
. q! V9 M/ Q8 T9 |; Q% \to unit_plan 9 b, Z8 v2 t( n7 {! F; ?* B
ask turtles [6 B" P/ O3 q/ {) s3 S
if (remainder who 5 = 1) [set a who 7 T  _, ^. B( C) n2 W
                          set x ( 0 - Wid / 2 ) 0 v& s# M7 l. F& i$ v
                          set y  Dep / 2 ]
  I7 s8 d4 M3 q/ Q           set b  int (a / 5) * 5
9 Z* }' G+ X6 ^7 Q# n  m    setxy ( xcor-of turtle b + x )5 r, R' m& ^! k+ E5 E8 e( D) U  i
          ( ycor-of turtle b + y )
1 s* z4 {* P5 i/ x0 dif (remainder who 5 = 2) [set c who7 p. }" |. R' q; u
                          set x ( 0 - Wid / 2 ) 1 c/ y0 T$ j$ v: ~/ O
                          set y (0 - Dep / 2 )  ]* }: S4 [3 b+ F+ j* D
                          set d int (c / 5) * 5/ a8 P) `3 |# g: P! R
   setxy   ( xcor-of turtle d + x )' ^2 s* r7 B# R8 f& T! f
           (ycor-of turtle d + y )
+ P: b/ N  _+ o' H1 _: z          4 X3 T# `- k: t" Z' K" `
            ( h  F. I- o* J/ Y
if (remainder who 5 = 3) [set k who$ A- Q6 @$ T( d, A0 `" \
                          set x( Wid / 2)  0 c7 V/ f! }) d% C% T( n/ ^5 m; S
                          set y (0 - Dep / 2 ) ]5 b, B1 }' w3 ]
                          set f int (k / 5) * 5) d6 J+ U$ M; F* E7 a
  setxy   ( xcor-of turtle f + x )' }* C% w9 x5 \1 }+ q8 v
           (ycor-of turtle f + y )
& p$ Z1 F4 ]6 |7 W! R  r  e           & B) N$ `2 G7 [9 s) m& I6 F
           5 Y7 o! |/ S, H: }* _; o" e
if (remainder who 5 = 4) [set g who: S4 S/ F" _- H/ {
                          set x Wid / 2
3 \' b3 t6 a* D! }                          set y  Dep / 2 ]
3 A6 d+ a- y0 Y% Q, C; [                          set h  int (g / 5) * 5
3 j, ^  L/ C3 h: [6 D9 Z  e6 f  setxy   ( xcor-of turtle h + x )8 W( V2 Q6 n5 G" U5 w. g3 _) P
           (ycor-of turtle h + y )
; r. Z) |6 d9 |2 m; ~' v' _                          
0 s. b& Y  }7 n/ A                          
% X% ?; ~& ^4 [/ }' R                          ]1 k: p6 p7 s1 I2 J
end) ~/ c" S4 V& f+ `2 k& _
0 p  G  i5 K" Z1 {* b9 m) g
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
8 q/ U; {9 O* S% X# w( ~# k7 p" ~应该是- x8 i, T  ~5 [0 T( O) L
ask turtles [
" [# f$ B# S7 T8 ~( ?if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) , U/ s# u$ Q: w4 Q: _& t3 a
                          set y  Dep / 2
: r; H7 r( @  X( S& j! U0 t           set b  int (who / 5) * 5
$ ?6 H. T, @. q* o# H    setxy ( xcor-of turtle b + x )
, c: ?* V, m- g% }& ~5 F7 w( G          ( ycor-of turtle b + y )]]
0 f0 l2 b+ g1 i- w& i1 M) Hend2 Y, R7 |5 k% U2 X( W
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-12 18:13 , Processed in 0.018496 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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