设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6810|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。: x) f% W' s7 Q3 O
) w8 \2 V+ Z, b. |' Z3 q0 D8 A( q) \
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。' m  Y9 ]1 `: e" |% [5 R8 `- O
% C5 \9 m; }/ G- Q4 x0 v1 O
turtles-own [a b c d k f g h$ E3 T9 H7 w4 r" w& m8 X. z
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 3 j4 ~% ~" P8 V8 l  E$ l+ J7 W# p
]
9 {$ Z% ]; f& F3 Gto new
) {: }" d: z0 [  ca
4 v7 I+ Y2 _& F# f! R  crt 5 * num_of_building& A( U; a6 V: l; ~' r* o  S+ r
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]5 U9 h# I. z9 N: n, o) H
  scatter     ;;keep center-turtle random positions - I. g' A$ A0 R
  unit_plan   ;;make up the building plan% C. a; i% U: c# j1 c6 m7 ?
end# ~1 e5 c" k. \. u4 e
to scatter
1 W& l8 O9 \2 g, D6 `! Q. E- Zask turtles with [remainder who 5 = 0]& A# P% ^1 |- I% D7 [
[
% W6 ]* P  N" G. P4 A, a. i) |# Dset xcor xcor - 6 + random-float 15
7 e* f0 K7 F2 r0 Tset ycor ycor - 6 + random-float 15* {- N$ ?9 l3 j( A1 x. B2 o
]
( g2 |# q5 }: w8 |0 a5 y+ Nend
9 h, a# p- L1 B6 Mto unit_plan 4 _3 q% [" t4 }! _# b3 x, [+ F
ask turtles [
" `, [0 E" ]# K& ]8 Dif (remainder who 5 = 1) [set a who * m! s: I* d. |! H
                          set x ( 0 - Wid / 2 ) ; Y8 I, ~# y. k; q! M4 b
                          set y  Dep / 2 ]
" P' i/ l: G1 _. T& g& R           set b  int (a / 5) * 5
, X4 d- `5 X) u; p+ `; Z* b    setxy ( xcor-of turtle b + x )- t: W# B) \6 P9 t2 b1 s
          ( ycor-of turtle b + y )
" ^: J" V# q" X! {% xif (remainder who 5 = 2) [set c who; W( `+ Z4 a; \7 j$ s
                          set x ( 0 - Wid / 2 ) 6 z& M$ S2 N9 E8 e7 U
                          set y (0 - Dep / 2 )  ]
, ?* `; Q0 ?( n, q# q/ G- ^                          set d int (c / 5) * 5* _1 ]/ r2 I# V4 f8 |( q
   setxy   ( xcor-of turtle d + x )) F) t5 b( y$ J% k7 r# r& p
           (ycor-of turtle d + y )
9 X5 m  J# R) p, q3 q% \/ Z         
+ U% \6 A3 n9 _4 |$ F            3 w6 x8 i  O9 O' y- w3 _
if (remainder who 5 = 3) [set k who
9 @- F" u' m1 }- V                          set x( Wid / 2)  + F& H  m7 S: C+ {% t6 B
                          set y (0 - Dep / 2 ) ], o7 F  d) |$ ~* {
                          set f int (k / 5) * 58 w2 A6 j2 i. k) f" O; `0 P
  setxy   ( xcor-of turtle f + x )
$ {7 \7 h6 x! q. ~' ~0 F           (ycor-of turtle f + y )
& ^) K4 V# D8 c, ~6 u& L3 |7 |, F           
% @9 C; b! k1 O9 W9 z6 t           ) ^' y9 K2 M& N' q5 F; `; \
if (remainder who 5 = 4) [set g who9 Q( G# q! p0 P2 A( ]
                          set x Wid / 2 : j8 v3 f: D+ L3 y8 I5 I  ~; w- ]$ E
                          set y  Dep / 2 ]
" y: g! s- b$ w+ H# H6 z                          set h  int (g / 5) * 5
, j4 K+ `. Y* ]- y% W5 I% U  setxy   ( xcor-of turtle h + x )
  {" s6 a. }5 n0 F! B           (ycor-of turtle h + y ) 8 E8 {/ K. u% \1 j+ B/ u
                          + b! c6 F$ G. S7 c) M; x
                          9 v* l/ k% p# h
                          ]
8 n: P0 `# c. _% x, U* Eend
2 E4 T' b& I, j
: [' D# J! H. N! s8 S; b* n! j[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
1 s! O: I* e3 B8 P3 D7 `! C+ M6 h应该是
  K$ A8 f* }% D+ U$ y9 Nask turtles [$ `7 l, I' \6 I$ b" a
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
+ h3 O0 R, m4 ]2 K' }8 l, ^  O                          set y  Dep / 2
) k: J. a' [( A( V( d% v. r6 M2 M           set b  int (who / 5) * 5
5 t) v- c0 m8 J2 m    setxy ( xcor-of turtle b + x )
; l, F6 F3 j' }3 j0 `- k          ( ycor-of turtle b + y )]]0 G, b; ]# R' Z& ~' |
end5 S" g8 [1 L: I3 K+ n0 {! }
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-25 08:15 , Processed in 0.021233 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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