设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9135|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。8 G) z7 [1 ?2 k( z+ u
8 D% Y, [+ a$ P% @# H7 @
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。. T2 q; [( L1 v- p( d

8 R4 j3 A( l  o, P2 Bturtles-own [a b c d k f g h
! Y; `3 R0 i. R# B" l/ T  x y     ;; these are the leaf-turtle's offsets relative to center-turtle " ~: R, o* d# w8 A% T0 q
]- G( m3 W) o" S' K& o0 h" O
to new& Z5 O- [& }. H# R. \; r
  ca- A: l. Q% T2 K  w$ K5 R9 |' [
  crt 5 * num_of_building7 r7 t; r9 c) {
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]" I6 d/ S) @  o" W' v8 Q
  scatter     ;;keep center-turtle random positions
7 }# Y# d2 e, Z4 y- t5 G  unit_plan   ;;make up the building plan" Y* w1 d9 [0 r" j/ m
end
) N% m  M4 c( Q. [, E. ?to scatter
# ?0 M! h& r& b* {" Lask turtles with [remainder who 5 = 0]2 F8 o+ w% B& o/ M1 N9 t1 G8 _$ h, P
[4 b6 D% q2 E0 F+ y
set xcor xcor - 6 + random-float 15
1 h9 }( k4 M/ q2 M! T3 y9 P+ P1 lset ycor ycor - 6 + random-float 15  \& f! q0 M* m+ x$ h
]
# x" i! o: P; f; i( S3 B( gend: ^8 h9 N' m' h( g# r2 u, D) n
to unit_plan
4 }- y0 k6 y  b! r9 ^$ g: Task turtles [) g) F2 }# X1 |
if (remainder who 5 = 1) [set a who 5 a6 Y% A* Z: V' {# F
                          set x ( 0 - Wid / 2 )
8 ?4 u/ N% c! T; W8 E7 A                          set y  Dep / 2 ]* c) k+ u/ f. q& E8 X
           set b  int (a / 5) * 5/ |2 v+ H2 z# h( V5 ]
    setxy ( xcor-of turtle b + x )
( S9 f2 m' o$ G+ ~4 T- x! \+ j  X0 [! }/ ~          ( ycor-of turtle b + y )' Y2 ~* p1 p3 a$ a/ h- j; t
if (remainder who 5 = 2) [set c who
" Y+ D6 {5 m, T                          set x ( 0 - Wid / 2 )
5 l1 V" A* D/ V3 w, ?- Q                          set y (0 - Dep / 2 )  ]" t3 o0 d8 \3 f! O9 O
                          set d int (c / 5) * 5
: G' I& A( e4 v$ A$ x: _   setxy   ( xcor-of turtle d + x )# q1 R; {$ V) Z: l: F: e4 O
           (ycor-of turtle d + y ) # _# K% h1 D. t$ X
          & O  z! ^/ K2 T8 R+ O9 }
            $ P% F9 T$ V8 A. {+ I  v
if (remainder who 5 = 3) [set k who
. P& J% X& w: Q, e                          set x( Wid / 2)  
' L/ w, n7 M$ K                          set y (0 - Dep / 2 ) ]% ]0 S  V, G  `
                          set f int (k / 5) * 5
9 R! c1 I  F6 X% @  setxy   ( xcor-of turtle f + x )
& b, R# y6 `9 i5 E/ X( p; G           (ycor-of turtle f + y ) " c% {: v; i1 w
           5 {/ m6 C( r. n0 ~. i: [2 o
           
. {( V4 B; a# lif (remainder who 5 = 4) [set g who/ j" b6 Q$ w( s  h% G
                          set x Wid / 2 6 h! _9 ~: n, u! S2 v- ]
                          set y  Dep / 2 ]' y, H# g8 C* n7 T- c$ p3 l: W/ p
                          set h  int (g / 5) * 5
# S; V) u: Y# [* k  setxy   ( xcor-of turtle h + x )) V2 }" `" y" ]
           (ycor-of turtle h + y )
" y* {* j! F* V$ G$ @0 z                          
. l& y& N8 o% v# {                          # V$ w- W7 s( k6 m1 \+ `8 J& G
                          ]4 s+ L7 N1 I" r
end
5 T6 r/ B0 M' U* g. j3 f1 x! K8 g" Y$ d5 ?! S
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
% z- e1 G: J- O' C应该是
. K  Z8 T/ ~, T/ V( \! s+ Vask turtles [0 E! w' M) N6 F% W1 e4 R4 {
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ! J- M( g, I% g$ p4 P
                          set y  Dep / 2
( {9 P( t: \& I+ _           set b  int (who / 5) * 5# G( e0 i. }# L
    setxy ( xcor-of turtle b + x )1 b# Q8 `' K' Y/ Y6 m( C, W
          ( ycor-of turtle b + y )]]$ A; q: E# a% g! o
end# h5 A, `& s! ^5 e2 Z" G4 W
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-21 10:24 , Processed in 0.020223 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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