设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7639|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
4 o% C* `6 G# y/ M
( B+ r6 r  ^" b$ `1 t# W9 h5 s6 d! O但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
* C8 Z, G6 g: i" x) z( n0 q; i
% B: e% [) @& k* x2 Bturtles-own [a b c d k f g h' q, _* z+ U0 w- I1 @: G
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
% P$ d  m& r5 k* w+ B7 p], ?) ~* m* h8 v" H- s1 Q4 T
to new
8 E* `4 A7 \& o# Z) g. r0 ?  ca; r0 j4 m8 S" i  e, p
  crt 5 * num_of_building
( u' m9 I5 D; k3 f# x  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
/ c1 Q  Y0 J# H! |. E  scatter     ;;keep center-turtle random positions
3 j) n' ?% ^; j2 {$ O: o; d  unit_plan   ;;make up the building plan
0 u8 U* u$ [% iend) M& {+ c9 |4 m" y9 j0 G& h$ z* S
to scatter
; I/ N7 P* x& I: s) iask turtles with [remainder who 5 = 0]4 {; g- ]. f- M9 b5 S, `
[
2 U/ L, W( J" r) X* {set xcor xcor - 6 + random-float 15) X$ {# \+ N! R
set ycor ycor - 6 + random-float 154 r; J4 d3 W1 P/ t
]
1 q  K, P6 I- W6 _end. b+ Y) \! y  q6 Y6 p, C
to unit_plan
9 d2 R& [  ~* j1 q6 J) D- V$ Wask turtles [
  ~9 J" K+ j6 _# n8 M6 |if (remainder who 5 = 1) [set a who
* {- c, U5 K" T% b8 T$ b                          set x ( 0 - Wid / 2 )
& ~! g: O' L3 l5 O6 D( |! T8 y                          set y  Dep / 2 ]  `4 L+ j# O! O
           set b  int (a / 5) * 56 e- t0 p) C& X! o9 A
    setxy ( xcor-of turtle b + x )* @& ~8 ~/ A) x0 a& }) a
          ( ycor-of turtle b + y )
0 A; E4 _2 Q8 Z0 W; k) Jif (remainder who 5 = 2) [set c who
' R9 m- o+ k& N- z% q: N, ]                          set x ( 0 - Wid / 2 ) 5 i1 x* k  w# z
                          set y (0 - Dep / 2 )  ]" J9 f4 ]% A( U# K6 ?- M0 l
                          set d int (c / 5) * 5) W1 w: H' m& X  C$ K
   setxy   ( xcor-of turtle d + x )
% q- G2 z3 \6 z2 ~" R$ G* Z           (ycor-of turtle d + y ) 9 `: e; a% |7 h
          - F$ n! }9 g' {& ?3 j
            
9 ]) v$ O8 E1 w! U9 ?! u- j4 Mif (remainder who 5 = 3) [set k who) E" X  O* q) F2 p+ w; Q
                          set x( Wid / 2)  $ L# w5 e5 n1 _
                          set y (0 - Dep / 2 ) ]
9 ]7 c  |9 H1 v1 G6 S- z                          set f int (k / 5) * 5- [4 S" J. _7 O* y
  setxy   ( xcor-of turtle f + x )) o5 M0 _7 @5 T" n- p: S% y1 A" C# h
           (ycor-of turtle f + y ) 1 q1 N  J' H' O2 W1 [* M# v5 c6 V
           1 e( T$ P) L6 _9 E9 @) ?
           
' H; ]. }& _( w/ Dif (remainder who 5 = 4) [set g who0 O9 D9 h/ r/ X# Z( z, ?5 P
                          set x Wid / 2 , o8 k: H6 W1 H% a6 R
                          set y  Dep / 2 ]
* R$ ^: X$ m, v2 H                          set h  int (g / 5) * 5! t, W3 Y/ s. c# v" X# r
  setxy   ( xcor-of turtle h + x )
1 F' x7 R% F/ ^9 ^3 o  X$ Z: s           (ycor-of turtle h + y )
- x- G1 a7 }# h7 U                          
4 I7 i! Z, h8 x, u                          2 d& T+ k7 g, ?. o/ _& I; _% n! o
                          ]  O* j+ |4 P. u
end
; j: c* @( c, A6 |+ `
6 q3 q% o7 A+ Q7 A) m) V$ O[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,7 C: {. R( V0 @* V7 |. Q
应该是! b: p4 |* t/ [0 e
ask turtles [, S8 t& ~6 V+ `
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) & S' V2 }! c7 @3 p
                          set y  Dep / 2
, B$ D7 J: _  l: A1 x! C2 r7 q           set b  int (who / 5) * 5
6 S7 o; @, H$ H    setxy ( xcor-of turtle b + x )" J  L( E+ s3 `' |
          ( ycor-of turtle b + y )]]4 Y& I/ x+ s& @
end. g  `' e8 w" U; [
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-10 01:08 , Processed in 0.017224 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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