设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8957|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。/ q( ~/ J7 b3 B5 F4 U
8 P0 D: }: L% L+ t& ?9 W* H# p
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。5 a& [1 U9 m) _( V
  i/ o& f4 Q% q
turtles-own [a b c d k f g h6 D* Z! O6 _: G& o, [  v9 }
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ' C6 p7 r; t) A: Y: p+ m( e3 x3 K3 W6 f# F
]6 C' N2 x" L8 u; j9 b
to new
5 k. S" r. I4 L4 T" @  ca; _+ g* Q& m  f
  crt 5 * num_of_building2 d, E1 o. e" k; X
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]) j4 Q! Y/ k3 R( c1 b
  scatter     ;;keep center-turtle random positions ( `' O5 i  S8 m8 {6 z. M
  unit_plan   ;;make up the building plan$ D  d$ l  Y" s8 t# S
end" q  }) M6 W" j
to scatter
" @6 t" A5 b+ bask turtles with [remainder who 5 = 0]1 n- |4 ?% e& }9 q. a0 T* e1 Y
[6 V( g7 s' Z( d
set xcor xcor - 6 + random-float 15# o1 l& O3 c; @$ C# F3 O5 L
set ycor ycor - 6 + random-float 15
, j9 g' j0 L  i4 `]
3 P/ o9 @3 l2 A9 b! d0 Rend
7 h% C0 l7 W$ }) ]to unit_plan
  ?$ ^& o1 V/ P- Gask turtles [2 B5 G6 E' }$ I, c. a+ j/ x
if (remainder who 5 = 1) [set a who 4 G2 x! s3 m' E! B+ Y6 G- r
                          set x ( 0 - Wid / 2 ) / Y" O+ Y+ L/ O' X% _5 ]
                          set y  Dep / 2 ]
, W! k( c4 H7 H' F4 _" T" D! Z           set b  int (a / 5) * 5; n. u! I1 Z6 x/ j
    setxy ( xcor-of turtle b + x )8 Y5 x7 e/ E! V4 \: F" E4 Z! ~- q
          ( ycor-of turtle b + y )
5 a) R! d$ R8 A- {- xif (remainder who 5 = 2) [set c who
5 U+ O# F/ |0 o3 s3 L4 W+ T2 Y3 ?# L                          set x ( 0 - Wid / 2 ) " Q. y7 p" i; E" c* `
                          set y (0 - Dep / 2 )  ]0 _: Z& u5 V- J% @
                          set d int (c / 5) * 5
# \5 f1 }* z8 F. @3 z4 l' y5 s   setxy   ( xcor-of turtle d + x )- i. t' U! G: |8 l0 {) n; C
           (ycor-of turtle d + y )
/ r6 H& ~% T! T# I8 D          7 o3 Z" \8 |3 f
            
& [/ k- l( i" f' ?if (remainder who 5 = 3) [set k who0 {( g) v- n% W- Y
                          set x( Wid / 2)  
/ M, k  D5 F9 O0 `; K* @) Y                          set y (0 - Dep / 2 ) ]
  @5 H# O* n' W! E+ v                          set f int (k / 5) * 5  G4 j& J; w6 P1 P; Q+ e
  setxy   ( xcor-of turtle f + x )/ [5 A( G) M, a; T. G6 Y$ x
           (ycor-of turtle f + y )
; Z2 s3 Q$ M6 o; ~( w           $ S7 ~0 i% L- s& q' t
           
2 e5 d2 ~4 n, j; sif (remainder who 5 = 4) [set g who4 a. G9 v/ d2 X8 g
                          set x Wid / 2
& p1 p: G# u" J/ {% ]) d                          set y  Dep / 2 ]
: L: @# D. `9 W% A- g9 E0 S) }( U# b                          set h  int (g / 5) * 5
8 S) n- _& r% t$ A  setxy   ( xcor-of turtle h + x ). j1 I/ e/ U( |, m% G9 x
           (ycor-of turtle h + y )
1 T6 E9 _# L: B4 L6 Q4 ]+ r                          7 n. Y. m& w" y$ n" B: _
                          , P- s, S/ p& T  n8 c5 |" i
                          ]  \  P( ?0 p7 e- A
end& f- e/ B" Y+ Z

/ d7 L% m5 M6 C[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,/ V, h' B6 Q6 X" X0 j( V2 S
应该是9 J: @% P1 g1 I# W+ p& z  W
ask turtles [3 {$ G" {0 ^0 k- |. e7 Z3 I. c! Z
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 5 C. x. `; u* F5 X" J# l, Z3 J, a
                          set y  Dep / 2
' |0 @2 {3 K) n& n$ d  z           set b  int (who / 5) * 5+ X8 D# C; s# Q6 l" X& o/ J
    setxy ( xcor-of turtle b + x )  W3 f2 f1 ~% B  S
          ( ycor-of turtle b + y )]]- e' b. X  K! f. V+ `, |- a
end3 d8 j* p$ \5 B2 T( \+ @( G( g
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-30 16:36 , Processed in 0.017031 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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