设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8829|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。- X; R' e1 Y' W, ^7 G; `
, }* r- y! ^, y
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。& f1 z9 ]1 n0 M
( j, z  @! x' s- X
turtles-own [a b c d k f g h
; b9 X" _/ R0 N5 A" I. x  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ! p" z2 P8 l# K9 n; Y
]2 O4 G( l4 h% b! O3 T+ r
to new/ ^( |$ Z+ _% a5 _
  ca$ ?0 M6 t7 [+ N8 I" z1 H& a
  crt 5 * num_of_building* d. Q. A" b) V) X- `1 l
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
2 a/ s/ y" m7 T. w5 x  scatter     ;;keep center-turtle random positions 8 p: u2 e! _0 t) H3 v: o
  unit_plan   ;;make up the building plan
5 i* a, A! m2 t* C9 Eend, Z+ t1 P/ A6 @( D( w* Q
to scatter" j& {/ }7 l8 j6 v0 Y
ask turtles with [remainder who 5 = 0]
2 `5 _' O$ {- z/ w[
, A9 D+ |& G5 c/ R9 ~" m9 Cset xcor xcor - 6 + random-float 15* ?. a: L/ z; [  c+ \* @
set ycor ycor - 6 + random-float 157 l* p/ U6 |0 j; j
]; d% Z3 \# P% E& F7 O
end2 e+ F  u8 X$ A9 Q3 X
to unit_plan - G. ]! j8 k" g+ A# o
ask turtles [0 Z! j  Q3 c0 ]2 r; |, w
if (remainder who 5 = 1) [set a who # a) J" x, P! J- i* M  G, G  C
                          set x ( 0 - Wid / 2 )
/ b0 x+ R- |. b( C' M- Z                          set y  Dep / 2 ]1 x* M, ?& V  B6 Z
           set b  int (a / 5) * 51 L; o  [6 R* X# }9 }3 N
    setxy ( xcor-of turtle b + x )
! |1 L6 t1 S/ h          ( ycor-of turtle b + y )
9 {# H: N% J5 C: W4 w/ G0 y; Oif (remainder who 5 = 2) [set c who" V) K( C8 F$ ?& r
                          set x ( 0 - Wid / 2 ) # |0 U# o) \) G) j- `
                          set y (0 - Dep / 2 )  ]( t5 H( S; r" y% Q. ~: K0 |
                          set d int (c / 5) * 5/ B$ T( ?8 L3 e) k( m2 ?0 Y
   setxy   ( xcor-of turtle d + x ): y* I* |7 g7 n" p' O/ P+ M5 D
           (ycor-of turtle d + y ) $ n& M! h; T& g
         
# z: J4 S4 W/ \/ M9 T, p( r            7 r5 S9 F1 }% }) e% [1 W1 d
if (remainder who 5 = 3) [set k who* |4 p) Y; _3 T" f
                          set x( Wid / 2)  
5 H0 Q. b* ]/ r. ^& l                          set y (0 - Dep / 2 ) ]
; ~. H7 K7 S% E3 ^                          set f int (k / 5) * 5
, ]1 Z1 Y; m2 ^7 [' [. d  setxy   ( xcor-of turtle f + x )6 r" ~& |1 C4 i. n) m; K: g0 d8 ?+ A+ b
           (ycor-of turtle f + y ) $ R) D) v" X( Z8 {$ S( S$ y
           
. P" ?" f1 y, i; g4 n6 _           
, Z' d* c) A# A( _if (remainder who 5 = 4) [set g who! h. F# ]3 m! ?2 n( l
                          set x Wid / 2
0 c0 M. E4 i  d: |. l5 {& u) {4 W                          set y  Dep / 2 ]
( S+ }  u' L8 x( A/ `: `$ W  D. ?                          set h  int (g / 5) * 5
3 t- S+ d" \- k# I- Y$ B4 y  setxy   ( xcor-of turtle h + x )
" }" P. {$ [9 A! p3 `/ z9 y8 a           (ycor-of turtle h + y ) 5 w, c( t2 p% a" n6 m" R' s3 T
                          
' q9 r% ^9 F, d1 O/ p$ i" G                          
3 h/ M. Y3 x4 a: Q9 w' Z                          ]
/ E- @" x7 Z. v4 k) f# U6 \end
8 Y0 W& f& E+ l+ z3 E- s/ ~6 v1 O. x
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,  t, M4 ]1 @6 ^0 h
应该是
! z& R* }$ K% x: ~1 g1 ]3 a/ f7 }1 Pask turtles [
) }' z' j6 w/ R1 I8 R: |, hif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
2 y/ h0 c2 a) w* m$ f# Y                          set y  Dep / 2 2 w2 c# x7 l+ h5 M" n6 g/ W
           set b  int (who / 5) * 58 \7 W! ^9 u+ a& B; [
    setxy ( xcor-of turtle b + x )
& m  \' K8 V! r3 x0 F$ H( _          ( ycor-of turtle b + y )]]; b) h# `) Y) e
end
3 A" R3 T5 w2 a$ ]之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-9 06:57 , Processed in 0.021878 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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