设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6760|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
; K& w' o" f& j; `3 H# ?. V6 D
: N: z7 M& K& ~但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。# N* E3 W0 g; ]8 P2 c5 E. C

( y1 B0 c, H7 Q/ @5 sturtles-own [a b c d k f g h
% W$ N' y" A" O( v& K' N* `0 B  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
* A) |1 N/ l( m( }+ b]3 Q4 T) L) w0 I6 o: N( ]
to new
3 u2 b. t5 T- R* m2 n  ca  g3 N' B% L" O# P0 S
  crt 5 * num_of_building
8 C2 C( W; y: H, W" b- V+ ]  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
% A0 r. I6 m: @  scatter     ;;keep center-turtle random positions 5 D; d- v0 d8 p
  unit_plan   ;;make up the building plan
* d8 q4 [# N3 r; M) Q; n% Nend2 Z. D% |& P* l' o& P! j
to scatter
; R. {1 W& f2 [2 _+ nask turtles with [remainder who 5 = 0], G( T- o( O/ W9 F
[
9 v% s# T) _$ xset xcor xcor - 6 + random-float 15
. l& X, y% u5 A+ W5 Bset ycor ycor - 6 + random-float 15
+ s0 ?4 A% X2 ~" ]  s3 u]8 N9 N" M' |4 d: v( `( K: F! i
end
* x7 w# ^! h% ?$ ito unit_plan # n, S# g* j# e+ B9 R
ask turtles [
/ j5 m: `5 Q( P# q/ k7 Hif (remainder who 5 = 1) [set a who ( T' E& z& c5 V5 ]
                          set x ( 0 - Wid / 2 )
& J. X9 I3 n- K2 ]* j$ {                          set y  Dep / 2 ]
/ [# [  {, F  N% ?( w           set b  int (a / 5) * 5+ t  w  u1 _8 C/ G
    setxy ( xcor-of turtle b + x )
/ Z' W& h" N; N7 I3 p2 R1 G          ( ycor-of turtle b + y )" [+ D3 R) q# [
if (remainder who 5 = 2) [set c who2 h2 E; m% n4 b) J( X: r3 n! F
                          set x ( 0 - Wid / 2 ) 8 C8 o% N) B2 y/ y; Z; A$ s
                          set y (0 - Dep / 2 )  ]
# {  M/ e; u$ g2 M5 e                          set d int (c / 5) * 5
) O: v  D3 ~% q, R& j, {6 X7 O   setxy   ( xcor-of turtle d + x )
- Y7 O7 r/ ]( s  b' i* t% l           (ycor-of turtle d + y ) ( }2 A7 s* ?! H, `2 ?, Z! c2 H% `
         
+ H! Q6 l% S3 {3 F1 O, i. ^            1 ^7 m8 C( u4 Q1 D
if (remainder who 5 = 3) [set k who5 B) M7 B6 l" e$ M4 o- w8 G
                          set x( Wid / 2)  
: m, N. J' q' B; @2 [9 L: H                          set y (0 - Dep / 2 ) ]
4 j. w: J. |7 P' f                          set f int (k / 5) * 5
# f1 H' x6 E$ q* V1 o, c" j4 G  setxy   ( xcor-of turtle f + x )0 G. Y  Z4 @: y! l" i, `
           (ycor-of turtle f + y ) . P+ s* p3 T/ T
           0 l# G9 L3 c+ `5 R
           ' d% `# s# P! F8 E& w6 x4 d
if (remainder who 5 = 4) [set g who2 m' `# ?. l- s5 V
                          set x Wid / 2
0 r, `: O7 D" e& f                          set y  Dep / 2 ]! G9 j, z: n! U/ f% l  E+ ~: I
                          set h  int (g / 5) * 5
. E! Q+ U! p1 R1 a  setxy   ( xcor-of turtle h + x )
' C3 S, V( q; X3 A3 T7 q' o           (ycor-of turtle h + y ) 1 i8 ^! X9 k8 y0 C* [& ~
                          
, B6 F  ~+ x* u7 @' Q4 G                          5 W7 E" R; j* W$ M0 V4 ~6 `
                          ]- i0 d/ R+ w5 X1 M: h
end( L6 I1 K2 R  M$ `' l5 ?. T
, Y$ g% H, I! p# Y+ [- b
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,: J1 q! x. W* d9 j$ x0 p8 U% K
应该是5 U, \+ u' Y2 m1 u2 L8 H1 N5 |
ask turtles [8 {9 p/ w% k% x# `& D$ x* }( F( r. B
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )   y5 w6 I6 V! W( f" s/ k0 e) _) N4 a
                          set y  Dep / 2 1 c7 Y- j9 |% W
           set b  int (who / 5) * 5' m8 p0 t" Q, t0 c2 y/ ?
    setxy ( xcor-of turtle b + x )8 r' q$ O3 ]. t
          ( ycor-of turtle b + y )]]: _4 c& y: \- O3 |0 f5 m+ _: B5 ~
end
+ \+ f# c. R. q+ @, ]之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-21 14:46 , Processed in 0.019123 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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