设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7200|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。2 r' \' h$ [) }- _' a
  l# S! D5 [2 a& t* v6 Q$ Q5 }
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。9 D: ~  }  M5 Q% w) [
* }: p# l) X" ~  D
turtles-own [a b c d k f g h! ?8 W0 p& F4 ^+ H. N, w9 M
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
# c, {  n5 O0 `]7 ]( i& z) y6 ]& W" S
to new
% T. l( @5 M) Q: ^% d  ca
. R. y* r# L2 ~( F  crt 5 * num_of_building
' n! L: e5 d) @8 t0 W  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]8 J' k, o2 A7 }% N  x# l
  scatter     ;;keep center-turtle random positions
" c$ j9 o3 x( s! `  unit_plan   ;;make up the building plan
( T. G+ X1 X% l: h' \0 yend
+ ~, g% I  Y4 N! _$ Cto scatter5 o3 X; Q0 d4 I* Q$ m- a) ~) n
ask turtles with [remainder who 5 = 0]
# Y, W2 T, l( I0 \' S; U[
: {) P) {$ K5 N. `set xcor xcor - 6 + random-float 15
; e) t/ x  |; T: I/ Rset ycor ycor - 6 + random-float 15
$ Z8 Y( K9 ~; F  U]
6 s( d" S. Z1 s" P) {( S2 A5 aend
/ E2 E) v8 t' p: j' u1 [0 i) Zto unit_plan
; |% f0 K8 F# Z9 K7 b8 T3 uask turtles [
/ X; A  y! R6 U! kif (remainder who 5 = 1) [set a who - {# j0 Z& p, B! L7 M; E
                          set x ( 0 - Wid / 2 ) $ N9 e5 m' C2 d! E- V/ e5 |. e
                          set y  Dep / 2 ]6 H6 G" I- _. q0 e9 U
           set b  int (a / 5) * 5. q8 _' i' ~7 c# r" R9 k& E: H, L
    setxy ( xcor-of turtle b + x ); Y! [* t/ D( n% M
          ( ycor-of turtle b + y )
8 f" X( G1 n; t; f8 A, F1 w( mif (remainder who 5 = 2) [set c who, s$ \4 S+ D$ y4 g
                          set x ( 0 - Wid / 2 )
: _& i+ u& o0 [4 f# L' O                          set y (0 - Dep / 2 )  ]
) Y+ r$ J# t! E* ?2 [) F" O                          set d int (c / 5) * 5$ v/ ~: D8 @5 B+ g# G& u8 U
   setxy   ( xcor-of turtle d + x )
: f& g2 a4 A  Q4 @( y" x           (ycor-of turtle d + y )
, m9 `, C* @0 _5 [  l; h/ g          # I# @6 K% V* i4 X
            
. }9 @& U% O3 {! gif (remainder who 5 = 3) [set k who) j4 ~  S1 T2 M3 r
                          set x( Wid / 2)  , g, {3 S. ^1 m3 O; P
                          set y (0 - Dep / 2 ) ]; r. k) w( B; N1 P" E# D9 ]
                          set f int (k / 5) * 55 i( |. C5 L7 A# g( Y
  setxy   ( xcor-of turtle f + x )
9 b& I2 P3 j3 P; U- p! _& c           (ycor-of turtle f + y )
8 X' Z! d- I  S! Q7 c9 `           % f$ h% V8 l3 K
           ( W! y- f( [. k: H7 g1 ^
if (remainder who 5 = 4) [set g who
! e$ u2 g, |9 i$ R9 I1 n                          set x Wid / 2 * z  t" L5 d6 V$ S1 a$ Q  h2 `, t$ t- h
                          set y  Dep / 2 ]- B0 z1 z; l/ l) H
                          set h  int (g / 5) * 5
8 p9 `$ A. Y% u  t6 S+ z  setxy   ( xcor-of turtle h + x )! P  V5 V: B! P" N' c. D8 K9 u* B2 i
           (ycor-of turtle h + y )
2 k) A7 q* Z" ?: ?% f8 c" u( I                          
9 C  ?3 O& p/ x! V4 o, Q                          
1 L: w2 ?0 k+ ], {, w                          ]
! g, O8 ~9 U, g" zend/ g" z9 ^9 q5 u: i& k+ a
) t) r, O5 h& v8 G  ^- S& v( p0 d
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,- o2 E  U( l: r! t& F
应该是
+ ?. ~" B" t4 t/ g9 u( ?ask turtles [/ h5 P! ^1 p6 h) E
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
' z# i: I3 g5 S. I3 c/ u/ j( E                          set y  Dep / 2 # Q0 I' H! x+ f$ F) h( M
           set b  int (who / 5) * 5
" {8 G8 X* `6 S/ \& I0 s3 ?9 d0 Q, ^+ I    setxy ( xcor-of turtle b + x )0 U9 R+ f) V& h! h, \. X+ Z9 v
          ( ycor-of turtle b + y )]]* t2 d# e$ r. Z
end
9 }( x* X8 Z# c9 ]6 U2 _# Z$ c之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-15 19:35 , Processed in 0.020573 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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