设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9058|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。! z2 q. S- R% R7 _) z4 L9 n+ }5 S
% \5 u; ]/ e; e8 [1 J& \; l8 v
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。$ Q: c5 D" C5 Z1 r9 b
. O9 w5 N, |: ?/ t" |- Y( O
turtles-own [a b c d k f g h. D0 M  O& q" l3 C7 d2 \/ R
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle " t# h, u2 D. f9 Z' r
]
. M( _) E; ]; w! j, U+ T( r: [to new, K: \1 B, `3 z2 w9 p) B+ @' U) g
  ca
; I7 {- P7 E7 S) A. J4 q  crt 5 * num_of_building
6 N( F9 T0 G  ?9 o  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]  T! {7 q# X5 P& K* f
  scatter     ;;keep center-turtle random positions
0 N6 }4 B' ?. E" q  Q  unit_plan   ;;make up the building plan- G( f" y; m: F, x6 d/ \  G
end
% W$ ?, `9 N1 S1 y1 {3 F. jto scatter
1 s4 l1 a# Y2 V6 Qask turtles with [remainder who 5 = 0]
& |0 Z9 J( h' ]$ q[/ G" v+ Y; p! z4 q
set xcor xcor - 6 + random-float 15
" X8 G7 d6 U. b8 mset ycor ycor - 6 + random-float 155 B5 g2 C6 m) H& C6 h% E, A2 u; K
]
8 j, T- v, u% S& x5 i7 xend
# `% a0 x% ]7 _9 s$ _8 x7 eto unit_plan % C! `) k2 R" }8 N/ A5 c: z
ask turtles [5 V- J6 z& V) U
if (remainder who 5 = 1) [set a who
$ B. J; v7 W4 p5 H; {& q3 q  T                          set x ( 0 - Wid / 2 ) 3 X: S0 |3 p0 q1 \) O5 d9 p/ z, G) P
                          set y  Dep / 2 ]
5 c+ c* M" M/ F9 {# o           set b  int (a / 5) * 5
, A6 L/ ^3 R! J4 ^; T7 x% ]; n    setxy ( xcor-of turtle b + x )& J# b6 z/ Y# M5 u0 w% B
          ( ycor-of turtle b + y )/ m) x2 w+ G  ?4 q; t! v$ u$ G. c
if (remainder who 5 = 2) [set c who" A7 \' B- J6 s* M  t0 o
                          set x ( 0 - Wid / 2 )
$ Y8 L$ Z4 x4 [+ z0 P3 F7 a6 n' y1 N                          set y (0 - Dep / 2 )  ]
! R0 F  |* R3 g8 ^: ]; L                          set d int (c / 5) * 54 r" g: l8 V) b" c8 y9 m
   setxy   ( xcor-of turtle d + x )) {; U# t  a+ C8 I) g* z8 ~: w$ c
           (ycor-of turtle d + y )
7 S% V0 s: d/ Q; `0 f          $ u4 |: U1 k, x1 {# Q3 [! C
            + F/ j0 c# d# |# x1 l
if (remainder who 5 = 3) [set k who& L; H1 ~# T  k
                          set x( Wid / 2)  
: ]: ]% \6 f: v6 Q+ w' Q                          set y (0 - Dep / 2 ) ]
7 X0 ~' g" q8 _$ q- y0 f0 |                          set f int (k / 5) * 5+ [  H1 N: l4 P2 E5 l" S8 `
  setxy   ( xcor-of turtle f + x ); x$ L3 S: a1 s2 b" x2 q0 |
           (ycor-of turtle f + y )
5 \+ m$ U' l" t0 ]* Q           
; g2 W8 `6 F% U, p% o% V$ A           : q1 @  |; M' X; `
if (remainder who 5 = 4) [set g who8 O) M5 f+ m) r2 I2 V0 ^
                          set x Wid / 2
! J) c0 Q6 ^/ S; F* a( b' w% Z1 M                          set y  Dep / 2 ]
- O1 m. M/ W! c1 Z1 L- t# r# r                          set h  int (g / 5) * 5. {$ q' b! g+ X
  setxy   ( xcor-of turtle h + x )- k2 V9 L: J+ z+ c; C! U' c  d
           (ycor-of turtle h + y ) 8 _2 s0 k7 G- [- L1 x
                          6 `6 @6 c/ K4 W) p% p9 K- E0 {
                          
1 c. m& v# b% X: \  x9 F% `                          ]
/ C  v# a1 x- s; }# L5 ?9 send  Q/ j& q) U9 C6 ~4 y

2 @# D$ E3 \- M2 d: a[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,# O: ~; b$ E, j9 }) T& d
应该是3 R( C' h& r; b+ B
ask turtles [
) T2 Q6 [6 _7 e' a+ u) Aif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ; h, b% Y2 V2 |; B! @
                          set y  Dep / 2 + e! z% l- p# e  X
           set b  int (who / 5) * 5% r8 {5 ?! I: }, m
    setxy ( xcor-of turtle b + x ); s0 V" a! u6 s% H
          ( ycor-of turtle b + y )]]
9 `# c6 ], c' Hend
2 h6 p  A1 Z0 g3 E之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-12 16:18 , Processed in 0.016882 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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