设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8822|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。# q6 ]# Z& |$ ], N- L

9 F; x& B1 g) X" L9 Y) |" C但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。; N) K0 h* x$ U; G% Q

: o, N* k9 s. Dturtles-own [a b c d k f g h
3 B/ S$ `& @2 J: A/ v9 A" ^2 }5 Q  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
. t' b0 ~7 T( C$ z7 d]: P5 d/ q4 H- v% Y8 q
to new" b; R& Y5 ^& L3 _" K! _% v2 P
  ca
4 p! }/ |2 ^: E& t8 Y" w7 d  crt 5 * num_of_building
& @3 T% c! ]4 p* I  F  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
& W/ w5 Y0 z* [4 X$ X  scatter     ;;keep center-turtle random positions ; A+ I2 I$ c4 G% \4 e
  unit_plan   ;;make up the building plan
7 a/ V8 i# ~5 A* K9 C; Y  ?$ nend
5 k* B. v7 ?- F  }9 l9 \' h& rto scatter$ `; N3 i1 R9 I8 f" f$ z7 @2 x5 D
ask turtles with [remainder who 5 = 0]
: z$ _% g& v3 A5 y2 f' r3 a7 S[
6 G) w+ K7 r) b% z9 sset xcor xcor - 6 + random-float 15
  ^3 O, h; d/ O" dset ycor ycor - 6 + random-float 15$ o$ _7 _- V+ z% h# j- v
]
4 }9 u/ ^& h! |- c9 rend$ g6 C: e4 t0 D$ r( F
to unit_plan $ I3 W# b, V9 \1 z0 ?/ V
ask turtles [$ c* J" F# ?, u8 A/ [) O, Q! p* L4 b' y
if (remainder who 5 = 1) [set a who
- ]% M0 x+ X, w: ^4 z                          set x ( 0 - Wid / 2 ) : Q9 _* f6 g4 T8 _) w
                          set y  Dep / 2 ]* m; z- \% b- x5 P
           set b  int (a / 5) * 5) L* n' `& j9 ^% b9 W; s
    setxy ( xcor-of turtle b + x )9 u, s; T1 x) {( S0 W$ W7 x. I) f, H, e
          ( ycor-of turtle b + y )
1 O# U% x% ~0 a% wif (remainder who 5 = 2) [set c who# [, i, ?$ l$ p
                          set x ( 0 - Wid / 2 )
. t# P( \- A' r% N- ]. f                          set y (0 - Dep / 2 )  ]1 g/ `" L* d* z, z0 p% |
                          set d int (c / 5) * 5. R: y0 d2 e' N
   setxy   ( xcor-of turtle d + x )
) X. w; R$ U$ I, m           (ycor-of turtle d + y ) ( [6 D2 H8 X! i  T
          # \: r: r8 T5 K3 u* B4 s4 C
            
( R# e/ h- e# s& Aif (remainder who 5 = 3) [set k who
3 E/ Q4 J$ u  U; j, u$ A$ m                          set x( Wid / 2)  * I* v, {3 X' G0 y$ _7 h  p4 [; G
                          set y (0 - Dep / 2 ) ]$ R, j+ S( O* `3 s
                          set f int (k / 5) * 5( r% Q$ ?6 _4 q! L. E* U' F. `
  setxy   ( xcor-of turtle f + x )/ m7 M0 o( c. h, C  n" I0 g' f! G6 s
           (ycor-of turtle f + y )
2 ~/ d5 k/ Y! M1 U, I  ~+ }           
8 V* ~! `# T0 ^; ?& t: \! W           
- o( O& F% b5 t3 q8 F, ~8 t% xif (remainder who 5 = 4) [set g who
- E( b3 t1 J( f6 R                          set x Wid / 2
0 B# z/ {3 c- r: x  V' e4 n2 s                          set y  Dep / 2 ]
5 x" U9 q+ c, p; s" o9 e9 _) B                          set h  int (g / 5) * 51 V# Y0 g3 X1 Y& r
  setxy   ( xcor-of turtle h + x )
( M, J: I' m/ |+ ^  B7 \. s           (ycor-of turtle h + y ) ' r( V% c" x( c0 r( i& c( L
                          
% ~7 Q  y& N( `* I% u! _- `                          1 o9 G* b* p3 \+ d* ^' H
                          ]  E% z0 j1 }( F) L$ e: h0 B
end. z& u! Q0 @0 _% p3 Z6 A' A) }

  R5 f# p5 b8 n( U3 \; {[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,5 u4 a! ^7 a- C- B. X
应该是
4 S0 k* F$ z& A' ?ask turtles [) R$ }6 ~1 Z+ u7 }6 v# ?
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
- U9 q0 y  i8 }# q3 w4 c" f                          set y  Dep / 2
' h$ O8 Q! ]. _           set b  int (who / 5) * 5
! D" V8 _! c* m/ M    setxy ( xcor-of turtle b + x )
* v# [; w* v" _7 J) Q. ]9 I6 Y          ( ycor-of turtle b + y )]]
, J: O( f0 a- send- W- Y/ L$ b2 d6 E' S% G2 \
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-8 02:15 , Processed in 0.016794 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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