设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9104|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。+ H- l8 Z) E" {' V
* e' V6 Q. m0 ~( X* ]0 B
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。3 _$ R9 [# G# }0 E- b* _

5 w8 |! H/ F2 f5 N2 s# c, Yturtles-own [a b c d k f g h
2 V7 ^, m3 g% c8 t0 ]1 t' ]% B1 y  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
+ @' M1 N1 {% b& p; s# F) \]+ M3 h: g# `7 y( p0 U
to new% v& O" I% {1 S
  ca& c8 {# ^2 L/ Z7 C; `3 }! t6 s' n
  crt 5 * num_of_building
4 |. l4 P6 w5 C0 s1 l. A2 t1 L+ Y  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]' H2 J! _) G" K. f  d
  scatter     ;;keep center-turtle random positions % W  `9 O4 ]$ F, w
  unit_plan   ;;make up the building plan/ R0 `( M/ b3 I! _
end+ U: K$ M" S* z/ ?
to scatter
7 h  Z2 Y8 E1 O# f3 n7 oask turtles with [remainder who 5 = 0]" i- g3 ?% `+ @6 I
[; G/ R* j+ W) w# R. o
set xcor xcor - 6 + random-float 15
' p; C, A* W% f, Uset ycor ycor - 6 + random-float 15
) a- [7 E1 c7 m9 P* j, v]4 Z8 e0 t: r  ^
end: n. B8 E( R8 S/ C8 G4 B# q" o
to unit_plan 9 d1 \! Y$ j. Y$ L5 F
ask turtles [7 q! y, K, k2 ^0 _8 e$ x- J" }
if (remainder who 5 = 1) [set a who
! S( O! W+ J' s+ o3 F9 J                          set x ( 0 - Wid / 2 )
$ q1 @+ ~9 @3 C; V$ y) Y                          set y  Dep / 2 ]
. ^- i6 `. e6 t1 B. N           set b  int (a / 5) * 5! t9 B3 N) ?) W" r
    setxy ( xcor-of turtle b + x )
) G2 l" g$ p! o2 D" X4 O6 g4 }          ( ycor-of turtle b + y )
7 P3 p( _$ R* O& F0 J( ?if (remainder who 5 = 2) [set c who! y6 I: w7 ?8 h9 r9 }
                          set x ( 0 - Wid / 2 )
6 x. P$ |& F6 p5 s5 N/ C                          set y (0 - Dep / 2 )  ]) Q8 u, V7 u+ E0 L) u
                          set d int (c / 5) * 57 |' v; D3 k, |- ?' z
   setxy   ( xcor-of turtle d + x )* {3 _# t/ a9 {* T6 W
           (ycor-of turtle d + y ) 0 _% @- E: Y. u3 C- H. a* C
         
  v/ M% U4 B/ i( A* A6 e8 R            
7 T  U, k5 D) _& E8 V( Hif (remainder who 5 = 3) [set k who6 Z0 a! D* \+ t& G
                          set x( Wid / 2)  # Z' M1 i6 a2 Z9 h+ G6 Y- \# }# ?
                          set y (0 - Dep / 2 ) ]
0 O/ M* Z, m' D4 f7 \: T; V) f                          set f int (k / 5) * 5
3 [5 J& p) Y" @0 q3 p/ H4 q  setxy   ( xcor-of turtle f + x )' a( E. R: b" W! T# s
           (ycor-of turtle f + y )
3 K3 P! W7 `& G! g" }           
* d1 X& Q3 H. O8 O2 n& ?7 t           
5 h) |; b3 u% J0 l; l% _0 p9 mif (remainder who 5 = 4) [set g who
3 z4 X+ f  ^. A8 i. R; L                          set x Wid / 2 / p7 f1 i% L9 ^" N9 t6 m
                          set y  Dep / 2 ]
3 p* V$ Q$ \7 {8 A                          set h  int (g / 5) * 51 \. X  J4 e+ D
  setxy   ( xcor-of turtle h + x )
( K6 Y; n! p5 X; N           (ycor-of turtle h + y ) - n% c: D' Q' S& ]
                          0 H9 t* o! |$ R/ c" P# H: h
                          . t8 x- `' B, H
                          ]
) O1 {" S, V2 ~. O, Uend
' [* X1 h! i4 g" [9 p  V( z$ z8 W- q5 J5 Z9 Q6 M  P( J7 \9 D
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,) T0 e( T% M9 e. a- p
应该是
9 E8 V; {' t& {( O& N! z) @ask turtles [# D0 `3 N/ y; {6 j7 }0 {+ C
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
" `; p) P6 B' h1 I0 C                          set y  Dep / 2 . j+ D8 |' [+ j" g$ I* s$ a/ M
           set b  int (who / 5) * 5
5 ]# M. n- n. W- r$ I' s4 U7 ]6 [. d    setxy ( xcor-of turtle b + x )! Q# E6 s, [6 b; w( I
          ( ycor-of turtle b + y )]]1 ^7 O) S; S* S9 K' a) g% g
end
1 D* E. b; V* f- \' ]之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-18 10:03 , Processed in 0.015408 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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