设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7796|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
: ^5 I/ c) C+ J& v: \" S9 `2 C9 A5 {. B$ F3 ]6 r9 I
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。) @3 B. ~' r: Q7 e, G
9 {" q( y) x& z/ w
turtles-own [a b c d k f g h
! c# E9 i) C. R' E1 `, p/ }2 q- Q  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
2 J" L. m6 s5 h* f- q]4 x! n: _/ ]1 h/ J. {0 K- u
to new; j! {$ O: v4 h+ b
  ca1 n# b- V% `+ n9 d$ ~
  crt 5 * num_of_building
4 ^: ~$ k1 @& j) i/ {# l. O  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]* k5 t3 z& K/ t; K4 W
  scatter     ;;keep center-turtle random positions
" z1 ^! |5 X) f9 u0 \) F& D; F  unit_plan   ;;make up the building plan
% N3 C2 H# V. o. T% s: Hend
+ @" N% p3 R/ R) E$ j: _8 [/ Kto scatter
( s3 P' m2 t( {4 s, cask turtles with [remainder who 5 = 0]
' v8 A; n6 x' G4 w  ?" P& N6 M[8 G" H' N7 r3 A5 z3 d
set xcor xcor - 6 + random-float 15
- e4 @- q! e8 t6 F! pset ycor ycor - 6 + random-float 15: A; @0 B/ A- m, p/ u  ^# `6 G# u
]+ _6 F% ^% f( h& P( ^/ u8 t
end
2 Z5 y) [4 t& D# Hto unit_plan 5 k& |6 @: I- r! Z: T
ask turtles [
: l) p9 w) {8 B) S( I  mif (remainder who 5 = 1) [set a who / O/ P( j) s4 ^- G& I, ]: ?; U
                          set x ( 0 - Wid / 2 )
6 W* Q' ?3 s9 j" O( w6 K4 b                          set y  Dep / 2 ]* f8 S: n2 k+ q
           set b  int (a / 5) * 5  A& E/ T- N: c2 w; ~7 {. \) |. ~$ N
    setxy ( xcor-of turtle b + x )
1 n5 Q; d  f* |7 K9 e" w  v          ( ycor-of turtle b + y )% q5 y' r4 P" p  g4 b) V* G
if (remainder who 5 = 2) [set c who# f+ |! h$ @1 c5 Y
                          set x ( 0 - Wid / 2 )
8 {+ }9 V/ \: q# j6 b7 V! w* E                          set y (0 - Dep / 2 )  ]
. o; y0 q2 H: a                          set d int (c / 5) * 5
7 Z/ [5 N7 A% z2 s0 Q4 W   setxy   ( xcor-of turtle d + x ), I! e' K& J9 K3 A: A
           (ycor-of turtle d + y )
# R5 a9 z& \$ X          4 \( r2 G- P: M2 @6 _
            - n8 z8 T# z: c. M1 c" `
if (remainder who 5 = 3) [set k who, {$ x; B1 r! o1 a- [5 p% ]
                          set x( Wid / 2)  / G" z5 }& ~% b0 s; ?2 Z. P
                          set y (0 - Dep / 2 ) ]
+ @3 j3 Z; R* d/ E4 J                          set f int (k / 5) * 5
# z' |! o) k9 F  setxy   ( xcor-of turtle f + x )
7 a( L$ c7 y9 H5 v% T1 |, T           (ycor-of turtle f + y )
! ~4 j2 i9 K5 M) D           # m5 K3 B- W" H7 P$ S1 B
           1 H8 W) H$ T. w9 a6 O
if (remainder who 5 = 4) [set g who4 O! J. [2 f1 ?$ A0 P' R& o1 c* h
                          set x Wid / 2 . W" u* F9 j  L% [+ g1 P9 o
                          set y  Dep / 2 ]
% J8 Y  X* ~$ g1 ]. P* T! R7 H7 e2 I                          set h  int (g / 5) * 5
. W5 f$ U: @- f7 d0 N  a  setxy   ( xcor-of turtle h + x ), a5 r4 B3 ]% |, A
           (ycor-of turtle h + y )
! _8 R; Y( P' U4 w! r; \                          
: g& f9 y2 u$ i                          2 ^; R0 ]8 {$ p! d
                          ]3 f+ U6 o+ b. A# u5 F6 t7 A
end9 ^3 v* T. M, c) }3 l
  |0 i; M! a9 N- ]  q7 G/ c- V
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,- n2 |5 c, V8 _. o/ ?9 }
应该是
& N; F& j1 h2 Zask turtles [
! i) Z" N" I" f3 h' Z. Tif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ; M/ C+ R- b- f& ~+ ~
                          set y  Dep / 2 4 v$ d  a5 K! x7 w, H4 p: n4 J5 C
           set b  int (who / 5) * 5
* x4 C' ^1 c' L. {: {    setxy ( xcor-of turtle b + x )# S3 Z  \" L. t2 R
          ( ycor-of turtle b + y )]]
+ L$ L2 [  J0 P# }& p0 X) Oend2 G  q/ i8 }$ g4 t* k/ d* B
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-2 04:27 , Processed in 0.017890 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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