我编的程序如下turtles-own [energy]+ I5 a: G5 O% q' P7 h4 ]& o! \1 u
to setup
( |- @; E3 b% c9 [ clear-all
: {7 e5 R0 @$ \' M setup-patches" O5 s* l9 ^6 v9 R% N
create-turtles 1009 X5 ~5 s1 h$ p4 K; V/ ` x" N/ {
do-plots% x- h6 `: v8 x& }
ask turtles [ setxy random-xcor random-ycor ]& x* R$ [% g/ a; s' N1 I6 ]
end+ o/ |* Y' ]. O! L
to go
% O0 ~) b" G9 b, u move-turtles6 r( H3 |% E2 g9 P
eat-grass! G% s3 J3 L: h) o: B
reproduce2 j& p( u8 u+ v1 z6 I
check-death
9 M, F& K6 [# A( w regrow-grass z# r6 p3 E, N" _
do-plots
( c! [& a" o4 [6 @& x6 D4 pend
( Q. y7 |. \! ^to move-turtles
/ G2 d3 i3 A# Q. {+ c% \$ _' a ask turtles [
& f9 d* i5 y }' k b" q# S right random 360' {* k e9 W/ n& N+ L
forward 1
& q7 U) a) k" r; X1 f set energy energy - 1
# B5 w( n! G0 Y3 @; O5 b' X4 o ]7 P3 d9 _3 X& @* P
end6 m; z6 o- J- f" ~! q4 n; {+ [
to setup-patches
0 L. X- W" P; v) F ask patches [ set pcolor green ]% g, w3 w, N) l$ J2 x4 j& H
end2 _2 I+ B; q% F) e+ ? ^' i
to setup-turtles
9 a- K' T; A+ |- @3 R create-turtles 100+ w1 B( z' _; e
ask turtles [ setxy random-xcor random-ycor ]* F# U1 t# @! e9 X& z, {6 K
end; P8 `0 v3 d, c4 y$ g$ ~' @* J
to eat-grass
0 S2 q! t! X5 z& l' E1 m% U3 \ ask turtles [
0 g( Y( e* G9 u6 q7 R5 F [ if pcolor = green [
2 K9 q. H9 O3 G) E8 ~ Z" W set pcolor black4 ~! R3 a" c" O* H/ L
set energy (energy + 10)( E- p# t& w* c' u) m6 i
]6 w! n" f5 n/ {% d# i" w
ifelse show-energy?
8 V8 G$ q+ H1 D [ set label energy ]: [+ n1 V. r% X0 T. s+ S
[ set label "" ]
0 A# a9 U0 p$ `- y7 V ]
, T* U( J$ X% O. {* w6 lend
/ k1 D& y# y. o0 G! I" }to reproduce
( A4 `2 J, ~8 M/ C7 n1 \- V- y ask turtles [8 C2 D; M% y! a, G2 ~ w
if energy > 50 [
6 s; S3 v0 m3 c7 R4 y! A set energy energy - 50- R: B) C' \8 c8 Z. S
hatch 1 [ set energy 50 ]
1 h k" O2 A. w3 q9 E2 B6 G ]+ P$ j( h5 h6 a
]/ x/ V, [! ~3 S( H) e# W2 J
end: u. M' T/ W' U( [! Q; U) ?
to check-death
% U( ?# _$ ~: g( @ ask turtles [
+ b+ Z9 M6 m7 s/ g8 N/ }6 z2 e if energy <= 0 [ die ]
. G- e9 P0 b( g: a+ k/ { ]5 W0 `6 C A2 Y2 P
end
1 B# F* V: Z0 w z9 l0 a; [to regrow-grass( e: O; y/ t( H$ b* H6 N W4 t
ask patches [+ C: R; m+ ~6 f
if random 100 < 3 [ set pcolor green ]
/ Q4 u+ y( w" h/ H/ c ]
' W E9 I7 H4 X$ r- {# cend
1 _$ L! g( M F$ a' `7 p, E" Kto do-plots9 n% r6 [4 Z* z( x9 L6 R1 E
set-current-plot "Totals"
. _0 I0 x6 N2 _% D set-current-plot-pen "turtles"
2 }& _! r% M7 e; ? x plot count turtles
- B, S, ^. d) L! H8 S7 r. o set-current-plot-pen "grass"- ~ r- {# d* w; v: N- }0 L
plot count patches with [pcolor = green]
' S& c; ]" R* a& v2 k* o8 a7 \end$ b$ q& ]/ T2 C2 G
可是运行时提示no such plot: "Totals"
% Y. H# q# T& [! J5 A, @error while observer running SET-CURRENT-PLOT
( U9 t3 N6 D9 A: G9 Z. E$ k* [ called by procedure DO-PLOTS
$ L9 _, G8 B2 D& A called by procedure SETUP
0 F& u! l5 J+ O4 g called by 按钮 'setup'9 |: K- X T' f! x7 M5 U
求大神解答啊 |