设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9044|回复: 1

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

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

% n; r& ?0 H& G/ T但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
) G5 ?* Y4 f5 U# r$ X) {6 d3 r5 h! Q& S( g! U' L
turtles-own [a b c d k f g h
4 c& Z3 L$ f# O  x y     ;; these are the leaf-turtle's offsets relative to center-turtle & ~# o2 K1 ~9 G! E8 T* j& B
]2 L( M; A: S3 m( l" i
to new
% A5 `. w% G; ~% G  G  ca( N+ |; u& h  I  h( p( d
  crt 5 * num_of_building
' b: w0 Z2 O/ K  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]! l1 @0 R. ?; r& ], o, E; b! S7 g
  scatter     ;;keep center-turtle random positions   A, r% t8 \# v2 P" P" s
  unit_plan   ;;make up the building plan% q+ z" ]/ H# a  j
end9 u) P$ M8 d3 T$ m) p- i8 e
to scatter+ M4 f/ y# @4 `+ N/ h: f
ask turtles with [remainder who 5 = 0]
5 s4 p+ j$ u6 y+ H# B[
8 `7 n3 {: J  O! M: u6 O+ tset xcor xcor - 6 + random-float 15
, K. h) W7 t2 s) Gset ycor ycor - 6 + random-float 15" H' U' _! @! O' M
]9 e" ?; J1 g1 a5 H! B3 L# b
end/ m2 P; l8 {! Q  B
to unit_plan # O; k; E- m- N
ask turtles [/ h+ z0 t8 O+ v5 m1 f2 M
if (remainder who 5 = 1) [set a who ( q. P+ ]# w& }5 Q8 m; n- A
                          set x ( 0 - Wid / 2 )
; P. R& J- S: ^2 {) @  Q                          set y  Dep / 2 ]2 a' S. B7 z$ y6 N+ Z% R
           set b  int (a / 5) * 5
6 z5 K+ |% c$ w    setxy ( xcor-of turtle b + x )
! Q- k' P" n* j          ( ycor-of turtle b + y )5 l# W+ ]' ~" s- ~2 K
if (remainder who 5 = 2) [set c who, N( Z0 ?- z& X, N4 }
                          set x ( 0 - Wid / 2 )
& N7 t% Q$ r) U9 t( L% K1 X' b' @8 J                          set y (0 - Dep / 2 )  ]5 f7 f6 T3 ?/ N  l3 w( n8 c  ?( x
                          set d int (c / 5) * 59 _: F. b8 {6 F( q* }0 s. Y! x7 R
   setxy   ( xcor-of turtle d + x )
. G) i2 |: R* V. M) t% J. L           (ycor-of turtle d + y ) 8 ]9 C# W1 y9 U: T. |+ H  k
         
4 O8 C1 f4 ?' R7 @8 H            
9 u+ H* e: o/ r3 vif (remainder who 5 = 3) [set k who4 L& f/ [0 Y+ _- {& v7 a
                          set x( Wid / 2)  2 j& i% j% E7 g- z! d- d
                          set y (0 - Dep / 2 ) ]9 K  k! L5 u7 C& [
                          set f int (k / 5) * 5
; C$ A, W: r0 [) t8 Z( g6 [3 L  setxy   ( xcor-of turtle f + x )
4 w4 c; G; M9 Q- [! N. N$ q           (ycor-of turtle f + y ) 0 u& R- z) x% _  ]
           . W8 Z; x7 y  |9 v8 Y0 O
           
2 r) \8 K: T( e0 u) oif (remainder who 5 = 4) [set g who* |3 \3 }! I; h; V8 d# r# s! }) v
                          set x Wid / 2
+ @8 ~8 C% E- i                          set y  Dep / 2 ]& a4 L3 C2 |  W: T' W
                          set h  int (g / 5) * 5
: t* \  v/ }% f) D  setxy   ( xcor-of turtle h + x )
+ }) `& @. p6 g7 S) F' k           (ycor-of turtle h + y ) 2 z( f4 F7 V5 S% G( k
                          
) o- _4 p2 b7 ^( a9 _+ D                          5 [5 M" P  {$ k+ ^
                          ]
' N2 ^: d/ a0 u/ Xend
1 z6 T% Y4 E( v: w. D" P% K) A: V9 W: z
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,/ a6 b. P- Q' Y- Y( f$ O
应该是
/ x$ _9 M% T& P: M0 ?+ Task turtles [
) N" B2 q/ D/ Fif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
2 D" u, F9 `' C                          set y  Dep / 2 4 e' `2 p) G6 s1 ?" F5 n: e
           set b  int (who / 5) * 54 Q2 U  x! [1 U7 b& K
    setxy ( xcor-of turtle b + x ), T3 d7 `4 o% W0 G) E$ B
          ( ycor-of turtle b + y )]]9 c; u0 o% N* w5 t+ _6 ?( p$ b
end
3 G2 s6 J- v. z* R# @1 C之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-11 13:39 , Processed in 0.017844 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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