设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8354|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
4 z& d! d, ^6 a% k, k
; f% Z3 Z  u" `; ?. R但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。2 o- _0 J" V# G+ |% w# M: [
/ s. i2 Y$ R; v; c) x6 r
turtles-own [a b c d k f g h
  O6 x; J% ^9 Z2 I$ [( ?  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 4 Z# s9 k0 O/ w& T1 b0 v
]- b# ?; M: X/ p% W$ v2 q
to new7 `. ?) q0 x1 \% ^
  ca, G. y+ f) u% E7 A9 `8 ?) d: c0 x
  crt 5 * num_of_building
! ?% W. R% m2 ?( ?' R6 [; ?7 C  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]( N: c3 K& b9 a7 v: {4 I
  scatter     ;;keep center-turtle random positions ' i$ L* T" v& e: c. Q9 g* E
  unit_plan   ;;make up the building plan
% J6 ?- g2 X4 q6 R! V  C7 Oend5 I. Z3 o* ~! G, N' E
to scatter
0 U+ ?+ S% {: G' Qask turtles with [remainder who 5 = 0]& H) ~; W: O0 F$ X& I, Q
[
  u. g2 P7 \) J/ Uset xcor xcor - 6 + random-float 15
% W1 T. L' \/ h  Dset ycor ycor - 6 + random-float 15
4 E" ]' h- X1 k5 C]: k8 ~1 _  g/ F7 G# H
end8 K3 a: I2 Y9 A' w' v1 t1 ~
to unit_plan
$ [& f2 h8 W2 q6 \ask turtles [
4 W6 i& V- ?, O' uif (remainder who 5 = 1) [set a who $ [. v/ y1 L) s2 ?1 _* y, M
                          set x ( 0 - Wid / 2 )
0 O" l% [+ f8 }* i, q) R% B                          set y  Dep / 2 ]
4 x( h5 V6 J) u1 V8 W           set b  int (a / 5) * 52 k4 [/ U; }% a% v& ]' t
    setxy ( xcor-of turtle b + x )
# d* b! ]9 |7 A& |' d# B          ( ycor-of turtle b + y )4 _, ]+ E& H0 u# s
if (remainder who 5 = 2) [set c who+ Z$ v7 ^5 \& a2 E
                          set x ( 0 - Wid / 2 ) 2 q/ R& w! h) \$ R" r5 c
                          set y (0 - Dep / 2 )  ]
" x1 E/ C. F1 m                          set d int (c / 5) * 5
) j  R- h3 j( ]1 A9 R+ `* ~   setxy   ( xcor-of turtle d + x ), M: z4 j' k2 `0 s$ N
           (ycor-of turtle d + y )
) d2 `- n2 H, d6 M+ G7 k3 l' ^         
& H  M7 d  m' C1 ~/ U            8 {' W# x4 h: Z  W- A6 W3 y
if (remainder who 5 = 3) [set k who
7 s9 z( R+ d5 w! P                          set x( Wid / 2)  - p8 L% e" ]. @& y6 @: h
                          set y (0 - Dep / 2 ) ]
7 w9 U; A7 S' m                          set f int (k / 5) * 5! Q" x" j" x6 ~1 q
  setxy   ( xcor-of turtle f + x )
7 O" R( F4 I6 E6 {9 q& f% u1 I           (ycor-of turtle f + y ) 8 f0 \4 z8 c* D
           9 B9 J' L% V$ {" }# J) J: D# \8 n
           & W6 v' U0 u- F
if (remainder who 5 = 4) [set g who
# ^) y% o! j1 r  g3 |- v                          set x Wid / 2 # |0 N0 P! c, ?* H7 q# G3 {* k" s
                          set y  Dep / 2 ]5 y" K" c' E7 X  X3 m3 x$ {2 ~" v
                          set h  int (g / 5) * 5
6 \% a( b5 A, u9 F  setxy   ( xcor-of turtle h + x )
3 p0 p  d$ T' x8 S- G" ^- k0 ^6 `           (ycor-of turtle h + y )
  I1 R9 \. S; w/ O) A                          
6 U& M( c% r6 {+ d# U5 C; P5 n                          6 G1 Q  \  R; b3 B: r! }9 i% N* q. x
                          ]( L' p( }( f0 k; Z3 ]* N
end% `4 B5 [$ T- [- m9 L
& P$ |2 f( m. j4 W  i
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
1 Y4 \  o. ~' \! x" a; s应该是2 A& N# C" D" f  F9 m! [
ask turtles [$ h8 M. L7 I  M. I& k0 A2 o
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
% g$ Z, \( G& v' K3 x2 g                          set y  Dep / 2 5 l) |: P- o: x2 Q
           set b  int (who / 5) * 5
. K7 Z' t( S; X  V    setxy ( xcor-of turtle b + x )4 l% A- B. ?' F, ?
          ( ycor-of turtle b + y )]]: z) y5 {2 {. s; r9 y. `! ^
end) p! @9 F' D0 d4 u# ?6 W( d: r  X$ W
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-14 15:16 , Processed in 0.016906 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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