我编的程序如下turtles-own [energy]
& c8 i" m$ v# s9 e+ xto setup
3 A( F6 {9 o: L" y: v+ S; n clear-all* L/ d& G" W* ]# J/ k
setup-patches
% c* Z0 x$ [5 R3 q, f+ N& J create-turtles 100
/ j }* E& h% _- L. {, X: ~ do-plots' E9 O' r; c( T2 f
ask turtles [ setxy random-xcor random-ycor ]( t0 k# p9 S& r5 C+ ~# y
end
6 W7 I/ W& H' M' ?& Sto go
7 u0 A) u) h) b4 U9 Q0 b% L move-turtles
- g8 x- J) b" G: f- G2 y& Y eat-grass! f, t: p0 S+ b- l3 Z; y, d) b
reproduce
) K3 a) R3 J, J: J u" s: o check-death6 y" s( K* ~' |9 Y4 c( s& n3 X. E
regrow-grass. ^" i7 T2 o9 O @* G
do-plots
p7 f- A1 c3 kend. t' c; z/ O7 o, G+ `! l
to move-turtles
/ B" l5 m/ N; x ask turtles [
1 R# c. z0 ]- {8 ` right random 360
: z( U/ b/ M, Z8 u forward 13 ~) ~! U0 k6 F: O' Z/ u1 `' l2 }( z
set energy energy - 1/ k2 T7 W' {+ F" m f/ {' V [
]8 l& H" f5 a: x. l
end
( f2 r, }6 b* o6 c1 ], Xto setup-patches
8 D1 H! j; ^) y5 d+ F+ H ask patches [ set pcolor green ]
3 D X2 o9 z) }end
* S0 {/ v$ B8 j3 B1 ?4 Y4 jto setup-turtles
; l9 M# K& C }: }6 W1 g; \% Z, K) |* d create-turtles 100
4 V3 P' [: \7 f4 p ask turtles [ setxy random-xcor random-ycor ]
( [. f$ l& j/ F# _) [: `( cend) N. z: o5 @4 r2 E6 l
to eat-grass+ j4 Y) Q2 X) R4 W2 T6 b
ask turtles [5 q9 c+ g8 L; j/ F* q
if pcolor = green [' p( K0 L/ y, R t4 K7 V( f
set pcolor black: E4 p6 v& p, ~/ ?( {
set energy (energy + 10)
. [7 s' _4 j3 ] ]
. d3 t: N' O% d) ~; O9 k! n" A5 D ifelse show-energy?
n! j* a) C) h6 U! I0 G9 m [ set label energy ]
8 g, Y; ^' ?0 w* @& F7 {; p# T5 E [ set label "" ]3 F% ^) q, s* V
]
; k; T) v' X# ~/ ]end6 Q, P$ q7 b' o' c5 G: P+ V
to reproduce
. ]2 c$ l" I3 p) z+ V ask turtles [' j+ N# S3 z- H, R0 A
if energy > 50 [
3 a9 d7 i s9 _7 x3 Z set energy energy - 500 h0 U8 b7 V- {8 I
hatch 1 [ set energy 50 ]
# Q" z$ r. [$ N( B$ a' e0 p ]6 I. K4 D' {/ Z3 ]8 u
]. n6 H1 {1 v% ~+ i( ], _' M
end4 n, X% e) E; r0 p3 `# S+ i2 V
to check-death5 e8 [9 z" S' H4 c6 g6 H6 e; S
ask turtles [- b3 w8 ~ Z' v# K7 {* e
if energy <= 0 [ die ]
, \0 t5 U3 d, [+ [$ w! B ]
" Z$ b9 e, m. E) Vend" B4 `6 A# S9 r8 D O
to regrow-grass# V2 `, L; s. B* M" {7 ?+ ^
ask patches [4 j- i% ?& T0 D3 C
if random 100 < 3 [ set pcolor green ]; V0 z0 R, a+ D7 J( x8 V
]
# w# T# }. K. M5 lend, ~* x. w0 h# y* G8 E
to do-plots. M4 u4 L: n: A$ d/ P0 _
set-current-plot "Totals"
6 t0 s5 x, g4 ]" N) ~) P$ q set-current-plot-pen "turtles"
+ S, X7 x5 k8 J0 }' v" F$ | plot count turtles/ r6 \, |, s% `$ r6 y) i8 Z
set-current-plot-pen "grass"1 Z6 \6 P! }5 h. }1 E* u3 I
plot count patches with [pcolor = green]7 N, l9 D0 F. s( M; u
end. c8 v% S6 s1 \
可是运行时提示no such plot: "Totals"8 z: U; `' ^+ ]) P+ i1 a2 v0 u
error while observer running SET-CURRENT-PLOT2 h* r) ?. J: _, c3 G; Z) q
called by procedure DO-PLOTS
/ a. R7 ]! e) o called by procedure SETUP# G/ q1 W" \4 T- K. s; I
called by 按钮 'setup'# K8 o Z8 e# @+ C3 J
求大神解答啊 |