设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8015|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。; f* y( F1 I/ S1 f' P
) Z/ b( l/ N' I( E7 q1 c! T6 p
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。: A5 x6 `6 `; l( m, e  e! j

2 {+ |, S" [7 P/ Z: i3 uturtles-own [a b c d k f g h
$ `# V3 w# |4 {2 U$ M7 }# w  x y     ;; these are the leaf-turtle's offsets relative to center-turtle * V6 W. A3 S. Q' `7 w9 {
]: d  l7 `1 P% k8 \, e
to new( ]8 T+ N! \9 f. ?: h) }' Y( p* u
  ca
! }3 q( y: k' T/ H  crt 5 * num_of_building
# Q' P1 k% d( E  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
+ T' @7 x/ p6 H' x8 p, l" q  scatter     ;;keep center-turtle random positions
: m& P2 i' t4 l* m  unit_plan   ;;make up the building plan7 F, }9 e3 ]5 b' @6 t
end7 `) F: S, d7 U; x5 S
to scatter
8 D# e( x$ h9 N6 j# ]ask turtles with [remainder who 5 = 0]
! j8 V2 ^+ ?, w7 O7 f. N. F! ^[
! j7 x7 @1 T! s( }& E$ zset xcor xcor - 6 + random-float 15& P; S% R' i9 K" n* s2 J, B) h6 x
set ycor ycor - 6 + random-float 15* a; x; ~# S* g) Q. _6 R
]
) u6 Z. d+ h* e7 S% a2 g, K0 n9 wend) {. y0 ]: Z- X' J
to unit_plan
$ t. n" ^3 ]/ \5 ~) u3 u* lask turtles [) n1 }8 Z9 Y' {) s
if (remainder who 5 = 1) [set a who
5 t0 X) l5 p: P! z+ P& l1 o                          set x ( 0 - Wid / 2 ) ) X# ?: Y. ]9 @0 H
                          set y  Dep / 2 ]4 c8 {" {: z4 A6 [/ M# E
           set b  int (a / 5) * 5
, Z, v- ~' [0 l- `% J2 X    setxy ( xcor-of turtle b + x )
- ?; V: J6 J' a9 y          ( ycor-of turtle b + y )
+ S2 m0 T3 e. _/ k  N5 }5 p2 jif (remainder who 5 = 2) [set c who8 Q: }1 P2 {( C" L5 S8 y
                          set x ( 0 - Wid / 2 ) 1 O3 F' N/ V3 c8 O9 E5 a) a
                          set y (0 - Dep / 2 )  ]
, ^. w0 J/ d5 t- n2 y) _9 C9 `                          set d int (c / 5) * 5& @- Z  k0 R  ^, h0 O1 p4 x
   setxy   ( xcor-of turtle d + x )
6 P. Q2 v- u7 A! [$ ]2 ^           (ycor-of turtle d + y ) ) O+ W6 l+ X3 s( S8 X
            p5 |0 E/ ~2 w( Q$ C+ B% G3 J
            ( t0 c+ c5 {' x) E( H
if (remainder who 5 = 3) [set k who4 h: p  x( j! a, K* Z& \+ U
                          set x( Wid / 2)  ( k- V3 L( C: R( d2 M  B$ x
                          set y (0 - Dep / 2 ) ]
# Q* [7 Q7 [4 N8 W2 I- A, k                          set f int (k / 5) * 5/ n8 {2 q+ r0 [  K/ }
  setxy   ( xcor-of turtle f + x )
' j; K2 u1 _1 d5 K$ X  d+ C# z6 s' t           (ycor-of turtle f + y )
$ i  w" @) V0 `! k5 ^           
: }0 ~; P. b' j, D" V0 t           
$ q7 w1 o0 s( T" fif (remainder who 5 = 4) [set g who% C3 W2 B  {) a0 C0 ~
                          set x Wid / 2 * O. J/ v4 J7 q" S
                          set y  Dep / 2 ]& r/ e5 d+ D$ u
                          set h  int (g / 5) * 51 _, M( `; v+ e5 E" C/ b
  setxy   ( xcor-of turtle h + x )- v# x# h$ O  v+ B* T- P
           (ycor-of turtle h + y ) " ~1 m$ l3 y% s0 G2 F
                          : C. D/ y, ~7 x. C& k5 d
                          * ~& ^' X, H! D2 D! C+ m
                          ]
, l( d* H# N+ Kend& i  B# J! R5 r: ~: _+ ^
- K) f/ A- n  `
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
6 w; [' }% K1 G" b* [6 p应该是6 K6 p/ c$ F: M% ^  H0 \
ask turtles [
/ V0 M& h1 d4 T7 x- a  K6 G) t& kif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
9 J! c2 }# ~1 Q+ k- R4 Q! Z                          set y  Dep / 2
) g9 V, f; u4 J$ _/ ?           set b  int (who / 5) * 5
- F% q: d( ]1 G1 K    setxy ( xcor-of turtle b + x )
" {3 @. K; j* h+ I; w& e          ( ycor-of turtle b + y )]]
) u7 n! w$ z% i$ Y; f6 tend
: x, s9 E# u9 E5 [- _, y6 K之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-28 16:56 , Processed in 0.015402 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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