设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7260|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。3 \" p& z. `8 s/ N% A. i7 j
2 N$ a# ]& x: ?# o7 B+ W
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。8 g6 P! W6 Q6 c; @
& `% x7 [: c% E7 f
turtles-own [a b c d k f g h
2 z2 K; q7 e- w1 a% n. W% q8 }  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
  o* ^' w% I8 B% b8 V4 y3 \]
" r; L. k  M# i, B; s1 F$ C# b* Pto new
$ b. c$ R& F  b  G6 f  ca! U) r* E% c4 ^0 v( R- Y7 ?
  crt 5 * num_of_building( |$ \$ @/ a% [9 i- Y
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]3 U7 m; M# x: W
  scatter     ;;keep center-turtle random positions 2 \6 U& T  n! q, z) K( P6 h
  unit_plan   ;;make up the building plan1 Z5 T" t2 b# {5 v
end/ D# A1 j) I- q, |) S8 O; }9 ^
to scatter
& G( k6 {5 G, a0 Yask turtles with [remainder who 5 = 0]1 R6 l& e% v1 ?; t& U
[2 Q% [, ?1 \7 Z2 e* b  u
set xcor xcor - 6 + random-float 156 o2 i4 U& t( D5 j4 n8 r$ L( J
set ycor ycor - 6 + random-float 153 V% d& }" ]' ?* x7 Q$ I1 n
]
8 O4 I) ^) O; m2 A( lend
5 [. L: X/ }1 Q1 ^6 l5 fto unit_plan 2 p" w6 m8 \5 g
ask turtles [
# N" ?* B7 R. r* j0 Q" dif (remainder who 5 = 1) [set a who : \$ e" u, W9 Z( l/ Q' v
                          set x ( 0 - Wid / 2 )
8 i- g/ M- {7 A/ e8 N                          set y  Dep / 2 ], B% A6 c! v1 R6 e* Q8 j
           set b  int (a / 5) * 5
3 X5 |6 Q; W. W. c    setxy ( xcor-of turtle b + x )
8 |' {! U% y, H, M# i          ( ycor-of turtle b + y )
1 X9 X. N* P7 A% eif (remainder who 5 = 2) [set c who
1 H; W/ z- {, ?0 \+ f! t* N1 L                          set x ( 0 - Wid / 2 ) 9 a* Z" l, f. @' n4 B- _
                          set y (0 - Dep / 2 )  ]% e: W* O5 g8 z1 ^' ~
                          set d int (c / 5) * 5  z% o- _# i! ?9 f
   setxy   ( xcor-of turtle d + x )( U& @0 j0 ?/ N5 n
           (ycor-of turtle d + y ) $ O" d# l. g1 d/ x: m/ o- I. |; Q/ _0 E
          # T3 z. z& B# i: z' i$ |5 o
            
* _1 [. x6 d. ?+ ~7 I4 \if (remainder who 5 = 3) [set k who
1 L7 \7 p" k7 u+ s- g9 C5 \% a" a                          set x( Wid / 2)  
" t- o& Y4 d0 p. O2 Q                          set y (0 - Dep / 2 ) ]6 j" }* i& s$ v8 C6 W/ U
                          set f int (k / 5) * 5
8 B* i( p2 y. g0 q, c4 I  setxy   ( xcor-of turtle f + x )" j6 `: _' }6 V
           (ycor-of turtle f + y ) + r6 p+ x# H8 t7 E4 c& M
           3 k0 d% t, J; z1 y4 o6 a
           
+ p0 g. Z5 u5 |if (remainder who 5 = 4) [set g who( s& R7 y6 l6 i
                          set x Wid / 2
2 x' h% G# y# V0 ^3 l4 |# F$ [0 J                          set y  Dep / 2 ], O+ X" T2 {6 w* V) R6 S  j: @% a
                          set h  int (g / 5) * 5
. y) C( w' f4 J* [$ g  setxy   ( xcor-of turtle h + x )
# x7 |8 I. u! C9 C/ \( [$ m* p           (ycor-of turtle h + y )
! G$ c1 |; A1 [: N5 z) H9 {                          2 v7 Z7 S% F* c8 l3 u0 |
                            G+ j. r6 X7 F+ }5 W9 ?
                          ]. l% E6 [2 Q) o2 y
end* x! _5 ]  A- i( b! H8 H0 Y& O

* p- \$ Y$ `6 D[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,% a$ D6 s9 v4 J, Y4 @4 q9 a
应该是8 Q; o* q  L( S$ v. v* d5 c
ask turtles [
( g+ z. K9 M# @$ A+ c6 J* k, ^if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
! U9 l1 h: i8 a, e% A* {                          set y  Dep / 2 * v) d2 \# V4 n/ S+ s/ S( W
           set b  int (who / 5) * 5
4 R6 K) Z: T! P' T+ ?6 _" C    setxy ( xcor-of turtle b + x )
& |2 Z- r" B5 l5 r9 [& f: m, D% f/ W          ( ycor-of turtle b + y )]]
1 {! v8 B/ n1 _0 }+ F( Q! Send! K4 i7 e1 D; M6 f
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-22 14:08 , Processed in 0.019337 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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