设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7867|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。' p6 x9 N. K8 \- }8 F. S
3 H3 V( x0 G  T$ s* ]4 r3 }
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
9 W8 k1 C" I0 w7 ~% K+ |) @9 x; d% D* {
turtles-own [a b c d k f g h
+ i9 l  {# m5 U! {  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 8 L( N8 V; }6 ?( h6 w. g* P
]
4 ~- e5 ^& [& I: b  [8 yto new$ |5 ~! W' [+ S( x* P
  ca, |; j# a' l3 j# m$ e9 }, r5 T, |
  crt 5 * num_of_building
2 ^: T8 K3 {$ ^, q  F# J) p* ?  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
6 D! t% i$ R. I3 |  scatter     ;;keep center-turtle random positions
1 ]/ a/ P3 K' P: d  unit_plan   ;;make up the building plan, ~9 w4 i: K( O1 B
end4 E1 e( r# L0 Y" Q
to scatter9 d0 o1 u2 [- t
ask turtles with [remainder who 5 = 0]
! F5 Y. q" ~% S, q3 y+ R8 I: j+ J[
& N: b$ o3 T. l" Sset xcor xcor - 6 + random-float 15
# u3 e/ D9 R7 I' S) \! Yset ycor ycor - 6 + random-float 15
0 ]6 B* w4 O0 u2 Q1 P]
* k6 q7 M6 c  t* s4 J2 z. Hend
1 c/ M" a5 z' t9 I0 M$ Gto unit_plan
4 u1 l1 ^, a# c- S% [ask turtles [
7 _1 M" d! B' `  e( r2 s3 kif (remainder who 5 = 1) [set a who
- x' o% A8 w5 R                          set x ( 0 - Wid / 2 )
& J2 G8 ~2 w' k  C                          set y  Dep / 2 ]
. m: N8 e6 C% K( Q- s  y           set b  int (a / 5) * 5
6 `1 `/ H+ D* w3 H4 _  y    setxy ( xcor-of turtle b + x )4 D$ ]8 ~+ e* J* [1 F1 D8 J% [
          ( ycor-of turtle b + y ), A% j4 c. O5 P! J' P" H
if (remainder who 5 = 2) [set c who
6 j4 B& x/ R1 I9 z- o- r                          set x ( 0 - Wid / 2 ) ) l* ?2 h5 z  ?$ K1 ^' _% X% D
                          set y (0 - Dep / 2 )  ]9 |4 o: k7 i6 ^- x  _4 U
                          set d int (c / 5) * 5
( H- n. m% h' C# J7 A+ ^   setxy   ( xcor-of turtle d + x )
' E/ b1 c1 K" C' }$ D" W           (ycor-of turtle d + y )
( \/ `4 ^2 Q8 g. D8 S  k          " o/ x% R8 P9 V3 @* C/ L2 o  O6 U
            : E# _/ O/ a3 o0 g
if (remainder who 5 = 3) [set k who
. x7 i, q' w0 B  r* {                          set x( Wid / 2)  9 H3 \" C# i/ j# [8 [% }
                          set y (0 - Dep / 2 ) ]
' Q) }- ^5 `* {: m" {/ C; l  Q2 H                          set f int (k / 5) * 5
1 S4 i. L+ O- ~+ a- @7 o" ~. y  setxy   ( xcor-of turtle f + x )
; {3 X5 q1 `5 B" l6 b           (ycor-of turtle f + y ) ) @% W! z5 A! S* |
           
7 }8 v1 M: D" G$ ]9 `           
& P, V$ o0 A. Y5 Qif (remainder who 5 = 4) [set g who7 u" S* B. ^# B* y; i: C
                          set x Wid / 2 # I# g* h* l. S( s: x* a% {3 T( B
                          set y  Dep / 2 ]7 r5 T& K7 c3 v# r/ D2 K/ `* t3 H
                          set h  int (g / 5) * 5
. L/ B- M9 s, }# w) ]/ w  setxy   ( xcor-of turtle h + x )! D% V9 f" m6 t) h
           (ycor-of turtle h + y ) / h2 P' g) s$ K' s8 y
                          
* y8 ]2 {" ]: L$ [                          - J* w2 I. Y" H7 w1 K7 N% x+ a
                          ]
& @/ d& X9 K3 h7 ?2 ~2 Zend. ~% }0 E' x3 X

% `2 C3 d" x2 p& k[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
# @' g) y2 [0 L% v应该是
0 n! D4 i' }9 x1 bask turtles [
: k3 {6 m9 r* [0 ?) ^, y# iif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
2 d! s* i( X0 w% d* V$ B( i                          set y  Dep / 2 ( J2 p" w$ m% b, K
           set b  int (who / 5) * 5
) ]9 G- v7 T  C/ a    setxy ( xcor-of turtle b + x )
* D* Y% O+ l  h* a: F          ( ycor-of turtle b + y )]]1 |! X: _* h7 U# U. l
end6 t3 |  F3 Q; q% g
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-12 22:31 , Processed in 0.016624 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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