设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9012|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。7 s, A+ w2 f1 r4 f# Z

; t( s, x0 {' y; p7 I) u8 {但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。0 R2 u" N9 k6 ~# C/ w, j
% C" Q5 P7 r" W3 Z7 A( W
turtles-own [a b c d k f g h
0 v6 `4 s; C, Q# I/ o, b% @# |8 h  x y     ;; these are the leaf-turtle's offsets relative to center-turtle & _7 N* B. P7 s3 h  ]4 A, H% N
]( N* c! P+ W& _% E
to new9 z+ [5 b$ ~; x" a, o" y- i1 C
  ca1 C& c* l6 h# `* h
  crt 5 * num_of_building
& Z+ U, E& M+ Y* Z4 Q  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]], r9 S2 Q# o, e& }
  scatter     ;;keep center-turtle random positions ) d6 M: b3 B: `; M7 d
  unit_plan   ;;make up the building plan
* F2 r4 t  ]3 v9 P- S8 O5 Wend
  A- J+ {- K; G, n/ G1 P) d4 lto scatter
. Q# i( ~0 {0 C4 t3 G: G$ q2 R1 [ask turtles with [remainder who 5 = 0]
  _! H& g( y0 f! [[9 t2 k' \; r+ t# q) R- h4 k: o/ i. }
set xcor xcor - 6 + random-float 15
8 w6 @- I! J# ~. J" Oset ycor ycor - 6 + random-float 15! ?5 Z0 G7 s; ]* I- T0 m
]
8 s+ F5 ~: r6 B* h; B3 H, C) _end
2 k3 ^- o$ g+ A2 i9 T! Sto unit_plan
7 A6 G8 G2 T7 v- S$ @ask turtles [3 U$ S% c- q, [( t. e
if (remainder who 5 = 1) [set a who
3 |' z4 g% W* y/ i! t+ R                          set x ( 0 - Wid / 2 ) & p) u5 J/ d, Y  s; s; t
                          set y  Dep / 2 ]$ Z; C  T0 s9 |& `+ c! V& o, C
           set b  int (a / 5) * 5
" W4 J: v% g$ g    setxy ( xcor-of turtle b + x )
9 }' p4 ]) p3 z. G4 t          ( ycor-of turtle b + y )
. a4 w: x& l- \/ O" _( u& lif (remainder who 5 = 2) [set c who) y; o- b4 B1 C  \& K' w
                          set x ( 0 - Wid / 2 )
7 J' W2 p, `- N3 i6 @6 Y                          set y (0 - Dep / 2 )  ]  y$ s, X1 K4 I# l/ O
                          set d int (c / 5) * 5
1 ?; Y0 \2 S7 r+ {# a" P1 W& K: S   setxy   ( xcor-of turtle d + x )6 I8 E% F$ T, G$ V
           (ycor-of turtle d + y )   w8 A$ U4 r8 f8 Z3 V
         
. c: o% y. F* V2 Y% i6 J, x+ m; I            1 }; P2 _$ B+ Y- V4 v! z
if (remainder who 5 = 3) [set k who
1 j2 Z. {% `0 }5 p7 g+ V. v& a                          set x( Wid / 2)  ! ]( d$ m/ E( |' o: Y
                          set y (0 - Dep / 2 ) ]
, d% p7 e- a; V$ {                          set f int (k / 5) * 5; }* I4 B  Q3 t+ d. r2 F* Q
  setxy   ( xcor-of turtle f + x )
$ Y8 U9 \3 P& s& F- p' _6 O7 A7 D% L           (ycor-of turtle f + y )
$ X0 S7 ~+ n( n0 O6 ~9 N- Q, d           
% h9 V/ X; x7 O* I. W8 e4 Y           
# b# r- k' F+ E* I- Q! nif (remainder who 5 = 4) [set g who
& [+ i/ A. h0 R7 q. \                          set x Wid / 2 $ J! u* `7 j% d0 t; Z& n: s* g
                          set y  Dep / 2 ]* d) [1 h4 {  _" K
                          set h  int (g / 5) * 50 R: Y" `% v! w( e! ^9 B
  setxy   ( xcor-of turtle h + x ); s1 d5 ~) x( ~- v
           (ycor-of turtle h + y ) 2 ~. v/ l; l, N: S- x. n9 K0 _
                          
" ~- ?" S8 x% P  u7 \. Q* u& o                          
5 _4 ~0 h; B  O" M0 O! {2 z                          ]' I# h/ s+ K/ ?! U; M: p' U* E
end$ D: A  u9 A. ^
$ I9 I5 I" v# f5 f
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
8 M$ {+ D& A% g" ?1 g. `应该是
! V) J/ h6 X$ W$ x& uask turtles [0 U. Q1 L$ x1 m3 U1 n1 B8 d
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
- K# s6 R; G& I5 T' i                          set y  Dep / 2
9 L- U- D; h+ ~3 f4 o8 d           set b  int (who / 5) * 5
$ L) `, T8 X( h    setxy ( xcor-of turtle b + x ); f: I- q$ }" ]( H  ?% @( f
          ( ycor-of turtle b + y )]]; V; g# j1 q9 ]; ^
end
2 v# i, @- W. \4 G* g3 H( }之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-6 15:12 , Processed in 0.026189 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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