我编的程序如下turtles-own [energy]
' [1 [5 c; V) c$ y2 lto setup
3 s; l7 h6 x7 S clear-all' ~% E" r6 c" C% p
setup-patches
+ v* M" g" `/ f3 t$ h create-turtles 1006 j9 c" k. w) k, ^
do-plots1 W) Z/ Q% j7 ^
ask turtles [ setxy random-xcor random-ycor ]
1 F& _/ B3 G3 I; {' @/ U5 ?. |end* B9 T& j. O; U/ k, I1 q6 w
to go/ Z9 N+ ~9 s5 R+ q+ {
move-turtles
) f5 A, y( H: c) r" v8 o eat-grass
) L' j0 y! _& C7 D2 D6 X; c reproduce, o" k- H% Y# _9 s0 |; Z6 h
check-death
* P0 o4 v- _5 m3 @6 `0 ]5 l regrow-grass) c/ P7 R- Z- Y9 B l% ?, B5 l
do-plots
$ a& X) g1 @) T/ N4 b) a% v) Zend( Z4 r, o: |5 }
to move-turtles) N1 W8 n# c, _7 K- ?& l: p
ask turtles [8 |8 B. A; e* c6 G
right random 360 Y @ D4 O t- J9 B
forward 1
1 m" v: p; z$ W6 Q+ i. E set energy energy - 1) C- q# B/ Q' |( J7 C1 C* {' ~
]7 ~' }. j8 }; I, ^
end
: e- u1 r; }4 s# L( q3 oto setup-patches
. V- F5 Z- o/ a. A* |" S ask patches [ set pcolor green ]8 `' s% p, \2 E; N3 V( M2 @0 H7 l
end6 h2 o$ [ j& }. f& a4 y
to setup-turtles! ~* H8 K7 V" C0 _- M) h. J* L
create-turtles 100
' Z6 i0 i& G$ \( e; d) d ask turtles [ setxy random-xcor random-ycor ]
, b2 E7 o# f; }) Fend5 O5 C6 B) {& h( E' L
to eat-grass' P- a+ S( s9 `# i4 Z9 J3 Q& o$ [
ask turtles [
2 N* Z& J* _$ ]6 ]; z if pcolor = green [
! ?$ L4 w4 B! h8 E0 _, W, _8 h set pcolor black; l4 F- i+ Z/ k1 \! X2 r
set energy (energy + 10)
3 t0 y3 |/ ~; k: @ ]
' [$ t6 J' @; P ifelse show-energy?5 ^; e( v6 @) _( m R# y
[ set label energy ]
% W m0 R; r& c: A( X2 x& X [ set label "" ]7 ^2 r, b1 B8 K% \0 y- h* w
]
9 z) G( B: B! @/ C( r Aend
0 K6 {" B3 ]7 \0 G3 @. y# dto reproduce
r2 m" P A6 R; N0 d ask turtles [" X4 P8 o& e! B* m" k4 G
if energy > 50 [' Y8 E9 b0 H; N x2 m7 Y6 O
set energy energy - 50& m' ]' s, ]4 V0 ~
hatch 1 [ set energy 50 ]
2 v% ?7 O0 L9 w) z1 Y ]
) I \3 |+ o) c+ D6 ~# L ]
0 u# u7 n# W$ W# v) e3 `0 A4 V# yend6 \( Q0 P. o& K, ] O
to check-death
- b7 ^: ]; K! W( Q0 {7 d' b ask turtles [
2 M* [# l) Q9 s5 E4 s if energy <= 0 [ die ]
- R- [2 {9 ~% N g& ]$ ?. q6 I7 B& o3 E ]
! b8 y# V8 c8 k* lend
8 H6 _ C% [ S( c5 jto regrow-grass% l% w" t: Z4 n* v
ask patches [
" w! j# ~- g1 ]+ |9 z if random 100 < 3 [ set pcolor green ]
! N4 Y+ e( T5 z: C ]) k3 {# U# u. C, g( G6 l
end0 S2 m2 U2 J! f2 F1 K I( y
to do-plots$ k) {. ^7 m' |" K/ Y4 g5 G+ N
set-current-plot "Totals"- S" W- r. K; e& o" V; o$ ]
set-current-plot-pen "turtles"
- d" h" @1 Y1 p/ o" Z; p0 n% N plot count turtles
2 X1 o. _- u" F( j/ u+ {( I% e/ X% M6 Z set-current-plot-pen "grass"
* L p3 k! f9 A$ r plot count patches with [pcolor = green]9 ?8 _, i9 A7 O% ]. n
end
: P) k% v P" Y8 y8 u可是运行时提示no such plot: "Totals"
9 q* ]) u: [! i6 xerror while observer running SET-CURRENT-PLOT
F$ z% `4 }' T* ^, R called by procedure DO-PLOTS
0 |. {' d/ R8 A* D% G( t# ^ called by procedure SETUP
o2 B% {1 B: z+ I2 B% T- B called by 按钮 'setup'& `# J+ a1 v3 ?% U2 T A/ N
求大神解答啊 |