设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8343|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
! C6 l0 Q3 L4 O$ @
+ ]- o# p0 c+ w% ^% S但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。/ x" a3 ~* r& Z( Y7 _
' ~  H( L1 W$ Q; F
turtles-own [a b c d k f g h+ m- C: {% O* d/ x% k1 w
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle " @0 e" [+ w2 m% h: N
]! }+ T: E: G+ V( F+ C
to new5 u1 c2 l8 E+ V5 [
  ca6 D- u( G5 I$ u5 ^9 M  ~: `" R
  crt 5 * num_of_building' W! G) r" B) N" f9 J
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
: F% s8 L/ v7 w" s* k$ @; z  scatter     ;;keep center-turtle random positions
7 a9 s, @: i0 r  unit_plan   ;;make up the building plan
  }+ C6 h3 w+ C2 C- V* \& N; r/ jend( Q, B6 O2 m0 v6 j
to scatter/ P5 N) G0 |4 x0 S3 h
ask turtles with [remainder who 5 = 0]
; l( B% R, x' I7 U3 j$ D9 D[  F3 I  k. _" @4 T! t6 \
set xcor xcor - 6 + random-float 15+ ~' {, |. J5 X8 L- s
set ycor ycor - 6 + random-float 15
% Y% T" S* c% c1 `1 i]9 @% \4 n# o  v# D
end: `# ^4 H0 \7 ]1 P
to unit_plan 8 w! ?" L# }6 k
ask turtles [$ S; w. E) T9 w6 ]
if (remainder who 5 = 1) [set a who
4 l* x( z9 }: q) ]7 e% ?% g& R                          set x ( 0 - Wid / 2 )
4 ?: l$ V  j& }                          set y  Dep / 2 ]6 E) Q- h9 k+ \( o% _
           set b  int (a / 5) * 5
( f+ M. [/ ?) {: G( l0 _* w    setxy ( xcor-of turtle b + x )
" t1 p& r# K. ^' U) x) a" t$ W          ( ycor-of turtle b + y ). r6 `# x! Z4 D$ C# }" C
if (remainder who 5 = 2) [set c who
4 Z. K: c$ p$ J" q2 v) G' A                          set x ( 0 - Wid / 2 ) 1 `: h( `& K) T( d
                          set y (0 - Dep / 2 )  ]
. k& f$ `& n0 b' r, ]; d3 {                          set d int (c / 5) * 52 S, I* i/ h1 h0 ?
   setxy   ( xcor-of turtle d + x )8 K* o/ B$ j) P. O2 {
           (ycor-of turtle d + y )
- M2 d0 F0 D# h         
4 Y! X2 M; Q1 ]7 k( J7 R            " U$ \' [7 v! J" Q- z0 @& a+ L
if (remainder who 5 = 3) [set k who: L6 i) a  X# o, u4 Q9 Q
                          set x( Wid / 2)  5 d. n$ f% k- T6 e& S, p" T3 I: A
                          set y (0 - Dep / 2 ) ]& B6 d5 w6 N% a9 Y
                          set f int (k / 5) * 5" [+ ?# Z: {3 X) d/ h! Y
  setxy   ( xcor-of turtle f + x )
, x% s+ k* W0 P1 a, \           (ycor-of turtle f + y ) # v2 e, {3 a' L7 t
           5 [, m7 q' E5 \- ]! ~8 a
           
' j) v; ]- V' F8 A7 C! _if (remainder who 5 = 4) [set g who. ~+ `8 f" S4 m9 Y# L0 _, M
                          set x Wid / 2 3 q1 o9 A9 _7 @7 i2 h! x
                          set y  Dep / 2 ]
+ w0 ~9 v1 H- U# p0 W: y                          set h  int (g / 5) * 5
1 Q) Q* t# P' `9 F/ j! K  setxy   ( xcor-of turtle h + x )- Z9 a' H0 N- ^
           (ycor-of turtle h + y )
5 j1 G6 G( ?' F& S7 E7 b                          ! ~8 [; x4 I, R  ^3 s- P9 x. ?- |
                          9 p; ]. n3 T* Z
                          ]
8 ^* Q% i8 q& Kend
1 X' I7 e+ j# R
/ o: g6 O0 |  [& M* C+ C[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
9 R# k. {# R5 f5 k0 H应该是
9 w6 y5 J* m7 ]; o  f4 Uask turtles [* `& ~# R, f. ?1 y
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
3 W# K' f8 j2 s2 h$ H- S/ T, J                          set y  Dep / 2 ) n% ]" K. U; [- y
           set b  int (who / 5) * 5% r9 v: G4 }+ }
    setxy ( xcor-of turtle b + x )3 t1 f2 N& }8 S2 n$ d7 u3 P5 @6 w; _
          ( ycor-of turtle b + y )]]
& v+ x) I8 g% G3 i2 G/ Send
4 S- U/ k, M* y8 x) K3 m之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-11 12:40 , Processed in 0.015614 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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