设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6814|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
. M3 o# Z9 e1 p( A- u# ^9 b# W- Y) B5 g& z
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
" |) `3 H5 ^% b' V, N
# J6 Z, ?- f3 @* h3 J* yturtles-own [a b c d k f g h
3 F6 D. h+ p  t( d4 _  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 4 b* L& Z9 a5 v4 h
]# J6 ]! c3 K) k! l' Y6 u6 e5 u! [# h4 z
to new
% q, g1 h3 z8 @5 i, }4 O  ca7 a) z1 b( }0 ^1 M; u/ |# I
  crt 5 * num_of_building
1 K; s- e; l! T3 W% e; M# C  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
6 f" K  b; T) q# ~  scatter     ;;keep center-turtle random positions
$ O( V/ Q' u; Z3 J1 s9 p# x" F  unit_plan   ;;make up the building plan6 c& u4 u  c: v6 S* r
end
' A- b2 L% Y7 g; B7 t/ ]! gto scatter
- R7 I8 X( q9 w, Cask turtles with [remainder who 5 = 0]2 f4 f8 W* B! d
[
$ @+ ^. T0 W" y1 L2 ?& X+ _set xcor xcor - 6 + random-float 15
* Q) L9 g7 P7 Iset ycor ycor - 6 + random-float 15, S: o1 v- M7 d2 J2 f
], w+ j1 g: ]+ F& _5 S4 i
end: ]2 h: @5 e7 t! ]1 D. T7 O
to unit_plan 1 P3 c2 l: A% v
ask turtles [8 }+ ?9 m1 t& s7 n$ z2 [( t
if (remainder who 5 = 1) [set a who 4 f7 g$ U) i2 S8 H
                          set x ( 0 - Wid / 2 ) + u$ u3 p( L& G5 Q& o( f" s! G
                          set y  Dep / 2 ]
& i1 `8 c' c4 B7 D6 ]! F           set b  int (a / 5) * 5
. ~' }; m2 J( w; A3 Z    setxy ( xcor-of turtle b + x )
# S1 O: e2 `4 n          ( ycor-of turtle b + y ): t/ G& U5 {- R  L& f" |3 T3 o
if (remainder who 5 = 2) [set c who3 z7 t, N* B; H1 X" `
                          set x ( 0 - Wid / 2 ) ; g* N8 y0 f- }! G6 j! e
                          set y (0 - Dep / 2 )  ]. |) V7 }; z* [! a% q
                          set d int (c / 5) * 5: G) ]* z; M) O$ e
   setxy   ( xcor-of turtle d + x )" l9 B" K' T- ?  P6 U/ C# u
           (ycor-of turtle d + y ) , ?/ x1 d+ t: Z: J2 T) v1 x
          % ]' @0 V$ r0 Y: K6 P
            
% x( q( w- v8 |) D& c6 R% Bif (remainder who 5 = 3) [set k who) Y: n6 _3 h& y6 M, I, G7 X% }5 C
                          set x( Wid / 2)    s3 d! H- c$ r8 P0 Q+ U( G
                          set y (0 - Dep / 2 ) ]# r2 v6 x1 c/ w9 N$ U0 r
                          set f int (k / 5) * 5' M. C0 l3 {4 t3 p( Q+ [6 B3 r/ `
  setxy   ( xcor-of turtle f + x ). L) R) w+ q  d1 C6 O
           (ycor-of turtle f + y ) 3 M2 a6 _6 X4 W+ u7 i
           / `. V/ V" x( B: Q2 J
           9 H$ V, F! d/ W/ t" K, t
if (remainder who 5 = 4) [set g who
2 i& L3 x% k4 ^9 i9 l8 m, j& b                          set x Wid / 2
, V1 @. ]& ~. N: J                          set y  Dep / 2 ], t: G% n% z0 I5 X* J" t
                          set h  int (g / 5) * 5
$ j& j. d. M4 d! e2 ?; k4 H  setxy   ( xcor-of turtle h + x )  D; T3 R* m3 X5 w/ P+ k
           (ycor-of turtle h + y ) - H% a( t. x7 r4 _
                          
. ]! L8 l4 M- {3 {0 `8 i1 t# I/ ~0 K                          
% ^( A0 l! |) g6 w; `! S9 u$ h                          ]' t1 U. B. h' K  N( ^1 [1 u* ~
end
+ k% ^: @6 [( A/ Q( \: p: f
) n/ n5 H2 h% z0 s& [" \* p8 a[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
2 Q7 g, ?8 e# l应该是
/ d$ h% `* o1 u# Lask turtles [) C) l- c" A$ ]& j) Z8 m, O
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
+ `8 g: U! o( i; }! b" U                          set y  Dep / 2
" a! e% N; j$ p3 A5 u. B           set b  int (who / 5) * 5
! g# g$ W* _2 u; B  R/ S$ z% z2 _. ~    setxy ( xcor-of turtle b + x )
+ W/ M5 \3 W* i, B3 ^# X          ( ycor-of turtle b + y )]]
7 j3 }+ g! }* @8 j: dend
9 _7 U# _5 x& E$ f之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-25 18:41 , Processed in 0.020098 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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