设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8177|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
# E' P  M! U' n4 ]5 _8 Z6 B# P- S* j8 I# J$ G
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
/ f$ X  @1 }( }+ L/ i: S" F. ~
turtles-own [a b c d k f g h
7 l: s; g7 |1 g9 ^$ X' \8 M$ B  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 5 J  N! u* L" h# a4 d* D/ Q
]* }. I! q: r4 o& Q0 T+ x2 x
to new
- O! g- i9 [% Q5 e! T6 i  ca0 M* Q( {" Q( k: J: i
  crt 5 * num_of_building. l/ z& r6 n% v, K
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]! W! A$ \9 n7 y/ l9 A5 `
  scatter     ;;keep center-turtle random positions
: T5 _; _5 V" k) D0 g  unit_plan   ;;make up the building plan
) @2 M/ c4 `9 d1 [+ Mend
7 h" {; f& Z. p0 x: N/ V& Y2 Cto scatter
2 e- N6 C( d2 P; v: [ask turtles with [remainder who 5 = 0]8 C) P2 @! I# @! z
[
: |# ]+ @. u. h; Jset xcor xcor - 6 + random-float 15
9 x: g* e# a' \! _3 m0 c) Wset ycor ycor - 6 + random-float 15
! L2 d9 ~: ~" j" a# W& e# ^% T! ?$ g. W, J]
1 _7 I, ~' T- f6 K2 v3 ~end* F. ]- m5 n" e. p! ^* }
to unit_plan # c& r3 Y& I; E
ask turtles [' f) u. o; U: I: H. W4 _
if (remainder who 5 = 1) [set a who
9 w& v7 l$ D3 `5 C7 N2 f" w' V                          set x ( 0 - Wid / 2 ) % M( v# n0 u' j; y9 l$ g
                          set y  Dep / 2 ]& F% n6 T2 ^4 S2 L0 e
           set b  int (a / 5) * 5
' c3 d# ?3 X# F/ o9 A" G1 ^9 c+ F    setxy ( xcor-of turtle b + x )
8 k! ~" d% m- g! o( O" H          ( ycor-of turtle b + y )
8 c& K5 ?9 g5 d! ~if (remainder who 5 = 2) [set c who
% V, t+ m7 b: ~4 O+ ^# r) y% m& }                          set x ( 0 - Wid / 2 )
2 D. ~% x, F  X                          set y (0 - Dep / 2 )  ]
$ J( V9 G" p/ ^5 |0 X  `6 U3 }                          set d int (c / 5) * 5/ R' G$ B- }! m# a; |3 y6 u
   setxy   ( xcor-of turtle d + x )1 I+ ?" J" D/ o2 q
           (ycor-of turtle d + y )
. t8 R) f( C9 _# f" g( \         
9 f. Q- n; _& i( I            
0 ~& {4 u: E4 M5 Dif (remainder who 5 = 3) [set k who  t5 j* J: ]& G+ G$ m  L
                          set x( Wid / 2)  3 c1 w4 s2 y( O! B) E. z* Q$ y% u
                          set y (0 - Dep / 2 ) ]( d  \; v* e  F5 }  M0 O% s
                          set f int (k / 5) * 5
0 ^5 d# C& P+ b2 e  setxy   ( xcor-of turtle f + x ). D0 B! b7 r( }7 I4 n
           (ycor-of turtle f + y ) 2 B5 U2 g$ C% V8 q
           
9 x& P, y8 {4 L9 w* B' h, a4 j, b           # O; c- ~" {' h+ G! A% p& f
if (remainder who 5 = 4) [set g who
0 g, b* q/ r% H) e                          set x Wid / 2
& Z5 P# [  B; E- r" b                          set y  Dep / 2 ]
1 ?  N+ X" t" C* v' g5 J                          set h  int (g / 5) * 5
5 {/ h, v2 x6 a; v3 Z8 v. n5 K4 S  setxy   ( xcor-of turtle h + x ), x' _+ m, @7 c8 ~* K: W
           (ycor-of turtle h + y )
" |8 b: c5 W4 Z! A9 V9 S& f5 `                          " s6 Z6 A- r. q( I! @
                          : A7 d. w6 S" ~' ~
                          ]1 I- p5 b) v/ D! P; J' N+ G
end
! x' N2 ]9 T1 S9 t; \% ]. [" b
8 U+ h5 K4 p+ }' h7 s[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,- W' |; K) h8 ^
应该是
2 g; d/ b5 D8 e, i# ~6 n6 wask turtles [
' L0 x, v3 p! C( q$ I! pif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
3 q/ X9 Q; e" R                          set y  Dep / 2 9 a) Y3 h$ f. s4 W' r5 I3 M/ G  P
           set b  int (who / 5) * 5
; ~1 O4 Y* \5 A5 G$ m1 U; ]) j    setxy ( xcor-of turtle b + x ): D& z/ }3 z0 Z3 I8 v
          ( ycor-of turtle b + y )]], }( l2 F" \2 K4 W  b5 i' Z
end
# e2 c$ W  Q" ~- Z4 J之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-14 23:21 , Processed in 0.020193 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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