设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7626|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
4 L# h4 @% Y3 C& p/ w5 Y+ L/ y
$ Z# k7 a5 N( d4 G; F但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
/ q' h! e7 S5 z+ z2 i2 T. i: \8 C3 I2 @$ @" p; M- X
turtles-own [a b c d k f g h
  Q: m1 ~7 X( T$ b) d/ U  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
: L* N( i7 m4 y/ P]0 R2 [5 \. \" b, \5 N
to new9 I. S6 n: I7 S  Y
  ca
% t1 T' I: ^9 O8 e  crt 5 * num_of_building: r( j3 N: Y  N' k5 X! N0 c
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
4 i" L8 W, v( Q% a) N* K6 n! H  scatter     ;;keep center-turtle random positions , T  U4 w" j* g% x' D6 ]4 R2 U) |
  unit_plan   ;;make up the building plan, E: f' j8 }/ r3 W
end
6 M5 m  [  D7 G5 L  {& R  [to scatter
/ m4 V1 z# V' i1 H' f; qask turtles with [remainder who 5 = 0]& W4 p, i3 m. g# J- G
[! ]% c1 V$ ?5 i( F; z9 a
set xcor xcor - 6 + random-float 153 [' F% u# y+ Y9 [  \! P' R" A
set ycor ycor - 6 + random-float 15
! Y6 {# [$ [9 n  P9 B+ r/ u! s]* D! k, ~5 G( G) [" F0 K" N
end
2 @0 K$ h( m* f$ tto unit_plan - M0 P* P9 T7 Z) U. B5 y
ask turtles [2 I) v' Z3 I' ?* p3 V: t: O# A' {/ U" ~8 M
if (remainder who 5 = 1) [set a who - Q- n2 O5 j4 Z6 g2 [7 ?
                          set x ( 0 - Wid / 2 )
3 J1 d. C; z5 J  o7 j0 K" B! A, m- s' @                          set y  Dep / 2 ]
4 f& J6 _- I$ T4 X           set b  int (a / 5) * 5
; o$ H" m+ `+ G4 @1 Y! O1 v2 L1 m8 ?    setxy ( xcor-of turtle b + x )
3 B: y! N# V; |/ _          ( ycor-of turtle b + y )
- K* i: J) U, C; T9 ]' xif (remainder who 5 = 2) [set c who
; I. d5 \- e( a) @                          set x ( 0 - Wid / 2 )
) }4 u4 Z8 f; r& r$ U                          set y (0 - Dep / 2 )  ]$ w! Y- W$ T  }$ e+ }+ U
                          set d int (c / 5) * 56 p2 s! I8 `' {
   setxy   ( xcor-of turtle d + x )1 l5 b( L4 V* ]0 p! N
           (ycor-of turtle d + y )
' {+ C: v/ c7 c9 S( @          3 V2 Q' F' N; z& `
            & `. N" L2 d, C( C
if (remainder who 5 = 3) [set k who
& ^) ]+ U. ?+ [/ \4 r! z+ ^                          set x( Wid / 2)  
1 ~. n# t4 Z% }; C! ?. C( b0 u                          set y (0 - Dep / 2 ) ]
* r6 k0 }5 e% H                          set f int (k / 5) * 5
: d0 T' Q. }7 i  setxy   ( xcor-of turtle f + x )
% _* T4 N1 H$ Q: B  B+ Y* W3 f2 q           (ycor-of turtle f + y )
. s; d; N  I/ R) e! _) o& Y           / o) O+ v5 P* u
           
- R3 D3 B% i' J  G0 Wif (remainder who 5 = 4) [set g who
6 E3 p* v/ D! T2 I4 Q                          set x Wid / 2 * q7 M, S4 q0 S
                          set y  Dep / 2 ]
# D6 C" f9 y/ s3 U                          set h  int (g / 5) * 5
5 x" }( B0 g* G: ~% ^% {  setxy   ( xcor-of turtle h + x )
# w; E6 \6 {9 y' S) |           (ycor-of turtle h + y )
; H4 R  ^+ k" D  t- b9 k                          . |/ ~- S+ j+ r* m0 D. Z2 r
                          
+ R0 {4 s1 c6 n( Q                          ]
5 A) J* Q3 b% }/ Y- p. b( _$ D, S! Dend
3 `* Z6 N) o3 z+ j  G+ n7 R) N$ O% B$ e; ^
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
7 u; C+ [' |) _, C1 b应该是
. k: X, Q$ o) h# xask turtles [5 @; r, ~( y9 h1 v
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
7 o' P% h, F6 E0 I3 I! i                          set y  Dep / 2
. R% {8 l& i6 e3 x' b( U" @/ [1 I           set b  int (who / 5) * 5
! \5 h# L: B  n9 c: v    setxy ( xcor-of turtle b + x )5 E; s/ |) R# i" A7 l
          ( ycor-of turtle b + y )]]
2 S6 h& d" B4 S& y; t: Tend/ x& h$ x& t! U. K4 L
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-7 19:58 , Processed in 0.016576 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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