设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8451|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
) C* s( }, Z) j9 N1 d9 A1 d3 v; |  r# r2 x( N) o; X
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
: a0 }6 L  o4 f  q2 P" {' N- e0 T" M" H" z  @( |* ]
turtles-own [a b c d k f g h
, x2 ?2 t  h2 \; n1 }- {  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 0 Q* x- q# m! C! d
]3 V5 }+ V) G. w5 I4 I( D! h
to new, ?2 }) B. t* h
  ca
0 U6 \5 }& f* p4 T; h  crt 5 * num_of_building) M/ x4 A4 N' e
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
$ C. R* a: T" H0 k. [# G  scatter     ;;keep center-turtle random positions 0 Z8 r7 D2 H0 w
  unit_plan   ;;make up the building plan
  B4 S# o; n5 r' G0 mend9 S' z0 ?' g  _( r( _! |
to scatter
9 }) L) x& {2 g+ [4 u/ \- m+ k" H; kask turtles with [remainder who 5 = 0]- |2 T. ^  T9 T$ Q
[
: ~% ~. j+ B' F# k6 T* o5 nset xcor xcor - 6 + random-float 15
6 |( R* W1 V$ i$ ~! Vset ycor ycor - 6 + random-float 15
( |+ G! j5 ]4 w* s& C: R5 F* v' t]
  U8 p) T* `4 W( @5 |end0 `, S6 l& A+ m( W3 P
to unit_plan 0 R: f9 v7 Z# Z
ask turtles [# c$ L" Q% Q; p3 a+ v8 b+ L( \
if (remainder who 5 = 1) [set a who
) r7 E6 l7 a% ^& q  q                          set x ( 0 - Wid / 2 ) $ l9 N2 }: T+ D5 \. h' @5 ?7 L
                          set y  Dep / 2 ]2 ?8 Y3 h! I: j, y4 w' O9 F  y
           set b  int (a / 5) * 51 O8 r+ H* t) D- N4 S
    setxy ( xcor-of turtle b + x ): Y1 M+ v4 t# N
          ( ycor-of turtle b + y )
: _0 L8 X9 w; r6 ]if (remainder who 5 = 2) [set c who
/ S" Y) Z$ J$ D5 z3 P: h2 J                          set x ( 0 - Wid / 2 )
$ o& y" Q" }% P9 @1 H: f                          set y (0 - Dep / 2 )  ]/ _1 c: f0 @) A3 D; @. |7 ~
                          set d int (c / 5) * 5
2 Q( R0 b. [4 D5 H+ j   setxy   ( xcor-of turtle d + x ). ]2 @$ E9 ^8 Q. D1 H
           (ycor-of turtle d + y ) $ I. \# @1 P* X) G. i  M$ J5 g
          + }# M; o1 M; j
            2 q1 X. I/ x  B( @4 f9 I$ S
if (remainder who 5 = 3) [set k who
0 ~; y/ R% ^' @/ W! [' H1 L                          set x( Wid / 2)  ' }5 @1 Z! G0 w: r8 O* [  T& [
                          set y (0 - Dep / 2 ) ]9 ~; h9 m/ J: y4 b3 I( [2 k: S! I
                          set f int (k / 5) * 5
' v8 @% G! z- j5 F( u1 W6 B  N8 j  setxy   ( xcor-of turtle f + x )
9 z4 f" v& s. R+ H7 l' M% u           (ycor-of turtle f + y ) - j# D. D9 f( q, U
           4 w2 l0 F; h# m; }" B8 Y
           
, a; ^2 V) o' a. Rif (remainder who 5 = 4) [set g who
3 C* k) t4 F1 X                          set x Wid / 2 # n1 e# x8 ~4 H7 Y/ g7 C# r4 b) t
                          set y  Dep / 2 ]
" M" O  m2 k" k: O' j/ r                          set h  int (g / 5) * 5! \* }& {, _5 Z/ D5 h0 d8 K& h
  setxy   ( xcor-of turtle h + x )
5 C6 |6 v  S& t. b+ v' {9 D9 ?           (ycor-of turtle h + y ) 9 i5 N7 ^/ P% c8 |
                          + }8 Y! {( r5 }
                          
+ v4 u1 t! f' Q, E; d                          ]2 G; M( c- \$ B# y7 _$ s% g; m
end
6 O7 G1 {+ B5 K4 c/ S
% _6 B' m% O- v- ^) O' O[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
- ~; F" z/ \% H8 Y0 U3 {7 `! l应该是/ |5 O4 L# P9 L' @, w* d% K
ask turtles [
& ~( W# k/ I7 G" L& ^8 k+ m# iif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
0 K' }) }$ C+ A7 e6 A                          set y  Dep / 2
' n8 Q; Q! A9 c8 R( b           set b  int (who / 5) * 5
$ ?* Z, X7 n: t* p+ }: c    setxy ( xcor-of turtle b + x )
/ k) q& w. P9 e, M" T4 q) i- p          ( ycor-of turtle b + y )]]
4 G, Q2 r$ Y+ S" B3 xend
3 x. O4 d/ M/ Z8 `: e之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-28 00:09 , Processed in 0.014849 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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