设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6733|回复: 1

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

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

+ D' I: B+ ~; O% a8 H0 z4 O& }但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。3 Y  a9 l8 Y' j+ w% Y' ^

7 f, x: g. n) ?# v, m  k4 j  k' Yturtles-own [a b c d k f g h
  q0 M0 m3 X$ A; x' ]: P1 x  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
8 l9 H; Q1 a4 C. E7 C]4 m0 T/ M3 \0 N3 ^. ^$ C" z2 c( t. Q
to new* \8 ]" [* W6 x
  ca5 K: ]3 M. H% S
  crt 5 * num_of_building
- q1 r9 H" G* i# g) F2 e) |% B9 H  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]0 ^  n& M- ]9 B, z$ M* `8 R5 F; a
  scatter     ;;keep center-turtle random positions
. |. ~0 p6 \& C" f& |' j7 P  unit_plan   ;;make up the building plan
: K+ Q3 U' R& d1 d* Pend
# f5 q$ B! K& M" fto scatter
4 B" R0 D$ x1 {2 ~, X+ Hask turtles with [remainder who 5 = 0]
6 Q9 s: p1 t1 @[9 `7 M8 e# P' ?4 s& s
set xcor xcor - 6 + random-float 15
0 ~0 P" j& y$ I! K9 Dset ycor ycor - 6 + random-float 15+ {) _: y" e/ L* w' K( k7 |
]
" L$ ^. w+ V; d2 E1 x0 c# rend
, M0 G' R. D7 w# X7 |# ?to unit_plan ! c* z! f& B+ i' `! n
ask turtles [
2 K8 y3 q, R7 C! q4 j5 Sif (remainder who 5 = 1) [set a who
9 k& l1 Z, F( V1 S- ^$ p! i                          set x ( 0 - Wid / 2 ) 9 T2 Q( _. L, o( k
                          set y  Dep / 2 ]$ |: ~" Z& W5 [- K( h' z- l4 J. i: _
           set b  int (a / 5) * 5
0 R! ?- W) l! m: T    setxy ( xcor-of turtle b + x )  |# k, w6 D# q% {
          ( ycor-of turtle b + y )1 Y* U* M9 U7 j; k$ {
if (remainder who 5 = 2) [set c who
& z- O, ~" k/ H9 z9 P1 m, k                          set x ( 0 - Wid / 2 ) ) k& L9 w) `+ J) f
                          set y (0 - Dep / 2 )  ]/ _2 v" e2 ?- X
                          set d int (c / 5) * 5
' t/ k. l8 [" V  B   setxy   ( xcor-of turtle d + x )4 D8 M, z: @! F& y* u2 E3 z0 [$ `
           (ycor-of turtle d + y )
& H9 z+ S- I' j% c3 c  ]          + x0 L( w: R) N" b3 k: M
            ( O, Y6 b. v6 u- s% S
if (remainder who 5 = 3) [set k who
$ {+ ]. v; D5 D: s) J* C                          set x( Wid / 2)  5 E" A( }0 Z) f( f
                          set y (0 - Dep / 2 ) ], C& f/ D( h3 u) V. H4 G* \# U
                          set f int (k / 5) * 5
- _& _% o. U7 T0 @: N  setxy   ( xcor-of turtle f + x )
& E+ \: J5 b2 I1 I- i           (ycor-of turtle f + y )
0 Y! l. }* U1 C- b" O           
5 P3 Z7 {* R( b5 l, X7 {           7 P, o# k' c: c
if (remainder who 5 = 4) [set g who5 v$ e7 [# C, C
                          set x Wid / 2
! Y, y9 _# Z* d7 c                          set y  Dep / 2 ]
( Q& F0 i' L0 k! a# s$ J                          set h  int (g / 5) * 5
6 r9 D) Y3 |# _; S, U+ ~  setxy   ( xcor-of turtle h + x )
) t" a/ X# M+ T* g7 Q           (ycor-of turtle h + y )
# ]8 f9 ]3 M0 X5 j. }" M  d                          
, h. r( p$ ?& [; d                          
% L; M( O8 p& q( R5 [7 Z                          ]
# q+ o8 Z7 S; Z& xend
2 g0 @; [. w& r8 d* u5 O9 u# s: O( O1 k" W* z2 e7 {# L& _
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
% o% B) p9 z2 {应该是
! S$ V7 l; E0 |ask turtles [
3 k9 B8 \8 x2 V! Z: ^if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
) Q6 A" D( D8 d+ I' n6 h6 [; p' M                          set y  Dep / 2
" X" T: h' [/ Z" \( H. J+ \; ~* Z8 F           set b  int (who / 5) * 59 m- E% f! ^1 Q/ p1 V* x
    setxy ( xcor-of turtle b + x ); p" e# e5 g1 C: s9 h, A2 ?$ o
          ( ycor-of turtle b + y )]]' A* s! E5 Q$ W) A" k0 k* {
end% I( |  Y4 X- i
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-18 23:02 , Processed in 0.026188 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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