设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7501|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
) P8 e5 ]6 E, a; ?/ _) k8 w0 S. k! q$ O/ R3 g( e" K4 W' j
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
& o5 @5 G  U) p( M$ a( [1 u2 ]* `0 ?0 J0 S
turtles-own [a b c d k f g h
$ n1 p! y: K' J5 R1 B  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
' K. w) ^/ l9 |) N; g+ I5 T]
" z# y. y  j. p- ^to new
8 g/ M" s4 {- U* x  ca  k$ N: S+ t$ y; W" e' `
  crt 5 * num_of_building% @# i8 d- \/ G. G( o6 S
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]2 T- D. y" T# [$ m
  scatter     ;;keep center-turtle random positions
, Z' I& v  r( L6 y5 @  unit_plan   ;;make up the building plan/ R$ o4 v4 o# _2 i. b% a$ P& M& c) }' H
end" b5 y2 \& _& G( M0 f" p/ m
to scatter
1 u' T( {1 H$ Z$ vask turtles with [remainder who 5 = 0]6 \$ _; z8 X$ n6 p7 @  h
[0 r7 E, D% ?* d
set xcor xcor - 6 + random-float 15
8 F- ~$ d* }& Fset ycor ycor - 6 + random-float 15
$ d; W$ L# Q- a, G% y]: C" ?3 A. q( f* x" h! W2 A
end+ Q8 y& G+ J: ]
to unit_plan
' b! b8 d2 H* E) S' Eask turtles [& P8 u. r% L% \+ }
if (remainder who 5 = 1) [set a who ' F) |2 D- C2 x. }9 T/ w) p. B
                          set x ( 0 - Wid / 2 )
$ \( @+ G/ j. Q- C1 b, G                          set y  Dep / 2 ]
& ^" Z/ ^. H; P  y9 Q$ B           set b  int (a / 5) * 50 y; ^: m+ m3 t) \$ _7 |
    setxy ( xcor-of turtle b + x )" e0 a  w. i; G
          ( ycor-of turtle b + y )- u% z, S! h0 a% N- z
if (remainder who 5 = 2) [set c who
( T' }$ `% `+ T; t9 ]# b! ~6 m                          set x ( 0 - Wid / 2 ) 2 S' r+ w7 q% h" x4 Z
                          set y (0 - Dep / 2 )  ]
: d& o5 g8 E& ]/ I4 I6 a/ L                          set d int (c / 5) * 5
" ^; Y- r2 y. a: C6 @0 w- G( a   setxy   ( xcor-of turtle d + x )
1 v$ H" a5 \5 r, L1 k           (ycor-of turtle d + y ) * O, D( a( `+ `. f" `- S4 s, \
          0 M4 X5 ~/ F+ O6 M3 {
              ?" s9 g, U# U/ x
if (remainder who 5 = 3) [set k who
7 ], `/ L0 X1 E2 ~& f                          set x( Wid / 2)  
% M, w& f( U5 I* F& m, U                          set y (0 - Dep / 2 ) ]
! Y" }# c  c# ?) ^6 T                          set f int (k / 5) * 5
6 ^1 _) P+ I, x& `  setxy   ( xcor-of turtle f + x )" x5 ?) m& K! r" G* _' c
           (ycor-of turtle f + y )
; ~- z/ |( Z, l8 w! Y3 X           
7 s2 ]: P/ K8 u0 q5 V3 C- [: m           
5 L, ~6 r; X& c1 b- sif (remainder who 5 = 4) [set g who
$ ^  m4 I8 q, k( \! I) \/ y                          set x Wid / 2 + f7 I4 P4 t: @& L" i& }+ V( v
                          set y  Dep / 2 ]
: I' _  j5 \# m3 {* s2 C" |                          set h  int (g / 5) * 5
1 ^: P% w. J, C" E  setxy   ( xcor-of turtle h + x )
- d9 I$ q. G( l7 q( j           (ycor-of turtle h + y )
& }; n# e6 w; N% c" y                          
( h7 V, |. ?3 g* T% a                          . Z3 ?8 a0 e* l
                          ]
, w( {' S7 w& w& H+ \end2 L9 r7 W3 p$ I5 W) c: V0 C
! k' h: I0 i( L0 g) S) `
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
* L1 S6 J/ |/ Z4 B1 n应该是
. `9 ]# H, o; g* Y5 j3 xask turtles [" o# l1 f! c( K* |
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ) G) s: t$ V3 a5 o) T3 E
                          set y  Dep / 2 / G: i/ \# V; Z/ k; y/ A' d  V
           set b  int (who / 5) * 5
: D; e" y: d4 {    setxy ( xcor-of turtle b + x )
6 D& f$ ?$ l# X8 E          ( ycor-of turtle b + y )]]
6 p- i# c  H5 M& t/ hend
' y: R4 }9 m% F! h2 C7 M/ g之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-19 04:27 , Processed in 0.020535 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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