设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7300|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
0 R- N# o% W% n! a8 @1 _& U7 o( A9 G3 ~; l. R
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
# u- `7 T" X! ]2 V  I
6 J- C2 Z3 Y$ nturtles-own [a b c d k f g h
7 `7 x  r$ }6 K  q  x y     ;; these are the leaf-turtle's offsets relative to center-turtle # O) B- l; T% p1 D7 A. Y' |' \, H5 B8 [
]) O; e) T' k. ]3 d1 J
to new4 w$ Y7 `# B; T9 J/ @4 m
  ca  l0 D% O" N* B8 b. c/ i
  crt 5 * num_of_building
5 F6 r0 R  `" X; X  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]5 P$ ~5 }9 e. v9 w: s
  scatter     ;;keep center-turtle random positions 7 X+ n6 v2 q5 e3 A, t. C  {
  unit_plan   ;;make up the building plan
. C2 a, q( s- z8 D) G: Jend
$ \( o8 V3 M* v8 l' R- B1 Uto scatter
, k/ o  Y( Y, K; x! A6 V: rask turtles with [remainder who 5 = 0]( p7 {" ?8 N5 T, a
[
! L/ B  K. ?! b# L$ j3 V5 L1 T1 d8 sset xcor xcor - 6 + random-float 15
, m9 }0 V2 U1 O5 y# rset ycor ycor - 6 + random-float 15
1 o: @9 I. ~/ z# x7 W. ^& ]]
9 v& W9 n  C$ n6 i- yend& M, t& l; N% S3 j4 I) |& S
to unit_plan 9 `7 I/ P0 H( U9 V* Z
ask turtles [$ s5 ~) T' T( y3 z
if (remainder who 5 = 1) [set a who
8 \$ M0 [( m1 G5 j. `                          set x ( 0 - Wid / 2 )
$ [* G4 F" ?; Q- Y& j6 m                          set y  Dep / 2 ]
% {8 K9 X9 j; B           set b  int (a / 5) * 5: |6 P8 Z$ W& {5 G+ v6 x
    setxy ( xcor-of turtle b + x )
; @7 _; C7 ^1 o& r2 l9 l8 p          ( ycor-of turtle b + y )
# V- w0 Z& [7 U3 a7 ]if (remainder who 5 = 2) [set c who
6 f8 [# ?% ]% a/ R; K: s                          set x ( 0 - Wid / 2 )
2 y3 [2 k* ]: E  S% ]* f                          set y (0 - Dep / 2 )  ]( h) \+ q$ o2 f+ _6 m% w
                          set d int (c / 5) * 5
+ Y7 E* E# v( p: b# ^5 c8 l2 v   setxy   ( xcor-of turtle d + x )8 ]' e" k  e+ @1 ?1 T. Q! Y
           (ycor-of turtle d + y )
6 C) s2 ~7 ~  W, a  \7 B- o/ Z          : n+ D* n$ c7 \* w0 S$ m
            
. K+ \5 Y8 J6 j' f5 u3 Gif (remainder who 5 = 3) [set k who
0 }2 l+ N' p. s- V" |                          set x( Wid / 2)  
. k3 `6 |7 [8 R; Y8 P                          set y (0 - Dep / 2 ) ]
. b- [8 X) C' F" O                          set f int (k / 5) * 5# O+ ]0 q  ?6 Z& A) E" w4 L. o7 u7 C6 y
  setxy   ( xcor-of turtle f + x )
! @  \% e# Q6 O7 k, g, }( C           (ycor-of turtle f + y ) 0 j- U: f: z0 m8 K* z( C, F
           $ m" w+ i$ d0 U& [! B
           
1 v  C. }! c, i& K9 gif (remainder who 5 = 4) [set g who1 X% r! z- s: l+ l1 V, s3 s/ j
                          set x Wid / 2 . f5 W0 K  H4 H, R) f* N' w
                          set y  Dep / 2 ]$ T. ~% |: n/ {1 n0 a# O) l
                          set h  int (g / 5) * 5
; f( f# Y2 |: G- m  setxy   ( xcor-of turtle h + x )& v& y3 u# f8 P/ m- T  L: f
           (ycor-of turtle h + y )
( k4 W1 ~/ t2 C( G                          1 E- K: w5 H" H3 \  _: I# Z
                          & |/ ?9 s. }6 |
                          ]
7 Q' w4 A& t% P3 D. iend0 P4 _+ L) }7 x$ }$ u4 _

3 l# P. `3 O, Z% c9 @3 V- f[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
1 K& f( D, U/ y2 Z应该是' d7 A) Y  K/ R/ T- o
ask turtles [2 j' \5 q+ c0 V6 R8 a
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
! f* i6 a8 {6 E  |! Z: L; j                          set y  Dep / 2
: d$ q$ `/ Q$ s: A           set b  int (who / 5) * 5
* \  `3 u/ ]4 [5 S. t    setxy ( xcor-of turtle b + x )
& d8 B. L  A  }; b9 o' `& ^          ( ycor-of turtle b + y )]]- p1 E" a6 |0 g) M: z! l7 {# Q
end6 M6 u$ r# X0 L& k1 Z3 o
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-27 16:34 , Processed in 0.016736 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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