设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8315|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。) d' U4 g2 j- }* _
9 |( I+ D" v  u3 u& i! a2 E, O
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。3 r( G; i* _% y& R

7 |+ _) R" ?$ b" o0 U% H! r3 Wturtles-own [a b c d k f g h% r8 ~: X8 j. _# y8 y) J. c
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
0 Z( B- h% m" r3 N  ?]( L# q0 T+ x/ `% C  T# r
to new
1 t# ?" F" M$ y% W  ca, \' e: y; F7 K) r
  crt 5 * num_of_building
( E1 B8 J3 [2 k  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]7 ~, e- ]8 r, Z. N. G# A4 |
  scatter     ;;keep center-turtle random positions ( n" Q. M  ^8 I
  unit_plan   ;;make up the building plan
; T2 X& Y  ]% O, O6 \! Send
$ x# D8 z, c  z, T! W* vto scatter) r" h! w8 l0 _
ask turtles with [remainder who 5 = 0]
, w2 D# Z+ ~2 \2 c4 S2 G[9 Q) h7 ~& x7 Z
set xcor xcor - 6 + random-float 15) f, E0 m+ Q% }
set ycor ycor - 6 + random-float 15
' T* ~' C( U$ }7 ^. n]
* f( ^5 {4 j/ v6 k: \3 xend. [% J0 {# f# H; F/ \: ^) U
to unit_plan 5 z0 \8 M: }/ ~& @
ask turtles [  d: `: L& }9 {7 t9 n
if (remainder who 5 = 1) [set a who 6 o# r# d" m6 k8 r7 B
                          set x ( 0 - Wid / 2 )
. O0 ~6 K$ M" [+ A6 s4 |9 Z                          set y  Dep / 2 ]
/ E3 S4 ~5 |  n1 U           set b  int (a / 5) * 5
7 A$ k) m1 {9 V$ \6 ]( B    setxy ( xcor-of turtle b + x ); r1 W! f2 X8 p" |% j) V5 c
          ( ycor-of turtle b + y )
% U$ h5 n: d+ p9 L$ v5 D& Fif (remainder who 5 = 2) [set c who- A0 S- ?/ l' I5 o; ?6 R, K7 z6 i
                          set x ( 0 - Wid / 2 )   C$ j; k+ n" k! `  B8 Z4 a
                          set y (0 - Dep / 2 )  ]
# @0 F8 G& ~, u" A8 S' W6 E                          set d int (c / 5) * 5
. }" Z% a! d/ f6 L; y+ r   setxy   ( xcor-of turtle d + x )  Z# ?4 y. x4 v: E8 q9 r
           (ycor-of turtle d + y ) , o, J7 ?6 O% \3 o  g* O& \
          . Z: Q, z8 f: g1 ~3 Q! @1 u( p9 k
            
9 ~! U2 _1 C3 _6 g% p$ uif (remainder who 5 = 3) [set k who, s8 K' i# e7 k% o% o7 x
                          set x( Wid / 2)  8 s5 c2 f. k& K. r- a; j0 r
                          set y (0 - Dep / 2 ) ]9 `: x4 j; e& z- x9 f
                          set f int (k / 5) * 5" A6 g% _9 O; R
  setxy   ( xcor-of turtle f + x ): ?- S& n: n* D7 m/ I8 W
           (ycor-of turtle f + y )
6 Z6 g* e0 m5 M# j           
/ r8 z3 G& t6 u9 U$ t           ; _. P2 h/ r# g, F
if (remainder who 5 = 4) [set g who& ~6 @( o! ~# u$ q: R* c
                          set x Wid / 2 $ N5 z0 w  U$ l
                          set y  Dep / 2 ]8 k# B! G4 s: r9 d
                          set h  int (g / 5) * 5
- K8 s$ W( z, n  @# @  setxy   ( xcor-of turtle h + x )1 W5 a- i, G* Q: L( A8 C4 \
           (ycor-of turtle h + y )
3 [! n1 d0 a9 Q9 i3 I' e! [                          
! C, ^, N# l2 L: a" ]                          
" I' N6 p0 P" f3 t' P- _# L                          ]. s) ?: W7 Q: }' e5 }+ r
end
/ |% R) |! t8 Q% n) g: i% Z) d& A7 u. w% W% x+ M# l! x* A
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
1 A3 O6 Q- W) {; Y9 a/ @8 x应该是
( x7 ^) l: l4 [4 D) v4 @7 L2 Y. }ask turtles [' S4 W. N# o9 l/ t6 D+ \
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) - ?+ s2 h1 }% v% m& ~
                          set y  Dep / 2 8 m6 c' w; T' E
           set b  int (who / 5) * 5
5 k- w7 v' A- x3 T    setxy ( xcor-of turtle b + x )
. y1 X% T4 i! a8 v( g          ( ycor-of turtle b + y )]]+ _4 U; C" {- q/ {" h
end6 |+ m% o) D$ u* z  C( K
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-5 16:07 , Processed in 0.017800 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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