设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7975|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
: Z5 M1 R4 G+ E: l
9 |6 u8 P7 g; }8 O但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
/ K4 L/ z% A" X0 K6 v5 J- S
+ U) H% s& t- Q: S( Z) j* Kturtles-own [a b c d k f g h
6 k6 ~. J3 i* G, j( l& D  x y     ;; these are the leaf-turtle's offsets relative to center-turtle & h0 H2 F- t# T2 O
]
0 U9 n) |( X7 o% {to new
2 F/ o1 X! e$ |4 g  ca
" {' L4 B2 u5 p/ {  crt 5 * num_of_building% e- y& ?" o% n; k
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]], c4 b5 N; j0 ~5 ^
  scatter     ;;keep center-turtle random positions
2 ]& Y: c' t6 ~6 @$ \  unit_plan   ;;make up the building plan, Y, @* T5 S8 C1 M
end
& P/ \! A) R' ^8 X8 Y5 Rto scatter
* F+ s3 M8 Z5 F6 o( kask turtles with [remainder who 5 = 0]
* O+ S, I" P  C0 K, S+ L[( y$ e; D, I& |* q7 T0 r
set xcor xcor - 6 + random-float 15) x' ~& Z4 l% ^0 {6 P
set ycor ycor - 6 + random-float 15# N( }$ _8 P. a# b9 _" s9 b
]
  Z4 G! h+ b) O; ^& Z3 X/ s2 \end
3 R( o% B; u) ?- eto unit_plan
1 m& Y2 S: K7 }$ i2 e1 l3 c( e6 Nask turtles [* G+ Y6 P$ b3 e+ k+ \( |7 D
if (remainder who 5 = 1) [set a who
6 O7 d$ x* v; h% ?                          set x ( 0 - Wid / 2 ) 0 i0 }0 |" S- |# A
                          set y  Dep / 2 ]
! W3 t7 ~8 [& d           set b  int (a / 5) * 5
4 S1 T, F  S5 M* F7 `    setxy ( xcor-of turtle b + x )
1 a2 C9 v0 V5 D/ H8 r          ( ycor-of turtle b + y )
, o0 b' f1 G) {if (remainder who 5 = 2) [set c who+ V7 K7 \) O0 D( k7 {( o
                          set x ( 0 - Wid / 2 )
9 B. ~8 g+ ~' m4 V- M& V5 g                          set y (0 - Dep / 2 )  ]
6 s9 e: Q) U2 p+ l                          set d int (c / 5) * 5
) f' p7 O  H% c! M8 V' {- `   setxy   ( xcor-of turtle d + x )* u$ U, j! w" A. i
           (ycor-of turtle d + y )
, ?) p* ?1 L1 N' B         
, P4 ?8 h( |" ]8 A  U% k$ z4 W& K            
; Q4 q! N" j$ V' W7 z6 a7 j- Mif (remainder who 5 = 3) [set k who
" f& c/ n% l9 E- j                          set x( Wid / 2)  
5 |2 m7 w2 k/ W7 b9 d                          set y (0 - Dep / 2 ) ]
2 q1 |" j" e6 {4 R/ \$ W9 |                          set f int (k / 5) * 5( ^1 k1 C, _3 b
  setxy   ( xcor-of turtle f + x )
$ s* Q. i1 u5 w! a+ e           (ycor-of turtle f + y )
, w6 p: T$ o% h           
3 [  D# q. ?7 J- Q1 W/ Q  Q           
8 j5 J/ s1 c: D: a; |2 kif (remainder who 5 = 4) [set g who
9 v$ J  b/ e, @9 x" X# c                          set x Wid / 2 5 Y3 Y1 Y6 j% B) F. F* ]" u" L
                          set y  Dep / 2 ]& T; f; ]' B: g) J( k; l
                          set h  int (g / 5) * 5
  s+ u8 U( }; P: k1 K4 }8 O  setxy   ( xcor-of turtle h + x )" S. ^4 r( M# P
           (ycor-of turtle h + y ) 9 Z4 B; a) y! z' N- C+ T
                          
$ V4 |+ j- g* ~+ f: v0 X/ `                          
2 p( L! U' M- c3 W( H- R                          ]
/ F& W# i; u( ?end2 T* Z3 N+ c% ?- \8 ^. U. |

" G7 d4 H3 Q; b* C: S/ p/ j[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,3 Y0 {8 B$ s* K9 Q/ l9 t: K2 k
应该是
2 l  ?: G; Q7 B4 n, ?& x( Eask turtles [( }1 i! j8 U' V& u
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ! J; `7 f- v8 z& `$ H9 u/ q
                          set y  Dep / 2
7 [/ g8 d- I* w4 C9 I, ]/ q( R           set b  int (who / 5) * 5& U6 a- Y: g9 |
    setxy ( xcor-of turtle b + x )
" x+ x8 |, o3 ~8 r          ( ycor-of turtle b + y )]]
, t7 ]9 Y# r0 D6 @! Oend
1 O3 ]( i, p6 r. p5 x4 Y之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-23 23:06 , Processed in 0.016958 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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