设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6650|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
# n5 ~' K, v& V0 z8 F* V0 N3 K+ v6 \6 B, D
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
* |, r% B, S& [6 j
5 Y/ `$ p0 {6 ]; ~1 pturtles-own [a b c d k f g h2 |2 q. V' J) s1 z3 R) U* n* [
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle # G, b2 h) d1 }9 `# g. v
]. {$ Q$ H3 `: G0 U$ v9 _
to new0 R# f* ?. ]' [9 Z- H3 r$ X
  ca
1 u- Y) [1 j* `9 y  crt 5 * num_of_building
$ e$ H$ Q0 U. G& D  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
  l- ~/ L- v$ L. }! m' D9 z  scatter     ;;keep center-turtle random positions % j: a, {' e8 k& I
  unit_plan   ;;make up the building plan
0 h8 O' a0 w% g" a3 ?% b# q$ aend
, ?  L4 R% K  \to scatter4 ^2 p$ c! `' p
ask turtles with [remainder who 5 = 0]& Y- k  X- O' E. l3 A% n7 s1 o9 C+ k
[- x; y( V, J% D: @
set xcor xcor - 6 + random-float 15& t$ ~0 x& {. K9 [* V6 ?4 j
set ycor ycor - 6 + random-float 15; K6 {1 J5 R2 ?; X8 G* X% I  K
]
) k1 d1 |; K/ D* }. w  x$ j9 A2 ]end
9 X* w' t7 m1 n$ _( Kto unit_plan - x/ b1 y; D. s/ h( ^2 w+ z
ask turtles [
  j; c" |1 y  `/ A, I* k, ^7 R5 Kif (remainder who 5 = 1) [set a who : ?2 a4 w: p- l( U
                          set x ( 0 - Wid / 2 )
9 j% a* e- ]9 m& g- s2 b                          set y  Dep / 2 ]
+ ]6 n" ]) Q3 M4 S- t           set b  int (a / 5) * 5
% ]6 x" J( X3 }    setxy ( xcor-of turtle b + x )& g1 O$ W! k( R, y% u" `+ d
          ( ycor-of turtle b + y )
+ G4 ?: B# P: ~3 m+ v2 e# Tif (remainder who 5 = 2) [set c who
2 A! w8 K0 ?  V/ M0 ~% V# \2 E                          set x ( 0 - Wid / 2 )
' c! v9 @( V" C" R0 c' V                          set y (0 - Dep / 2 )  ]
. J1 W8 R8 i! H5 B" q& v) ?                          set d int (c / 5) * 58 t  l4 \$ P6 r, }* ^' y
   setxy   ( xcor-of turtle d + x )( `, W. _0 v- F5 u5 O# F% V$ t
           (ycor-of turtle d + y ) 4 h. d0 ?, D5 N. {7 N9 G( v, U
          * y9 w2 k/ ?+ g0 j5 u, H. f, Y4 M
            
2 P$ T7 W) r. j$ Nif (remainder who 5 = 3) [set k who3 i5 s# O. H8 m% B0 @
                          set x( Wid / 2)  
) I9 ^  a, _; G8 `( I: ], O                          set y (0 - Dep / 2 ) ]: n7 e. s1 |+ z, a- }
                          set f int (k / 5) * 5% w" T  G0 _: e# p$ ^/ V! X+ H% c
  setxy   ( xcor-of turtle f + x )
: O; `1 ^/ r4 l/ a6 ~) `# A( R           (ycor-of turtle f + y )
3 z- C; C& A- y9 S. S           
+ f; I5 G3 e9 ]2 A# a           " ?) x: \. A6 h. c: N
if (remainder who 5 = 4) [set g who
* O) O$ D2 Q0 p! H  E' l4 B7 P                          set x Wid / 2
1 q3 x$ r3 Y' Q* d1 u" W- c4 ?                          set y  Dep / 2 ]6 @  ]/ m; h3 L. D" e! U$ ^
                          set h  int (g / 5) * 5
8 ]8 ^+ `, e+ I" O( W# A  setxy   ( xcor-of turtle h + x )
/ f" a+ g% ^9 A( E3 m7 r- l           (ycor-of turtle h + y )
; S* K" A6 n3 j8 s( _& J                          
( j6 j5 n. u- V; E6 }9 p                          - ^* K3 P4 q& W+ j: p( ~9 H. n& W- ~
                          ]" v' m* b. |) H# }5 q/ O
end& j+ I1 Z4 Q. ~; ]$ G1 w/ K# x- B
" e& R* W9 G$ S/ q% n1 N
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
+ y7 n; W2 U7 }. l* W+ j应该是
% y6 D, F$ K. {ask turtles [' _: H* [; I7 A; @3 C' W
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
3 ]* A' Z0 x8 O                          set y  Dep / 2
5 A6 s' b* V+ y$ R( F9 {           set b  int (who / 5) * 5
5 K# M/ }% @: r# O    setxy ( xcor-of turtle b + x )
2 e' G8 K) U( S+ }          ( ycor-of turtle b + y )]]8 b1 f1 H" s: B1 f& y* L- T
end
" L# W4 N- o! I; w之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-7 19:07 , Processed in 4.421305 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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