设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8859|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。1 X+ g2 n3 x9 d$ t% O, q

0 l1 P/ ?. `% E7 W! x  M但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
  v  y# `, i. l( _5 z. \& E
' d( e1 q  }5 h; `# ~% sturtles-own [a b c d k f g h
# x% i! A. n- V0 Z7 T% _9 v1 X  x y     ;; these are the leaf-turtle's offsets relative to center-turtle $ ^, D, U$ u+ [, T
]
; n" x' |* g4 u( W7 y# [- m& mto new  ^, o( A/ X9 \6 D
  ca
$ r- F( D$ K% m, l- e  crt 5 * num_of_building- i: w, V, E0 x+ x# @- `4 X! d
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
( L7 Z2 p# u9 ?. @2 z( {% P* |, o  scatter     ;;keep center-turtle random positions + v8 ~' y- z5 m) ]; P. }
  unit_plan   ;;make up the building plan" @) S/ i; j6 Z2 W1 D* F
end( Q0 _! m& E) h9 I* W5 t
to scatter
  w3 w) E! u1 t# K# W+ b" Task turtles with [remainder who 5 = 0]
: ^3 D/ V. g* Q/ v  q[
! ~  a; ]# D0 u: k7 ^set xcor xcor - 6 + random-float 15; {: ?: M7 b1 K  U. g
set ycor ycor - 6 + random-float 15
/ K! J: g; H: p% I  F]7 G7 Q# p% M* P3 Y
end0 S' _' m+ x; S6 u( f
to unit_plan
$ V7 z' I! ^" {+ K7 n9 Q+ T4 |ask turtles [$ t/ p: Y) D4 X2 t! w
if (remainder who 5 = 1) [set a who
4 z  ?- I! f# N' i                          set x ( 0 - Wid / 2 ) ! Z5 {( S! _" l! |
                          set y  Dep / 2 ]# V, G* f8 I) }+ y# ~7 @& s  C* W
           set b  int (a / 5) * 5. h' J$ q+ S2 p8 X+ {
    setxy ( xcor-of turtle b + x )
) q) ^/ n% f; M: V* [# J( f; S          ( ycor-of turtle b + y )
" @: @" I9 e, M  P( f* k$ o5 m/ gif (remainder who 5 = 2) [set c who
( U/ M( U, Z# Z                          set x ( 0 - Wid / 2 )
# E! C. F4 b  ~$ k                          set y (0 - Dep / 2 )  ]7 e1 x  b6 J& ?+ E* q+ c) W: j
                          set d int (c / 5) * 5
6 ]; {, ?1 e/ d& G' I* ~   setxy   ( xcor-of turtle d + x )
4 y, b" p9 n; O5 d           (ycor-of turtle d + y )
5 Z* X" F) p3 t% P3 h4 z          / w# c+ d- v: k
            ! N! A  ?. `9 H% P# n' S
if (remainder who 5 = 3) [set k who* X8 |1 J6 l7 ~: H9 e
                          set x( Wid / 2)  : a* C4 R6 h1 y
                          set y (0 - Dep / 2 ) ]
' A% O) [1 S. p0 z& B- e                          set f int (k / 5) * 5
0 a! x& ~* Y6 h1 n5 K  setxy   ( xcor-of turtle f + x )7 \( x3 r6 j# g8 M
           (ycor-of turtle f + y )
5 I/ g, v( T% |           
/ g6 h; t3 J, Q/ @           . I0 p' y7 \/ Z' y; M( \- ~
if (remainder who 5 = 4) [set g who
9 N& i/ a" S1 @2 v+ M5 n3 X                          set x Wid / 2
5 B8 k. f4 u! D) }! O$ n2 ?                          set y  Dep / 2 ]
7 s- f/ v* K3 L- Q  E                          set h  int (g / 5) * 5* V9 W& I6 K' Q3 B6 C' i
  setxy   ( xcor-of turtle h + x )
  M1 g2 n- O& o; ^' m           (ycor-of turtle h + y ) 7 R& c% P3 E4 [/ W! p
                          
7 J' ^+ \( o3 O5 W' Q                          
0 x6 \: t3 q! X) a$ D& y                          ]. E" y% A; w* H  t4 l$ ^
end3 A+ j' G; d8 t" C. K+ H' |* Z

2 c, Z, k2 I) V! G0 M' K[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
/ Q: y5 s* v  s7 m! E应该是% c5 E+ \" J. h, {8 l
ask turtles [
" S0 u; i  G5 _! Tif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 3 t! a! B4 Z7 s4 b3 w
                          set y  Dep / 2
8 L; d1 T. r+ R+ ?! x/ n           set b  int (who / 5) * 5, r1 ^, n! y0 R8 H
    setxy ( xcor-of turtle b + x )
4 x9 Q. P/ I" L1 l2 M+ j          ( ycor-of turtle b + y )]]
3 Q1 w4 I5 u  [8 |$ k5 gend
& _3 z: C) K/ d4 A' Y! f之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-12 10:11 , Processed in 0.018154 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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