设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8953|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
! g8 _/ D5 A7 \) u" ^
& F5 m5 `2 {; z但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。5 Y' W3 T) g3 S: U& O1 v# P
) Q4 w5 l' S3 X, ?0 P1 m
turtles-own [a b c d k f g h1 F* o4 _. }# K" m; |* Q
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
6 k( C; Q! {% U8 t/ F" V], W/ H1 d4 h: T. o8 e  T
to new
$ P! V' i8 }6 D  @6 Q  ca
7 F$ l, [8 U1 z# [3 z2 Z  crt 5 * num_of_building; a, h+ i' q* _. t: d. Z
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]. K  L1 ?3 ^) \: C
  scatter     ;;keep center-turtle random positions 4 l5 O. d6 P, w/ u9 O, q- Y
  unit_plan   ;;make up the building plan
1 i/ B& W$ O5 q( u; l( Send
5 @4 o2 T# X; r" Rto scatter4 A# A# e# x0 ~& O) d' G
ask turtles with [remainder who 5 = 0]
% e7 g+ r( s+ Z1 k  b[
5 i5 b5 N1 ^9 c' w  `# `set xcor xcor - 6 + random-float 15
3 a" h! I! k9 Z7 W' T! Lset ycor ycor - 6 + random-float 151 n7 _- z3 e% t  a& d% w
]/ j& t- D/ j5 |
end. R7 i: C- M$ r
to unit_plan ' b- P; x! Q0 r3 f9 t+ B) j+ M7 s$ \
ask turtles [; x: l% f* }1 ~& g. O# y/ N
if (remainder who 5 = 1) [set a who
. o* t0 K& M! X                          set x ( 0 - Wid / 2 ) ; O  \3 c% z, E. S/ @* l8 A. Q
                          set y  Dep / 2 ]
# X+ C1 F  W& X; C           set b  int (a / 5) * 5$ e- G/ A6 U$ V$ ~% V# k) L
    setxy ( xcor-of turtle b + x )
+ y) }' B$ W: a% s1 W          ( ycor-of turtle b + y )
0 z5 B5 H  p' V  ~3 R+ Aif (remainder who 5 = 2) [set c who& }& e$ T0 f! k7 P0 }. |9 f
                          set x ( 0 - Wid / 2 ) 1 ~2 ]6 _% ~! r* x3 h2 R2 E
                          set y (0 - Dep / 2 )  ]
* ]) O5 t$ S# G$ p. h                          set d int (c / 5) * 5
3 B2 [3 y5 E" x6 r5 T9 p4 n8 ]   setxy   ( xcor-of turtle d + x )
. C5 Y" P, l3 a/ v! ?& S           (ycor-of turtle d + y ) & m, d1 Y. @3 t' G6 w
          ) H' X* E- A% e
            
8 G, V' F( K5 u7 [0 }if (remainder who 5 = 3) [set k who3 A3 [7 g5 O( j1 _
                          set x( Wid / 2)  
; L4 j. O$ d$ B) Z" I4 ^7 Y; k+ v                          set y (0 - Dep / 2 ) ]% o/ F! J/ @; O1 P/ a& k
                          set f int (k / 5) * 5
3 T7 s  Q: y* Z  setxy   ( xcor-of turtle f + x )
1 X$ x2 u% b8 o7 ?9 E" ?$ \           (ycor-of turtle f + y ) 2 k2 h# {/ B/ J4 i4 I8 m
           
; D+ W7 }6 @# t' G% I7 ]           
$ w7 M& \' t, M4 eif (remainder who 5 = 4) [set g who( `4 \: K+ U) _) F4 z
                          set x Wid / 2 7 c6 x( u) `, r  o
                          set y  Dep / 2 ]
) O8 X6 W+ G7 G& Y. B                          set h  int (g / 5) * 5% f& ^* e9 I$ {2 j  F  Y
  setxy   ( xcor-of turtle h + x )
6 |1 @* h  V& _$ s           (ycor-of turtle h + y )
& t; O/ t" L# j8 P8 U- T3 e' L                          / n$ F% X" G5 \8 O1 e6 {
                          
- s* T0 D0 `- ?. [. I' R                          ]9 C9 _! }2 b' p, p# v$ x
end3 O1 i: k5 C" n. X  p+ p
6 j' ~, ~6 s- P& N: F9 L
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
; D* _# I% D& l  i0 c6 s应该是( v5 C- k# J  x7 R: U
ask turtles [
6 _) s( M1 k# P1 ~' G/ B( t9 D! bif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
) k' V2 C# i+ ]5 U7 v7 i& w                          set y  Dep / 2
: _- F8 t# ]* b; g* W  |* b           set b  int (who / 5) * 5! E1 Q; g4 w- V3 }" S5 X  L
    setxy ( xcor-of turtle b + x )5 q0 L7 c# \8 j) ~; Z1 L; Z
          ( ycor-of turtle b + y )]], ^" J( l6 h% a, h9 D
end" ?+ h( _! `. Q6 [0 `6 C7 H( m; ~
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-30 02:06 , Processed in 0.014872 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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