设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6958|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。% ^! a& b7 ~" A# [8 e
$ G1 ~5 j! |+ y+ N
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。) `4 D2 e3 ~5 `/ M) N2 L& i% L' C
( E0 e; L) L; }: n
turtles-own [a b c d k f g h& }5 D" [/ ?4 Z  N% |: z" `0 I
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle & H+ F& g. ?, S8 e' D: w# T
]4 w% L- f; ]6 o, u' A
to new$ K; C' ]8 A! V9 i9 n+ M
  ca( j; F+ }% g0 ?1 z# G- N* H
  crt 5 * num_of_building& Z9 @7 y. @" f2 o
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
. I- e7 f) [/ F* x6 }" @5 ?6 s$ Y  scatter     ;;keep center-turtle random positions
5 H! V/ {1 P" Z9 O  unit_plan   ;;make up the building plan
! g; A# U- H! f5 K) O. xend
2 I# \. O8 [( dto scatter
6 h( ^. t' I; Y6 p0 Hask turtles with [remainder who 5 = 0]
+ P9 M9 T' u2 h- x* h[
5 M- q$ T* a" h; J- k2 V& Sset xcor xcor - 6 + random-float 15
3 u; d& V2 U; K( \set ycor ycor - 6 + random-float 15+ _5 [$ @& E4 A# B9 t) j
]8 {2 H) D6 u7 Y
end1 T& ?: U3 C- p2 g. ~
to unit_plan 8 ~; o7 j- Y' ]9 o5 T
ask turtles [4 o% w/ z1 e! q& B
if (remainder who 5 = 1) [set a who
3 D: Q7 W- I% m8 M' X                          set x ( 0 - Wid / 2 )
. q) N  T2 s( u                          set y  Dep / 2 ]
$ @2 f! R& s8 p) A9 f: o           set b  int (a / 5) * 57 J$ e) U$ l$ M  H5 R4 `1 }# q
    setxy ( xcor-of turtle b + x )
8 N  C% H8 k: @: P0 C! y          ( ycor-of turtle b + y )# w& C- K2 W9 y) r% Y
if (remainder who 5 = 2) [set c who* {/ f+ ?( q. i$ G! m. {( w6 i0 G
                          set x ( 0 - Wid / 2 )
# I5 w' M  o( \9 I1 J                          set y (0 - Dep / 2 )  ]
" e8 U8 b2 T1 t                          set d int (c / 5) * 5
3 j' k" C6 l& l1 f; J: s$ ]8 d   setxy   ( xcor-of turtle d + x )
8 C+ I9 e: Q3 X/ A+ d  h" r           (ycor-of turtle d + y ) , X5 C9 E% [. ]/ O* |: Z6 L
         
" D8 ?( P* f$ @2 b) F6 @8 w            
6 a$ s0 |. M* Z3 |, z+ i$ Oif (remainder who 5 = 3) [set k who
$ s& C2 P0 E  i+ U                          set x( Wid / 2)  
, E! ]$ N1 k4 @! I$ v; z. h7 p                          set y (0 - Dep / 2 ) ]
% T4 e% M2 p5 O# b  g: h$ f) W                          set f int (k / 5) * 5
0 ]9 b# S8 o! g- C' J  setxy   ( xcor-of turtle f + x )" Q& a- ?' r5 Y% m
           (ycor-of turtle f + y ) % U6 A% h5 q2 u; m8 k
           
1 J0 Y2 v( j* y% N* ]           
, A  m5 o1 {% ?+ Jif (remainder who 5 = 4) [set g who3 r6 _1 Y7 d3 w2 N4 R3 e6 B" g
                          set x Wid / 2
  y8 h( A- S+ B" `* B7 K' ?5 Q                          set y  Dep / 2 ]
6 K; _! t( {! {& h5 L1 l* s5 q  v2 w                          set h  int (g / 5) * 5
) r, S8 v* ?' ~9 z+ R$ c( J  setxy   ( xcor-of turtle h + x )
0 F. `8 n! e/ b( Z( E, A           (ycor-of turtle h + y )
0 B/ a) d0 d. h) e                          
$ i$ P. D7 k( D' T1 z6 k                          3 G4 N* q' m" m" A6 M+ G' h  h
                          ]6 c7 l5 @! \% I) i0 B6 e
end
1 d) P5 o. K0 `  i. H: }. {( j( i4 _8 L( I
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
/ i; X( A7 Q- D, K0 ~% W' |$ n3 o! b& x应该是' @, y9 [5 ^& }
ask turtles [' o. }, @* F: s* m7 g: s! @
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 6 ~3 w! m3 c) E) _
                          set y  Dep / 2
+ w' z+ }7 E  j9 {& C) M           set b  int (who / 5) * 54 K9 m1 H8 y8 d
    setxy ( xcor-of turtle b + x )
& ^9 z! T# c: Q7 J( @* h          ( ycor-of turtle b + y )]]
; `" ^: B  ]3 u. y$ @' q' Send
0 K: x' g! C2 {2 L* X0 F! @之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-14 09:43 , Processed in 0.019175 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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