设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8501|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。& A# K7 Y" @1 O3 z$ y; d

' a7 J  n" M) n0 ^" g2 R  b  ^5 r但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。$ S7 E# y) H* T4 H

4 d' ~5 F0 S. j" xturtles-own [a b c d k f g h. C/ T- [5 z0 N: z0 e# E
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 8 ?, n, A# K1 g3 W5 s$ R# Y
]
. _6 E/ X. l, r$ j4 _' w3 Ito new
" i. f2 D0 E, V  m  ca
4 X" l1 C1 a7 V9 `. l2 }; l* _! B( t2 f  crt 5 * num_of_building9 d! K- G8 L  t
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
  {, G) u4 {- ^* |0 M9 O) E  scatter     ;;keep center-turtle random positions ( N& {( F" P; |
  unit_plan   ;;make up the building plan
- Y: F$ ^" t* c( x( e! Nend
9 x" p8 z9 @) I1 Xto scatter
2 y8 v" g( `# J1 V3 o2 U/ hask turtles with [remainder who 5 = 0]
: `) d, r8 P! ^; e[+ Q4 [. b! T6 e& @; r2 h0 @
set xcor xcor - 6 + random-float 15
0 c* a& n  q0 y3 F! Jset ycor ycor - 6 + random-float 157 s0 H0 B% j7 O: x) K
]
' p; a' s+ V; S8 R& zend2 T" x8 V- ^5 V1 z. N& x
to unit_plan % {2 G9 P4 \$ E. V; M, g
ask turtles [# ?/ Q) X5 W( ?4 t0 e2 a4 x( @
if (remainder who 5 = 1) [set a who 5 x% A3 ?/ W7 y6 T
                          set x ( 0 - Wid / 2 )
6 @$ R$ q; {$ w1 c. q$ \                          set y  Dep / 2 ]3 \% M1 H% c/ |; D" A. D) c& T
           set b  int (a / 5) * 5$ k0 o) Q" o% O3 @4 s* G
    setxy ( xcor-of turtle b + x )9 h) ]0 h$ T4 T9 c, U) n
          ( ycor-of turtle b + y )
+ K# W6 j: f# D; C1 _if (remainder who 5 = 2) [set c who9 x9 S* D6 K/ x& Q) w+ m- J
                          set x ( 0 - Wid / 2 ) ; a6 @: l* c) p' V4 H6 n
                          set y (0 - Dep / 2 )  ]) q2 z+ ^' h& B4 m$ T' P
                          set d int (c / 5) * 5
5 S" v/ X$ u1 W, L   setxy   ( xcor-of turtle d + x )
  W  }6 [: Z! Y' L% _- g2 ?           (ycor-of turtle d + y )
% j' n( v0 z- N. f) l6 s         
7 m. }& u$ r: E  ]            
3 w9 B3 h0 H; F+ U. wif (remainder who 5 = 3) [set k who
4 B" N( f/ M! z4 ?# q7 \/ u- o                          set x( Wid / 2)  $ m5 s% _# E& D
                          set y (0 - Dep / 2 ) ]2 Y1 y- b4 m) ^- E4 g- h! l
                          set f int (k / 5) * 5: I" w+ c: y1 e0 V
  setxy   ( xcor-of turtle f + x )* w" g/ p. F. l8 y: [+ t" X
           (ycor-of turtle f + y ) & l. D* o: u8 ], M# y2 c
           
$ F, U  U, r  n+ j# k1 `5 R5 Z           , m1 h+ n4 ^. n6 X7 `2 W
if (remainder who 5 = 4) [set g who) b& B8 ]1 Y3 I7 l
                          set x Wid / 2
: j# r" C; x; _2 M                          set y  Dep / 2 ]1 P- _' N% q$ Z" K! J
                          set h  int (g / 5) * 5
' o. U+ C% h) {3 I  setxy   ( xcor-of turtle h + x )
0 l3 a+ R2 f7 o           (ycor-of turtle h + y )
$ C  S6 l+ f9 L( [5 v" A& y3 J1 H  @                          
9 ^% `/ C- C/ |* b3 j  [* X. P                          
5 b" \, [8 I' t' h  x. A8 ^                          ]
  X* S3 k) s; P" k; |8 h& v" f3 Tend
! ?- P$ K7 t+ l6 V2 @+ i
5 o& a0 Y: Z) s: R' f- x3 w2 Z[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,, V* r4 b% O5 `
应该是
3 M( @) N& a' p) m& M# C5 L( ^ask turtles [: t$ B  z) B7 b+ c' E: G. J
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) * u1 L. H- o" G
                          set y  Dep / 2 ' g4 m3 D0 q0 H7 C+ k0 U8 @# Z
           set b  int (who / 5) * 5
) l& {! R- }1 t4 P: a/ C& r5 n  f    setxy ( xcor-of turtle b + x )8 J; N! ^& ^1 \% @% L. K
          ( ycor-of turtle b + y )]]5 ]$ [' Y, g9 a0 H6 m0 I; m
end
# t6 l: `' f) D: w8 p8 `之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-5 18:09 , Processed in 0.016419 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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