设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7155|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
: o' Y4 h' Z6 E) G) z9 H; f2 f0 {2 q
- a  W" T  u3 r5 t& _. U: B3 C但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
! S7 g5 F5 G3 E5 }( A, G& G+ n* `3 {: K
turtles-own [a b c d k f g h" F- S7 w3 K8 b; W) J
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 0 z, Q5 K* G3 W% j* h0 A. ]8 o8 I
]; c1 z+ A. y9 J3 I
to new( K8 L) F) ~) u1 N' _5 Y3 {
  ca
5 X$ M  a7 h% I; o2 H8 D  `  crt 5 * num_of_building
. N1 m% C" C, W" P  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
" c! n3 X% O' F! M  t3 A  scatter     ;;keep center-turtle random positions 5 H8 l4 Z: ?# e/ x6 Q$ L+ D
  unit_plan   ;;make up the building plan
0 x  C8 w* ^/ ^end* e8 \' S) t/ f& ?$ U
to scatter
4 C: F! c7 t3 Z7 y: b. y2 _ask turtles with [remainder who 5 = 0]
$ q! c3 ]9 ~( t. z; Y% x[
: k& [) }# e& R* dset xcor xcor - 6 + random-float 15
- x8 H1 i9 l- A; sset ycor ycor - 6 + random-float 15
" {: P% P2 Q2 G0 y* D]) j( G! N3 ]1 h8 K* M. p
end* l  z' B% T1 ^3 a: O
to unit_plan % S, N9 S: ~7 g  W. O& s* n
ask turtles [
7 [( Y$ x9 m& W* W% Jif (remainder who 5 = 1) [set a who % x! e3 G6 b7 [& k; t; x
                          set x ( 0 - Wid / 2 )
% [# P8 [2 R  k/ l  U0 t) q/ {                          set y  Dep / 2 ]
+ B# J: q; d$ Z2 ?           set b  int (a / 5) * 5
" B! S4 |% c  R; f+ c2 g- V5 D0 u    setxy ( xcor-of turtle b + x )6 ]( r8 k$ O, K' m$ ^' \
          ( ycor-of turtle b + y )
+ a8 q( t6 A! ]# N- p9 f* p( aif (remainder who 5 = 2) [set c who3 n! @* _! b5 f- G: d
                          set x ( 0 - Wid / 2 ) 0 s! z+ J, L: \( |6 q( w- r( l" }) j
                          set y (0 - Dep / 2 )  ]. v4 e4 r/ R( `2 T3 s2 O
                          set d int (c / 5) * 53 r: J2 G7 @8 F6 x
   setxy   ( xcor-of turtle d + x )
9 u) {: S* u6 N( x4 I  g6 D           (ycor-of turtle d + y )
5 P: g* N( y8 n3 K0 E, R         
: A$ E$ q0 q$ i4 g6 s* w* r' I            9 R4 ^9 w. ?5 [
if (remainder who 5 = 3) [set k who: g* b' O. i9 T1 {0 l( l( w
                          set x( Wid / 2)  ! y0 z7 ?, ]. @$ @+ H
                          set y (0 - Dep / 2 ) ]$ T6 U4 V; W9 o$ }. h; }
                          set f int (k / 5) * 5
8 F1 Q! M8 I7 |  setxy   ( xcor-of turtle f + x )
! C2 K4 g" V6 C$ u* a           (ycor-of turtle f + y ) ) O/ s( I6 K4 F$ L
           4 J3 ]! w6 k9 o
           
: |1 r* F4 K! r5 `if (remainder who 5 = 4) [set g who* ~* x% R6 Z; i; a, @  [) Z9 @8 Z: q
                          set x Wid / 2
& X6 {; _1 e1 \% D6 F                          set y  Dep / 2 ]
2 n6 g4 Z8 }8 d- C; V6 J                          set h  int (g / 5) * 5/ J! K) u. t3 `
  setxy   ( xcor-of turtle h + x )1 ?! F9 N" @& J4 |
           (ycor-of turtle h + y ) % P& X7 S0 q2 Y$ r4 N
                          
' D, A: X- W4 j" z                          % Q/ r. N$ [* L$ X
                          ]
6 I# z5 ]6 @5 [" l8 D; G+ e1 Eend: U0 f7 z  x1 `/ n9 r" D$ e9 H

0 s' z9 w; @; M5 ?[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
! M- @6 t2 Y( s/ J) H' _9 ~应该是
0 i8 }7 {7 p$ k8 F3 J1 E% |  B( @ask turtles [/ f( r( L7 {' i9 D- G+ c; e
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
* i+ s8 `$ q3 J; ?! f" H                          set y  Dep / 2 6 B8 Y5 j0 M: R' I
           set b  int (who / 5) * 5" L8 ?- u% F6 o
    setxy ( xcor-of turtle b + x )
# f" R9 H5 K0 k2 r% M8 b          ( ycor-of turtle b + y )]]3 ?/ }" C* W# C/ }
end
; M2 J$ N8 a; N, F' o3 }$ o: e之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-9 13:41 , Processed in 0.023298 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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