设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7522|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。1 q- f  D7 o; f: s5 J6 K, r

+ [( A$ G" }+ C; ~8 V9 R8 ~但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。" ]& G* z! p8 t! Y5 O6 Q8 A

5 ^$ O0 ~2 p$ jturtles-own [a b c d k f g h& H# H$ Y- j; ^: X/ ?
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ! p% i$ l0 m5 b6 X
]
8 K" @: P5 ]& }* wto new( I( ]2 k" W& c% k! Y
  ca
$ M) ?* h* v( ]3 p- T) G  crt 5 * num_of_building: B9 ]) G7 d; \9 K* e4 W
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]# c: j" k! }' ^
  scatter     ;;keep center-turtle random positions
* n- P9 {3 a/ M  unit_plan   ;;make up the building plan
: V2 b2 {6 Q; H/ o7 G6 y' Rend" u# O, X& i; T0 o# z3 c, V) \
to scatter9 l0 l6 e7 T; h2 g7 g0 d7 A7 H0 c; ^
ask turtles with [remainder who 5 = 0]
  o9 P8 L$ H, I" N1 T[$ N! |1 C4 x- y
set xcor xcor - 6 + random-float 15% ]$ {, p" F' F" |( d! r
set ycor ycor - 6 + random-float 15: C0 Y8 S6 ~0 k6 }) F
]
( j9 O1 M7 j) L3 rend9 T* J' H& j0 l2 R
to unit_plan
& |  }  C1 [/ c+ j) f1 pask turtles [
8 V5 H' q' E2 n2 X# K# }" |if (remainder who 5 = 1) [set a who   x0 G9 G/ h+ ]% f
                          set x ( 0 - Wid / 2 ) # T2 `; @4 s$ Z0 W
                          set y  Dep / 2 ]. M3 U5 A# V0 M- Q  D
           set b  int (a / 5) * 5( n* O+ d  K+ G" e- E2 G% u
    setxy ( xcor-of turtle b + x )3 y' u1 O' \: `0 t2 b
          ( ycor-of turtle b + y )
' V" V6 @' `5 d/ g8 k5 Jif (remainder who 5 = 2) [set c who
/ N- {1 c/ f: \                          set x ( 0 - Wid / 2 )
0 _3 @" I( x/ D+ F& }9 ^- k- M' r6 T' k                          set y (0 - Dep / 2 )  ]
7 b! V3 c2 W/ j9 W  K8 c% _                          set d int (c / 5) * 55 c4 H% I0 ]( L! g
   setxy   ( xcor-of turtle d + x )
: n% y; J: j: q* p( t) n7 @6 `. ^# S           (ycor-of turtle d + y )
% Q* x4 L6 \0 N0 f" }3 _7 L/ j          2 s# K* `8 L8 h0 f9 f; r
            , H3 F! b7 A( X/ V/ r
if (remainder who 5 = 3) [set k who$ J1 h1 V! M% J
                          set x( Wid / 2)  
! h3 M/ Y7 T% q                          set y (0 - Dep / 2 ) ]/ I) H- s+ P, G) X) H
                          set f int (k / 5) * 5( i, A: O. @- A9 {7 Q
  setxy   ( xcor-of turtle f + x ); B+ K" v3 Q* m+ M
           (ycor-of turtle f + y ) 8 x# H% J! t& E" I8 e0 P3 b
           
# V7 ]* a# D3 _2 ?3 r             {* w  o, Y& @/ ]
if (remainder who 5 = 4) [set g who
- R: x9 M9 k. o' d                          set x Wid / 2
/ f1 @+ \) B  k! C1 l: R9 `3 g                          set y  Dep / 2 ]
6 [# L* @) c, t( N4 w. i/ w; J7 G                          set h  int (g / 5) * 5
/ `) H# H8 M, A% Y! [  setxy   ( xcor-of turtle h + x ): ^- C/ ]$ F. X4 Y- r4 {
           (ycor-of turtle h + y ) & h& H6 b$ K6 J" P& @8 Y6 Q8 W
                          
9 g$ c: @$ F& l7 s                          
7 ~4 i- M3 F6 c                          ]
  h! c1 \( e3 U' ]8 Vend
9 m  U, b: U$ k8 T
2 {; I% K8 o. n  P- L; f8 I. b[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
$ W- B3 R; ?, v$ Z* v! o! K应该是
# h8 i3 D) f, L7 b: x8 Nask turtles [! W* w2 {+ T8 M+ @6 k' y0 \- f' s. c3 V; M
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 6 [; R. ]' `2 c! Q5 W
                          set y  Dep / 2 4 Y1 ^3 @" N% Q) i' u
           set b  int (who / 5) * 5
2 k$ @8 n" F# _  `' l2 _    setxy ( xcor-of turtle b + x )
! \# N5 n  S5 G2 Y) A' u          ( ycor-of turtle b + y )]]
4 G9 F( B2 `9 j: S5 ]! a: r+ Zend
' {" v' @) M7 N1 d之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-21 12:27 , Processed in 0.015319 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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