设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8066|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。0 J4 [4 N* q5 n5 ?; n( m

7 \3 N, B: I: h8 v" O0 _  J+ C; d但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。% N( ^( R7 L7 q5 f" q

) O6 P3 W& q* J+ h! yturtles-own [a b c d k f g h; e; d# G& p) e) |  V
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
" ]" N. v' U7 p% f$ V$ s/ {. A3 v]/ l) U' d3 V+ A% L/ U* V
to new& K) |) n! Z& H: q' p  S% C1 e) z, Y
  ca4 X# p) V1 F5 ^* ^9 j
  crt 5 * num_of_building
. e; r# p. T& c, x% E  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]' O, V) ]5 x) g0 X0 F
  scatter     ;;keep center-turtle random positions 8 S, B1 v) S2 @1 f, p
  unit_plan   ;;make up the building plan5 W8 n/ r8 K0 z5 o4 @! d
end
1 d: ~5 Q, F: n" J& g  I' Wto scatter" d( D- O6 M, Z$ ]$ I! y
ask turtles with [remainder who 5 = 0]
& t4 B% a/ s; s. _[
% F$ X7 g" b- iset xcor xcor - 6 + random-float 15
' z3 F5 l4 b! |2 i7 J: wset ycor ycor - 6 + random-float 152 j" m% j3 L9 w# L/ p8 G, N
]
! a$ e6 P  ]2 N2 F2 l: _3 r/ fend
! f9 z9 C5 _  y; Eto unit_plan 8 F- \. F7 h6 R& {$ F9 y
ask turtles [" [5 X% b+ B! h
if (remainder who 5 = 1) [set a who 2 y$ }2 D& }) X  r2 {) ^4 c8 s3 y
                          set x ( 0 - Wid / 2 ) + `; W' T5 w+ d# p" a- j7 E$ |
                          set y  Dep / 2 ]
$ G& B5 V& Z' E. B2 @/ z           set b  int (a / 5) * 5
) S+ O$ s3 k. z& d6 k    setxy ( xcor-of turtle b + x )
7 ]' @3 ~2 }% @- `3 B0 D          ( ycor-of turtle b + y )
& Y3 ]; U5 M. d4 _# o( y3 Yif (remainder who 5 = 2) [set c who  Y5 C( f& z2 x
                          set x ( 0 - Wid / 2 ) 6 q! M9 o& b' \2 ~5 f% F3 Q. N
                          set y (0 - Dep / 2 )  ]
5 E9 V) X- L: Y. R0 E7 L! A9 F! ^; l                          set d int (c / 5) * 5
) }' B, B- Q: z0 u3 p0 }& p   setxy   ( xcor-of turtle d + x )3 c" O/ f9 s: C. f: V7 Z: C
           (ycor-of turtle d + y )
: N. Q$ V- Z$ r( j1 `0 {         
# l2 y$ O' G/ ?$ v: \; U1 i+ \            
5 g9 i( w& M  t- J7 }$ kif (remainder who 5 = 3) [set k who
! N# \: w, H9 a0 w* E# E$ {: W+ ], @                          set x( Wid / 2)  
9 ^5 E  J( D7 P+ I6 G                          set y (0 - Dep / 2 ) ]
( T( c1 t6 X+ z( r  B# P9 ^9 S                          set f int (k / 5) * 5
) z7 P$ a* ~. Z- H8 D  setxy   ( xcor-of turtle f + x )
3 H# s5 T: B4 z0 a. {4 \4 r           (ycor-of turtle f + y ) 3 i( a/ [6 b7 X
           
% a+ W. M* Z, N7 C0 i' i% H           # @  Q# ?2 y; h7 ]3 D( C
if (remainder who 5 = 4) [set g who- {; ?. K% `0 Y: e# p7 l
                          set x Wid / 2
4 a/ T& d0 a+ [# k7 z$ z; h                          set y  Dep / 2 ]/ \" {, k; x+ r2 u
                          set h  int (g / 5) * 5
# d# n9 Z' m3 ~  setxy   ( xcor-of turtle h + x )
* s  K( c- c: }' }( P& `# r9 s% R, B           (ycor-of turtle h + y ) 9 \8 `! r1 Z* f) @' C% M$ X. ?
                          ( G% i; R) z/ G' g0 J$ Z
                          + s& U2 h, F7 w/ V* f8 p2 ?% Y
                          ]
$ \. S0 ]. d# y6 ^* cend
7 H$ I$ [' Z. h7 d7 A9 P3 M0 E* U! J/ |; o) `8 N' E# b! O, Z
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,/ l) x0 G3 s! J3 x, t5 M5 U* j$ P
应该是
8 v& p7 p7 v9 v7 Pask turtles [$ P! M! c+ }/ Z3 o/ [# z/ O: V
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 3 |! y- v) _! f) B8 V1 r1 ?
                          set y  Dep / 2
3 q+ |( i: n! {% L) [6 u% H           set b  int (who / 5) * 5
$ d% R8 w% |9 [' s& r: E    setxy ( xcor-of turtle b + x )$ J. j  }5 G: w2 m( `5 Z
          ( ycor-of turtle b + y )]]
" u) A* L  R& o5 k6 v9 @end0 }" o: z5 B$ E; i
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-3 05:55 , Processed in 0.016932 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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