设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7518|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
" H1 Z  i, j# Z/ Y5 `  ~
0 L" z! A5 U' c1 @$ r但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。0 x, C- r+ F7 @

) j, C4 Y5 I# g; Jturtles-own [a b c d k f g h0 J) z1 X# `& c
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
0 Y& H2 i# [6 v2 }% ^]" u' D0 X, X( h- l, x" I
to new- U: e: k' G7 h# Q" K- \5 x
  ca5 o* p  ]6 `: d6 Y) w
  crt 5 * num_of_building
- S  Q, T3 z6 D- Y  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]( S$ ~1 N9 M* ?
  scatter     ;;keep center-turtle random positions
- [5 x  _, T! S: q: Y# H$ U  unit_plan   ;;make up the building plan; t6 \0 K$ g* o2 V+ J3 I( s
end! W7 Z5 Q3 S7 D4 L
to scatter" P( Z4 t2 {2 w
ask turtles with [remainder who 5 = 0]
4 G; u# e& B* \9 h, O4 S7 k[8 j! P; a" `3 x1 ]* f
set xcor xcor - 6 + random-float 15
# P# K7 m3 g. j$ K9 n5 t8 N5 eset ycor ycor - 6 + random-float 15
  Z0 l/ a  e8 ~3 k( T! t6 F]$ }/ v' B. h0 E' W
end2 f: P  j8 U; }( i' {: A- D- W
to unit_plan
9 x, F3 c; e1 I0 z1 S- Eask turtles [5 ~$ Y, ~) G% N2 Y0 j
if (remainder who 5 = 1) [set a who : c2 z( I+ G4 z$ R/ c3 S" T4 _
                          set x ( 0 - Wid / 2 )
9 Y; y2 `% w0 S6 L                          set y  Dep / 2 ]
; g+ |" }; W5 \- s           set b  int (a / 5) * 5  {2 l; B6 w$ O) g# P
    setxy ( xcor-of turtle b + x )
* E9 f' ?  ~! c% V- i          ( ycor-of turtle b + y )2 m6 F/ X7 ~0 e; [2 @
if (remainder who 5 = 2) [set c who
9 B$ ~* U' t3 |" ]. k: r) y3 `                          set x ( 0 - Wid / 2 )
! X$ c; J* M) {6 g+ ^                          set y (0 - Dep / 2 )  ]
$ |7 w% b! ^! @3 t/ a: D  o& ]                          set d int (c / 5) * 52 D) j1 d! O8 g7 }% c4 o
   setxy   ( xcor-of turtle d + x )0 A9 x6 i$ l- j9 Y8 Q! z7 ^5 ]/ o
           (ycor-of turtle d + y )
8 N+ b0 x* ^: K$ |          1 i/ I  G$ h  c% l* V4 T7 f: x, |( X
            # S. x( x% s9 K; }4 G
if (remainder who 5 = 3) [set k who
' S  S  {2 A5 Q; R, ?2 f                          set x( Wid / 2)  $ u2 ?. D' \: Z
                          set y (0 - Dep / 2 ) ]
5 ]; W2 E* W% I( F                          set f int (k / 5) * 5
% l: {# Y: ]( f" m- v  setxy   ( xcor-of turtle f + x )
( l* S/ N: n/ y$ p/ x) m           (ycor-of turtle f + y )
" b% I4 k5 W5 S" }2 s           
# U" u+ v: w7 C  a, s1 w( ?# P( b- ]           8 c2 n, l$ G/ M9 \( t9 F
if (remainder who 5 = 4) [set g who
' @. p2 d% M+ y! ]" y6 `$ `) B' _                          set x Wid / 2
0 M$ C% ~9 X5 D( d& N                          set y  Dep / 2 ]
$ H: A# t+ V1 n' l& x                          set h  int (g / 5) * 5! ~  n+ g3 T! v/ L8 L1 W
  setxy   ( xcor-of turtle h + x )0 n% Z, l9 k5 z4 M7 f
           (ycor-of turtle h + y )
9 y; x/ N# h: i* D                          
+ y/ h1 M( D! w4 k! m7 i                          ' }) X/ S. O: o
                          ]
6 h2 g2 |1 `  {8 send
0 k" K8 z! x; d2 j8 J- Y: M% x) t$ y1 @/ o( K* v
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
3 s' y1 W* O0 [应该是% K8 U/ `1 V7 P+ l$ G: X
ask turtles [0 l1 P- N1 A+ a% ]* R( Y2 I
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ' s, j- |$ M- I+ G; D* `9 C& E
                          set y  Dep / 2
+ y2 [4 r% N% D) k  L: O           set b  int (who / 5) * 5
1 B' X3 V8 d" y5 V. y9 j    setxy ( xcor-of turtle b + x )
; S! O4 F6 @) G- G: R" f          ( ycor-of turtle b + y )]]
3 L, t- `& I, f# ]% H2 {end
$ ~5 d4 p* o3 a- l之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-21 03:09 , Processed in 0.014353 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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