设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8375|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
; N6 {2 M7 S% T; e* A
6 x8 p6 P- `! Z5 M; u1 S但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
: W, h, T( z# H* y& @! ^" A5 Q& M2 D8 K7 Z$ x
turtles-own [a b c d k f g h
3 v7 Y1 G- g: P% C* Z# a, C$ m7 n  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ( [9 o0 F2 y# _- N1 O
]  T& Q7 }, m2 s5 o0 ~3 w
to new
5 r) j+ H6 a9 y* A# _" `1 Z  ca4 }# d5 y5 U, C6 R
  crt 5 * num_of_building
! o1 F  x/ n0 `, P  ~  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]& N$ u" l% z0 k: c
  scatter     ;;keep center-turtle random positions
" M$ z+ [, s& z  unit_plan   ;;make up the building plan! Z. `5 n  a! p) k" f1 W8 ~1 P3 N
end
5 j' N% g3 D9 I/ a2 e2 Fto scatter, Q- O2 N- M7 x" N' m3 X
ask turtles with [remainder who 5 = 0]
3 h  P6 u- A+ P$ v% C; b: n[
% [) u4 ?2 l( Nset xcor xcor - 6 + random-float 15  H6 n7 g0 z5 b# f# I2 b
set ycor ycor - 6 + random-float 152 e' _; \" `) I+ b8 M
]; @! f8 `. p0 N9 K) O  L5 z& e
end2 K/ `% K. u) r  \) t8 Z" Y
to unit_plan
& W6 w3 x4 o0 ^9 qask turtles [
4 g4 n" `) n2 Yif (remainder who 5 = 1) [set a who
9 E- M5 P0 L8 H2 m, G                          set x ( 0 - Wid / 2 ) 3 ^4 Y) F' ?+ n$ ]# R, B
                          set y  Dep / 2 ]
9 X: ]) v# X9 H* o           set b  int (a / 5) * 5# u. m: b9 }  M6 h, ~1 ^
    setxy ( xcor-of turtle b + x )
3 X& S3 I, N9 C8 D$ e, D          ( ycor-of turtle b + y )
. W# t2 z/ ]( x  @& V0 M3 Oif (remainder who 5 = 2) [set c who
5 U+ h1 x5 |5 {% A. o                          set x ( 0 - Wid / 2 ) , S; ^) {: i7 u  ~! k: b: e0 B$ Q3 e
                          set y (0 - Dep / 2 )  ]
1 c4 |* B6 d/ E7 K                          set d int (c / 5) * 54 b7 B5 Y2 f* f, p2 s. f% M( A
   setxy   ( xcor-of turtle d + x )
3 F2 @7 C) P0 i! O           (ycor-of turtle d + y )
7 C3 G' c, G7 p0 W1 O% @         
# G  P2 i. n6 h$ m% L6 U$ s            , ?& k8 p- f+ ]8 `& @: ^" b0 I& E
if (remainder who 5 = 3) [set k who
0 Y  A/ I' q% T* x                          set x( Wid / 2)  
! q7 r$ w/ D6 x* ~9 p+ C) I- g: M8 E                          set y (0 - Dep / 2 ) ]$ t' f: ~- Q, F
                          set f int (k / 5) * 5
+ _6 _. w: Z2 ]( L, A9 v  setxy   ( xcor-of turtle f + x )
) h% }) g3 B6 |' t3 B           (ycor-of turtle f + y ) 2 J: {" D. w5 ]4 d/ i, J
           
/ r! \  `- |% K" c% t           
7 m# \( B2 a( G( Iif (remainder who 5 = 4) [set g who) M- e$ \/ Y5 L* S# \
                          set x Wid / 2
; m: ~* o$ a8 S, N% @9 T8 t                          set y  Dep / 2 ]" X: |. f5 Y, I5 Y! j
                          set h  int (g / 5) * 56 H; n+ `/ {7 I4 K2 `/ [) ~: e' y
  setxy   ( xcor-of turtle h + x )# F( B2 D$ w8 T5 r1 `  t4 y
           (ycor-of turtle h + y )
/ o5 a, X" Z6 `. W) Q+ i/ e                          
: E: l/ z' A4 B, ?  B* t3 F' J3 G; q                          ( P: g  G' _# p; y( ?
                          ]! h9 y/ A; J$ s" B
end
+ g( e( o9 a+ {# e1 p. H0 b; S# N
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
8 H3 s: J9 k! H" E: U' R) t应该是2 ^& c' H3 C" t, `3 e  A! A1 t$ {
ask turtles [
$ E5 z/ t) f8 Q- x; y' H. Nif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
) k/ p( v7 B7 V$ k/ Y( c+ a                          set y  Dep / 2
# p6 |4 |' T. @( _' I1 a( |           set b  int (who / 5) * 5
/ [8 C/ A# n! F7 y    setxy ( xcor-of turtle b + x )
  L$ ?6 o' o6 {; J" }  d          ( ycor-of turtle b + y )]]8 q: V% q+ s3 G" M0 D( m
end
2 i, c: K' X; W, ~: z之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-16 20:45 , Processed in 0.013373 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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