设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8697|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
; l6 u- a: V3 Y
% S7 T* C7 n% A( @- X但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。) |, Y* u' z! Z8 d

0 l! G% F0 n! p) gturtles-own [a b c d k f g h
6 C6 J7 f; i+ h: M7 L  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
7 ~/ a/ \6 t9 ^3 p]$ Y2 t, S9 v: E8 |
to new4 }$ q" Y" F0 D6 _! i
  ca& k* c& \8 c0 Q1 r
  crt 5 * num_of_building
# b4 q* v6 D- U3 k0 X  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]! G- A5 f4 ~' C/ y8 s
  scatter     ;;keep center-turtle random positions
7 O4 }- x1 r- w7 ]# s  q2 l" d0 ]" i  unit_plan   ;;make up the building plan" ~- s6 m$ M) i3 M. e- e
end5 J( T6 s- z3 H; Z9 m: I% h
to scatter* _$ J$ g- u* U. d8 `
ask turtles with [remainder who 5 = 0]; A' X) |  ]+ E6 r  M
[) o" c5 t7 u% Z& @) }- ~
set xcor xcor - 6 + random-float 15
8 V8 p" t7 ]" @: f. Kset ycor ycor - 6 + random-float 15
9 d7 G3 N3 X0 o# `0 c2 |]
8 x2 _, m* f: O0 P! pend
# q: R  @- F/ }  Z. Q* U  e+ X& \to unit_plan
" j  b# t6 L! K, T* a8 r  y( y3 Pask turtles [, S9 J. P- H) g* ]% n, S7 \
if (remainder who 5 = 1) [set a who   ?1 i) c- t" C- v' S( D
                          set x ( 0 - Wid / 2 ) 6 E$ X( @2 I$ T' T2 L0 `" s
                          set y  Dep / 2 ]: ~$ Q- u# j8 c9 V/ ?
           set b  int (a / 5) * 56 p7 N5 }+ T, h+ N- @  J. P
    setxy ( xcor-of turtle b + x )
: T6 ~4 @& ]- m5 @          ( ycor-of turtle b + y )
8 W  M4 c( Y4 hif (remainder who 5 = 2) [set c who- c: f& G, h" E/ f$ v3 R
                          set x ( 0 - Wid / 2 ) ; L+ W1 ?5 U, e9 l! I4 V4 c! o, @
                          set y (0 - Dep / 2 )  ]) D; |9 C& X* Y! C
                          set d int (c / 5) * 52 G) [$ C! q3 O
   setxy   ( xcor-of turtle d + x )
3 p+ k+ s1 k" L, g& \6 ^6 m           (ycor-of turtle d + y )
+ b' `, H. r, r8 N          3 _3 z/ |5 y2 F$ p( T" r. W
            
. a% B. t2 R; |+ U& S! t7 O' zif (remainder who 5 = 3) [set k who: N4 a- t3 ^6 }* R5 }* z8 T
                          set x( Wid / 2)  
. B5 `: [# t) B3 v9 k                          set y (0 - Dep / 2 ) ]
, y+ t) [- G4 Y: g                          set f int (k / 5) * 51 Z) N  a" i0 C* v
  setxy   ( xcor-of turtle f + x )
. V; B# f: |3 M& X# p3 v, M7 E           (ycor-of turtle f + y ) % h# ]1 ^5 h7 K1 N& W* A! e
           $ @; i2 X2 Z% r' U# u; Q9 I
           : w* j% Z) y! f$ G1 e( I; f( @
if (remainder who 5 = 4) [set g who
2 C, ^4 K" x0 M                          set x Wid / 2 ( r0 t8 x6 X/ L7 m  h; x% J0 B1 G
                          set y  Dep / 2 ]
! T! @1 M- A7 F0 b& A# b0 r' L                          set h  int (g / 5) * 57 t- G! P- Q3 Y5 {6 T6 w2 K
  setxy   ( xcor-of turtle h + x )  I4 S) i" F7 M0 e  x4 z  s
           (ycor-of turtle h + y ) 5 v" M9 H- Y* `. A8 r+ @
                          # e8 Z7 w1 ^' D8 _
                          
; a6 J7 ?  h& C6 L                          ]( g) h% n, w& m& |
end
* h2 b9 C- f) @( A5 m! N8 n' ?* k/ D4 I5 k+ @
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,3 ]& ^0 o; j6 K* K
应该是; Q3 e3 Q3 D; r2 A
ask turtles [3 i, R; @  a6 u
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ( i: a% e1 I( P3 s: u7 W
                          set y  Dep / 2 0 c' i4 w4 @0 K9 T1 q( u  U8 b
           set b  int (who / 5) * 54 F& z8 c% c/ `1 e
    setxy ( xcor-of turtle b + x )
$ k5 r5 u& X7 T: N, x# G          ( ycor-of turtle b + y )]]1 b/ n  F  H8 _' L& q& u
end
: Z) [. S+ `, H  U' O% {7 M1 L之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-27 01:47 , Processed in 0.012812 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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