设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8853|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
8 H/ n+ f2 s% ~/ R$ L
( k. v) @9 P/ X' t但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
1 c4 v* F4 @& p1 C# u2 s4 L/ Q/ g' n
turtles-own [a b c d k f g h3 h' A2 c9 m$ {
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 6 e7 Z, g: Q4 I5 y2 U. t! F
]
2 ]/ u4 C/ p. H9 g* Y, @: Wto new6 \$ k4 g; a1 q
  ca
9 i1 ?, {& N3 g/ J& C' I4 l  crt 5 * num_of_building
5 S4 R5 l: U+ f" d# T6 _  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]- c" C0 ]& f" `+ i
  scatter     ;;keep center-turtle random positions 1 v: m% v; ^7 A3 m. j8 l5 v8 O
  unit_plan   ;;make up the building plan3 V4 ~! j. U, V9 U$ }
end
7 U. D8 f6 i: ]' y" g7 zto scatter5 C: k. y4 Z* H: S1 q2 L
ask turtles with [remainder who 5 = 0], d1 H) R7 Y/ Z* f# K4 t
[6 R) k$ B+ h1 g6 y/ R$ U
set xcor xcor - 6 + random-float 15
3 e# C8 a3 b& U! q% Kset ycor ycor - 6 + random-float 15
$ j0 m5 k; Z# L6 x- F]0 d7 R! b5 r" g6 \5 C" |# `
end3 ]$ S, o* R6 G! m; }% w$ _
to unit_plan
5 z8 P! \0 b7 Fask turtles [
/ R8 C0 M; I; C' b9 p# H- Tif (remainder who 5 = 1) [set a who 5 f  H, @7 x7 i$ Z' r
                          set x ( 0 - Wid / 2 ) 4 k  T$ `# V; L2 t$ z
                          set y  Dep / 2 ]
( U' N9 T! k( Z" \" Y3 z5 H4 A           set b  int (a / 5) * 5( R8 h" [0 ]. q$ ~& `( l2 o
    setxy ( xcor-of turtle b + x )
) b6 Z% x9 x1 P3 u          ( ycor-of turtle b + y )8 `# ]/ a9 o" b4 i1 M2 V7 k$ o4 M! g# T
if (remainder who 5 = 2) [set c who2 O6 B5 N+ ^" m) Z; Q. }% Z0 i: x
                          set x ( 0 - Wid / 2 )
' l( Y. k0 f' k6 W, k( F' E                          set y (0 - Dep / 2 )  ]# D, `% E/ w- Y. D5 R8 X
                          set d int (c / 5) * 58 i6 _% C! g9 n$ h& n
   setxy   ( xcor-of turtle d + x )
5 F* Y1 r+ X4 x% A4 J           (ycor-of turtle d + y )
) ?$ f" n: J. Z7 e# v         
4 d& l' ^) Z. Z( y. G( C4 i- c8 B            : P8 c1 a) ~5 i' T
if (remainder who 5 = 3) [set k who
6 v3 g. ]0 V; C+ U( X# `# }4 Q                          set x( Wid / 2)  " H2 y- t% `4 _0 @) T: g0 h- e; h
                          set y (0 - Dep / 2 ) ]
, @5 h3 H: V$ \                          set f int (k / 5) * 5! {* \' t" L1 \+ I& C5 C0 t7 w
  setxy   ( xcor-of turtle f + x ), u' k) ~* N. Q$ A) \( {! W+ c
           (ycor-of turtle f + y ) 9 }& ], O7 C8 g
           
# Z5 |% H. I9 |           % {8 i8 L% s+ @, g2 x/ N
if (remainder who 5 = 4) [set g who* r; M' a% X( h, s
                          set x Wid / 2
4 j) |2 h+ n9 ?0 `  V2 X( A3 R                          set y  Dep / 2 ]! w3 A' Q/ c  `. i3 V' Z) ^+ Q
                          set h  int (g / 5) * 5$ p' z3 t- {& a
  setxy   ( xcor-of turtle h + x )
. X" B$ s' {" g0 u( s           (ycor-of turtle h + y ) 5 h- d9 j+ i8 s- y
                          # m' Z6 J& N+ ~7 E* |  u9 w
                          * ^4 ~% R& G/ }4 z  {+ ?6 A
                          ]9 ~* Q5 H6 G5 C( Z, g" U
end
0 L( j& }3 O+ C' z7 Y3 F/ o' V; W/ ^% d6 B' }& J
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
5 ^6 V% a& M4 p  W' _应该是4 p: ]/ Z! x3 q) t9 `- h
ask turtles [
0 \; C  @3 F  J, Gif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
$ D3 x- s/ z, V' m* [' h+ K1 n                          set y  Dep / 2 . Q" r7 g' T/ V0 \( o
           set b  int (who / 5) * 57 a( j/ l2 K+ h
    setxy ( xcor-of turtle b + x )0 ^; f/ T9 a6 M3 L  ]; f4 k
          ( ycor-of turtle b + y )]]! W7 T0 [7 S! M9 l( j  \) ]4 y: A
end
& i& O, E5 T) l" L$ q6 D2 _% \之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-11 18:44 , Processed in 0.014615 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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