设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7347|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
9 K+ n- @/ i; v. D0 }
: C) M$ J1 \2 T% M5 p6 G$ r7 F但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。' w5 J$ j0 {/ a5 r0 ~: ^6 Z* P' f
' ]. u! O! k- F7 i5 N8 T! ^
turtles-own [a b c d k f g h
& B( |& _, U- J( N  x y     ;; these are the leaf-turtle's offsets relative to center-turtle , A6 b5 [! i9 B5 X4 m3 \
]3 B% n% _7 k( x$ i( ]
to new
1 e3 e$ [* U# y3 l( \6 `0 _1 o  ca
4 \8 K2 I- W$ e  crt 5 * num_of_building
! V! H% I) l1 R$ Z" H8 Y  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
7 H- s) g- x2 Q8 H8 u! y. N  scatter     ;;keep center-turtle random positions
( s" B$ z/ h: M9 t0 A# x8 ~  unit_plan   ;;make up the building plan
8 [% f. M% o( F, Wend. p6 o4 g- G; ^, d5 f
to scatter
" O7 U" p8 k3 f( fask turtles with [remainder who 5 = 0]
  W: n4 k4 H+ s& Z2 U  Z* L[; ~& ~9 v5 G* ?1 \
set xcor xcor - 6 + random-float 15
5 k) k# @; ^% y" Q7 Hset ycor ycor - 6 + random-float 15
1 l) Q' t: q! f: j9 @4 c7 c. j5 ]]) d& l" }$ N* ]3 j5 X6 @
end6 G; v1 e. X- }% h
to unit_plan 4 z9 y+ v: O/ s  Q
ask turtles [+ {+ f# \  |+ t. E
if (remainder who 5 = 1) [set a who
) Z8 I/ ]* m" u2 }: K: y4 h. V! r                          set x ( 0 - Wid / 2 ) ) _& @' u* @6 `2 g( ^9 [+ J
                          set y  Dep / 2 ]
/ D8 i: H4 b2 P$ |, z# Y. [           set b  int (a / 5) * 5- S7 x- S* E" K# L2 b; P8 X
    setxy ( xcor-of turtle b + x )
' Z. G4 y$ q: X; [          ( ycor-of turtle b + y )9 g" j; c) Z' F" v# Y% F
if (remainder who 5 = 2) [set c who( L+ {/ }; r: c- ~( O
                          set x ( 0 - Wid / 2 )
4 j/ c  y+ ^/ T$ u# h7 g  g9 E                          set y (0 - Dep / 2 )  ]
" ?8 \, H2 Z2 B                          set d int (c / 5) * 5
# }- D$ ]9 j+ n) I   setxy   ( xcor-of turtle d + x )1 W4 O2 \- u% F; P
           (ycor-of turtle d + y )
, U: u0 K9 G, Z  r# ~         
: F9 E5 s# b( c  V            7 d3 l. x+ ?8 C8 q+ X1 {
if (remainder who 5 = 3) [set k who( R. C* y! E7 m' B
                          set x( Wid / 2)  $ z& \' v7 z2 e! [  ^7 H
                          set y (0 - Dep / 2 ) ]
7 W' [( W2 X7 X# i: `1 S                          set f int (k / 5) * 5& [8 x$ g* \: _* G' ]# N3 W
  setxy   ( xcor-of turtle f + x )! o, ~) X; {7 Y. V; A' `( k9 z
           (ycor-of turtle f + y )
" O6 {9 _4 k+ n2 n- m3 _; e1 Q           ; \8 B' ^6 d# i
           5 l7 y. T0 x4 g" n
if (remainder who 5 = 4) [set g who
2 D7 r3 Y  x+ ^) N5 S& {                          set x Wid / 2
1 d% S6 j4 x7 j) G% m3 V9 k) _! {                          set y  Dep / 2 ]
$ O0 G$ A$ O. K2 U1 Z                          set h  int (g / 5) * 5
- G# g: B0 k  h' }  setxy   ( xcor-of turtle h + x )4 u. i/ y7 @% J9 }9 W3 p
           (ycor-of turtle h + y ) ; Z: C# @5 k" C- P4 @& ~
                          " C+ Z; w4 @" d9 h# B' Y1 _
                          
8 s: j) K! T* L/ {1 U8 Q8 p+ c1 C- j                          ]
& L4 i  K* S  }end0 g, Z% C) q) x7 z# [
1 \/ y' N+ m/ _
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
8 R& u! w- R) S3 J应该是
% }) O- ~$ K! T; Hask turtles [: h& A5 i6 ~/ a9 z4 }
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) * F! n' ?+ _. g4 T" ?! B+ [; @
                          set y  Dep / 2 * p% ~, H& q/ S$ z+ _. B3 I
           set b  int (who / 5) * 5
5 j$ _$ C* _* `$ ^    setxy ( xcor-of turtle b + x )( V! ~3 u' M5 N6 D
          ( ycor-of turtle b + y )]]$ E3 G/ s1 r0 o' }5 C
end0 @/ C  @+ M, z0 B
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-31 23:49 , Processed in 0.019660 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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