设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8256|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。" G6 w9 ?" r# y6 n5 A

% M- M& ^! R! T但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。! y( ?( C' s! r. n1 H. B8 t( L+ M
8 E  Q4 o$ {0 @; s$ M
turtles-own [a b c d k f g h
7 g. U: H3 X! k+ v" r  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 2 I) W6 q$ q- Z
]
& b, |* k2 f4 X( y% Tto new
4 Y- P4 T" B  \  ca
+ _( `4 }6 T, F% i# b  crt 5 * num_of_building2 U$ r# C, I# L
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
8 t' i- b6 C) S, _% d* |% s0 s  scatter     ;;keep center-turtle random positions % N% p. o$ v" D9 t
  unit_plan   ;;make up the building plan( |4 i, P( H+ z, m( k  u
end, [- Z. Y( I* J, M0 v, B6 s: G+ s
to scatter) z" b8 y' O# q- X
ask turtles with [remainder who 5 = 0]
9 z9 C  D# c" [) x+ _( C* l[
4 z$ a! H; ^% d9 N) L; c4 j1 `, \set xcor xcor - 6 + random-float 15
+ v  j' {. t1 q1 lset ycor ycor - 6 + random-float 15
1 |/ i' `# x) }0 |, |0 x]
; m4 r% m7 Y( b2 b0 [end
6 N1 m2 ]) k5 S' s8 M( tto unit_plan + H5 F$ ?8 Q* @  m- U
ask turtles [0 I8 u9 ~6 h# `* A* E4 C0 e9 Y
if (remainder who 5 = 1) [set a who
8 `& ^( N# y( c: G4 _                          set x ( 0 - Wid / 2 )
6 V. ~5 F4 x  Y. K' O- E: `                          set y  Dep / 2 ]7 x$ d7 G# U) k$ b& ?9 s1 u0 M
           set b  int (a / 5) * 5
3 w7 J0 P0 c, H$ Y; H6 W. N( @: U    setxy ( xcor-of turtle b + x )% Y$ Y( }5 b; w" m( `' v
          ( ycor-of turtle b + y )
0 `4 E6 d. X( h4 Zif (remainder who 5 = 2) [set c who
% H5 H6 G! |, _" R) z9 e                          set x ( 0 - Wid / 2 ) 5 v' Y8 J7 a  V8 I
                          set y (0 - Dep / 2 )  ]0 j3 G- c4 J7 N1 k
                          set d int (c / 5) * 5
/ z" a; i. S2 g8 X9 `   setxy   ( xcor-of turtle d + x )
8 _* |" E) P9 n0 o; ~/ J- I! M1 d7 n8 O           (ycor-of turtle d + y ) & z1 q% @, ?+ }& ]& ]
         
6 L. J. x3 v- @3 t            
& G- W$ X4 _. D4 x8 \0 Aif (remainder who 5 = 3) [set k who" r0 }. E' S8 U
                          set x( Wid / 2)  
  }3 g/ W+ G  _% [                          set y (0 - Dep / 2 ) ]; P( f7 d4 S3 V' K' U" x
                          set f int (k / 5) * 5
. e( I  `8 ]  D& `7 k  setxy   ( xcor-of turtle f + x )/ r: O: ]3 o0 F
           (ycor-of turtle f + y )
( c/ a# N3 R- T. D. R           - f9 l  a& F; n3 M# ]+ g0 B
           
- \3 J1 |. l( J& l/ G' Dif (remainder who 5 = 4) [set g who9 X. H* K. ~3 D0 u$ L
                          set x Wid / 2 3 o$ m+ p; _; `0 v' H" u
                          set y  Dep / 2 ]
; A4 ?' z4 H9 r% a                          set h  int (g / 5) * 5. r- t4 y$ ^' K$ }% q6 h6 o
  setxy   ( xcor-of turtle h + x )
- ~& ?9 B7 l/ Z8 M% [           (ycor-of turtle h + y ) - e# i1 V2 A8 f/ T
                          ! y: t$ u# T, u$ J' \- c4 Z
                          ( y# s  D( V7 v; `( A
                          ]. N, i6 A& }7 D* z! ?- S
end
) J- r2 U1 h% j) N
& R( ]/ A* Y( c/ }6 v[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了," c0 L0 d/ t# C. t3 ^3 G, O
应该是
) x2 `- u3 b, q) e) Sask turtles [
: h( m' F. ~% d  R  Zif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
3 K9 ?6 m5 O4 |! p! ^0 k                          set y  Dep / 2
3 r0 {, o# n7 H. q1 q9 K           set b  int (who / 5) * 51 L7 e3 |& @9 {. _0 t
    setxy ( xcor-of turtle b + x )4 W- X# r( q+ R& t; s- n2 M
          ( ycor-of turtle b + y )]]9 j' I6 v) a0 f" N# e
end
& z" y# {7 U; d0 O* y之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-25 11:35 , Processed in 0.023973 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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