设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8303|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
, x8 U  {: ?& a; z8 p) G! s3 h" w2 q0 }
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。  X7 v- X  f: c# I. y
7 S% ~3 ~- I$ [
turtles-own [a b c d k f g h
" Q' l% A  V3 @1 j, D1 \  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
) z2 ]) S0 X, b% L4 {]
( r4 F% I( @' g+ T: [1 N& q; l8 Wto new) W% J+ f- p8 C! \# A
  ca* f8 Z3 B0 Y# o  \
  crt 5 * num_of_building
4 }/ x5 e9 S! r& t: R* r3 K  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
  W! t6 Z0 G# [: _6 I# \  scatter     ;;keep center-turtle random positions
; a9 X' h% P' \8 h& W  unit_plan   ;;make up the building plan+ C( l6 B; m% a9 N5 p- x
end% Y$ T, @( w. O* A
to scatter/ w* ?3 e: c, o& W5 C' j- v
ask turtles with [remainder who 5 = 0], T6 d* W5 ~4 [0 X
[& Z! \4 `' T6 d; ?
set xcor xcor - 6 + random-float 15
: q* R3 n( @: n* `set ycor ycor - 6 + random-float 15% e1 W  I% G; {% C( R6 n7 T2 ~
]! s9 ~8 s' R& g0 z
end
3 s$ w3 w* U( |  \to unit_plan . u: E% ^  K' X; ]
ask turtles [
$ _3 l+ V" p( z  v+ S# ]/ C9 kif (remainder who 5 = 1) [set a who ! R- `# H3 M, W# C
                          set x ( 0 - Wid / 2 ) : o! @7 K- n5 ]
                          set y  Dep / 2 ]0 Z0 h6 h9 \  V5 I
           set b  int (a / 5) * 5- \  g+ X" [! G7 w, T
    setxy ( xcor-of turtle b + x )
! M! W8 M/ P: Z          ( ycor-of turtle b + y )
8 E4 B! m6 q6 w4 V# A9 aif (remainder who 5 = 2) [set c who
& O; X) ^, |8 z. f$ o                          set x ( 0 - Wid / 2 )
* [: N% H- ?9 g/ d  x$ [' |                          set y (0 - Dep / 2 )  ]
! x- ^( w' F  e& d0 b$ j" x7 a9 I  M                          set d int (c / 5) * 5: H6 {0 h0 g+ |% Y2 s% o1 {
   setxy   ( xcor-of turtle d + x )
# R" d* L$ v# u' Z5 G* h  p           (ycor-of turtle d + y ) 2 @# Y, T& W* F6 l; i) y
          2 @) {" D/ k3 G8 H
            
. S, n. c+ Z" t2 i+ t" Sif (remainder who 5 = 3) [set k who( e5 d; ^& Y3 b# d1 m0 a6 z, b
                          set x( Wid / 2)  0 Z) Q' G; k2 ^) f8 l
                          set y (0 - Dep / 2 ) ]$ F: T5 _- D. u
                          set f int (k / 5) * 5
" A# U1 C2 f/ q* o, o0 l3 v  setxy   ( xcor-of turtle f + x ): `& P5 _! W% l8 B  S+ O3 E9 T
           (ycor-of turtle f + y )
0 H- l2 g1 M2 B8 Q  T             L* ~' h* K0 g8 d9 u% W; H% `5 G
           
) j# B. Q% |8 V9 b( p3 F! |/ Fif (remainder who 5 = 4) [set g who
) s7 m/ q5 m4 |. R                          set x Wid / 2 - V: p& J/ c' o! [
                          set y  Dep / 2 ]
: U9 E. e+ j0 `4 D                          set h  int (g / 5) * 5
# X5 ?* X* r% N0 X$ M- q  setxy   ( xcor-of turtle h + x )- ]3 P! r) P$ V4 Z$ ]
           (ycor-of turtle h + y )
* u2 F) F4 Y' x+ [$ v3 f5 e: {                          
' h) {# R1 x. b& C% o                          1 v- \' y6 W; j1 r6 ?; [/ z
                          ]% C( T+ [* y8 v0 F" r& }: Q& X6 h, O8 A( D
end  a8 A( c* x" Z* ~) t. }! k/ ~- t

6 y- Q6 D% F2 U[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,1 V* \9 D, L# V; _# \5 f
应该是
/ ~  p7 @% m& l$ g& qask turtles [+ `' P/ D5 `0 w( [, ?  q
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 6 S) M7 ~: C+ j
                          set y  Dep / 2
7 U9 G4 e0 I; Z6 I7 X           set b  int (who / 5) * 5
# x. r. Y: _9 u2 T( e7 [+ {" P) O    setxy ( xcor-of turtle b + x )
$ G: m/ Y0 {6 S          ( ycor-of turtle b + y )]], g# N, i) L8 h0 B1 i) x1 r
end
9 `, a4 `8 f! ?4 d; P. O之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-4 00:00 , Processed in 1.233659 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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