设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8203|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。# {7 G$ T+ o6 d

7 T* i  u: S: ]% Z, t但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
4 ~# o1 ]% w, a- P" U& O; f
: r; F, o; M1 k0 ^3 Bturtles-own [a b c d k f g h' W5 w$ q7 G& M, t6 [
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 0 ^& i: d9 Y: M$ i8 |. D
]
( H) h3 ^$ _" }& x3 Wto new
% n" U) l9 i: J8 v6 p  ca, t, P0 y$ o6 J" C+ K
  crt 5 * num_of_building
* K" h' O) v+ u+ \% C  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]: m7 I- g1 H3 F4 k, j9 G% k" ^- i
  scatter     ;;keep center-turtle random positions + T0 |2 I+ @+ l7 @$ Q" V, o- J7 z
  unit_plan   ;;make up the building plan& s9 j5 D) Y( u
end
7 C, z8 X  D: p) h9 \& J( Y' fto scatter1 W' \9 @* B$ B3 S
ask turtles with [remainder who 5 = 0]
1 c8 v" P3 E' _" U) P[) R1 a7 T6 e" Y0 T
set xcor xcor - 6 + random-float 15/ y. p4 x, L" r. [) C& ^
set ycor ycor - 6 + random-float 15( {1 W  o" Z5 D! q, T/ D
]
( O# G5 k) Q) E  ^9 pend: ^7 T! C# z; G  a3 x
to unit_plan ( H7 I* h/ _" @2 [; Z1 d6 G
ask turtles [& t  U2 e0 |1 ^$ k
if (remainder who 5 = 1) [set a who
7 ~5 H  S% r" l+ S1 J                          set x ( 0 - Wid / 2 ) , k% B5 W. Z  ?: |: ?# s/ x. E5 V
                          set y  Dep / 2 ]# M" m, I+ f% z; r* F
           set b  int (a / 5) * 5
% V$ s, v3 z" v3 |# E: x- F    setxy ( xcor-of turtle b + x )
. n* T# @8 ~2 F2 e$ C& {          ( ycor-of turtle b + y )9 V& B8 H$ O' n$ x: m2 o1 w) o9 P
if (remainder who 5 = 2) [set c who- H. B+ z  Q& \. h9 \  o
                          set x ( 0 - Wid / 2 )
3 d$ F: }6 C; R                          set y (0 - Dep / 2 )  ]
: d; ~! A: U/ f& I% O2 B                          set d int (c / 5) * 5. Z: `" i9 e  s. U( K( t3 Y
   setxy   ( xcor-of turtle d + x )
0 G' e2 k/ _7 h) I1 [3 d           (ycor-of turtle d + y )
7 }& F5 z- w0 z4 n, F         
3 v8 P0 d0 _$ |            / {% l0 N1 z5 Z: p# x" w% C
if (remainder who 5 = 3) [set k who
. t9 B  V8 O8 ], U                          set x( Wid / 2)  2 d0 P6 p% _/ Q& e% E$ W
                          set y (0 - Dep / 2 ) ]3 Q9 d% w9 `! x) e2 j
                          set f int (k / 5) * 54 ]* e  w/ p6 o% m0 ?) J% U
  setxy   ( xcor-of turtle f + x )1 \$ ]0 E* i5 C9 c& g7 ^% O% q
           (ycor-of turtle f + y ) ( H6 a+ H  L4 Q- {
           % C/ [8 {# b% u
           ) [. E/ m' Q4 n% Z$ C
if (remainder who 5 = 4) [set g who
" e/ w4 K9 i5 K( N/ Z                          set x Wid / 2 * C. D  Y+ }. l5 C3 h) C: _, k, F
                          set y  Dep / 2 ]: |9 Y4 k% G1 M% W3 b) h
                          set h  int (g / 5) * 5/ g- b9 ^. V. ^& r5 k& r6 N5 h
  setxy   ( xcor-of turtle h + x )9 ~* O$ D% h  r8 `% x% T
           (ycor-of turtle h + y ) - e  s" T0 _' E7 ?& V0 d
                          
) f' b& X9 o" e5 t$ j8 b                          1 A9 Y; I) s! |. I* M, Z
                          ]: t8 f3 J7 M" r" E, j5 \
end
# i! O% R0 t3 Y; K, n
" e: b4 ]0 m' a+ @/ s8 v8 W1 r[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,. }0 N, ?4 Q0 p+ G  X
应该是
0 s  n1 d3 U4 H8 T" Dask turtles [
0 e: k9 Q& N/ \; L6 eif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
( w: F! w5 E! V! s1 B( h                          set y  Dep / 2 ( o0 g9 F0 w# v, g, @
           set b  int (who / 5) * 5- w* i) H, f# ]) C
    setxy ( xcor-of turtle b + x )
, Y% O. H7 A1 K, O* U; ]+ }6 p          ( ycor-of turtle b + y )]]5 Z7 q0 M/ s& ~7 E7 r8 x* l8 l
end
! B+ J, y9 D0 w3 h6 S/ M之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-18 07:04 , Processed in 0.022122 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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