设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9063|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。5 d3 }/ d2 K/ R7 s  X6 Q1 f

/ n' U) ^3 V! T6 R' F但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
! u  `8 S4 F' U3 \* L# c" @. ~7 Y; H7 ]' P# d
turtles-own [a b c d k f g h
) ~) {' }8 y+ Q; N+ {. a0 l1 G  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
/ J1 m( w* e) D' k! D8 B1 u]
7 N. T! c3 W5 m4 a) [to new% K! u9 b0 V0 v; ]
  ca
% [% u* A) _2 ~  crt 5 * num_of_building
) ?! R2 D/ O- R' d* S6 \% _  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
  W' e; k0 g3 P8 N: f  scatter     ;;keep center-turtle random positions
! d3 _( H) w% Q! [: h  unit_plan   ;;make up the building plan# o/ r5 a# R- i; b' F& q$ Y2 G
end
3 z. C5 |$ b; W; U* |/ [* S8 oto scatter5 E& p9 R$ z3 t2 v( n
ask turtles with [remainder who 5 = 0]
% _2 \% {0 S2 n1 W7 O7 q: f) p[3 m5 G! b" [. ~3 ^6 C& O# Z0 o
set xcor xcor - 6 + random-float 15- _2 T- E: M. x% Q0 v0 y" }
set ycor ycor - 6 + random-float 158 }7 J  \' B1 U2 _9 \
]
5 b$ @1 z8 I& t: m* M6 a" kend
4 w+ P1 P* W& C+ F/ W- `1 B7 }7 w+ `to unit_plan * t. U  X( y  I# b- d, z
ask turtles [0 l5 x, J$ C! ~5 u6 B
if (remainder who 5 = 1) [set a who
) {) m* W2 B; X# {                          set x ( 0 - Wid / 2 ) 0 Q- H" |" d! W7 l* w7 A$ x: c$ R
                          set y  Dep / 2 ]( v3 p9 u7 v5 g) y5 M
           set b  int (a / 5) * 52 K. w+ {! t& p) B: k
    setxy ( xcor-of turtle b + x )
# n! m; i  Q) y5 [$ {0 ]: _          ( ycor-of turtle b + y )
5 u% Y5 ]7 n& G2 r+ \9 ?4 Uif (remainder who 5 = 2) [set c who, b- t3 {2 V/ T8 S5 U; ~2 v2 J3 j
                          set x ( 0 - Wid / 2 )
7 L0 v. [; n6 f7 [$ g5 E) C* w' G+ X                          set y (0 - Dep / 2 )  ]
2 h2 j* h' d% o" V. ?1 X                          set d int (c / 5) * 51 Q5 p3 N% s0 D5 D: m7 L' R
   setxy   ( xcor-of turtle d + x )
4 p" ~) C. p+ P' f* H9 m6 _; w           (ycor-of turtle d + y ) , e7 l$ e3 D. Z) H$ t
         
; Z( F/ n: x" O            
* ^3 n4 u1 [0 V+ `if (remainder who 5 = 3) [set k who  m) w! O1 D# B* j
                          set x( Wid / 2)  . D$ G% i& y( K! v  k+ ~
                          set y (0 - Dep / 2 ) ]# M, s" {4 Q! a& ^2 O5 Y9 _7 u7 O
                          set f int (k / 5) * 5
. P; y8 p8 H$ o& U9 s0 n* l: E  setxy   ( xcor-of turtle f + x )
5 k$ n0 r$ b/ `/ ~           (ycor-of turtle f + y )
2 S4 f" g" d" T8 b* m5 j$ X           
; u" ^& f, z' t; l# l# T/ y           # Y9 T3 @% g( I9 p% \9 X
if (remainder who 5 = 4) [set g who. W; }: h* k# \8 h! G
                          set x Wid / 2
8 K  O! m' {8 g/ Q2 S- D                          set y  Dep / 2 ]8 ^' S* u( v3 c# c0 o
                          set h  int (g / 5) * 5
5 H' m* n2 I2 f2 R1 n3 F  setxy   ( xcor-of turtle h + x )9 ^2 @7 \. _: _7 j, f
           (ycor-of turtle h + y )
- \$ j) a1 T5 j- ?9 O1 R& m  O/ D& e8 N; h                          9 v; C  R3 C  G4 Z8 B. P+ K* R. [
                          
. v, g" @7 u, Q                          ]  b% I! k7 j% @: U; j5 P
end
. X/ y: D1 ~+ o+ x& I& h& m4 T# n6 }8 B: x
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,; r0 X/ P3 |# p. y& ~
应该是1 a  E! O3 L( U: }2 F$ k/ {2 K
ask turtles [
7 H' q7 z+ P& P4 m  }+ z+ w: kif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
2 I/ Q( |4 S4 b: G                          set y  Dep / 2 % b/ }* i, K, q1 H( F4 V
           set b  int (who / 5) * 5& Q) O* \0 t8 R8 @  Y5 _% F
    setxy ( xcor-of turtle b + x )8 }' ]5 }4 m5 @. H9 I+ h$ F4 ~
          ( ycor-of turtle b + y )]]
/ x% S2 U. }) h5 X6 t0 Wend
2 g0 B! k9 M$ n" C$ F# p+ U之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-13 06:47 , Processed in 0.018120 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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