设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8812|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
. a' s9 u) X+ u
: o2 m6 _( S' q+ w$ O但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
1 h( P# q* E( x8 |4 Z6 X" R# G& o+ s! O. v7 B; w# d, n' h
turtles-own [a b c d k f g h- q! X& m7 T- q  [
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
, _& A5 P3 y9 c, R8 p]8 c6 F0 {5 A( r4 ^. J/ e! G$ {
to new
( W) |5 q. W2 J4 u  ca2 [4 I8 I3 e0 H! q; ]5 n9 |2 b- d
  crt 5 * num_of_building- U! X' ^. ^# j3 P: s
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]9 k! A& z3 j! U) \) d6 Q: c. p( w
  scatter     ;;keep center-turtle random positions
; [2 Q* x: Q  l) M* v& t  unit_plan   ;;make up the building plan- n  R, c- ~" W) y1 F9 I+ `
end( e, [: s% U. l
to scatter
4 u( n( o+ c3 b6 q' X2 k+ x: iask turtles with [remainder who 5 = 0]
9 E6 w$ e  N7 w2 @; Y0 E4 [$ u[9 N. Q% c. v0 `/ Z/ e
set xcor xcor - 6 + random-float 15
& N3 G9 v3 L( jset ycor ycor - 6 + random-float 151 i, F. L" _# I; z; a, k0 k1 E
]  j  W' U, N2 B4 E  @
end% U# q) w  O, ?" i
to unit_plan 1 Y- C/ }& i7 `* \
ask turtles [
9 U' Y% C$ ~6 rif (remainder who 5 = 1) [set a who + t2 g! A2 j) t8 c; K
                          set x ( 0 - Wid / 2 )
, ^; ^) U6 \- g  @                          set y  Dep / 2 ]
' {" }- c  q4 ^           set b  int (a / 5) * 5) o0 C. R; L  a" f2 s+ _, {
    setxy ( xcor-of turtle b + x )9 y# {4 ^# i9 B1 {
          ( ycor-of turtle b + y )
. m) K/ p3 K, Tif (remainder who 5 = 2) [set c who) r0 E: i  B' a9 v9 m3 t
                          set x ( 0 - Wid / 2 ) 8 R, I( R4 L# d! s7 _
                          set y (0 - Dep / 2 )  ]
1 O0 u' S8 R5 A; t5 a  k4 \                          set d int (c / 5) * 5
1 \  ^' K6 p# e7 w! ]8 C4 H7 n   setxy   ( xcor-of turtle d + x )
) ^, a& v: M3 s- I1 }7 ?           (ycor-of turtle d + y )
& c: F/ p5 E+ A) k8 A         
, a# S3 u, g! y2 s6 J  [& T* V) @7 W            
9 {- @- I5 S. b9 yif (remainder who 5 = 3) [set k who2 S' F4 O) E) l' i' p8 g1 h& d
                          set x( Wid / 2)  
9 x6 |4 R% k, b4 C8 l! f% N, I                          set y (0 - Dep / 2 ) ]
% U& {% ]! T3 ~: c( }8 ^" r: B- o6 ?                          set f int (k / 5) * 5; Z7 V% m( O0 x( [1 L, T% ?
  setxy   ( xcor-of turtle f + x )
: d9 h. z# I8 q; x) j* L           (ycor-of turtle f + y ) 3 F& h3 @- \  J8 ~% m
           
# {( z4 z7 o8 v' n6 A4 Z" e           1 K* R1 y/ N9 d9 p8 B0 n& e- a7 r
if (remainder who 5 = 4) [set g who
! N* A  H& {, k: y                          set x Wid / 2 % c/ f0 J# Y# F4 m( ]3 T) m
                          set y  Dep / 2 ]5 R7 ^4 d/ X( |+ R7 o: ]# F
                          set h  int (g / 5) * 5
9 n9 O7 h8 G2 g) Z4 _* o  setxy   ( xcor-of turtle h + x )
' g7 ]  n* W$ K5 `2 t6 Q           (ycor-of turtle h + y )
4 g" Q/ D1 b; D9 W" K: o6 P                          8 m: M: e$ A6 @: [
                          
  Q  i: K! e; u$ A- N7 Q3 O3 o1 D                          ]' H5 z  A! N1 n* P. F* S  i
end
- {1 [, p6 ^, w) q8 y8 l0 V3 K8 m
. M7 h1 N9 s2 G- E[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
. \+ g+ }, L& D应该是1 p7 {$ s' `2 R  Y% }
ask turtles [
! i: n+ |' E' w( \3 R" i9 n3 K+ v9 Mif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
8 O7 L* h4 F" g' C. N                          set y  Dep / 2
  b% q/ f/ U% K* Q& o) w           set b  int (who / 5) * 5
# Y( a$ [( ^' @9 Z& ^    setxy ( xcor-of turtle b + x )7 ]3 A1 b9 C7 _  F- [) J" m9 {7 z! U
          ( ycor-of turtle b + y )]]' c2 H2 s9 w0 N
end
2 ~# J) m, C) c# ]9 K9 ]之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-7 06:37 , Processed in 0.016982 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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