设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8283|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
8 v& e3 u# i! v9 M4 I8 K
9 D/ s, }1 @* |% |' {+ }- _% L5 g8 Z+ p2 A但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
) `9 R2 C9 W3 w  S% |, x5 R" B5 @/ Y& }( x6 E
turtles-own [a b c d k f g h
7 j! i2 H! O' u) q5 t- Z+ V  x y     ;; these are the leaf-turtle's offsets relative to center-turtle , }* s" [6 Q7 D0 D
]
- C/ O; Z, o8 F# T. Ato new& [: a" @0 h2 ?2 m- S8 a
  ca
: h' v4 ?6 _4 T( ~* U  crt 5 * num_of_building# j; G- {. ]& F
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]( f' p$ T) G2 `7 f' ?
  scatter     ;;keep center-turtle random positions 9 n7 p- \( J! N8 T- j- V/ Z
  unit_plan   ;;make up the building plan
8 x* v; ~6 m  G- U* @7 ?end) g9 l: c. Q5 e6 n' {7 c
to scatter
1 d" H6 W: I0 N; qask turtles with [remainder who 5 = 0]
3 g8 q9 B( d; h$ ^$ B6 O[, f1 B& \8 n2 _1 U3 ~) M
set xcor xcor - 6 + random-float 152 C3 a0 D# w& H3 H
set ycor ycor - 6 + random-float 15  s3 F5 }$ T8 q! q7 G- A+ X
]6 ?9 _  |" Q; ]2 L4 Q
end$ W2 n# x5 o6 F2 I6 }, q; ^
to unit_plan ; }& |9 `7 I0 G$ |+ M* M, o5 D
ask turtles [
9 ]9 f6 d* b$ h! y; Yif (remainder who 5 = 1) [set a who
4 C+ v1 M& u3 o% x$ h7 X                          set x ( 0 - Wid / 2 ) / B3 [3 S5 C7 z3 s
                          set y  Dep / 2 ]/ q5 v; `& B; L/ q) R4 x& [
           set b  int (a / 5) * 5
0 P2 _7 }% h4 }9 u0 b: m/ T    setxy ( xcor-of turtle b + x )
( i$ Z! s& a  ]4 `0 S, u          ( ycor-of turtle b + y )" a3 B. L7 a9 D
if (remainder who 5 = 2) [set c who
% {% X, [. F  s  A$ k3 o5 N; ~                          set x ( 0 - Wid / 2 ) " s& b4 ~- L0 c% y8 X1 h
                          set y (0 - Dep / 2 )  ]
3 s; G, s8 J2 J7 h                          set d int (c / 5) * 5
2 m: d. @) T2 u8 b   setxy   ( xcor-of turtle d + x )
3 H! ?; a7 s0 I           (ycor-of turtle d + y ) 6 \  W. v4 x8 v! Z6 S
         
! I: h9 a6 {! R" o            + P; U/ r- i1 I8 i4 @6 ]7 A2 x
if (remainder who 5 = 3) [set k who5 I/ S; v& g8 L7 U% z/ F- w
                          set x( Wid / 2)  7 u& f0 T( B5 v2 r9 X
                          set y (0 - Dep / 2 ) ]
  T' u* x7 m* R4 f                          set f int (k / 5) * 5
0 Q/ g6 m. }) |. h: I/ v; t  setxy   ( xcor-of turtle f + x )# n$ T; R% u7 l% s
           (ycor-of turtle f + y ) . K( N& i9 m) ?. |: a
           
+ x. a) j, @* `6 u* f7 u7 x5 H           4 ~& _: O/ @( `3 ?# l% r9 s. ~* Z
if (remainder who 5 = 4) [set g who
" z6 i4 Q8 J! c" `6 P' T                          set x Wid / 2
% v5 a0 b5 l$ g/ i+ \  W* U                          set y  Dep / 2 ]
* H  B) ?/ ^. `7 N, _& @7 ]  |( M7 L                          set h  int (g / 5) * 5
5 J. @9 j# ?' C; [# y  setxy   ( xcor-of turtle h + x )9 c, ^: Z9 x) b( |+ k9 B$ [4 I
           (ycor-of turtle h + y ) ( \, G: _! y* R' z3 d
                          
1 ^% D! f; S9 j4 s9 c                          % V9 l; W. [9 t
                          ]
, f( \8 c, _' B7 {end  X' |" m1 s7 W2 ]- W; `; e: v$ J$ M
, _9 o/ m4 x- ?) L/ L  Q' k% K$ Q
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
0 N# @7 x2 j- |& k应该是
- T0 @( f" P# ]. U) l) @4 c3 Uask turtles [, I% ~( x' O( d; @' |7 [
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ! R- e- t2 U4 |: _
                          set y  Dep / 2
# y% p" Y) ?4 a& w           set b  int (who / 5) * 5
6 p, o- i# A0 y! j  Y    setxy ( xcor-of turtle b + x )
; z+ E' n+ P; n/ |7 X' U: l+ L0 j( u! M          ( ycor-of turtle b + y )]]8 |8 }3 |2 ]( O! [
end
' K7 H! }5 r4 [) s3 [之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-30 15:48 , Processed in 0.014996 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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