设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7645|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。2 a9 C. s3 ?7 D: h, F7 d4 {& z' y. G

) q) c6 P1 N% A5 Z但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。. M2 J$ Y4 E+ m4 u$ o
# R8 v3 }0 I4 `7 e* o
turtles-own [a b c d k f g h
. A$ g/ S: t% R- T, c7 W  x y     ;; these are the leaf-turtle's offsets relative to center-turtle " x; l# ^* D+ O
]
+ L: q3 {8 \! X. B$ xto new3 r3 X  s' s: k/ L8 @2 ]# t
  ca* u6 E! {" c+ {/ C! [# W
  crt 5 * num_of_building; k( Q6 l  A7 y% \8 z% _& V
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]; h3 O3 |7 g, t1 \# V
  scatter     ;;keep center-turtle random positions 5 L3 T1 f, \# E2 A) R: l
  unit_plan   ;;make up the building plan- y+ f& j6 c  m1 {! E
end# P; g) Z" D" \9 v8 y
to scatter8 C8 D6 ~7 |/ x, d% _
ask turtles with [remainder who 5 = 0]3 f- R$ a& U  J/ y. Y1 |% r
[1 k9 R, N: R5 m& S8 B5 b5 k
set xcor xcor - 6 + random-float 15
! q; ^- {3 z2 @' t% F3 t; uset ycor ycor - 6 + random-float 15
" D0 X; v/ L2 u0 h) i]7 R$ C; H1 `3 C6 ^) ~" B
end$ I( @$ f5 E6 B6 f3 c: F0 F
to unit_plan * V7 m! U, I; ?+ s
ask turtles [* D7 ~! M- K# y& e* ?6 j
if (remainder who 5 = 1) [set a who
( D3 Z0 x4 p& ]                          set x ( 0 - Wid / 2 )
4 T: V' g4 |" J                          set y  Dep / 2 ]
& o! V. o8 R+ ~) i$ D- R           set b  int (a / 5) * 5
4 N4 J1 B9 }5 q    setxy ( xcor-of turtle b + x )1 s1 h, @/ O/ s8 i$ @% d
          ( ycor-of turtle b + y )
# i+ N  B" U( q! _# G3 H, r3 zif (remainder who 5 = 2) [set c who
$ V- S% c& M5 ?* v/ l4 r, ]9 L                          set x ( 0 - Wid / 2 ) # `& Y+ d' m6 x' n
                          set y (0 - Dep / 2 )  ]
0 u# h) |5 Z- l" z! n                          set d int (c / 5) * 5
* b8 ?8 K" Z2 a   setxy   ( xcor-of turtle d + x )
9 `1 u0 ], ~  g6 E           (ycor-of turtle d + y ) . R6 u0 A* I( S. D) i3 T" w
          / a# O: T# E9 X
            . K6 E; z5 f: n
if (remainder who 5 = 3) [set k who# G6 l9 f0 i1 O0 C" A& R  e8 ^+ o
                          set x( Wid / 2)  ' w# K0 j9 ?9 [5 o" o/ G
                          set y (0 - Dep / 2 ) ]
3 e+ P, V5 j) P" ]                          set f int (k / 5) * 5; E4 _! c/ |  c' {
  setxy   ( xcor-of turtle f + x ). [# I; _: D3 s8 g0 @% h
           (ycor-of turtle f + y )
" B& W. W$ L. Q8 s7 Y) B: q) X           9 H, D! u( e8 g( E
           1 S$ [- g0 @) ^1 B9 o! t
if (remainder who 5 = 4) [set g who
# s+ w7 c" Z- ?; @                          set x Wid / 2
* q5 K! W! T' m3 a# m# Z* r                          set y  Dep / 2 ]" v" t6 m, `/ W' U
                          set h  int (g / 5) * 5$ f' H% }0 ]4 ^* j' @( @( ~
  setxy   ( xcor-of turtle h + x )
6 S8 A: M  s. x1 d1 X0 k$ C           (ycor-of turtle h + y ) 3 Q! D8 `$ P1 E2 n# H
                          + X: P9 N/ p) s) ~8 E9 h
                          
' ]: J* `% o1 b; r. G/ S* c                          ]
, |8 F# R" E3 u, lend
0 ], i8 v. r! G. [% X% Q( _' I: B1 M& n7 i6 T7 C, R
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
% N2 C; O: E* t应该是
9 A7 ?/ J5 Y  z7 p: j: Vask turtles [
/ t, Y  @, x" }* Mif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) - |" ?/ b, l9 `2 X2 o4 u: J
                          set y  Dep / 2
8 J8 F% O$ P& r) a0 l% ~# F6 y           set b  int (who / 5) * 5# T1 e; ?  x8 e, k
    setxy ( xcor-of turtle b + x )2 D: `# u5 W4 y, r$ W$ n- S
          ( ycor-of turtle b + y )]]
5 e( y2 Z0 o; I/ {end( s! P) R" a% U5 X* n5 r
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-10 20:23 , Processed in 0.017208 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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