我编的程序如下turtles-own [energy] a7 Y) V4 ^; m
to setup: M9 E2 @$ J( H0 n3 x4 V- E/ A
clear-all/ y2 t! ^1 J/ p5 D9 D% i
setup-patches2 j) X1 S( l* I0 a6 e
create-turtles 100
' q0 n, j& ]0 Q2 ~ do-plots
L: X% t& d8 I; W) r& A/ n ask turtles [ setxy random-xcor random-ycor ]; E0 t9 D/ L4 y
end( t) N$ \6 R5 m$ G% a- f
to go
% }' L$ t2 x$ T- Y move-turtles
$ i, w) @7 n. s( d* e7 f" D8 g eat-grass
7 G6 h$ |3 k* ^2 ~3 y4 A4 n" J reproduce
. X2 s2 i0 H! N check-death) d" r: L2 G2 ]/ R' Y, U; P* W
regrow-grass: Z+ a$ V3 s' R$ o4 |1 j2 @
do-plots
9 Y3 `7 g. ~) }end5 \; d7 c: `- a/ T3 Q
to move-turtles5 d" e* ~$ i) E! J$ ], L2 H. `
ask turtles [
/ U: e3 [" j; v2 {8 P+ `4 R right random 360
$ O! a4 ?; H+ L6 T forward 1
6 J$ z, f6 v. T3 i/ ~2 | set energy energy - 14 n6 u7 D$ x9 H- v
]3 Y9 C- |/ U2 X+ u3 G
end* L4 l, G8 n5 G) A2 s
to setup-patches5 B: p& t3 y" I% b6 |
ask patches [ set pcolor green ]# Y2 r/ {' x1 ?8 F
end4 z6 b7 B& w8 [/ t7 b$ n
to setup-turtles
. a& q4 f$ `2 a2 e( v f create-turtles 100
2 D" t" c5 V, h, M ask turtles [ setxy random-xcor random-ycor ]
4 D/ a" z- s7 C# t/ t) ?$ \end
, w+ m, {9 M5 S$ m2 a' h+ |5 [1 uto eat-grass
6 N) A% Y0 {, f- I( s5 [4 i ask turtles [
( U# y8 _2 ?( v, P if pcolor = green [
; \3 \0 ?: Q* H% t% F set pcolor black
2 h/ `' k8 v( l: i- g. A' Y5 Y3 w8 N set energy (energy + 10)
) L" t8 s7 Y, m3 B( c3 p ]) w+ Q5 s9 ]/ k' ?
ifelse show-energy?
% @; j# M6 M+ c' K. U% m5 c' Q+ U [ set label energy ]: d$ x; n& K/ @) B
[ set label "" ]/ W4 w1 |; [) F, b$ X" ` n. ?
]
5 ]9 c. n+ a+ ^ V1 E! zend+ o& f( S2 h+ q, t+ b$ p5 N3 g0 H4 W( d
to reproduce% l. [; \! |8 B0 h% e
ask turtles [! D4 ]% ^$ _8 C* a, ~! ?/ M
if energy > 50 [6 O* ?) E& L& @8 V% c# A1 \
set energy energy - 50
( _5 R" w/ b- X* j% N hatch 1 [ set energy 50 ]* V: g% F; D( [1 [: M0 w
]3 z* _" T$ q- `3 f9 d- I: l; I
]/ s# A8 X, i( N# u* L* Y4 l+ A
end& k3 v1 M- A( |/ F& i) p
to check-death9 k5 g7 j) ^: k) b0 j$ ~
ask turtles [* k- q3 F* Y V% w
if energy <= 0 [ die ]( n0 f5 r# X* I" Z9 P7 Y3 Y9 U: d
]
- I/ g8 e0 ?5 |$ u kend, Y/ ~4 T% y* d- t6 o% t
to regrow-grass$ h. b0 U0 l! r7 q* ?
ask patches [
/ y ~, _* p8 r( A% R1 H. B if random 100 < 3 [ set pcolor green ]* P( [& z9 r8 f" R1 C, I3 O
]- \" s6 k% t- W, s
end1 X, F7 Y& X: U0 V; k4 ]& j
to do-plots' P5 v, }! l$ g3 ~# ]7 [
set-current-plot "Totals"
$ r6 r4 y. }* y$ e: v7 d set-current-plot-pen "turtles"* J4 m* @9 A5 T& i( { C
plot count turtles# r6 q9 q2 P3 j, w/ S
set-current-plot-pen "grass". d! p7 W/ r0 b: i$ R. @4 ^+ I0 L7 ]
plot count patches with [pcolor = green]
/ p) E3 E s% f+ m; J) u; ^end+ f; y* z2 Z9 F
可是运行时提示no such plot: "Totals"
9 Q$ b5 d7 f6 C% ^ K6 Lerror while observer running SET-CURRENT-PLOT7 w1 z0 w' z+ e f
called by procedure DO-PLOTS
0 B) N- I: U" V5 f6 k/ y( k called by procedure SETUP
3 M; }6 w! P3 A: V# @! l/ Z4 i called by 按钮 'setup'
- {: D" [& k0 ^求大神解答啊 |