设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8048|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
8 g4 ?1 R( L5 M- H  \/ X$ T8 U, B: v% Q$ u  L4 o
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。+ g" [! G5 p$ S3 `3 V: H' U
+ k% W# E% O, `" G9 G
turtles-own [a b c d k f g h
! m% l: ?& x9 D9 B, j9 F  x y     ;; these are the leaf-turtle's offsets relative to center-turtle : O0 ?1 D! U7 `8 F3 c. n$ c
]+ J7 ], M8 d  t* X
to new
$ ]8 y$ M: t% ]* x  ca, Q- z) b( X$ R) j4 W6 w
  crt 5 * num_of_building
8 K) V5 f1 N$ G# Y  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]7 x! a& s6 \4 V
  scatter     ;;keep center-turtle random positions
2 T, X3 g7 G& X- J  unit_plan   ;;make up the building plan
& `7 |& w# `7 q4 I, G& B5 F! z0 j) cend9 \& A4 W9 R2 l
to scatter
2 v# Y7 p" u3 V. L- {# Vask turtles with [remainder who 5 = 0]
1 h9 h& Y. y* x7 S, x* x[
# ~. |: K& Q4 U9 H/ yset xcor xcor - 6 + random-float 15# V* ]0 A$ Z& c! Y5 e+ U3 V1 C+ @
set ycor ycor - 6 + random-float 15( k. {' f& G$ H+ X! h
]
. @/ Z, [- a+ [. {end5 M2 m5 Q7 E/ h
to unit_plan
% }. [1 A7 N9 \" h+ M& Xask turtles [# M2 i" F7 C+ G% a0 E' M
if (remainder who 5 = 1) [set a who 1 X) W4 C& a) N0 i2 e7 q. w& |
                          set x ( 0 - Wid / 2 ) + b% i- [) v* r' i
                          set y  Dep / 2 ]
2 R' w/ I" u* R' z+ l" a- i0 @           set b  int (a / 5) * 5# f0 O6 ?' h! p& _* H1 {% h) v
    setxy ( xcor-of turtle b + x )/ ?2 ?6 Q. h& Y- ]4 \2 J4 b
          ( ycor-of turtle b + y )
: O6 @: j4 }# B# p. Aif (remainder who 5 = 2) [set c who9 Y: J. w. q. u# O4 q. z
                          set x ( 0 - Wid / 2 ) + z* o% q7 `8 J2 t+ `2 U
                          set y (0 - Dep / 2 )  ]% s# v: q" J* D7 E! T. x
                          set d int (c / 5) * 5, b! H6 R" R) |9 s2 Q
   setxy   ( xcor-of turtle d + x )
" }5 h! i' ]( ~           (ycor-of turtle d + y ) 7 J- p  Q: f9 H
         
+ L2 H8 i; y# {+ g, E# K            
2 [6 }2 x. _$ X+ b1 Hif (remainder who 5 = 3) [set k who: g2 j8 s7 I4 s3 l( T6 p
                          set x( Wid / 2)  + A# v; h: q# ^! q2 Q
                          set y (0 - Dep / 2 ) ]) l$ p; u9 R8 {# M
                          set f int (k / 5) * 57 S! _1 C% C7 }/ k! X
  setxy   ( xcor-of turtle f + x ). [0 M/ {4 p7 U. _; [3 z0 d
           (ycor-of turtle f + y ) . `: l  _2 V2 X3 s* N, M$ }3 @( H
           
2 \# R8 N9 o4 ~  S) b5 W$ ^           
) }& R3 a3 z2 o* L. wif (remainder who 5 = 4) [set g who
2 B( m9 T8 I* l                          set x Wid / 2
+ A& Q( c+ s+ {& J                          set y  Dep / 2 ]  D: ?4 B' F6 Y) ]
                          set h  int (g / 5) * 53 k: Y4 t, s% g8 |# ?( n
  setxy   ( xcor-of turtle h + x )
+ ^# }0 K" m5 o           (ycor-of turtle h + y )
& I6 q% i5 J' k; ~/ n6 r$ S                          $ f% N9 ~+ K; E3 Y
                          
' |: }5 `" R3 A                          ]
7 G: i4 ]$ X) U; X" jend& L# f2 L  N& k3 H" M& Q
) }' M8 j) T8 m# B; y
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
& T" ~! k: `' R7 S; D0 }' r6 [应该是
  t) o! a8 D; {# q; r9 o0 dask turtles [# z7 u1 R8 t1 j1 t: A! J, ]
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 3 J9 f$ c. d. R/ z0 L
                          set y  Dep / 2 ; o6 o7 F# z* x) j0 f$ i! m
           set b  int (who / 5) * 5
6 }6 @0 t+ P1 V5 T/ g' Y& a    setxy ( xcor-of turtle b + x )
# z& d1 ^, O! \$ z: W0 C          ( ycor-of turtle b + y )]]8 `% D. v5 N6 v! k7 Z
end
9 i. X  j. E! i- J- [' o& k) ?, L之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-1 18:15 , Processed in 0.016820 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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