设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7939|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。8 l/ h+ w- O9 V6 S
7 y9 i) a$ P9 ]" x% w. v: j5 U
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
; D. K  a3 w% K0 n
+ z& Q! f) i* a% Gturtles-own [a b c d k f g h
9 ^3 h1 G# t! i% a* s  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
# z+ q1 I$ Q; R  r1 F5 }& o]
9 q; b" C, B  [  y% V+ y  [9 h) E0 Kto new6 S0 W5 _2 z/ Y: c& \0 {+ W
  ca
. d7 j% o8 m0 _  A3 [  crt 5 * num_of_building5 Y; H% |6 i$ Z1 M( V* Q7 v: g
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]( q1 Y7 k/ g( y# T9 B6 f
  scatter     ;;keep center-turtle random positions 4 l! J  I  x  D. L: q; \6 x. I9 G
  unit_plan   ;;make up the building plan- c5 w$ W3 Q" V5 e' `) w; `
end+ V9 Q7 @$ M- `
to scatter
9 {% _% \1 t) {. Z! E' h5 h4 aask turtles with [remainder who 5 = 0]9 `& U+ R, y& z
[+ h3 u8 L& i1 I, f
set xcor xcor - 6 + random-float 15( x; ^2 ~2 N+ b2 K4 {" b# a( K/ c
set ycor ycor - 6 + random-float 152 I0 I. B2 d' C6 p( Q  y
]
- b$ x' f. }( Aend& a5 c; |" j' V9 }2 r. ~
to unit_plan # h7 v, g: J/ A- t* E: [  Z" o
ask turtles [$ r8 ]6 D8 ]2 y# d% O* i: j7 m
if (remainder who 5 = 1) [set a who 6 J: L4 b& l  M2 Y$ ]! T9 e
                          set x ( 0 - Wid / 2 ) + j1 h) S2 m. Z8 e8 M
                          set y  Dep / 2 ]
+ Y3 H1 x9 K1 ~. b) c! `1 N. F           set b  int (a / 5) * 56 S8 h1 C1 h8 E' E* Z
    setxy ( xcor-of turtle b + x )( y& y- V8 y& ?  c0 H! I& v3 g
          ( ycor-of turtle b + y )  p" j3 o9 D2 x* `' O! {
if (remainder who 5 = 2) [set c who
' c1 q9 C5 j. \                          set x ( 0 - Wid / 2 )
  J* _# [+ h0 D  h5 M  O" U# R- s                          set y (0 - Dep / 2 )  ]& f5 }# q% X: l# b5 l
                          set d int (c / 5) * 5) Z& ~( x# |" U
   setxy   ( xcor-of turtle d + x )0 ?' s8 D5 A& R" C; K0 `
           (ycor-of turtle d + y )
- ?- r( G7 ~& i" n         
4 x/ j2 v+ o6 c0 ^, v            
! _5 k" y. E9 J8 l7 h  w' a, i; Rif (remainder who 5 = 3) [set k who! g* J* d; n0 B8 ?; s
                          set x( Wid / 2)  
) d- g) K5 F) p2 o                          set y (0 - Dep / 2 ) ]+ u1 x8 u8 ], x6 s" C( r& [
                          set f int (k / 5) * 5
7 P  I& m9 g( d' b7 c1 O  setxy   ( xcor-of turtle f + x )) U$ U2 n2 |/ h. r. m, [* Q
           (ycor-of turtle f + y )
  _* a" {! [" v7 X) y- C* Q( B           2 b+ ?& D* z# d6 c' u5 W& j5 {4 t
           
. L! M9 X) U5 `/ yif (remainder who 5 = 4) [set g who
4 D; I* d. J. J7 G! ^9 Q, M                          set x Wid / 2   ]) _* V( g! }4 z3 ?
                          set y  Dep / 2 ]5 O% d( x! c) M- Q
                          set h  int (g / 5) * 5, f4 M* C. p! o  w  L$ I( Y  S
  setxy   ( xcor-of turtle h + x )6 y6 e: a: t& U3 U) i) f
           (ycor-of turtle h + y )
! t; a( `; p) j: M; y                          
! C- c. z! {& g9 y3 A) A$ z                          
: e1 y4 N7 z6 }; p# R1 M# I                          ]
; N- e4 U! R5 u7 A2 P- M- ?end$ ?- z# w( b; \7 Y' u5 |

/ C; A* e. i. ]8 T/ t. o[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
4 ^& ]9 n  E  D- s" @应该是. M5 m# |  L. G8 i0 D
ask turtles [
; i  W: s& `- ?if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
0 U6 i5 l' O+ c" ?" ~! e4 n                          set y  Dep / 2 3 \$ T/ k- g) h* f3 U
           set b  int (who / 5) * 5  p/ X' n! r5 s7 [' D  x/ O
    setxy ( xcor-of turtle b + x )
+ I" w+ S4 r3 ]" E6 {# w          ( ycor-of turtle b + y )]]) l% W7 n/ d7 c3 S
end
: u* q0 r7 o! c/ h之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-20 06:25 , Processed in 0.018849 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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