设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7574|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
$ [( `7 E. }+ a. [( e! P+ z1 g  c6 m' J
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。% _! W5 ?0 i- h5 M) I6 e$ Z. z8 k! c
" ]  t1 e& g# @& D1 K$ w
turtles-own [a b c d k f g h
1 O3 [5 v" {6 Q$ k* |+ V  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ! n& l- @' s$ ^2 ~" S
]
& }% _+ }+ }' h7 a3 n3 bto new
* Y0 P) A) x6 K( x4 }) F  ca
7 \. k* f7 X7 Q6 w: p- g' T  crt 5 * num_of_building
' v) j9 f- ?( ^  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
% Q* B* {& Q+ {( j( W+ [  scatter     ;;keep center-turtle random positions
- H! H: s7 {7 U# ?. W  unit_plan   ;;make up the building plan
& }3 }  x( o, y3 H# _end
5 K6 Y* @9 F% Q0 Q6 ato scatter
; h) s. }. S$ fask turtles with [remainder who 5 = 0]
/ N3 r/ u/ Y" j6 U; a[1 z4 S$ g- W4 z0 p
set xcor xcor - 6 + random-float 15
' C- ~3 T  F% U8 Y4 k8 g* iset ycor ycor - 6 + random-float 15
  @' C6 K5 f+ m/ v]
: k0 C" J7 j: v& }: xend/ {2 s. |- i  ?0 U" g. ?1 Q
to unit_plan ! w, L* P4 ]' \6 C4 _/ u$ b
ask turtles [
0 n. \, t+ V7 J" D! _5 Pif (remainder who 5 = 1) [set a who 7 O6 E# _" Y* X+ Z' s
                          set x ( 0 - Wid / 2 )
1 q. v5 ?) h- i; `7 @* h+ E                          set y  Dep / 2 ]  ]+ z( ~  G: B
           set b  int (a / 5) * 5, O; f8 A' H/ t1 A
    setxy ( xcor-of turtle b + x )
& c# S7 c( r" @  F- c          ( ycor-of turtle b + y )
5 o' a- l9 n7 V# _! Aif (remainder who 5 = 2) [set c who
5 P4 z' _: `. \6 \4 v7 D( [  P. L                          set x ( 0 - Wid / 2 )
! O; L" M9 \1 U& ]5 D, l                          set y (0 - Dep / 2 )  ]
! E5 |% X" z* E3 h. C                          set d int (c / 5) * 5
* j. q; \0 I7 N* W; N- E   setxy   ( xcor-of turtle d + x )" b% l( P7 c- @: c8 K9 x
           (ycor-of turtle d + y ) - Z1 f3 S  j$ X! T
          ! B2 y1 q* h% u1 p: {0 c
            
% m, q; E( x: i6 {5 m' ]if (remainder who 5 = 3) [set k who
! S- p4 V! w& H. l/ u% P4 S                          set x( Wid / 2)  ' J3 Y1 Q. _3 N! N; g$ @
                          set y (0 - Dep / 2 ) ]
5 @9 {! Y, F4 E6 B2 [% _5 J                          set f int (k / 5) * 5
" E3 ~! W( r/ U9 x: \* x  setxy   ( xcor-of turtle f + x )
. ^' ~: \0 b1 u9 p% j           (ycor-of turtle f + y ) : u$ j- B2 s5 C5 m
           
; i# V1 u( S9 v           5 D& H+ e6 K4 Z1 V$ m
if (remainder who 5 = 4) [set g who
% x- K  p& n1 ^) U2 A: c2 {. T4 y                          set x Wid / 2
& A# G; Q2 y/ O$ O5 d* D                          set y  Dep / 2 ]
8 q6 R# J2 P. x" ?                          set h  int (g / 5) * 5* H$ j$ {. C. y
  setxy   ( xcor-of turtle h + x )8 {% e& C' L' b+ G' k8 N
           (ycor-of turtle h + y )
+ z( ?2 v6 W! d; c! r% @$ a                          + M2 }. u  M. \$ d" q# O( H. A
                          
) b5 t/ |+ T3 J: A& F                          ]+ t2 P" k5 d( M
end* |, H6 `4 `% W8 o

0 Q6 B# @. ?' c/ G2 k1 A& G" j[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,' s# [  ?9 S) t0 @' K9 Y
应该是
% d5 W1 t' Y. h& t( m: cask turtles [
! Q5 e: j. s3 r) yif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
8 _- d9 o* u; Z5 V9 a4 x& |2 y                          set y  Dep / 2
; _( A$ J! L+ B, u+ n           set b  int (who / 5) * 50 \/ B0 |/ w! T- Q2 w
    setxy ( xcor-of turtle b + x )
3 Z! P5 y/ u: M, Y5 ^9 @2 l: Y; o2 o          ( ycor-of turtle b + y )]]! c1 e2 ]( m5 i& \1 V( o2 w
end
, o( S( ]  X! W( s之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-28 15:53 , Processed in 0.020711 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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