设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7601|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。( \$ w5 C( `  @1 g% v& o  [

, G7 Q5 V5 Y$ h4 V! t' u但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。! |6 [8 F2 N2 w% b

/ a6 a! K& L; n9 ?7 {& T: |turtles-own [a b c d k f g h
3 p% W% J9 r2 O  a$ Y  x y     ;; these are the leaf-turtle's offsets relative to center-turtle : @: j. i; U. W
]2 [- v/ U6 ?3 m; q% ?8 V
to new9 ~# X1 Y3 K6 l' P1 i, c
  ca( S+ G! \& a0 R3 F8 M0 ?# D0 ]
  crt 5 * num_of_building# P& ]$ [" k- K3 M! D0 E( M, @
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]; n: }4 g3 Z$ E4 O9 h* ~9 _, f
  scatter     ;;keep center-turtle random positions : }( L$ _5 _7 K' X
  unit_plan   ;;make up the building plan
- o; j1 Z# S2 Nend
' G) i& l4 f4 ~9 M3 v/ e+ ato scatter( d; F; J/ v* g: j
ask turtles with [remainder who 5 = 0]
( q  h/ n3 \: S( _$ i, e8 I4 G[
. K. l* m6 k7 g' m5 I. Dset xcor xcor - 6 + random-float 15- |( a  t& `; B
set ycor ycor - 6 + random-float 15# _* A& W9 [% i% N1 t, i; r
]
, e, T( n/ `/ X6 \- Cend7 j$ k  I: o' U& e/ b
to unit_plan % l0 h  t! O# S7 n7 p
ask turtles [& m3 M: z' Y& B1 h
if (remainder who 5 = 1) [set a who
( y; h+ P2 z& d5 U' B0 c                          set x ( 0 - Wid / 2 ) 6 f3 @  a7 n$ U8 t
                          set y  Dep / 2 ]# k$ ~3 ?- s3 @3 Y7 R3 S
           set b  int (a / 5) * 5
' y7 W6 Y" V6 ~; @" O9 f    setxy ( xcor-of turtle b + x )
  q: m0 `; J1 d* m& }% [) s: d' j% I          ( ycor-of turtle b + y )
; O9 Y; v7 l# s5 U" I$ N( N0 gif (remainder who 5 = 2) [set c who
& d$ C! @+ h& ~0 L                          set x ( 0 - Wid / 2 ) ! w1 r- @3 B; o! W4 m1 j
                          set y (0 - Dep / 2 )  ]
+ D& c, F' z) \- f, U4 L                          set d int (c / 5) * 52 w2 g# O9 J  ]" S' E
   setxy   ( xcor-of turtle d + x ), ^8 S' i7 T( O1 K- W! K
           (ycor-of turtle d + y )
$ J3 t" Z* ?9 ~' R+ D( N6 T7 r- Z         
8 n  N$ r2 h' L. @) x# @+ R            * ~3 Q8 G# ~1 `7 ~& g& h, v) h
if (remainder who 5 = 3) [set k who5 V6 E" G8 P$ B/ `6 b: r$ A
                          set x( Wid / 2)  , L  a1 o8 u0 B$ W" E  T! J* j
                          set y (0 - Dep / 2 ) ]
" A) Z' D: x: h/ P% `  G  F3 i                          set f int (k / 5) * 5
1 X, P5 x7 ]2 w  setxy   ( xcor-of turtle f + x )
  d7 @) Z7 b0 g- H           (ycor-of turtle f + y ) ( m7 l. n) h) h: y% Y/ q5 ^
           
, G/ \2 `2 P3 }0 g# k           3 K- F5 E9 B  b0 u* i
if (remainder who 5 = 4) [set g who# Q! b1 F9 ]4 K- {# G6 }9 W6 l
                          set x Wid / 2 $ J2 f; E1 `* v6 A2 C: P) e
                          set y  Dep / 2 ]
" c; A$ u; Y/ a! C* f                          set h  int (g / 5) * 5
1 v$ K9 A' h( A0 Y* U( w- D  setxy   ( xcor-of turtle h + x )& h. O7 j: s6 {  I' g8 C
           (ycor-of turtle h + y )
" g5 E- E4 i4 v9 _, y                          
! M  H* j# c. Y" r$ H                          
& k! j# Z0 w, g: l- d                          ]
" a; ^/ ~, I# @/ K/ ?end
9 |; _: ~% T3 g8 n
+ ?% C; ~  s; n[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,! L# d5 N5 w0 A
应该是: f. s  q  u, H2 e& E; }
ask turtles [
) x5 E, `  Q) V0 B2 Hif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
; E' I/ }# L# N) l, R) H3 d                          set y  Dep / 2 / H+ \3 v: A1 v: `
           set b  int (who / 5) * 52 w" H0 M& K5 w  h9 f2 O
    setxy ( xcor-of turtle b + x )
0 `/ I! d/ y9 h, [( m          ( ycor-of turtle b + y )]]* J* q$ o; @2 W9 k
end
; B( `1 Y& ^* _$ G: x7 A之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-3 13:32 , Processed in 0.025473 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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