设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9074|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
5 f# s4 F" H5 E, V0 z7 M/ h5 G3 w5 }
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
  o, ~3 B+ r5 a7 B& b6 n
2 N4 w( p# I( Y: I- Z, yturtles-own [a b c d k f g h0 j5 d1 a2 q( h& Z& Y$ |
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle , m1 w: [9 J! ^( @/ K
]3 _7 J) ]( x: X! {: `. @2 q
to new0 f2 x' _  C% A
  ca
$ d( x- o5 S4 l' _  crt 5 * num_of_building$ a! _+ o, b* q1 R8 o4 |( w7 L
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
, K% G/ J* k2 v; A6 l# N4 f  scatter     ;;keep center-turtle random positions
$ @8 V. b4 J8 [! W$ w$ ~  unit_plan   ;;make up the building plan
$ {+ Y" a! _, L$ V, h3 {end) Z1 Z6 d$ E$ `3 U+ l) A5 {- o
to scatter, S& S9 F8 G2 c) g9 p
ask turtles with [remainder who 5 = 0]
+ z; ~$ v! D: M+ z* \. H5 m[
; q- f9 S" s, _2 Aset xcor xcor - 6 + random-float 15
: Y  O) r6 @% t8 L, Yset ycor ycor - 6 + random-float 15
, B  h# u- g' D' n5 d, V]
0 u8 w4 P7 r5 B  [% K; e5 Qend
8 U# q& F. Q& m% f% |+ yto unit_plan - z+ [1 P# D6 W6 }
ask turtles [
: O5 `' W) r- Tif (remainder who 5 = 1) [set a who - r5 ^- Q( A) ~
                          set x ( 0 - Wid / 2 ) - p. U, E$ ], V4 \2 f' |; X* i
                          set y  Dep / 2 ]
$ ?, ^  }+ V* L" ]$ d0 B! M           set b  int (a / 5) * 5+ i. |% r6 g. p4 o! B/ a& a- q; g
    setxy ( xcor-of turtle b + x )1 ?9 e6 o5 M0 P& k
          ( ycor-of turtle b + y )9 D9 [; c) z! K3 `5 L5 x6 p& Z
if (remainder who 5 = 2) [set c who
5 L* |# D0 D6 u, |6 C                          set x ( 0 - Wid / 2 ) 3 \& A0 J# R- r% D  F# M; x% q7 |
                          set y (0 - Dep / 2 )  ]
  q: h9 M7 f8 d- E2 u                          set d int (c / 5) * 5. b0 \4 j- t* Y( d# P
   setxy   ( xcor-of turtle d + x )
* G. o: D2 v* t  q& r           (ycor-of turtle d + y )
3 O' }5 ~8 a: M1 R% B. h          ) c, O4 T3 h  u
            
- ~/ F1 ]) U" m. n2 Gif (remainder who 5 = 3) [set k who
. t* n5 d0 r! L* L* G/ `2 h                          set x( Wid / 2)  
* N  ]0 i) P% x" J: s  V                          set y (0 - Dep / 2 ) ]4 F- @# c7 E5 z' S2 M5 L
                          set f int (k / 5) * 5) M; K2 r1 j( Y
  setxy   ( xcor-of turtle f + x )
# q3 T! Z) ?& P  ]           (ycor-of turtle f + y ) " T% T/ }' d9 U6 X0 E" [
           5 D9 Z+ s; V7 ]. N& X) m: X5 B
           
8 C" k4 R2 n5 K% {7 |% e9 aif (remainder who 5 = 4) [set g who. M& y+ u  z5 D6 S' x
                          set x Wid / 2
7 ]8 t3 |* Q6 Z                          set y  Dep / 2 ]
7 c5 H- i2 F! J8 u5 S                          set h  int (g / 5) * 5
% ~  M9 T& I3 k* ]* T% k8 v9 `$ R; h  setxy   ( xcor-of turtle h + x )
. g- {# h$ ?! {( ]           (ycor-of turtle h + y ) - ^+ _7 v/ {: G
                          
4 P3 U. R- ]$ D! t  F) P                          
! O- \" z- E) T                          ]2 K& a6 `8 i$ C& z8 o, t
end
! I( y: z1 n! H' ?: a4 r- e. z) |( X% i
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,' t1 Z% w$ O0 C. J7 R
应该是
: m- S! @' E" r  |9 n# |# aask turtles [! j  E* c; w! Y/ l
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
# X2 `/ y% _. s$ H                          set y  Dep / 2 ' R% f7 B6 u: }# t* Z5 z
           set b  int (who / 5) * 52 i" Z: R* t% w4 G
    setxy ( xcor-of turtle b + x )" v: w+ t# _5 K, t5 i' }5 i2 C
          ( ycor-of turtle b + y )]]
( R1 D# }: ^4 L! U+ X7 E/ tend! Z) {8 l7 j3 I" K5 K* q5 R: V
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-14 09:35 , Processed in 0.017538 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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