设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5896|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。4 l* W* v% Q! x9 U: h. W

6 ~& O- ]  e! S" }; Y5 P# d. n2 ~$ }但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。. V9 I+ z8 g4 G
, ^+ ]+ Y% J9 t4 a
turtles-own [a b c d k f g h- N+ B" g3 x8 V5 C( d
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
  S( w: F0 l; T* ?7 n9 w/ ?]
% a. i' r) |4 |# d: uto new9 D3 n/ D5 t3 N: }: i& h+ n
  ca
# {9 G8 s" x  b; A- _* j; q5 a) N& |, G  crt 5 * num_of_building
2 G* Q  \/ S& w: ~1 Y" @# _  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]9 n( }3 s# Y5 v4 p
  scatter     ;;keep center-turtle random positions " t) P# _( Z3 b0 l' l5 G$ A
  unit_plan   ;;make up the building plan- Y0 u3 R, n1 \. f  X) W; T* g
end
& @, ^. [5 z0 w* ^) V  v9 r0 ]% s" zto scatter- |3 c& L- c' ]2 e/ \  S# o
ask turtles with [remainder who 5 = 0]; v( S$ W# [# U" T2 S
[, o. h2 t' y' [' s4 C
set xcor xcor - 6 + random-float 154 l/ q6 V" @$ s2 l) u- U
set ycor ycor - 6 + random-float 154 }. }8 P6 j$ o% \/ z  O0 V
]4 b+ d. W, N' ?  G
end1 b- W1 J1 J- F* U; a3 r& G
to unit_plan
& w. E1 A. }8 b+ |6 Y, c* {" Dask turtles [  ~9 R( G$ Y) u
if (remainder who 5 = 1) [set a who
8 i1 J5 ^/ u# \4 s# L0 h* s5 K                          set x ( 0 - Wid / 2 ) - D# u* `* ?4 t! `* g
                          set y  Dep / 2 ]
) N, F  h6 L  S' z+ j0 ?. M           set b  int (a / 5) * 5
& W6 Q. Y) Z' Y+ K    setxy ( xcor-of turtle b + x )) N# B( [% t) F2 B: S* P$ j
          ( ycor-of turtle b + y )
! v6 `9 z6 _# S. a0 yif (remainder who 5 = 2) [set c who
0 w9 O4 ?  E: l( F9 s                          set x ( 0 - Wid / 2 ) ) a; D# e& p- T$ m, W
                          set y (0 - Dep / 2 )  ]
2 S1 W5 t( @& b0 G7 {                          set d int (c / 5) * 5; ?% y6 c8 u, G
   setxy   ( xcor-of turtle d + x )
8 b) P" A: ]' j9 R. \- W! d8 d           (ycor-of turtle d + y )
' U) u1 F$ ?& E; ]         
2 o" m: [) ]  ~% d5 E            
2 |2 u! G3 w7 G7 r: w) bif (remainder who 5 = 3) [set k who
; m- c& O- T  x. k( n                          set x( Wid / 2)  
1 X6 |/ e5 L" R                          set y (0 - Dep / 2 ) ]
0 O& H3 z; d2 F0 B                          set f int (k / 5) * 5. ?6 x5 H3 H0 F: `' ?' _5 \
  setxy   ( xcor-of turtle f + x )
2 p* U& f/ d) n4 Z3 R           (ycor-of turtle f + y )   N$ j- x* `6 E! L, Z4 ?
           
4 W) u2 \% x4 Q) W           
: L4 n, @! U6 h# j% H* wif (remainder who 5 = 4) [set g who& n' c$ B* t+ O
                          set x Wid / 2 4 b1 [; b1 e8 N' |  G
                          set y  Dep / 2 ]$ g# u' V4 w! P9 F1 H1 Q
                          set h  int (g / 5) * 5
2 F; E: Y: o0 o$ Q  setxy   ( xcor-of turtle h + x )
! {$ S; g+ m' f           (ycor-of turtle h + y )
" Q% d: d. @0 ?4 u: l7 V' O                          9 J0 r! G$ o# L" K8 I0 x2 c( [
                          * e4 k! w8 _& y3 y- V
                          ]( I$ _% ~/ V8 P/ t* t' Z2 c
end
. M9 \% D4 h, l9 p4 A3 H0 F' M) `  O0 Q( Z: B
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
, y" A" O1 V2 h* q3 M* C! b应该是
0 c7 [/ h) w3 oask turtles [0 W7 Y# Z/ ~! A) F
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
$ M0 N# V6 z1 ?; `4 P! a9 j2 P                          set y  Dep / 2
: i: z  p9 @1 w0 J3 ?/ G           set b  int (who / 5) * 51 v! @+ R/ A' _) Z  u! ]
    setxy ( xcor-of turtle b + x )
8 Z9 E( [4 p7 K' H; q          ( ycor-of turtle b + y )]]9 ]7 `* ^& e- a' V  E6 C3 R2 w
end9 S2 ~( u% z, v/ _% ~
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-6-30 04:02 , Processed in 0.016777 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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