设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7699|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。2 J0 h; M4 ~+ X4 j

* X; p* K/ A) _5 e; w+ f但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。* G) m* H5 B/ L$ e& n

$ f6 t& [; e/ W8 u9 R0 Yturtles-own [a b c d k f g h6 m/ V8 O2 T/ I$ @
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ! f! \; @* f* C8 z
], Y9 ]: J0 ?& ~/ s  E: y* D
to new
2 {! O- l8 l! q8 Z; W3 d  ca
2 a' {3 V2 W4 P  ~  crt 5 * num_of_building/ d+ ~: T; O2 B' |; T0 O$ S
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]], H' o; I- N1 x7 R$ G/ ?
  scatter     ;;keep center-turtle random positions 2 f* T9 E. J$ m9 W
  unit_plan   ;;make up the building plan
# B$ [$ E/ h, D. Z$ Dend6 `+ `7 m* [' Z/ p& ^
to scatter5 C4 T6 [. S% b8 G* B
ask turtles with [remainder who 5 = 0]- _8 P2 I$ ~) [3 ?  m; w
[
& u' T9 Y8 M5 h$ X8 x) c0 Cset xcor xcor - 6 + random-float 15
* M1 }- @0 }. |  i( Eset ycor ycor - 6 + random-float 15
5 k; s3 E% P$ m+ N]- v+ S$ c3 u" G# n4 D) a7 v
end1 G5 T/ N4 `5 z9 E& D1 o
to unit_plan 6 U! }& ?' h4 `4 ?8 ]. o
ask turtles [
& R' {+ G. U1 ?2 Q7 q* \9 Nif (remainder who 5 = 1) [set a who , S# H7 V" |9 u/ F5 i1 L9 V8 ~8 g
                          set x ( 0 - Wid / 2 ) * C3 T/ S) g& q+ x
                          set y  Dep / 2 ]2 u5 G$ T: U6 G6 g9 ~
           set b  int (a / 5) * 5
- b/ b3 I4 F) d. A6 e. z: k6 f. j    setxy ( xcor-of turtle b + x )
1 [0 {, @0 i) b# l. Q- O9 A3 x: G( s, g          ( ycor-of turtle b + y )
* g6 O; t: i; F+ zif (remainder who 5 = 2) [set c who+ I9 H# d3 e# P% t$ z' T
                          set x ( 0 - Wid / 2 )
/ _7 v* ?# S: w7 _, E8 [' {: T                          set y (0 - Dep / 2 )  ]
, b8 r- z2 h$ b4 Q! m9 g                          set d int (c / 5) * 5+ q1 H" |, n% B4 l7 K! |( u
   setxy   ( xcor-of turtle d + x )- @: c5 u- w' I$ g2 d1 |
           (ycor-of turtle d + y ) 9 a; F' n% z% u5 G" m
         
# u& g7 e5 N+ E9 [! L  G            + V# K! r9 j1 M6 a( W/ q# P: C5 K( R/ e
if (remainder who 5 = 3) [set k who/ @4 A% n9 G5 p0 ?/ m) ]: r$ U. ~2 r( m
                          set x( Wid / 2)  ; C9 ~1 C% S3 X4 m' u$ f
                          set y (0 - Dep / 2 ) ]
, t5 C* I: A" o' w! i! Z                          set f int (k / 5) * 55 Y2 ~+ R  _  F+ W& Y8 f
  setxy   ( xcor-of turtle f + x )
! w) o# L$ P. m( U           (ycor-of turtle f + y )
7 y  b: }, Y$ J2 `* ?- d3 m           9 N, {% b* Y1 d/ y, y( \% o
           6 Z; Z* s  F7 h
if (remainder who 5 = 4) [set g who4 i3 Q  u# s6 b! E3 o
                          set x Wid / 2
9 {) M* r' W  z  ]# f& I                          set y  Dep / 2 ]
7 k1 m. h* I/ d0 P$ j                          set h  int (g / 5) * 5& N2 o' K2 D, F! N2 g* X
  setxy   ( xcor-of turtle h + x )
3 B- U9 y) Y) C# n) L6 g6 P9 {           (ycor-of turtle h + y ) & p7 o- @" q( o  S- j6 |
                          % V  ^2 i* S" f/ K  J
                          - N0 |: Z3 O* \. U9 f! A0 e) v" I
                          ]
' [0 Q* M; J. [8 Bend
6 d, C; u/ e0 b- n) f2 J
6 M& e* A- ~8 r6 r/ z[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
" E0 P" E5 V  {0 E( L应该是; Y! o8 P: U9 H" i
ask turtles [
5 L, Q, E- z' m  J7 _7 V+ Wif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) , T- n8 \+ y6 |/ [+ v. O/ A" p3 l
                          set y  Dep / 2
# n7 y/ M- ~- o           set b  int (who / 5) * 5
1 b3 o4 d( M( D4 K  q    setxy ( xcor-of turtle b + x )# ^/ w* A; S! d9 v
          ( ycor-of turtle b + y )]]9 v" j9 r9 \6 |; e; L. i
end% s8 R5 V& M5 ]5 y. z( P
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-17 15:50 , Processed in 0.013467 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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