|
|
在这段代码中我设定了一个stopped?变量,初始状态设为false 。运行过程不能输出stopped?为true 。始终为false
( D6 e" k. P1 U3 W [0 m" tto go
5 b8 N1 x4 p( K5 S s+ Q( Eif not any? turtles with [not stopped? ] [ stop ] , I# t- W- p2 r
ask turtles with [remainder who 5 = 0] [
0 N( T* J+ g9 d4 I' w! t7 i5 y$ \set close-mates (turtles with [self != myself])with[0 X) [- }3 z- L
(abs(xcor -(xcor-of myself)) < X-Dist + Wid )
/ a8 m: z7 b Qand (abs(ycor -(ycor-of myself)) < Y-Dist + Dep ) ( h9 X7 l! |( q$ r, B, P& v
and remainder who 5 = 0 , g; L4 ^' r# a! P9 ~5 o( X
] & w, q" ^: Y1 U2 i' D
ifelse any? close-mates
! w* L/ M8 }3 ]2 W6 T1 X[ / A: S0 ^ E" A7 r- k4 j
set closest-one min-one-of (close-mates with[self != myself] )[distance myself]; Q$ u) T0 r* t' t; X& V
face closest-one# B3 Q6 m" O% z3 s6 W$ s
rt 180& v8 m! O& T0 J* N
fd random-float step-size3 a! C7 B! d' d9 Q5 L
avoid-walls
" X6 p W/ {+ _$ [8 e# Gset stopped? false]2 V% ], q# L# @
[set stopped? true]
: W. b9 Z D1 J( a] |
|