设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6799|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。, E. a. V6 q" R% E* L) U4 n

) ^, d5 ~  f9 L" C9 n* h( O但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
. H5 ], O# |  x
; _6 ~  h4 I6 s% x4 c, q8 Kturtles-own [a b c d k f g h; F2 m3 I2 m1 g. S, W  B$ l3 p
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle - L) G- f1 |! x' v4 l0 I
]6 v- K  X6 W: @8 V, S5 O
to new
; c3 J& [5 t8 o5 E7 r  ca+ J1 x7 \4 w; C+ x
  crt 5 * num_of_building
" `9 B' J: j" ?& ?0 o. k' T3 {) g  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
  u9 N! q, h( Z8 |  scatter     ;;keep center-turtle random positions ' ~" }1 v% V" K( o" l
  unit_plan   ;;make up the building plan4 V3 w+ S- g) z8 W
end4 t6 H' C! a, `9 P9 R
to scatter
6 J- _' R( K" S: Cask turtles with [remainder who 5 = 0]
$ e4 _6 X- H& L0 l; w# \[# _  O0 q/ C$ F( |
set xcor xcor - 6 + random-float 15  g- |$ ^! y5 K
set ycor ycor - 6 + random-float 15
) v1 j1 \" x( F% n: ~8 `) W]9 d) @/ V, R+ D" G
end
/ t! s2 {  e  H5 ]1 jto unit_plan 7 Y( C# }& C/ U% G% y, |  b
ask turtles [7 K; e) T% |& U, g! X& E6 X
if (remainder who 5 = 1) [set a who
6 x* l& f4 \. c" L5 u) k                          set x ( 0 - Wid / 2 ) ( e3 A7 C; J  S3 P& Y: r
                          set y  Dep / 2 ]
5 T6 `% W* M! d, l7 b1 y1 N- i           set b  int (a / 5) * 5
6 k& S, X7 I. B8 h5 W    setxy ( xcor-of turtle b + x )
& O! t# k# V' ]" z+ O" s; g% \! Y( n0 z          ( ycor-of turtle b + y )
" V! s+ B, e, x) sif (remainder who 5 = 2) [set c who
% d! M4 y; {! G5 [                          set x ( 0 - Wid / 2 )
. a6 ]2 k  ^+ P5 K" i; d' E6 e                          set y (0 - Dep / 2 )  ]* M1 p" D# S; ~
                          set d int (c / 5) * 5: o' c5 t" Q7 ]
   setxy   ( xcor-of turtle d + x )" I$ }+ H6 U3 }
           (ycor-of turtle d + y )
$ J# r' h2 ^: Y+ u3 {         
) m* p. E; b. q) M  p/ l; b' S            
! _) W: i* O& p) Hif (remainder who 5 = 3) [set k who* p* m; S# o: {5 ~
                          set x( Wid / 2)  
' g4 O* G+ [+ @, v) y                          set y (0 - Dep / 2 ) ]9 ?5 g( N+ m& X; t" g; k
                          set f int (k / 5) * 5
. u" m+ M0 ]  i  setxy   ( xcor-of turtle f + x )9 K) G/ z! c+ P) E* \4 F/ d
           (ycor-of turtle f + y ) 5 `# S* T, \3 c
           
9 R( \! g7 l/ {4 M2 Y           
# d/ P. w) a) h$ E1 r- f$ S& T0 lif (remainder who 5 = 4) [set g who
% P- a5 f' F, t" t( H1 Z                          set x Wid / 2
  w& h! K' `9 }  a; d+ @8 w1 O                          set y  Dep / 2 ]: S: G/ {, U; M9 Y+ U0 N! p
                          set h  int (g / 5) * 5
' l) F3 ^& P) p* A$ m% m$ e0 e5 Y  setxy   ( xcor-of turtle h + x )( O9 N3 d9 |, T) K- g* Y
           (ycor-of turtle h + y ) 3 w. p! f$ _- c4 o1 l' W+ W8 {
                            V4 Z0 e  q7 o1 r% b& m. G3 z
                          ' F9 _" s7 s6 \, l! w/ S
                          ]' O0 x/ O$ G4 x4 S1 N" s
end
1 H) E- N; K: w$ _: ^
- n( M5 m) K/ [" @: l; P4 C2 `) [[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
) W( V! S; ]6 a8 Z4 @应该是
" Y9 t& U! S! c( c5 Lask turtles [
3 |# `8 g5 ]/ P) Y$ W- Y( e  rif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 9 N0 r/ z% x/ v; g, \; b) @
                          set y  Dep / 2
3 q1 E( h' o+ c9 J           set b  int (who / 5) * 5
1 ?# g' W8 b5 h6 }; J    setxy ( xcor-of turtle b + x ), o* h5 `6 v8 w: _: B
          ( ycor-of turtle b + y )]]4 ]0 \; L& u# y6 O2 v* t9 T$ E
end8 h; b7 ^( }7 l$ }7 P3 K
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-24 12:27 , Processed in 0.015795 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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