设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8413|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
& I+ `  k$ H) t
" Y- s1 N( \0 T但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。) O8 D& u4 t  y% |' l

: D$ x) \9 k+ p/ A1 V, p7 c* |4 Iturtles-own [a b c d k f g h1 x8 u4 E% W3 u/ H7 q9 s6 @
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ' }% m* i! j& i6 I. z# y% t
]
( _  F0 s7 \; P3 C. V1 }to new
+ B* q9 d3 @5 I% J5 e0 n  ca; S3 j/ V& H2 t# E- W" ]
  crt 5 * num_of_building! {" w* @# D8 ^/ R' j' ^
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]! ^8 u$ Z+ a7 l" j3 K
  scatter     ;;keep center-turtle random positions
4 ^6 G! M$ h* M$ S  unit_plan   ;;make up the building plan
* v( d! g1 Q2 C- send
+ c- E% b$ o, D" Fto scatter
1 C0 {! J5 K0 ^9 g- i: [: Task turtles with [remainder who 5 = 0]1 ?% Z& a8 y7 D1 u% Q  C
[
. ?& O4 B9 x& k3 l# ]4 `set xcor xcor - 6 + random-float 15+ z* a) W/ {/ L) |
set ycor ycor - 6 + random-float 15
. I1 \3 J9 |- \  K' X6 d* F]
8 f1 h0 L/ p/ ?& |2 Cend
& A% G* N+ ^" O5 Y+ Y/ p( X1 Y" Vto unit_plan
4 l* W4 \. J+ }; K: Q8 s$ hask turtles [
; O  |3 d  F% G  [if (remainder who 5 = 1) [set a who $ @# Z7 t1 B& ~0 d
                          set x ( 0 - Wid / 2 )
9 g' F2 W& K7 i& g/ G/ L. W/ V                          set y  Dep / 2 ]) V8 w* @( `& }/ X
           set b  int (a / 5) * 5
$ O; Y4 a- X$ D% W: q    setxy ( xcor-of turtle b + x )
: Q0 a& t: n! |0 Y6 |          ( ycor-of turtle b + y )
5 z3 g) Y4 N. n* @6 w- v6 eif (remainder who 5 = 2) [set c who/ w6 r: A$ C, }! n7 N
                          set x ( 0 - Wid / 2 ) 9 i* Y6 M. l% Z/ S/ h
                          set y (0 - Dep / 2 )  ]
) \: W' D3 r: [, F$ _                          set d int (c / 5) * 5
' U- [+ b2 l% X   setxy   ( xcor-of turtle d + x )
4 s8 Q7 {7 x& k( _% Z           (ycor-of turtle d + y )
" e) _1 j/ n8 b          2 m  v8 _* i/ i; Y' m
            + F# a  W, i" U' {4 Z4 {
if (remainder who 5 = 3) [set k who
% F1 n1 i9 a( R+ _; K) z; u' b0 r                          set x( Wid / 2)  
$ R- K# a, X! M7 _' F                          set y (0 - Dep / 2 ) ]1 }3 k  y3 W" U2 y" q
                          set f int (k / 5) * 5
* m: a; B; Q9 {  setxy   ( xcor-of turtle f + x )1 f- H! X7 W' c7 |
           (ycor-of turtle f + y ) 9 c& K& O5 b7 L5 N
           
3 m) z6 {9 T3 k$ I           9 K8 M7 U3 G: y
if (remainder who 5 = 4) [set g who3 E. F! v: k/ }5 ~" u
                          set x Wid / 2
8 D  R( r' p( k  A4 q% C                          set y  Dep / 2 ]
7 b9 [2 p1 l0 q                          set h  int (g / 5) * 5
# |5 C0 j# S; v$ b7 F: E$ r+ K  I  setxy   ( xcor-of turtle h + x )
0 j2 h5 P6 k. F2 v           (ycor-of turtle h + y )
) I9 }/ F. c  ]" o3 H8 j                          ' B$ H, T3 H  @" W: @2 b
                          ! E3 l0 L# D  d* U% K# x
                          ]; [: {6 G/ h5 V* ~- X: H
end$ t9 i3 l* I  A: V

5 g/ D# q# ?# P% i* U7 M( O4 w[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
% I7 s9 B- @/ s6 Q& N- K1 u. Z应该是
& I& J9 S; |! @' e) Cask turtles [
) m; ^, b: b2 P* v# eif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
: u; h0 f/ @+ O: i& b- S                          set y  Dep / 2 ; ]) {. w) c9 T; h9 f
           set b  int (who / 5) * 5( h: k7 m2 B2 }
    setxy ( xcor-of turtle b + x )
8 w% \1 Z, j/ m+ s  ~6 g; r6 c9 k          ( ycor-of turtle b + y )]]5 }. M7 D9 _7 F  ^
end
) `! ]7 U! t0 r3 _9 s之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-22 19:31 , Processed in 0.018173 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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