设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8221|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
2 O$ j1 r" p. m0 G9 h$ X% F. q9 W0 t7 u5 G
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
8 h0 U+ q4 T6 m% [1 k! @$ W% h' S/ G3 P$ Y; u
turtles-own [a b c d k f g h
; l. R$ V/ A. |4 R  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
7 Y- D$ N( C; K; q) `]$ i- a! N" n. T! S$ i) v+ N
to new3 S$ s  `9 w8 R- B
  ca
3 W1 X1 S$ c1 |  crt 5 * num_of_building/ r5 R4 j  J9 m: X7 H
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
4 M/ p/ t  _" U% K- w' G9 E. ?  scatter     ;;keep center-turtle random positions , w1 w0 s& Q% V
  unit_plan   ;;make up the building plan5 U* M! U( F( h2 `4 e
end3 `" ]# D6 {2 R
to scatter0 j6 _( P7 y( Y7 Q; |+ E' F6 ~
ask turtles with [remainder who 5 = 0]. c9 H7 K7 [5 T8 e1 R
[
9 J* f4 G* Q8 P/ `) tset xcor xcor - 6 + random-float 155 {( `) j! I* u9 Q! E( r5 Z/ ~
set ycor ycor - 6 + random-float 150 |" n  f4 o; I4 w9 w' h+ t
]
1 h6 {" Q# B) v$ Hend; X/ p6 M- i) V5 @: s, U8 A# b
to unit_plan
' Y. @4 q9 v# X# P5 R. Q7 P6 n  {ask turtles [; E; Q3 ~1 }) l
if (remainder who 5 = 1) [set a who ' m4 _6 ^3 J# u. k$ G
                          set x ( 0 - Wid / 2 )
, X8 Z% h& N/ b9 G' m                          set y  Dep / 2 ]
4 S4 N" C  Q9 p( r           set b  int (a / 5) * 5
8 t5 u4 s9 y# E, h    setxy ( xcor-of turtle b + x )! ~4 u: J/ @% |5 u8 ^# M
          ( ycor-of turtle b + y )* ~. f$ w, F1 X; V5 Q, P
if (remainder who 5 = 2) [set c who
% X8 u" E; o# D8 `7 T8 D* b' H" ^                          set x ( 0 - Wid / 2 )
, Q. @, ^4 E4 d) p4 I                          set y (0 - Dep / 2 )  ]* y5 v5 }) ]& U) o
                          set d int (c / 5) * 5
6 E' o1 x* Y& B! }   setxy   ( xcor-of turtle d + x )
' U: z6 {/ R# T" L+ \7 i  i           (ycor-of turtle d + y ) * Y" x4 I+ `# `" }6 k6 _
         
$ k3 ]$ S) ?, ^! z            
' n4 w+ _) h$ ]. uif (remainder who 5 = 3) [set k who+ s6 O8 `# h  V! u* H
                          set x( Wid / 2)  
3 f& V( {1 G0 a( B) |                          set y (0 - Dep / 2 ) ]
% ^+ `# D. Y) S( k& Q3 s                          set f int (k / 5) * 5% ^, |, S$ L# [9 }3 e) U4 t
  setxy   ( xcor-of turtle f + x )
% @0 ~6 d. v3 I% P           (ycor-of turtle f + y )
: ~9 I1 M) y$ v- n1 F1 \           
3 h& m. B3 R/ Q2 e  S           
7 `; E: p4 e# x/ Q2 A( I& {if (remainder who 5 = 4) [set g who5 `! [0 a2 @8 B8 [1 L
                          set x Wid / 2
3 n; ^; e# \. n5 b0 F                          set y  Dep / 2 ]
* a' |0 O1 }8 P' q! [* z2 T                          set h  int (g / 5) * 5. e$ K# x" h/ ?1 F7 O5 t' Q
  setxy   ( xcor-of turtle h + x )% }& ~3 O" Y% z$ j
           (ycor-of turtle h + y ) * T/ N$ }; l9 N
                          
5 A$ t6 R- P; Y                          - B" Y0 g4 d1 \" O% V. [
                          ]
3 M6 S4 S3 U( s, aend
; N1 A- }4 ^  y) V; w  o) K" ?' A0 _, w+ v6 o
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,8 v4 k" Q9 ?7 ^- d9 `
应该是6 }7 @  L" M6 e. V6 q3 t* X
ask turtles [
2 O; E7 j: J  |2 h6 N$ Q) _if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
9 K# \0 a2 Z' u* ]                          set y  Dep / 2 0 d( Y, G4 s" E; w4 J
           set b  int (who / 5) * 5" o' C6 e" u( l% Z
    setxy ( xcor-of turtle b + x )
% L: v, x, f/ f) Y) a, s          ( ycor-of turtle b + y )]]1 O# v& c& o$ X6 E& S
end, E. @4 K' o$ f+ P& [5 j& n" W
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-20 17:41 , Processed in 0.017970 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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