设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8573|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。9 l/ q  T+ j- z, ]
$ ]1 d) b: V' g  _/ U6 _3 W
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
) h, R1 K% T; I% Y
$ {5 \8 A2 J4 z+ T0 b" x. g7 Kturtles-own [a b c d k f g h
3 x& o5 n( b0 I  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 2 i0 }2 w8 c3 `( c0 ^; ?# ^
]1 w2 {" V/ ^7 d" _/ q: R
to new# K7 w2 B# V. m+ T( b9 w9 ~- p
  ca: m# u4 i5 j* Q; _
  crt 5 * num_of_building: ?1 u- U0 d/ M2 b
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]% A+ Q( ]& T: Q! Y) ^0 R% F/ z
  scatter     ;;keep center-turtle random positions
/ k5 g7 d3 `: g+ p/ u+ f3 T1 c7 h  unit_plan   ;;make up the building plan
3 n$ g! N" D  K5 s( _4 c- X2 Kend4 T' m' }1 M6 }% J) P
to scatter
$ C* n3 t  `. J% J& d7 _& R& Nask turtles with [remainder who 5 = 0]! P+ |' [+ N5 f3 s
[
( ?' _& X" y3 k$ _' ?( \9 v% b0 ]set xcor xcor - 6 + random-float 15
" p' _7 F& ]' S& z6 z$ t2 oset ycor ycor - 6 + random-float 15
$ `& m0 K$ N* H* Z* p: L6 c]' Z1 z* D6 K8 L9 w3 o3 i
end
6 B+ E8 s4 k, J! ]to unit_plan
5 u7 \; t; ^: Hask turtles [8 R  W- d) H3 D( z9 j1 ^/ h# X: i
if (remainder who 5 = 1) [set a who - M8 M- C' N5 W7 d& e1 D3 C
                          set x ( 0 - Wid / 2 ) 2 l4 ]$ e' a  ~: u0 r
                          set y  Dep / 2 ]  @  |' h0 P8 _2 s8 g9 {
           set b  int (a / 5) * 5
5 E5 ?% q- ]' Y- t    setxy ( xcor-of turtle b + x )* |. ]$ q1 k% D% a) `% O" t
          ( ycor-of turtle b + y ): {! G: C3 ~, F
if (remainder who 5 = 2) [set c who
/ v0 y2 ?+ A4 j; n# c2 H                          set x ( 0 - Wid / 2 )
8 b0 ^9 G' H; X  y                          set y (0 - Dep / 2 )  ]
6 `$ [; H* c# ?  n2 s                          set d int (c / 5) * 53 a7 ]5 }2 J! @4 f
   setxy   ( xcor-of turtle d + x )
1 ?+ M9 \4 E- L           (ycor-of turtle d + y )
! \! C. C& B8 P- c         
$ M0 C2 H4 Z# U            
5 `  b4 n; `4 J" D7 u% @if (remainder who 5 = 3) [set k who
7 F3 Z: u5 B  n                          set x( Wid / 2)  - f- o( r2 U* k+ i- \& d
                          set y (0 - Dep / 2 ) ]( T' a5 {3 J9 [+ }5 ^6 p: Z
                          set f int (k / 5) * 5
# c0 R  A. A4 Z# }  setxy   ( xcor-of turtle f + x ). m' B5 p- ~8 ?/ ?
           (ycor-of turtle f + y )
. a* A- V- u# n4 S, s5 z' s5 q           * ?8 |: }5 n9 ]
           
0 y$ X: Z8 M$ ^8 ~: lif (remainder who 5 = 4) [set g who
% ]: c* q2 `8 y  A                          set x Wid / 2 * o; P9 r  X8 H7 X0 }  w
                          set y  Dep / 2 ]
' w3 f1 o) P* R' v$ s( Q( m# ^5 r                          set h  int (g / 5) * 5
+ \! p: y- L2 G9 @) C4 {; j  setxy   ( xcor-of turtle h + x )5 _" s) d; B0 j2 E( |. T0 c4 o
           (ycor-of turtle h + y ) + X# q* y, x0 [" M
                          
. e# R7 [' G$ y) b5 X% V                            h2 B+ }9 {. ~! h
                          ]
/ \# S3 l' h! g* y5 u; _# fend) ?# t. T8 u* V* `+ e6 p) n

, T- _; [$ D5 W5 m" q* P! Z[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
& k6 O& m6 i. Y9 i: q应该是
" L2 |$ e8 W, z6 K# o- Iask turtles [
2 i. R# L9 s8 b0 y+ {9 I* n& B% C1 \" wif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) - B9 [: ]( F5 C7 O4 k- l
                          set y  Dep / 2 1 z# @/ ]+ t/ y$ r, @+ |
           set b  int (who / 5) * 5* ^! s/ U' h0 W( @. T7 |
    setxy ( xcor-of turtle b + x )6 j$ e  A. W. l% c9 l2 o# u6 `
          ( ycor-of turtle b + y )]]+ A" ~: s% G9 P; O$ a. I- m$ X
end
# E3 P! H$ ?9 S( ?: v8 d2 G" X2 T+ y之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-12 08:32 , Processed in 0.012933 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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