设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7252|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
: L7 z( e" T) N1 I) B) @/ \& C3 S/ [# ~! y& ?
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
  s; ?0 G: r* q" C3 I: x, t- l9 a! T8 c) R
turtles-own [a b c d k f g h; z5 @+ d8 k  H
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
! W% {$ m! y) s" E! x( @7 N]
' L+ a6 X$ r$ M1 a) w* Wto new! t8 T+ O  o9 Z9 m% n
  ca0 o$ X- U( q6 e8 [* t7 _0 M& g
  crt 5 * num_of_building, U# p/ q  ^) ^  l. v1 a
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
* U& F4 m! B# O# j0 @5 W  scatter     ;;keep center-turtle random positions & ~7 X+ o# e6 e- {; `$ j
  unit_plan   ;;make up the building plan  q! l# w& ?: a) F, K8 ^
end- n" D: Z! u# d
to scatter
+ f" t0 ?1 s* uask turtles with [remainder who 5 = 0]
; ?5 c( L: S# `% h  Y% _+ z[
) F( \) g6 r# Z5 {6 z/ ~set xcor xcor - 6 + random-float 15
' s, Y- L6 E  R- Gset ycor ycor - 6 + random-float 15' u7 G% c& h) y* \0 ^: \5 u. S
]" k, p: D0 f. P& f
end
' P- a% v  h) o7 W6 @. }to unit_plan
9 ~5 V1 i* q# M( l; T4 s8 aask turtles [& s. S: N4 b' T( ]+ @9 I5 P8 j
if (remainder who 5 = 1) [set a who : X! R# ?- A. ^' X& z$ K! A: o
                          set x ( 0 - Wid / 2 )
: @8 O1 i/ A, [4 n2 ], n                          set y  Dep / 2 ]. T) g: l$ v1 r2 T. n5 N
           set b  int (a / 5) * 5$ x  P( Y9 D# b' `# b6 x+ W
    setxy ( xcor-of turtle b + x )
: x1 T9 s3 W* a. }$ `, W" ?          ( ycor-of turtle b + y )* y0 @- o% J5 a. E
if (remainder who 5 = 2) [set c who! _. E( F3 i; M+ o- V. P
                          set x ( 0 - Wid / 2 ) 5 y8 r& ^( d" M: c2 @6 J* Y0 o2 B
                          set y (0 - Dep / 2 )  ]) Q8 E1 T" a: L0 K# S- R7 V; k6 S' W
                          set d int (c / 5) * 5
" Z& F' ^1 a. C* ^) Z) R: b3 a   setxy   ( xcor-of turtle d + x )/ |2 |( U% O& T. y2 b
           (ycor-of turtle d + y )
5 g" ~# {7 J1 m2 `          * _7 k4 F& F- |5 j3 P& i
            
2 g7 }$ ~% }% T/ jif (remainder who 5 = 3) [set k who
) ]5 @1 r; E8 \: {                          set x( Wid / 2)    c* l0 d8 s. q; |8 d" X5 t. B' S
                          set y (0 - Dep / 2 ) ]
+ P1 R/ g* v8 `# K$ u7 y* D3 [                          set f int (k / 5) * 55 V; |. v& z0 k% E. y; l) J* |/ T
  setxy   ( xcor-of turtle f + x )
4 {/ c* O, L* ^4 O& Y5 q           (ycor-of turtle f + y )
/ d7 u& G4 j2 W% w5 E" |( y, _           
; _0 o  E% l1 l7 E: h8 U3 X# Z             a, z" b$ {9 U5 P
if (remainder who 5 = 4) [set g who
" y9 u0 q. A8 l0 T  x% x                          set x Wid / 2
( h4 V: n6 n( m, K" ?- S2 d                          set y  Dep / 2 ]
& V. K( |. @/ l                          set h  int (g / 5) * 5
$ F1 G6 C/ {( C  setxy   ( xcor-of turtle h + x )
, v) @2 l: C% Q! {           (ycor-of turtle h + y ) + F  N5 [; X. G1 v( e5 s
                          0 m! g- v" G( f, O
                          ) p$ l5 I4 k9 S! c, f6 v! G" G
                          ]
% E3 n8 g- a! q* w6 U2 @* O3 fend
0 ]* {5 b2 C# S  {  d( C
+ w% x. B9 _0 ~! n. t4 ?/ K[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,4 r1 O9 r9 i% b: R2 @6 ~# J
应该是% N' y4 E8 _* r5 T% N) K
ask turtles [) b$ s) [! D2 ~% T
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 0 w" ]$ h( `- @( U+ }, w. P% n
                          set y  Dep / 2 / b. v5 q% @/ ^0 v4 J9 ~0 r# P
           set b  int (who / 5) * 5& H( r) a8 ]) n2 }/ K! M
    setxy ( xcor-of turtle b + x )
  l! d, _- ^5 s" Z' e8 I          ( ycor-of turtle b + y )]]
2 f( X* A, N" T9 qend, C8 ~- R! J$ {$ E8 x$ }' k9 [
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-21 23:51 , Processed in 0.016616 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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