设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8895|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
  {: i7 g; `2 T8 R  I  I; a: c( q8 h7 f4 |
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。( S2 j5 z" {7 W: R/ T; f& C6 m

& ?; V, P+ t! [0 N) ~  [turtles-own [a b c d k f g h
' B: o  Y4 d/ c  Y6 ^8 r/ N8 Q# |+ Q  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ! g- ?; F) O# p5 r
]3 s+ |1 `' W8 [7 `
to new" _  T- c- R7 u; W( g9 \
  ca5 C* j' P0 P. q$ r7 b8 G# d0 Q
  crt 5 * num_of_building
& w9 o6 X% p6 h  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]5 O4 W7 `  r& `% }1 U' Z
  scatter     ;;keep center-turtle random positions ) y! j- ^( E; W5 H2 b' M# w! ^) C
  unit_plan   ;;make up the building plan
% _! T& N4 N8 Eend3 _& e3 w5 ~* O
to scatter6 c4 K. v) O+ B4 A$ G2 l
ask turtles with [remainder who 5 = 0]2 m8 }6 t9 T' t- O6 x
[
; ~7 T% K$ _3 O3 ?3 {set xcor xcor - 6 + random-float 159 {0 d# ^  M0 C: B" y4 L
set ycor ycor - 6 + random-float 15
4 b5 s. t0 h6 {' h, `]4 Z6 ?. i8 o- o; F8 j
end2 C8 {9 ^( p' a; t+ t5 b  Q
to unit_plan
& ?, T+ w* h2 h5 ]7 aask turtles [
. i+ _9 Y4 S; X  @! lif (remainder who 5 = 1) [set a who
+ J7 F( M7 S$ r- }3 D) f                          set x ( 0 - Wid / 2 ) , A% _0 [. l0 B5 ^1 H+ c
                          set y  Dep / 2 ]' R6 {: X( |% d' h# f9 N
           set b  int (a / 5) * 5
( I5 k/ y8 r/ S- p, n6 |    setxy ( xcor-of turtle b + x )
( {% L1 k3 G" X; q$ ]6 b          ( ycor-of turtle b + y )& T4 g1 f) f2 B; T4 g$ q8 @
if (remainder who 5 = 2) [set c who/ s/ ?# P" [. |4 i
                          set x ( 0 - Wid / 2 ) 3 C0 n- k; }' L- t# q+ B/ e
                          set y (0 - Dep / 2 )  ]7 `' H+ a0 q' @8 N
                          set d int (c / 5) * 5
# X# m; \* a# F$ {. b- q   setxy   ( xcor-of turtle d + x )
, e  B+ o6 C. B8 \  e           (ycor-of turtle d + y )
* `3 o/ m* e9 ^* Z( C+ F  A         
$ H5 k) Z4 u* n! M            9 l! X. ]2 `- K- C
if (remainder who 5 = 3) [set k who+ w5 s- y8 \/ s
                          set x( Wid / 2)  
1 G: s; u8 j9 W- ^5 @                          set y (0 - Dep / 2 ) ]
5 R; ^3 i1 l) J% C* x! j8 b# A                          set f int (k / 5) * 5
5 \/ C# [+ ]/ u7 i. K- n: @  setxy   ( xcor-of turtle f + x )5 e' q/ Q2 ?% r0 W4 [. w& T8 c
           (ycor-of turtle f + y ) + c0 h/ g, e% Q: e1 D
           ) g. M6 `8 T, O1 z4 ~0 B
           
4 o+ y2 W+ N( `if (remainder who 5 = 4) [set g who
: d0 v! S7 X4 F; o" `8 m# K                          set x Wid / 2   G0 S% u" c( x' k8 A7 l9 g
                          set y  Dep / 2 ]3 a# f4 c4 w+ ?; \& d4 V9 w% s
                          set h  int (g / 5) * 5
+ m7 \2 w- b% j6 ]  setxy   ( xcor-of turtle h + x )4 R5 D% I( f+ B
           (ycor-of turtle h + y ) 1 N  }, B7 D* {1 x2 c
                          6 _+ t9 H# u1 C0 X3 N; s/ }
                          . `# y' I! k7 M" k2 Z3 [* `% ^, [
                          ]
; E/ X$ C2 C) R* _7 R  Iend) P  z7 o1 G) v% \8 D1 C6 H! N

! U9 `* Z9 @$ `* P$ H- r  E[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,0 ^7 B+ a# _% O) @: \
应该是
  }% E3 i+ ?4 B  ^6 Pask turtles [0 B6 j- V% {3 @& j( J7 r4 k
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
. }$ l3 |$ R/ r! ?0 I& }                          set y  Dep / 2
  g0 |* O  d; x( s% t* q0 {           set b  int (who / 5) * 5/ T' L5 w- ^& I6 J$ P
    setxy ( xcor-of turtle b + x )2 ^  {1 W/ u9 \+ P. m
          ( ycor-of turtle b + y )]]
! J6 y& |# e; z7 Xend
2 \. s" H: e; a) Z9 t之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-19 17:04 , Processed in 0.015458 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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