设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8004|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
2 o; K5 n, l8 h& J* R' n/ R+ L; U0 [6 b* y) S" S
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
& U' N" r3 o6 Q) k; n! a. w$ Z) X6 L4 g- @8 d2 J0 `* t
turtles-own [a b c d k f g h- o9 d% }7 _; M* `
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
  n2 f2 t7 ]4 |: `]! m, x' |9 Q* P# R
to new. }8 ?  n; r/ b& L3 k
  ca
+ D6 S) f6 `4 i7 `3 w; f9 I  crt 5 * num_of_building
" n2 x, H' w) J  y' j  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]$ E6 |* F: H3 M  Y. }, q
  scatter     ;;keep center-turtle random positions ; q( C! ?$ s$ F; a. u
  unit_plan   ;;make up the building plan
# c) l' I2 X6 Yend0 P& _3 W: Z7 j- @9 c8 q; i
to scatter
) p" m" N9 c% y/ \' |& v) eask turtles with [remainder who 5 = 0]
$ V2 T$ B3 E/ @[
0 x* w$ i1 c5 ^5 d) Q; E: Y) X# g3 mset xcor xcor - 6 + random-float 15
" \: m/ g' s' `9 h. G  Qset ycor ycor - 6 + random-float 15
6 D' x/ m; \# F1 d) r/ T7 J- `) N]
; |& y! \; b* x2 M5 send
. W& S: H$ f! W9 L+ dto unit_plan 7 W( \% x  K0 J6 l! ?0 |0 ^3 P% E4 p
ask turtles [
# ]- ~; _8 f( b) R, x" sif (remainder who 5 = 1) [set a who
( E3 _* V$ E- l6 w. J& w  T6 O                          set x ( 0 - Wid / 2 )
  k2 ~# @0 |) N6 z% M* o; ]                          set y  Dep / 2 ]
9 u& Q; `1 Y3 W& \2 t           set b  int (a / 5) * 5, m( G7 y% j4 q, q: S; i2 O
    setxy ( xcor-of turtle b + x )
% t6 ^9 n8 y1 l! r. A4 [+ m' m9 K          ( ycor-of turtle b + y )
8 X: B" ?6 _8 h! Cif (remainder who 5 = 2) [set c who
/ Q4 I9 O8 V9 A) I- ?. U                          set x ( 0 - Wid / 2 )
% O+ i6 G" C) E* A                          set y (0 - Dep / 2 )  ]
) O" m" T- G  `3 U8 u9 L2 B                          set d int (c / 5) * 5: D/ d4 S3 Q" ]5 c
   setxy   ( xcor-of turtle d + x )
# ?2 ^: |5 \2 u           (ycor-of turtle d + y )
, \7 y9 T- z0 @4 ?0 `' o- J6 T          ; |9 E. l# e5 b/ I7 E
            
( Q# \- J5 I/ f* M; nif (remainder who 5 = 3) [set k who
9 g6 _* ~" ?7 K" K* p- B                          set x( Wid / 2)  
/ h; p9 d! g1 n' x                          set y (0 - Dep / 2 ) ], l8 w  }) i) e. s8 H' b9 R' U; b
                          set f int (k / 5) * 5
) j4 N) b8 [2 i+ e+ f' L; O  setxy   ( xcor-of turtle f + x )  n; c8 B/ s" L
           (ycor-of turtle f + y ) 7 L, p2 \9 N: j$ n
           
; g6 {$ ?6 _' N7 j           , f: Z" x& l/ N) Z9 Q* l9 W
if (remainder who 5 = 4) [set g who
' ]1 ?& P) j4 i  F& @! J                          set x Wid / 2 ; n+ @$ T8 b+ l3 J4 _$ |
                          set y  Dep / 2 ]6 v. A" t: S3 h3 F; C
                          set h  int (g / 5) * 5
! b& a9 l' C0 f8 r0 G  setxy   ( xcor-of turtle h + x )$ X9 W  l7 V' V, B) l4 E
           (ycor-of turtle h + y )
; z& I' b3 q) H8 x4 W: _; W, C                          
$ \- o7 ^' D$ n) w5 E                          7 q3 L. o- n6 U  |
                          ]
& y$ ?% C: I5 S" T" A- |( @! B+ wend
9 r3 ]2 ?: t  r& v3 Z% _2 ^
* u; ~$ Q- V# O; ^[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
; t' z3 g% A" @% ~应该是
% w, a  d+ w0 u6 Jask turtles [
8 A; W3 z8 S1 h4 fif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
, w  V- y8 }0 o                          set y  Dep / 2
2 S3 {/ I7 s) v3 Y0 h; x3 @           set b  int (who / 5) * 5
) s0 a/ n: t0 g& F4 N5 j4 X    setxy ( xcor-of turtle b + x )) k) p: _) s  K
          ( ycor-of turtle b + y )]]
6 Y/ o0 ]/ u# t# L. aend
: Y/ U# F5 D! q% w1 v# a$ L之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-27 21:36 , Processed in 0.018733 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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