设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8128|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。  a5 {9 U0 X  c
# t6 F8 `( ]5 K- J& ^, Z! E
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
, n' F7 |! O0 }, X: Y
0 d+ t5 t; Q! ~* ?turtles-own [a b c d k f g h
- k4 Y3 `' o6 h9 T& f0 a  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
0 E. V1 G4 x2 C, w) r]6 l$ ~. J' P0 X2 Z; V: Y% }  B
to new/ W( _1 w4 u& _* r( @2 `3 _
  ca# K5 A5 ]9 s8 f' r
  crt 5 * num_of_building+ K; j- ~" H- c- u5 c# _$ z+ C3 e
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
1 o, \8 t  a1 U  scatter     ;;keep center-turtle random positions # v4 c9 s4 }8 B3 V, X2 h
  unit_plan   ;;make up the building plan
+ L3 @, Q4 v8 A1 Vend1 t8 M2 }% X$ ^6 p4 D
to scatter9 X% I2 i9 z: T2 \. Z5 u/ S
ask turtles with [remainder who 5 = 0]
( A& ?8 \8 X6 y0 N- I* R[
: u, |: z7 ]2 [/ z/ ?# s0 pset xcor xcor - 6 + random-float 15. l9 M/ m: `0 z# U* }, d4 P7 H
set ycor ycor - 6 + random-float 150 V, ~, k! ^- X9 a5 X: ]
]; Y. [7 i& ~5 G8 ?, u. B) g. [8 N
end
9 e. p8 @* ~7 G! w9 s8 e7 k2 }+ [0 D. ]to unit_plan * \. R4 Q6 G! M1 I8 h/ d
ask turtles [
+ N8 _$ ]$ \" Rif (remainder who 5 = 1) [set a who ( G3 C. {/ C. ?% J
                          set x ( 0 - Wid / 2 )
% J/ `3 g8 G* p                          set y  Dep / 2 ]
7 X% ]4 ~$ ]: H  s           set b  int (a / 5) * 5: u/ Y1 a! e& M4 V
    setxy ( xcor-of turtle b + x ); z, b: S% \; l  k
          ( ycor-of turtle b + y )
8 ?4 Q+ p# Z/ M' T+ Q4 q' Rif (remainder who 5 = 2) [set c who
8 a% S0 ]' L1 u1 r                          set x ( 0 - Wid / 2 )
) v$ A6 S& @2 o  X+ A. S1 G                          set y (0 - Dep / 2 )  ]# h7 n9 x$ J6 d6 W
                          set d int (c / 5) * 5
. o2 N& r1 X  P   setxy   ( xcor-of turtle d + x )
* d- N9 D+ c* R. `9 n8 E6 h  H           (ycor-of turtle d + y )
  N1 o$ l+ d- r% s         
6 H' v9 U4 r$ \            ! W3 `: X  P" Z
if (remainder who 5 = 3) [set k who
8 G# ?1 C9 s7 o) C7 N& U/ n5 t* T                          set x( Wid / 2)  ) g: B5 |0 Q+ p9 J# N( Z
                          set y (0 - Dep / 2 ) ]7 g( l! k5 E% A
                          set f int (k / 5) * 5
5 p3 Q2 q1 q8 _9 n  setxy   ( xcor-of turtle f + x )
6 M% k, }9 Z+ s/ n; q6 c           (ycor-of turtle f + y )
, i( [* Z* }% `3 f  @           
* l8 f0 q, C0 `7 C' w1 I           
' s% t: t; s/ T5 V# D' oif (remainder who 5 = 4) [set g who' ]' m2 I  f9 U$ R  i8 Z
                          set x Wid / 2
  h* m  J3 Y4 l  T                          set y  Dep / 2 ]
3 q+ B. V1 t1 o                          set h  int (g / 5) * 5. Y- c# T0 C* X4 R
  setxy   ( xcor-of turtle h + x )
. K  f, T9 @3 F1 C$ }           (ycor-of turtle h + y )
" Q/ S+ [, s0 Z3 R0 h% G; ?                          9 J- |6 w1 ^. r: F, E. C
                          
. J3 c$ _( p& E, p0 u! W                          ]
% s  k  b( z# Iend
) J: l4 G* X5 ]7 U
( ~& g1 `7 o" x0 A$ v0 z[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
# z6 d) {0 U5 u: P$ j, J应该是! L7 t" }: j3 @- |, L' c2 b& _
ask turtles [
& C5 H' O' y- Xif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) . c2 `4 \0 r; [, O3 V
                          set y  Dep / 2
' t& {# d/ z' m6 t$ x           set b  int (who / 5) * 5
8 g$ H% f; Z. v$ ]4 A( S    setxy ( xcor-of turtle b + x )
. D& y! j5 j  J5 ?4 T  \: @1 ]- e          ( ycor-of turtle b + y )]]$ a& ]  f- ~/ x, _; \' ]- Y
end
) k5 V1 S- b) R( W; K" m, X之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-9 05:02 , Processed in 0.022185 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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