设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7384|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。' m2 [9 I) y. V' T( ^4 \

5 H% t# C9 J8 R# h但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。% c. k: M9 Q. E

" J  Q" @( M" ]7 G& {* Aturtles-own [a b c d k f g h( i+ y- R5 |$ V: A6 V" p& H8 Y
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 8 l1 ?8 g$ ^" U) ^0 t
]
( r5 X* t, x* W5 Hto new* j  y: i! Z$ a
  ca6 \6 g0 a- U# `  P' Z3 z. o
  crt 5 * num_of_building
: w3 V9 a, L2 D" w2 Z/ n  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]% h! j- S, K& z' L" L
  scatter     ;;keep center-turtle random positions ) G) s0 h" u2 L9 _8 D
  unit_plan   ;;make up the building plan. i8 H& T: A- J5 M$ Q' W4 A8 V
end( h6 n3 W* N3 I' \+ k' e1 T
to scatter6 u* u* g6 A6 S( d5 ]# T0 b
ask turtles with [remainder who 5 = 0]
6 U$ E/ X) r' Y5 I0 k[( e* f& K! [7 K6 G9 J" j
set xcor xcor - 6 + random-float 15
# n/ X  X  M3 f2 t8 ^2 q" pset ycor ycor - 6 + random-float 15
6 D6 O4 I2 _2 C]
; H" \) P6 z- p& I/ G0 B& bend  f5 j$ ]" P- K: t5 C& [/ J; W6 W3 k
to unit_plan
1 ^, X2 g/ k) t- Z: Lask turtles [
' Z/ c, _& ]7 t0 Mif (remainder who 5 = 1) [set a who
( o* M5 [& q# u                          set x ( 0 - Wid / 2 ) - @5 O! g8 C% e) f) g- z  d
                          set y  Dep / 2 ]
) i# O+ z5 I4 o* `           set b  int (a / 5) * 5  H& R. u$ j& j  j
    setxy ( xcor-of turtle b + x )
$ U1 V: n& _& E; I7 x  M) c          ( ycor-of turtle b + y )& N$ J  N, E8 V7 B4 M9 w
if (remainder who 5 = 2) [set c who  f+ N$ {3 d! n0 ?
                          set x ( 0 - Wid / 2 )
- `! \+ J3 a; f. K* \/ {5 P1 G                          set y (0 - Dep / 2 )  ]
& i0 k+ @& u( Y9 r                          set d int (c / 5) * 5
# `3 N# m& Z; I$ q4 p( e4 {3 U   setxy   ( xcor-of turtle d + x )
4 [  d; x4 y5 n, M8 _" z           (ycor-of turtle d + y )
: k  h3 w8 E- t4 q* o$ G! n          " G3 x4 M% v6 l7 A
            # Z2 Y9 y) C6 X% j, z' S
if (remainder who 5 = 3) [set k who1 X2 n8 i2 n0 f% e' N' g4 P% K0 I
                          set x( Wid / 2)  
( ]6 T* u6 E4 ?& r/ X                          set y (0 - Dep / 2 ) ]
3 Q: @7 M: I! S- B                          set f int (k / 5) * 5
' E( @  _% d* r  g# t7 W0 J  setxy   ( xcor-of turtle f + x )
( G, Z4 }/ C  q. {! {2 ~           (ycor-of turtle f + y ) ! Z0 [! G! e( h) u) M+ x0 [3 m+ A
           
$ w  }6 u2 }+ B7 ~           ! D  P# n4 x) T  T+ h
if (remainder who 5 = 4) [set g who. k, ~$ v$ j  S: s% ?
                          set x Wid / 2 7 A& y- U; E9 I% H: d
                          set y  Dep / 2 ]1 h, e" z6 `. }  K5 U/ U* @
                          set h  int (g / 5) * 5
9 [9 F: d' c/ T) ]" Q. `: P  setxy   ( xcor-of turtle h + x )
: k6 J  \# |( X. @8 P           (ycor-of turtle h + y )
" U/ I2 H; O- o! D. ^) c# |                          # F. G6 }) M, q3 f
                          0 g9 [$ q( L7 p
                          ]
, c0 @- v& b0 x8 G1 I; ~end
; p- p5 t5 Z% R: O- b% w* m- O( w& T4 ~3 G: p
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
- ^, {- o% H% D% Q2 V) G. d% y2 W  D; W应该是
; u( K$ W$ H5 l% f" _ask turtles [
$ l3 s5 i, n8 B8 }3 [* qif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 7 \7 |& d8 I7 w" Q) z
                          set y  Dep / 2
, U; M# E  B3 X4 Q! ^! T3 x  I           set b  int (who / 5) * 5# h. `% C4 H1 @. b% @
    setxy ( xcor-of turtle b + x )& {: w2 V' x6 p0 V, \  d
          ( ycor-of turtle b + y )]]
  o; x2 r$ h' k6 ?end! b1 T6 m- F& }, U/ [# r  N
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-6 04:19 , Processed in 0.015548 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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