设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9027|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。( T+ h1 X+ ~# t8 V0 q
& v! f* t: o0 L' V
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
5 n7 x" E; e  u' D  H) r
4 b8 W! y4 G  y0 g, _% z3 zturtles-own [a b c d k f g h
7 O6 Y( Z# L0 L$ D6 F  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ) ]* |- b  O. w! n2 \% S
]$ p  Z& P6 G, p1 z3 i( W6 ]
to new+ d6 W! J8 |1 m$ j% _# l! d
  ca
, q8 E7 y6 h# s! _$ V* P- u  crt 5 * num_of_building1 B6 o' E( q8 z* U8 a
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]9 T7 o8 S5 n9 `- N/ \$ ~$ U) y5 k2 a& @% F
  scatter     ;;keep center-turtle random positions ' n1 J( b" t) x  i- M
  unit_plan   ;;make up the building plan! I+ P* D/ I/ z& F, u
end! s/ s3 g! \+ W
to scatter
3 j7 ^8 E! }; G+ Aask turtles with [remainder who 5 = 0]7 M! F1 D- A& m' m0 V
[
3 s& Q( T: L  h2 I3 aset xcor xcor - 6 + random-float 15% ]) b$ F5 u; K4 ^+ i1 n
set ycor ycor - 6 + random-float 15
3 d9 o9 Z/ g3 x- X5 f" [* g; U- D], N' `% B$ O2 ~
end$ _' N8 B% P8 S$ g- ?+ H: v# w, x
to unit_plan $ I4 I% G: t7 A9 V& m1 [8 }3 q' f2 f
ask turtles [" H% N, L! d) |& x& U8 E
if (remainder who 5 = 1) [set a who ; z5 Q; N' ^: H
                          set x ( 0 - Wid / 2 ) ; }# ?2 V8 M- ?4 C3 `! l% r- \
                          set y  Dep / 2 ]+ @3 w+ |9 f$ y3 w4 n8 V' K
           set b  int (a / 5) * 57 \' @1 {! Q9 r/ n3 _. X) J
    setxy ( xcor-of turtle b + x )
, f  e" f9 F4 `/ s          ( ycor-of turtle b + y )
8 j$ ~) D. i2 r; u% ~+ \' \7 ]if (remainder who 5 = 2) [set c who
0 g- Y2 }6 t: j+ Y% V5 ^6 w                          set x ( 0 - Wid / 2 ) 6 \, x7 r: }4 f5 X# R6 L$ c* x! \
                          set y (0 - Dep / 2 )  ]+ A! |  {3 d6 M0 E0 Q
                          set d int (c / 5) * 5; G8 L. x# K0 a& H6 T. O
   setxy   ( xcor-of turtle d + x ): A  L, f; w; Y, x, b
           (ycor-of turtle d + y ) % b9 a# z, u0 J$ \4 ]
         
+ y+ g$ {- h8 D            4 \3 j9 w$ O( o" E+ p
if (remainder who 5 = 3) [set k who
- K( u/ Z5 w0 h8 `: Z                          set x( Wid / 2)  2 [  j  z5 R/ B6 s
                          set y (0 - Dep / 2 ) ]
; P' o. o% k  \                          set f int (k / 5) * 5
( ]4 _' A6 l/ _; h' D  setxy   ( xcor-of turtle f + x )
1 \9 ?2 z( D# C! r& h0 Z           (ycor-of turtle f + y ) 0 B4 L! ~( d1 w# Z7 ^" K( e
           
2 _3 b. f% S7 R2 j4 q! V           
9 y; J) K+ k7 z2 ]: zif (remainder who 5 = 4) [set g who9 m: L( P# m+ U3 u3 n; c! _
                          set x Wid / 2 1 q0 d( e; [4 c1 W9 r
                          set y  Dep / 2 ]5 O6 l* @3 w% t; m4 X$ p( d- P
                          set h  int (g / 5) * 5
; T( x" w4 N' C5 i2 C  setxy   ( xcor-of turtle h + x )
+ E( q0 b* Z; F( l% g0 @( E1 s, X           (ycor-of turtle h + y ) 5 Y, T  y- E) \+ V- B! t0 S
                          
9 K" E, N9 x$ b                          
4 Q1 v% l) o- Y6 n! q0 O4 _                          ]7 n* D! u2 U0 P$ J7 r* D
end* y6 C3 b% c7 I5 i0 E8 _
& S: e1 a3 ~1 w* c$ y
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
) y9 q# m& A  y: j5 `$ P9 t应该是  A. u! V& o1 G% ^' K
ask turtles [
; t# n; F, X4 e" M( k& Xif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 3 ]1 v6 s1 X! A) r
                          set y  Dep / 2
3 v! s2 T+ Y5 P# B, ~5 h4 |           set b  int (who / 5) * 5
- v0 z% t, f1 `: q6 d+ b- p8 @    setxy ( xcor-of turtle b + x )0 W" \$ g* |& \0 o; O" ^" [) e
          ( ycor-of turtle b + y )]]9 u4 a& w, u) b$ ?& D* b9 L
end# A7 ~8 r% a* O
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-9 19:24 , Processed in 0.017067 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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