设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6224|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。- B) @% h; L2 M

$ B$ \, @8 d4 _: K; Q; I8 v, C但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
. T7 k! b& M( a" ]3 |* {9 D1 ]1 S+ Z: \' }% c6 N5 ?4 w1 g
turtles-own [a b c d k f g h8 W5 P9 s. T: O0 p* ^
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
+ i+ d: E' U0 `/ []
1 x7 e* P6 {8 w9 n1 E: Vto new( r$ p3 e) A+ r+ p& ?
  ca
# T4 w0 a3 s; e% k! {' ]9 M; @4 }& [0 D  crt 5 * num_of_building
: {5 B0 z( X% C/ Y; Z7 x, x6 {  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]5 L, y) l' F/ l! _5 `7 G/ b. [
  scatter     ;;keep center-turtle random positions
0 R2 I$ K8 x4 y1 z8 T  R+ b) s3 b" L  unit_plan   ;;make up the building plan
- b, r( ]3 D5 P2 B# Tend0 V# u! s1 d; N& y
to scatter
9 g5 ]- s8 y; u* h. t. G* Mask turtles with [remainder who 5 = 0]
, w+ a4 E2 G8 a0 a% f/ h[
% N, D8 P: G3 ?, kset xcor xcor - 6 + random-float 151 E% D* G) I( U  \, |/ E
set ycor ycor - 6 + random-float 15
5 @; T7 f0 O! l, W) P, c]( `: ^4 I, B; N- F! J% h
end
; _. m0 M7 ^. s& mto unit_plan   G; P$ U  B6 c5 b$ }. v
ask turtles [6 n" n- j! h; t7 |5 K7 F- x9 X
if (remainder who 5 = 1) [set a who
' i& D" x' [! z8 t5 W( V, C3 _" D                          set x ( 0 - Wid / 2 )
: _0 O8 g, _; h2 f; p, o- p0 ?6 c                          set y  Dep / 2 ]
0 P  c! c; ^8 w, ]           set b  int (a / 5) * 58 o) n* y9 c' w5 B1 s) L
    setxy ( xcor-of turtle b + x )# c1 E; }9 E6 I% z' R$ ]+ D  L
          ( ycor-of turtle b + y )) Y6 t/ D+ ?5 [  A, J# A6 u& c+ z
if (remainder who 5 = 2) [set c who. u% K: X: H* q# F
                          set x ( 0 - Wid / 2 ) 6 {: Y9 A# H- p
                          set y (0 - Dep / 2 )  ]( ?9 p( C0 S8 M2 c, d
                          set d int (c / 5) * 5% H, T  E% y8 @2 ^6 |  l, [3 b
   setxy   ( xcor-of turtle d + x )2 ^6 _/ a5 R# r# k& B) t/ g- ]
           (ycor-of turtle d + y )
* {6 t: s1 n- G  S0 Q          ' g& L6 L. _4 P6 i, a6 f" m% C
            - H% i) I+ X0 `( e7 X
if (remainder who 5 = 3) [set k who
* D3 O0 m. s- Y% W! D                          set x( Wid / 2)  / W0 [- n' R( H; r9 N
                          set y (0 - Dep / 2 ) ]6 k4 H& [( b( q. u1 u
                          set f int (k / 5) * 5
, _  o0 I* u- [$ Q, U7 |9 [  setxy   ( xcor-of turtle f + x )5 Q, C" W1 i3 U# U9 I% a" `8 a
           (ycor-of turtle f + y ) / O: ~  B3 e$ C
           
9 Y; A3 v5 I6 m! U+ o; Y& R           5 ?8 @* M- c9 h! W$ |' t) Y- G
if (remainder who 5 = 4) [set g who$ C* H4 m4 x: |& d/ p
                          set x Wid / 2 5 [8 e9 {$ Q5 {2 ~7 w1 B
                          set y  Dep / 2 ]
! E9 H6 |1 w3 _& v6 `! q- O: x                          set h  int (g / 5) * 55 q+ Z/ O- e# F6 {
  setxy   ( xcor-of turtle h + x )2 I2 h. P5 u' D! E) p7 T& V6 z8 y
           (ycor-of turtle h + y ) 0 |. F6 E3 H$ _# U! l
                          
$ |1 q6 w$ e! ~- D9 W                          
8 C5 Y$ t- g7 ~" r$ @9 j                          ]
: o2 ^% ]5 D4 G- G$ h7 Rend
9 c. j  G* i$ J7 ^' {
' o+ h( v: q  s+ o5 ]1 _[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
, B3 S" j9 m. @  o7 j4 J应该是
8 ]2 X5 D" E0 ^. eask turtles [
8 S/ j& Z5 A- |+ l9 [if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ; a, [: n* M; C; p+ @0 P: i' s$ U
                          set y  Dep / 2 6 o  w" H( \- i" n+ Z' s
           set b  int (who / 5) * 5
' T$ o0 Y2 P  y3 L    setxy ( xcor-of turtle b + x )
4 l! O; F2 Q5 }5 C7 Z8 V- ]          ( ycor-of turtle b + y )]]' p/ c4 d: f: D% t
end9 x1 j; X6 J5 Q6 h1 Y( ^! k
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-9-2 10:35 , Processed in 0.012831 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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