设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8496|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
; p5 @0 H7 k! G# I- Z: Q, u& [# P! W- v8 @+ l$ K2 d% j) N2 \, e
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
5 a# Q: b& h/ l2 p$ s, H. G% K# e( b* A
turtles-own [a b c d k f g h' h- b3 @7 g2 ~* a
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ' Y+ t$ ]4 V) b0 K( L7 K5 c
]' [  a2 U# o0 Y' ]. F4 T6 ]! q& }
to new
9 g& M2 M3 w; z0 @* Q: W& d! T  ca7 d6 n# ~6 }7 I2 K: _; B( {2 T
  crt 5 * num_of_building1 j& t) ]- o: i3 H: S  k8 S
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]& n/ F1 E9 h+ H0 \, K2 j$ J' E0 g6 @
  scatter     ;;keep center-turtle random positions
, i. v1 u: Q# h8 P' ]5 Q  unit_plan   ;;make up the building plan9 x# ~) y9 e0 P: C8 t! |
end/ A- Z9 u% J- e
to scatter
9 e; A4 {1 t+ q3 S7 B6 Oask turtles with [remainder who 5 = 0]7 s* t8 c/ |. C& [. I4 w
[
$ X$ q0 q9 G: B% S8 s# eset xcor xcor - 6 + random-float 15# T' H/ }8 {& ~) e8 F' s; x  P
set ycor ycor - 6 + random-float 15
* |1 |/ D2 H* u+ M]
% K! T0 |. X! Y. q' uend; ^: n2 }1 z, I) f' E% m
to unit_plan
3 s  U. |& w; n% a) d" x7 Iask turtles [% ?  ]* g5 P+ d6 n9 B4 x  C, |
if (remainder who 5 = 1) [set a who   J8 j; P) Q! U! n, x$ S: K
                          set x ( 0 - Wid / 2 )
9 a9 z& P  i+ D                          set y  Dep / 2 ]
" K. k3 l8 l" s           set b  int (a / 5) * 5& l4 w6 s+ W2 ^9 f5 R
    setxy ( xcor-of turtle b + x )7 K  m* X8 `( |2 |( J6 W- g0 ^
          ( ycor-of turtle b + y )& R+ u, T5 v3 U) i, f2 J% U9 B
if (remainder who 5 = 2) [set c who7 a9 s8 B/ A4 c) ^- j% a, Z0 G. {
                          set x ( 0 - Wid / 2 )
& A* ?) S4 s1 p                          set y (0 - Dep / 2 )  ]
6 E& a' X5 N: S) g4 u                          set d int (c / 5) * 5
' h# d/ P( r, F   setxy   ( xcor-of turtle d + x )3 P+ e8 F# o$ W$ Q, Y. F
           (ycor-of turtle d + y )
, e' y2 U2 s; v% p/ o         
1 `3 e1 I( {' N3 n  ~  L            ( J) ?2 v/ {; O# M  @8 K: n; I
if (remainder who 5 = 3) [set k who
3 p# J! a, l- Q6 q# n0 S' @# ^                          set x( Wid / 2)  
1 d4 ]$ I8 P( {+ d7 a' O0 ]                          set y (0 - Dep / 2 ) ]' b5 A! C* Z- s8 }- V8 F
                          set f int (k / 5) * 5
/ p- m& Y, Z% w5 w+ N; e0 I$ ^4 J. j  setxy   ( xcor-of turtle f + x )
7 {! b1 ?- d! r; j9 s: a           (ycor-of turtle f + y )
' I0 T5 Y8 I6 C+ d  R9 b7 F6 T& g           
6 _* ]! Q/ C) P           1 Y, _4 V9 l: C
if (remainder who 5 = 4) [set g who
5 F1 s) |: C  T+ }4 h                          set x Wid / 2 0 }; H6 S+ {$ O0 Q' \0 m
                          set y  Dep / 2 ]/ y% j- b  `$ Z' N, u; f" F$ t1 v
                          set h  int (g / 5) * 5% n5 _* i0 r7 z+ U- \4 v, J/ ^
  setxy   ( xcor-of turtle h + x )
6 b, K9 ?& x) O  d0 U4 c9 n( Z           (ycor-of turtle h + y )
# X# ~3 V' l& l# `4 `                          
6 |6 K0 {$ c1 _0 A) a  o; v                          
; x9 \% ]5 \8 t8 K1 v- }) f/ ^                          ]
2 a# }& f4 X( `, Z$ V8 ^end2 ~: \' H9 f+ i1 e5 _% I3 q
  b) I2 M* u1 U% W  A
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,& F' s! o5 P2 W5 N
应该是/ Y$ M# v9 b% ~
ask turtles [
$ E9 I+ O) U: D- Hif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
$ D% P; I6 @3 d4 o' n. e                          set y  Dep / 2 2 A7 r' I  I; U5 a
           set b  int (who / 5) * 5
& u7 v0 ?' M" \* B) S! E    setxy ( xcor-of turtle b + x ); }) g. E) w5 w  N' j" s+ d
          ( ycor-of turtle b + y )]]
; d2 H7 @, \1 o1 e0 L$ Y1 Zend- _* ~$ x8 T, @4 x' B; f  m
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-4 17:34 , Processed in 0.016034 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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