设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7263|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。$ O- N3 [8 f7 m* u

% d$ M* G8 i! V: {: S3 h, y但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。9 Y. V  k/ v6 X5 {1 U
6 w+ z: g& |* s1 b- y( H) e
turtles-own [a b c d k f g h# a  m& Y! B$ T2 e0 K
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 1 e3 m- l7 ~/ R
]
8 P0 k$ H( f( w& p) _) Q" {3 Dto new
' G/ \; x4 d& U- K; L; Z  ca( H" E! K3 Y7 q
  crt 5 * num_of_building' c" Y& Q5 g0 l! f$ g
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]; F+ a9 G$ G  g( o: v; f
  scatter     ;;keep center-turtle random positions # |: f! i& n7 f# c, U
  unit_plan   ;;make up the building plan
/ M, }, ?. ]7 N6 f( h9 o% \$ dend! F* E1 ]4 T# u# V
to scatter
) y, }) J7 a2 ?) v/ t) |6 G* rask turtles with [remainder who 5 = 0]; m( z% Y+ L' W1 _* K6 O
[
! W! h( t- ~, W1 x9 Fset xcor xcor - 6 + random-float 15
' ], z5 C1 r' r- K$ Bset ycor ycor - 6 + random-float 15
8 z( ?1 x. L/ r3 j) H  X- L( }]$ S& I; X6 R% h( h) ~
end9 K7 R2 }' U$ l
to unit_plan
. ~- U3 ?# m! iask turtles [" s9 c7 A1 h" U: Q
if (remainder who 5 = 1) [set a who
6 P' b' L7 Y. U" ^, _3 Y+ p' V                          set x ( 0 - Wid / 2 ) 4 F0 V6 ]. F7 x
                          set y  Dep / 2 ]8 N1 \& v8 {6 \9 }) l
           set b  int (a / 5) * 5  o2 A+ L, A9 `2 ]" R2 f8 s
    setxy ( xcor-of turtle b + x )
: I! ^8 J) Q+ y% e7 e. [: k          ( ycor-of turtle b + y )0 e. A- P; x2 ^( i# h+ O- w
if (remainder who 5 = 2) [set c who
  d2 J: m9 t# P& D' f                          set x ( 0 - Wid / 2 )
: Z9 L6 O6 ?9 G: |2 n                          set y (0 - Dep / 2 )  ]' O1 d" j0 t! ~- B  h: e
                          set d int (c / 5) * 50 v- k1 V2 M+ _4 I
   setxy   ( xcor-of turtle d + x )3 E& G) D+ }$ F$ \
           (ycor-of turtle d + y )
; X8 C3 h, R" \! l         
! l  t7 q8 ~  q4 s1 {- x. u            
% T& Z) z) E8 u1 F& Cif (remainder who 5 = 3) [set k who
3 v; L3 P. M, e9 I7 j                          set x( Wid / 2)  
" {# s6 U! U8 Q: P3 i( q) |  g, {                          set y (0 - Dep / 2 ) ]0 b: p7 n' d* n7 p1 h; [; d) S8 c
                          set f int (k / 5) * 5
; P4 q3 z# o( x  ^3 W: V8 A7 o- y  setxy   ( xcor-of turtle f + x )/ r( P" E+ D6 Y, A) Y( Y2 x
           (ycor-of turtle f + y ) ; Z, U0 H8 r5 j$ m$ y1 i5 u
           
# n6 E7 B4 L8 |2 H           
6 V; V+ Z6 V4 C  D0 @: J/ E5 Fif (remainder who 5 = 4) [set g who* Z2 b" \$ N+ U
                          set x Wid / 2
4 i+ l, n  V. a2 ~* u& V                          set y  Dep / 2 ]
# ?% g- @  K1 V" G% C  d9 v, T                          set h  int (g / 5) * 5! a4 |5 x7 e( x
  setxy   ( xcor-of turtle h + x )
  E, T- y! J7 J  D5 B8 @1 O+ L           (ycor-of turtle h + y ) 2 r/ ]. X, A8 u) b
                          
% O& U  D, ^! v, v4 p( h                          / Y+ i- z& {- h6 T
                          ]2 f( s: S2 ]( U
end
' f% C) u; H) n/ ]
) ]/ K- I3 Y9 o; A* Z7 Q  g[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,9 j- L/ A4 N. Q$ G
应该是
3 n0 Z( d+ e% e! O1 d3 Yask turtles [
0 v8 o( d7 p$ d5 yif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
2 S( l" t, D" z; m                          set y  Dep / 2 , C/ |9 U4 Q/ X1 t
           set b  int (who / 5) * 5# c3 ]7 T/ x1 x  T
    setxy ( xcor-of turtle b + x )
( Z$ s) t- Z9 v. u! U          ( ycor-of turtle b + y )]]
) I) A- p6 \# @) q5 p; s4 ~8 t' pend3 {' C* y; t0 h- _* ]
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-22 21:14 , Processed in 0.015864 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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