设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7523|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
/ h$ r7 i+ U7 O& O" p8 i7 O7 g. }/ t5 F  ?  r0 J( T' T
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
1 a! E% _: r. B5 w/ a/ B% m2 N0 p5 C& @5 k
turtles-own [a b c d k f g h
: @% D2 g) m; R3 Q& P  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
9 F0 W, i: l- I5 G0 T]
. @! }4 B9 M+ G% }to new
( A) p- N! e0 s  ca
9 Z( p% B( R) K* Q5 H  crt 5 * num_of_building
  p$ k; C4 _3 a" t# ^  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
6 q" l- ]0 j$ h  scatter     ;;keep center-turtle random positions
5 L; J$ d! L8 T! w! C* i  unit_plan   ;;make up the building plan0 R: L5 B* R" f
end
" L8 B! X- }+ Oto scatter
" t% Q- B& t, i- D' u( m) Iask turtles with [remainder who 5 = 0]% v. t9 z5 h8 D# |* l+ A' D" b
[
1 D. b  @# G/ i' M* h, l, g5 e: jset xcor xcor - 6 + random-float 15
* U& H6 T1 t, q% v4 jset ycor ycor - 6 + random-float 15
" i9 I8 t2 w7 f* }9 C& c8 |0 C]0 j* s" B( ~+ k! @) E& I6 _
end
* ?( w) b$ Q: J1 u8 l# Oto unit_plan
8 X0 g; c/ K! N+ y2 [0 Q) }ask turtles [4 w3 X0 Y8 M) E! H# x
if (remainder who 5 = 1) [set a who
4 Y! q- f7 h* z4 n6 b2 d( N                          set x ( 0 - Wid / 2 )
3 C- q4 l: O% B( m' [) ^                          set y  Dep / 2 ]1 J4 I7 K% E2 e; n/ }3 M
           set b  int (a / 5) * 54 I1 c0 g. @* e: n9 V
    setxy ( xcor-of turtle b + x )
% s/ U4 l4 K$ \' o# `; F+ a          ( ycor-of turtle b + y )
3 M! G/ @5 o  s: B6 `1 L9 Eif (remainder who 5 = 2) [set c who2 E, E) x" X, X* F7 m
                          set x ( 0 - Wid / 2 )
  j  o. A# m8 V9 V8 ~                          set y (0 - Dep / 2 )  ]. _6 Y: b# [# F; s6 P0 ]
                          set d int (c / 5) * 5
  @5 J  z; l; K) r  ~* S   setxy   ( xcor-of turtle d + x )
& {$ Y$ S5 E* B1 G$ e  N4 [           (ycor-of turtle d + y ) & R' a. T  o/ j8 D/ g# I
         
) F" T+ N6 f% F) _            ' m/ K: t! @$ g
if (remainder who 5 = 3) [set k who* `7 Z, S8 X* z9 }: Y
                          set x( Wid / 2)  
# T0 `4 X4 W- a/ i" a                          set y (0 - Dep / 2 ) ]
7 j( a7 x8 x% ]                          set f int (k / 5) * 5
0 ?$ a  s2 V1 N& P  setxy   ( xcor-of turtle f + x )
7 d. a# ^' u8 H$ _* L, F9 M4 [! V           (ycor-of turtle f + y )
! g4 `# ]. W# c           1 q1 N. ~- r7 ~
           6 r5 j0 ]4 I& b4 j. R
if (remainder who 5 = 4) [set g who% l. \- o: [* S8 o4 [2 e  i4 ?
                          set x Wid / 2 ( [- O8 |* _. z& v: |1 O
                          set y  Dep / 2 ]
8 a7 a6 i: C9 ~: c: k" I- L, M                          set h  int (g / 5) * 55 ^4 H* T) D: d1 H) j
  setxy   ( xcor-of turtle h + x )
% u# e! p- Y2 n           (ycor-of turtle h + y )
1 C7 D# c' K6 r7 A9 N                          0 j8 d$ x# {& w% _- z
                          
, S& `$ J7 B; V6 E' h                          ]6 Y& }6 W3 @3 O5 l5 o
end) G9 \+ H& x8 C; }% E

6 ]0 v6 r0 Q9 U# ^# S[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,! o, H: a% G# P' c
应该是
. u/ o% J5 o2 l- q, N! m3 Lask turtles [: H0 f; ?& [) c; k
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
7 I2 Q, \) H/ ^; v4 E7 X                          set y  Dep / 2   D. Y6 @1 U# Q* a* X4 J  T0 A! o0 [% ^
           set b  int (who / 5) * 5
1 S+ g) S7 ?! O/ k, j! n  b    setxy ( xcor-of turtle b + x )
7 W, V( }3 a! D* V9 w/ z          ( ycor-of turtle b + y )]]+ X5 ]/ x& s' o' t) J
end# z1 b9 ~) F, o$ ~
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-21 14:40 , Processed in 0.022211 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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