设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8171|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。6 X4 ?- m2 I& x) G+ \

* \  z# q( n  A0 f! M7 ]但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
/ s, m, r( |# v4 q! `" |8 c6 e
( p9 G  Y( d) k; x8 E; e2 ^turtles-own [a b c d k f g h# t' N8 `6 d; _0 f
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
  F. l* ]6 \% O) s. C]
$ G! A7 _6 `# ^to new
6 c1 I' @0 q0 I9 ^( l  ca
: X# ^! `: Z' @! ]: y2 B  crt 5 * num_of_building
! _% U4 z0 c3 x  [: o% Q  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]/ Q6 _0 B1 @( }% w5 y
  scatter     ;;keep center-turtle random positions
) B: l, Q$ H% x$ T5 a( ^+ V* U6 v  unit_plan   ;;make up the building plan
2 o- M3 ^, V; I. u* @& Y8 q0 r; V4 oend2 k- s* L9 A  N$ A
to scatter
" H8 z* Q- w! i& j$ U) zask turtles with [remainder who 5 = 0]; g6 P3 H- R7 y3 n7 _( R- S
[
* Q" l1 h, {1 u5 M5 H  aset xcor xcor - 6 + random-float 15; B$ O0 F- I. O  u( d( u
set ycor ycor - 6 + random-float 15% L+ `' _  h7 U! C- Y
]( Q! @( p  t% V6 g& N! W
end3 N9 c. Z4 J- \9 |
to unit_plan
$ f! V  B; e% E8 Oask turtles [* z& C4 o/ A; V  `* h# l+ u
if (remainder who 5 = 1) [set a who
, u0 L* @" Y* R& L8 K% k; u) `; g% Y                          set x ( 0 - Wid / 2 )
2 c: f  i! O% y8 J                          set y  Dep / 2 ]8 W! ^9 b/ E- Y  O. h/ T; T
           set b  int (a / 5) * 5
6 u/ d2 D) d8 F) K( q3 u3 S    setxy ( xcor-of turtle b + x )7 z- I, |1 g8 i$ a& `
          ( ycor-of turtle b + y )4 {4 T4 t6 O! {; A' k, H
if (remainder who 5 = 2) [set c who
' P& V9 E7 m- c9 O* O9 J$ M  B6 M- R                          set x ( 0 - Wid / 2 ) $ N7 M  V  w1 h9 l
                          set y (0 - Dep / 2 )  ]
; W, ~) I4 `& x# w& `9 _9 H+ y                          set d int (c / 5) * 5) i+ [$ _( Q# Z2 r. b
   setxy   ( xcor-of turtle d + x )7 s/ [2 f1 e2 a, n
           (ycor-of turtle d + y ) : n# U" ?8 c8 [- N
         
: Q7 G- l8 {2 `, s: Z            # g$ s9 S3 c( s
if (remainder who 5 = 3) [set k who  e8 y) O- H! `- k
                          set x( Wid / 2)  
: n, E" t1 O3 d' x, z6 x$ l9 J( N                          set y (0 - Dep / 2 ) ]# r# |) X( K' r2 g4 O; D9 s
                          set f int (k / 5) * 5+ a1 U: K" y) v$ w3 J& L3 g& ~
  setxy   ( xcor-of turtle f + x )% ]. i7 J1 i. @! r7 [" H
           (ycor-of turtle f + y )
# r3 S# P' |  I( `4 X           3 L6 @* j% ~  m3 s3 P* @
           
" w: f4 v9 N$ w# G: dif (remainder who 5 = 4) [set g who6 s0 u# w. V( M$ f' P
                          set x Wid / 2
! _- I# t7 ?# ?& U  u" l9 C                          set y  Dep / 2 ]" P6 q: y6 d: f1 P, ^2 Z
                          set h  int (g / 5) * 5- r& q9 X% I9 `2 X6 R) H
  setxy   ( xcor-of turtle h + x )
5 ~! F9 ]3 o9 t! ]! U6 i  h! q4 D           (ycor-of turtle h + y ) ! y1 z5 E6 a( {0 ~
                          4 v) y: d/ W+ g0 g* b
                          ) ^1 }+ a$ O0 C" ^
                          ]7 r# [; h: q' O5 V( i
end
4 V9 g) X* t9 v% S0 Y" _9 U5 @2 Z- P) _( b' R+ q# `8 v
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了," B3 L1 y+ s4 ~+ g9 j/ ]4 S& I
应该是
2 Z9 Z& G, W1 j( c% |ask turtles [6 p0 i3 {3 ~: F2 N. v, G; \6 a1 G
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) $ R7 J; l) V7 j# y) {5 C4 ^  G  n
                          set y  Dep / 2
( V6 d/ g- U- u5 m& j           set b  int (who / 5) * 5
6 N3 q5 P; r7 V& `    setxy ( xcor-of turtle b + x )
4 E  u' F( R3 i5 s* ~" H4 |  k; x          ( ycor-of turtle b + y )]]
- ^3 w; Y, w1 d1 Hend
% M0 S5 @* M0 c之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-14 12:03 , Processed in 0.021039 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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