|
|
在这段代码中我设定了一个stopped?变量,初始状态设为false 。运行过程不能输出stopped?为true 。始终为false& r& o, a8 Y1 T) Q ^% [9 s x
to go7 V( R$ h9 b+ d
if not any? turtles with [not stopped? ] [ stop ]
- b3 ~4 C/ U8 g4 m4 Wask turtles with [remainder who 5 = 0] [
+ y0 M1 e+ K: qset close-mates (turtles with [self != myself])with[: _5 z6 a; P2 L, ~
(abs(xcor -(xcor-of myself)) < X-Dist + Wid )
+ `$ b9 D5 r( Dand (abs(ycor -(ycor-of myself)) < Y-Dist + Dep )
, K. C5 o+ g3 Y5 p0 x- Vand remainder who 5 = 0
1 p. p& E) y( F l]
1 h0 ^0 Q# Y; g5 Q$ Rifelse any? close-mates ; d/ o4 x& o& l" k
[ 6 ]2 p' h# N# \& k$ X( e
set closest-one min-one-of (close-mates with[self != myself] )[distance myself]( Q1 I. ?1 R; Y$ D; F ]( k% x
face closest-one
( k& s: Y1 V- w* prt 180$ C; Z; ~. P0 x [3 l8 ~" H' h; D" L
fd random-float step-size; Y* t8 _9 U/ n" B& M
avoid-walls
. t; E3 q- ?+ ^' S* b' y- Uset stopped? false]: Z; Z U; B" _, ^* Q( {- H
[set stopped? true] 9 M% T, t/ L$ |1 ^! q$ z' w
] |
|