设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7789|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
! N& y6 W2 Q: E* Z
) y! W! y* N$ F但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
) T: d! ?! t4 r( \$ [! [/ X6 L+ K; R, n+ l- L
turtles-own [a b c d k f g h
& N, q  T8 A- h+ g1 \  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
2 v" T9 X  w2 H]7 T% ?# Q! L) m& E6 J
to new
. e" k# t0 n1 ^) c- `) H  ca
; |0 W# w3 K% H& d5 H) U8 M  crt 5 * num_of_building( ]$ h$ w4 g' \0 `7 k
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
/ i$ d9 ]) [$ T. q' Y" \9 U  scatter     ;;keep center-turtle random positions
+ h# a7 \5 F+ c  Q- ]  unit_plan   ;;make up the building plan
" ?; c) c& C2 d) W- c' f! Vend8 ?5 V) \2 i% `2 N' |
to scatter
3 G3 p+ V  D  X! B5 S! Pask turtles with [remainder who 5 = 0]
5 S* w  m2 N0 H3 ?" M1 ^" h[
+ z9 S. l" p, B/ _. xset xcor xcor - 6 + random-float 15- o" I* X# x  I7 z0 g- }
set ycor ycor - 6 + random-float 15
6 o2 F  R  V/ y9 V/ s% \], V8 H3 I8 G8 s2 x  v) {
end
! x/ Y" h2 }! Jto unit_plan
- t8 k" {" N: H1 d/ U: k2 P8 Gask turtles [
. R% P/ M/ y, g$ {4 n' }; E9 _if (remainder who 5 = 1) [set a who
3 e: Y3 f( ?1 _                          set x ( 0 - Wid / 2 )
  d% t" B4 k' x, D5 F                          set y  Dep / 2 ]3 [/ }% V$ X. U7 @
           set b  int (a / 5) * 5
: C9 ^1 L% e$ m! [- N- |    setxy ( xcor-of turtle b + x )
! n) }$ }) V! G8 d, I2 O1 m          ( ycor-of turtle b + y )
9 z% b/ [$ q1 J) Oif (remainder who 5 = 2) [set c who. V4 Q! G( I  r. V, H# y
                          set x ( 0 - Wid / 2 )
3 f% ]6 Z! a3 J- R4 x' X2 A                          set y (0 - Dep / 2 )  ]
6 p) w* `8 H% w5 `. F                          set d int (c / 5) * 55 E3 l; R* O4 Z2 e# S. [
   setxy   ( xcor-of turtle d + x )
( G3 K  b/ b  T$ ?7 Y0 T           (ycor-of turtle d + y )
7 u7 m7 D% V) J6 E          # f; ~3 @! M7 u1 Q1 v% p! p
            
* R$ M, o! G. B# b+ aif (remainder who 5 = 3) [set k who6 w6 r$ F7 c; W) u
                          set x( Wid / 2)  
3 X+ [1 R) u0 }4 u7 U- n                          set y (0 - Dep / 2 ) ]- r: h4 X7 Z1 \( e8 V
                          set f int (k / 5) * 5
5 u" J9 ^. Y" A7 K1 k& T. J  setxy   ( xcor-of turtle f + x )
! d8 H: n& l! ?5 r/ i: e7 U' l           (ycor-of turtle f + y ) ! x4 I0 _% S) |4 m0 r) a
           
$ _* r! A. Q7 q0 m, T  }% l& G           2 X. m( r6 q, ]) @0 U& Q
if (remainder who 5 = 4) [set g who
1 j' S3 b7 l; x                          set x Wid / 2 * i: @9 L& Z% C* t
                          set y  Dep / 2 ]
# V, ]" V# y" j                          set h  int (g / 5) * 58 W% W0 s9 r. }/ O2 M8 n
  setxy   ( xcor-of turtle h + x )* _" g2 j( C* {/ n4 n
           (ycor-of turtle h + y )
; i- H3 |5 X! ?! b/ ?                          
. T3 G# k: U3 _$ {2 a  j: j. _' T/ j                          0 @/ C6 \: u3 i+ p% I
                          ]* g0 Q3 [- U/ `2 p1 C2 K( o! B
end- E. m5 s, M7 n9 O

' }" c; d9 t$ w6 n) v* ]% g[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,  z* z+ [/ i! x# Z  T# j
应该是) o  z! q' U4 A: c
ask turtles [
# R& c& p) M5 e& }if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
& k9 ^* G* {+ h( I) w* Y                          set y  Dep / 2 $ ], @! K) {2 I, q$ M
           set b  int (who / 5) * 5
* R( G5 Q) S: |- [1 H4 m' Q7 `5 j0 H( y    setxy ( xcor-of turtle b + x )
2 Q0 m5 y3 }! o6 {* j9 E5 S7 C* T3 K          ( ycor-of turtle b + y )]]4 t; y; G  t9 G2 c
end
# C7 g- R' Z5 F0 m" B之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-1 06:26 , Processed in 0.015952 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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