设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8257|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
4 B+ E0 B6 A! }: g
+ B+ B- F9 b7 }" X' Q( C但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
& z6 f+ Q% f- U: \( H4 H" f
8 b# i. \  ~0 x! @+ F6 Sturtles-own [a b c d k f g h
7 ^- s1 t1 @% F: k& q( W( V, x  x y     ;; these are the leaf-turtle's offsets relative to center-turtle $ j- @0 g( U! v( t; R6 [
]
/ n' x7 D4 a  `" e! T1 Uto new1 D4 K5 h, i8 A5 N6 E+ j! ]
  ca
  b. c3 U0 h# c* d% j* k  crt 5 * num_of_building1 x) b8 S* ^, n# Y* K
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]* \- F! ]2 x! n! V/ {8 e/ f
  scatter     ;;keep center-turtle random positions 1 @2 q5 A$ v4 a, ^. E# h
  unit_plan   ;;make up the building plan
) Q* E5 v/ F: D% g) p7 v2 y1 Rend# E/ A% Z2 _6 J+ a9 y% a
to scatter
0 O: x" @; s8 B' T" task turtles with [remainder who 5 = 0]
: b8 v! N5 z9 ^' L  T0 q$ U( y[
5 B( |- z) f8 F$ W8 X0 oset xcor xcor - 6 + random-float 15- i  D. q- i3 S, D% A: O* E! }
set ycor ycor - 6 + random-float 15% }) [6 a, W# v3 h( |# b9 F
]
  p, u  v% |( q. z2 ^2 a' Jend7 v. e8 w  B, S
to unit_plan
6 A1 `  [8 `  D" r/ @0 Dask turtles [' @; p5 D/ g* J
if (remainder who 5 = 1) [set a who
! O4 D4 i. i9 r" r, V( j6 s7 n/ c                          set x ( 0 - Wid / 2 ) : R% P" \2 i* B3 _  O
                          set y  Dep / 2 ]
3 P4 [: T) Z6 R1 l$ y           set b  int (a / 5) * 5
, L6 b7 q5 S' o2 h. g% i# E    setxy ( xcor-of turtle b + x )
9 T* p2 [9 j& r6 Y( ?2 g1 S          ( ycor-of turtle b + y ). K3 ]6 j: u$ L% {# I
if (remainder who 5 = 2) [set c who
& Y: x  o' }# N                          set x ( 0 - Wid / 2 )
8 o8 O6 @9 L2 w# c1 i                          set y (0 - Dep / 2 )  ]
# P6 j' z8 d8 {" h4 G                          set d int (c / 5) * 5
( `8 ]5 z3 e7 u9 i' g6 K   setxy   ( xcor-of turtle d + x ). |! q! G! j2 t, c, e0 \
           (ycor-of turtle d + y )
- ]' W+ z' R  h2 w! ?          * m& U& P/ u4 u2 i) N3 T' T+ h
            / W9 N4 c2 I$ H7 ?: [- w
if (remainder who 5 = 3) [set k who) p4 w" [1 m1 C
                          set x( Wid / 2)  
6 y2 O2 J8 z5 i3 E3 z3 P, g                          set y (0 - Dep / 2 ) ]  d. B7 S2 i( v( b& P0 q9 U
                          set f int (k / 5) * 59 I* ?. X  R6 O8 H: x
  setxy   ( xcor-of turtle f + x )
1 h% v0 X/ P+ m8 x' P, D( d           (ycor-of turtle f + y ) & R8 q7 O! L0 A, r; C
           3 X+ Z+ _' d# q, O; [
           
2 U1 B: z5 M! b0 Gif (remainder who 5 = 4) [set g who
7 |9 ]" k. V7 ^/ y! n                          set x Wid / 2 7 u; N& S% }9 l6 m; w+ L2 F& ?
                          set y  Dep / 2 ]
4 E4 O8 `5 B: d* o                          set h  int (g / 5) * 5
$ B( m  E; K; I  setxy   ( xcor-of turtle h + x )3 D  c5 F: ~8 x- {
           (ycor-of turtle h + y ) 6 ]+ ]/ k7 B. h6 e* i
                          1 S% ^7 P6 W3 {. T* d; v2 [
                          7 ]- S; C/ K& J' g
                          ]( K3 K3 a2 y, t  O2 y# S
end
1 [' L! [" S5 i
: m3 h; @9 u0 c0 h0 c4 B[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,5 \: u4 K# |* {( q! |+ \
应该是( Y5 C$ S5 y" `9 z$ C
ask turtles [& _6 f. S" I6 ~2 r7 v4 P. u/ e
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 2 G; B. }9 C* p8 B9 m* @
                          set y  Dep / 2 " M, |9 i; I' o) z% O3 N* m& s  ]$ T
           set b  int (who / 5) * 5
, @' p( D0 a- ?, o/ Q    setxy ( xcor-of turtle b + x )+ M- t4 l/ H2 S5 m3 [
          ( ycor-of turtle b + y )]]- b8 d, Z  a+ f9 L- `: k
end" k0 y5 n2 V/ w$ o
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-25 17:32 , Processed in 0.018429 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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