设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7629|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。8 b3 o2 X# z5 J- y( H" r) Q9 K

; @/ D" F9 N( Z: |但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。+ B+ n; x' h$ R8 j. i
  L8 w* N$ s3 N; W' j" r
turtles-own [a b c d k f g h. m7 I( T8 F8 c) a9 |( y. R
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 8 B4 _" {( k3 V
]
7 k- K! I& i; ]( d  w" ito new5 l( X8 `1 [& B6 s
  ca
. h4 n: [$ d4 h: ~4 w  crt 5 * num_of_building: a0 G) d8 O  r/ _  J2 e+ @
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]! o1 g  l, z2 p/ c) f
  scatter     ;;keep center-turtle random positions ) i- P( U/ n* w( c' r
  unit_plan   ;;make up the building plan  T: d! v. I/ M% t* T- v" L" a
end
) B! o2 m9 r& j) K5 F$ fto scatter# j" C. [1 d" u2 Q
ask turtles with [remainder who 5 = 0]
9 R0 p. I' u8 x7 O) x- D[' M5 v" p/ H; R6 v6 d  a
set xcor xcor - 6 + random-float 15
' ]4 c' V* R* F! o$ T3 K8 i" uset ycor ycor - 6 + random-float 154 L" X! K6 y; D, o
]
9 O% ^1 k9 r: t1 u& g  i. wend
, k6 _# l+ x. F% p8 o7 hto unit_plan ! l+ b" }; m4 p, _4 ]
ask turtles [
* ]8 b7 M8 @7 ?, Vif (remainder who 5 = 1) [set a who 6 g+ N7 P1 N5 ^2 W/ E
                          set x ( 0 - Wid / 2 )
. r. C: Q9 V) K% S+ M  d                          set y  Dep / 2 ]
  c1 Y$ b! W+ }8 H  @- L5 f' m           set b  int (a / 5) * 5
1 p4 n; _, w4 ^; _! |  b& R    setxy ( xcor-of turtle b + x )
0 Y) U3 C- u0 [8 c: n; j- F# @          ( ycor-of turtle b + y )5 C' W4 O" W6 y. j$ q- I! A
if (remainder who 5 = 2) [set c who' L  Q& l& d6 Q( U# |2 ^
                          set x ( 0 - Wid / 2 )
# F7 C, l. |; e9 t. {/ K                          set y (0 - Dep / 2 )  ]
$ C2 t+ U# L1 r& B4 j. I                          set d int (c / 5) * 5
8 d4 J6 L5 R0 t  q' o9 b( b   setxy   ( xcor-of turtle d + x )% }1 d+ w) c; S5 A* E
           (ycor-of turtle d + y ) 8 d. R, q# t- V, v7 P
         
3 V. y& s* s" k" }, E            
9 ^( t& p5 X9 P2 d6 \if (remainder who 5 = 3) [set k who4 i& q# T$ x0 j) N8 U& G7 G
                          set x( Wid / 2)  7 U3 U$ X/ R! M$ E
                          set y (0 - Dep / 2 ) ]8 o9 |  l( M/ s9 @
                          set f int (k / 5) * 5
# l& l# q3 w& }; R' }  setxy   ( xcor-of turtle f + x )8 x+ Y. a; z/ c+ x  Q: L0 Q6 C+ N
           (ycor-of turtle f + y )
8 w/ A7 l0 ?2 y0 T           
& R2 @  i' U) M1 m6 J5 I           6 \  o9 S$ J" ]
if (remainder who 5 = 4) [set g who
( K' @4 @7 u: a                          set x Wid / 2 . f' T0 b3 h. o7 I* c! P' |$ i/ K  k6 Q
                          set y  Dep / 2 ]8 ^$ W) ~7 a4 {# J) Y- L5 Y' \: e; U
                          set h  int (g / 5) * 5
/ T  P& {4 j' M4 G  setxy   ( xcor-of turtle h + x )5 F+ x6 {4 j: [6 o' C
           (ycor-of turtle h + y )
8 }, j8 d7 O$ \+ i& l$ L                          3 E! y- m9 a0 w( s2 ~% L5 v) c
                          2 G4 z+ U+ j4 X0 Z6 [& e  t
                          ]
$ z4 M4 h5 g  ^# c/ ~- ]end' ]! B* l. M$ H7 `

  b) P4 x0 @# ^9 v/ p[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,7 C/ F+ n! }1 s! o% D$ B
应该是
" B8 _: \9 _) K* C. y0 Nask turtles [2 c5 x. S/ {% W9 a
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
; b- M! ^! ~( |+ u- L# J6 N1 t                          set y  Dep / 2
" h1 `2 Q3 n( l7 d/ M, L. U6 o           set b  int (who / 5) * 5
9 m1 ~* z) s$ ^: J1 O1 M. N- h    setxy ( xcor-of turtle b + x )4 r; z6 }6 J! j& k+ U
          ( ycor-of turtle b + y )]]2 P/ k& T: r& X7 Y6 `, z. }% r( H
end& e$ d0 \+ k+ G
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-8 11:27 , Processed in 0.023423 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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