设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8277|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
$ M  d' t3 _2 M: `7 P' f; f2 I3 _0 J# K! ^$ j
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。! d3 x1 `, D) V; H  c

0 x/ E1 \- x* T- i4 Vturtles-own [a b c d k f g h
& j9 o1 L5 Q2 w' x  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 6 r9 S; ]" B4 U4 W7 c
]% ^5 `3 S/ j6 W( a) ^8 d
to new$ \+ m) f# l8 {+ D: s) o3 A
  ca7 l: h! f2 \& G* V
  crt 5 * num_of_building
% D/ J4 v6 q* \4 q" ?  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]1 {! H; r$ C# _& N) a; d
  scatter     ;;keep center-turtle random positions 6 T' U2 F9 h& Z7 j. p
  unit_plan   ;;make up the building plan$ @0 U* D% |  C7 Y
end
# C4 S& e/ H- B. bto scatter4 ^) }+ h, ?  U8 z& b. R6 E
ask turtles with [remainder who 5 = 0]8 Z4 C" }+ z  P' ?+ i7 E
[2 f7 N- o) v! d3 q
set xcor xcor - 6 + random-float 15
4 x. u( [9 X8 E3 b7 i5 n& c1 e  Wset ycor ycor - 6 + random-float 15
  Z$ P- z& C! P* ]) W]
7 p; X5 @1 ^: }& m7 Q8 ^end
9 N0 _6 ^& v0 [/ k' c1 Wto unit_plan
5 T- m' M3 ^" j8 c/ i# r, y; z5 Rask turtles [- J4 H  i$ {; k/ g' v# A& m* S/ B  B
if (remainder who 5 = 1) [set a who * E' |5 F2 s# h0 @
                          set x ( 0 - Wid / 2 )
: d9 U' [) X. \% C1 D                          set y  Dep / 2 ]
* q' k7 j# R! `# Z/ V1 _           set b  int (a / 5) * 5  O. @! G8 d) @# C0 d
    setxy ( xcor-of turtle b + x )( Q( {( e, t# ]. }! m0 o
          ( ycor-of turtle b + y )
' a8 J$ g# O) f8 g: cif (remainder who 5 = 2) [set c who
& ~$ t% {( T+ w$ Y! h                          set x ( 0 - Wid / 2 )
3 S- k8 b" s) A7 r$ u( O                          set y (0 - Dep / 2 )  ]
% n5 e5 {  @7 p1 V                          set d int (c / 5) * 56 R# b) R& l0 ]: z7 }0 B
   setxy   ( xcor-of turtle d + x )' L) E, V' ?' m3 v( z. M" p
           (ycor-of turtle d + y ) 2 N& f& A+ w: o1 R' A
          & v  B0 \7 M) U: w
            
) y- q& P4 |$ t" b! i2 b1 m4 {if (remainder who 5 = 3) [set k who# {; p- h( q' a( t1 S) K
                          set x( Wid / 2)  
! h1 W: \1 ~9 R( C& l! b- t0 n# ^                          set y (0 - Dep / 2 ) ]9 ?/ |- C% S4 r+ i7 b& l$ V
                          set f int (k / 5) * 5
4 w, d9 h  |9 d: H) z2 E( F; r  setxy   ( xcor-of turtle f + x )
" N3 A+ f+ u. O) @" E: h# S           (ycor-of turtle f + y ) 3 I" z6 Y0 o: c5 Q' c. L
           
6 ^0 G- \. ?6 d  K           - s0 r! R: p. G& Q& ^' g
if (remainder who 5 = 4) [set g who
1 V( y) B( V& q5 _0 O& t+ |                          set x Wid / 2 5 M: t4 o6 {' Q6 O# x2 p
                          set y  Dep / 2 ]
2 c. ~4 Z- b0 P5 [                          set h  int (g / 5) * 5; Y* ^1 o' H5 \2 U9 l* H' L1 P
  setxy   ( xcor-of turtle h + x )8 q( i) h; h) ^' F* Y2 A+ p, `& K
           (ycor-of turtle h + y )
. x9 S3 j4 F& t& O0 v4 e                          
. }: M2 o% t; f3 s7 E+ h; x6 N' p                          4 _$ @3 A$ _5 X) j0 P; {
                          ]
6 A& O( [2 A( j+ B" r5 W# u8 Dend0 ^4 [" f% R* ?! W1 ~; d
. T1 ?( U9 u' n2 \, d
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
2 A8 x' j, _  x' D1 c应该是0 s$ F( e2 L* Q7 F7 i
ask turtles [
- F, n" X* H" h6 h- I/ g4 ]if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) # W& T( p- a9 L( {% B7 u, J: d
                          set y  Dep / 2
2 Z% |2 O9 v7 ]2 w. i6 A) N6 B- X           set b  int (who / 5) * 5
& M) E; T. A% l, N/ H- s" q    setxy ( xcor-of turtle b + x )! D) D% Z- G; b
          ( ycor-of turtle b + y )]]0 W( ?3 D0 a" n
end4 o! p. r, L8 @9 ]0 I% [
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-28 23:33 , Processed in 0.019920 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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