设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8943|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
0 U  b1 [! L9 t5 d: S1 B7 h0 Y
- n  T. ~9 W" D0 _但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
" m# \9 [! \3 G, N4 {
" O8 W( A6 X8 hturtles-own [a b c d k f g h2 s5 X& D5 e( m/ h, E
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
4 Q6 q, ]* P% j5 D1 X]5 d# ?! ]5 \2 p1 k1 @, {6 `( n+ p% i
to new
, y7 V& t+ j  z4 l+ o  ca* K& J7 W' H$ m* J
  crt 5 * num_of_building; k3 H! n% k* @- C, J2 e" E; a
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
& W$ {) Q, w! _  scatter     ;;keep center-turtle random positions
. `2 d4 P, m0 k7 o) r4 u  unit_plan   ;;make up the building plan
3 p" k4 r2 M. G+ M- `end
* e: c8 C# v) b; f2 A. [$ W5 jto scatter1 v7 y! c& P; X) C2 W- F# D
ask turtles with [remainder who 5 = 0]
7 C, N2 X6 P: }* m# D[
) l; v/ X3 M7 r) O; Dset xcor xcor - 6 + random-float 15
% _: P; M) f& q9 i( e1 Wset ycor ycor - 6 + random-float 15
6 V' n2 l; u4 ^0 A]3 y  M3 S% p3 h- d* r9 h# N6 ]+ X
end
8 b/ a! j, r, z5 K4 p5 E! Eto unit_plan
0 G7 Q5 V2 C) s2 `$ y' ^+ N7 ]ask turtles [
2 j* @1 t  {3 [! K* Hif (remainder who 5 = 1) [set a who
. ^# b( D) b9 h) L$ }5 D6 Q" W4 f                          set x ( 0 - Wid / 2 )
# Z( `' G9 z; I* v3 X3 k: X% N                          set y  Dep / 2 ]
% T5 b0 a8 `1 s, ^           set b  int (a / 5) * 5
2 n, v& e1 A8 Y0 A/ \* r    setxy ( xcor-of turtle b + x )
, f& f# N( ^; l' M: h% ]/ j! T( Y3 A          ( ycor-of turtle b + y )% I" i# l' S4 [1 w0 _& [* E
if (remainder who 5 = 2) [set c who
! A( c0 |/ @9 [                          set x ( 0 - Wid / 2 ) : M2 ]+ C/ G9 W, S
                          set y (0 - Dep / 2 )  ]# T, V3 k, ?' q0 x* l
                          set d int (c / 5) * 5
" A' R4 ]# X7 I* ~9 d& D+ _5 {  G   setxy   ( xcor-of turtle d + x )
# W" j$ ^, G; A: f8 r& f" {           (ycor-of turtle d + y )
3 x; f, D$ Y* P- M          8 J  O- ?0 \( ^2 F& Q
            
  _9 E8 y  B/ l" @- D$ o% {. l8 Bif (remainder who 5 = 3) [set k who  k0 W% g9 Y( c3 e$ s$ {) b
                          set x( Wid / 2)  
8 x; E! d( o9 K9 f- I                          set y (0 - Dep / 2 ) ]$ S$ B; F& B$ C& p8 Y2 l" R. A% e5 w
                          set f int (k / 5) * 5, N9 L' l4 N/ ~$ M8 H# N. a
  setxy   ( xcor-of turtle f + x )
- s# b& P# j. J9 ?7 n/ P" V           (ycor-of turtle f + y )
9 W% t3 [6 a0 c0 Z" R& k           $ K4 K, y, x. \: t" A; n
           8 i! `6 Q9 y% L. k
if (remainder who 5 = 4) [set g who
: V9 L# m' U! ]) D7 g                          set x Wid / 2   Z. A3 ?0 `$ U7 \. |3 C. s" d
                          set y  Dep / 2 ]
( C/ ?* |/ G5 \                          set h  int (g / 5) * 5" N5 ^/ I- G/ d
  setxy   ( xcor-of turtle h + x )
3 u% Q0 {* z  _) w7 V+ F+ ^  A# x           (ycor-of turtle h + y )
! L% f+ ^/ [$ y) x$ I2 e% b8 @                          2 d( L' I9 K& @5 U4 Y* }) a* ~
                          " [7 I9 k* p. t1 U
                          ]
: A2 m8 w2 ~# {3 u  {' P. T3 Yend7 D+ k9 c" [; h2 Q: P; q

! D" m; m! U% t" ^7 V$ V  q  a[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,% T/ x7 B+ B! `# L
应该是5 K+ D" O  F. a
ask turtles [+ B! E* u' i  H) ?' D9 C
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) " Z) Y9 j, C/ a* m7 h
                          set y  Dep / 2 6 M% I" q& j, Y; {1 R+ n
           set b  int (who / 5) * 50 Z! y# D; f( z; m' n
    setxy ( xcor-of turtle b + x )
) v; @' B: L# l4 o! [1 X* s9 l& O0 m          ( ycor-of turtle b + y )]]
) k# t" y8 g# C4 E( _: |$ r1 Fend" r" A( P6 B. `: L2 L; m
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-28 00:14 , Processed in 0.015267 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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