设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8321|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
0 T* S" @- f, I) H' o3 v( L! ^. P! P4 h$ [% Q- G8 t8 l
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。8 [" X# K: o) _/ j
5 B9 G; X  A4 X; E" L$ R! `
turtles-own [a b c d k f g h. M) S- ^- V3 n/ F. c9 C
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 3 F. |- G( u& Q& C9 V3 R
]7 m, ?$ k+ e0 c! ?; M8 Y/ x# V4 K
to new
3 f. \3 I" v( w  ca) U2 K3 P: I1 J* w( K
  crt 5 * num_of_building' U5 S% w; c8 h5 C
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
* a8 ~8 a# {( c  scatter     ;;keep center-turtle random positions
& g- g2 V- k) p0 I/ ^& M0 r5 F' J  unit_plan   ;;make up the building plan& s. ~- A. e+ x  `
end# e: k% `4 Z0 C& h8 ]7 X% l# q
to scatter6 d( _9 v2 o- \
ask turtles with [remainder who 5 = 0]/ ~) K4 U9 x! [1 R" r5 a7 A  i" Q
[
- D2 R2 c* `9 q+ Yset xcor xcor - 6 + random-float 150 W" E7 h3 s. F
set ycor ycor - 6 + random-float 15
& b9 E* n( K1 d/ N/ X, E]
- l8 E$ [2 L0 M* [end7 `- i' v5 E% X  h
to unit_plan 9 m# B* @, |" ~. T
ask turtles [. w( E0 w/ B" O
if (remainder who 5 = 1) [set a who
8 g9 p% s  _3 ?+ b% \' L                          set x ( 0 - Wid / 2 )
  Z; _0 i/ R1 j9 q                          set y  Dep / 2 ]
0 m2 K7 F8 I, ^' X" K           set b  int (a / 5) * 5
4 G5 v8 E1 ]; s2 h' j    setxy ( xcor-of turtle b + x )
$ T: \# Z- j: [  Y" `( V          ( ycor-of turtle b + y )! ^! Y  }1 `3 Q# k
if (remainder who 5 = 2) [set c who! E3 n, C. f7 _, m
                          set x ( 0 - Wid / 2 )
# B  e& f2 C, f- R0 Z                          set y (0 - Dep / 2 )  ]
# i7 B6 H: ?: j- D; B                          set d int (c / 5) * 5- p7 H1 Z4 j7 m5 v3 x/ K( {3 H
   setxy   ( xcor-of turtle d + x ): R- P: d! q7 S& ?+ c# s
           (ycor-of turtle d + y )
$ V  I% }8 b3 s9 R3 `, M  _          6 P& y5 K; A+ d2 Q3 ^1 V% c5 J
            
  A# {. }6 `. W1 ^$ e: Vif (remainder who 5 = 3) [set k who
# v/ v' f. Q* \) z% K0 w( j                          set x( Wid / 2)  $ k  o) f. P& f  C/ D) R  s
                          set y (0 - Dep / 2 ) ]
- q# R0 y9 F/ q$ L9 Z# I2 r                          set f int (k / 5) * 5
) C7 _8 Y9 f0 \, I5 e  setxy   ( xcor-of turtle f + x )3 V* ~9 @( G; T* X" j' ?4 ~
           (ycor-of turtle f + y ) " Q2 `7 L) Y$ ]# f
           7 k9 {" `5 o2 F, L( R
           
$ W3 T9 X6 n* N  J% Bif (remainder who 5 = 4) [set g who
0 i7 X) u( g4 S% c  ]7 X. D% [  g                          set x Wid / 2
) {& n, E6 D. N                          set y  Dep / 2 ]
* j- U6 {6 ~5 W+ K' {                          set h  int (g / 5) * 5
  J+ |2 ?  }; l* Y  setxy   ( xcor-of turtle h + x )
+ U. U; k$ N$ {- U2 `           (ycor-of turtle h + y )
) o" y0 d1 ]: |$ \                          8 t3 k3 N' J' [9 l7 B
                          ( s. ~+ l% W' J$ p  @
                          ]1 _$ E  z$ P) y" ?4 w7 p
end  o, g. B" z; `' V" Y& M0 e

' T) p$ F& C. ~+ ~$ z( x* ~6 a2 T[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
7 {: i8 l/ s$ u9 J4 c. p: s应该是
$ ?# ~4 F6 S) b/ X. zask turtles [
& x" S' O  k( _1 o3 E3 I  l% Bif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
3 I& T* U2 L% M                          set y  Dep / 2 ' ?6 s; m3 f' G; L, |  j
           set b  int (who / 5) * 5
! D( H2 \: S# P# x7 @' `3 q' }1 y    setxy ( xcor-of turtle b + x )" s* q9 j9 T0 |: `9 h
          ( ycor-of turtle b + y )]]
7 f+ M9 u2 m$ y# b/ e. I% b- }end2 D7 o' @8 u' J( L: C8 }$ w! o  ]
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-6 16:36 , Processed in 0.019061 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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