我编的程序如下turtles-own [energy]5 ?3 z4 R- c% b+ O
to setup
; \1 _$ f/ |. Q- L7 v2 S( [ clear-all" D- e4 S- S7 U$ S' @: l
setup-patches) R* m! u$ o; ^1 k2 Y, R$ n
create-turtles 1004 F3 A- ?# g0 `8 J
do-plots' Q( j: \1 P3 s' N3 e
ask turtles [ setxy random-xcor random-ycor ]
; |5 [1 l3 p! V# Dend
+ `1 v5 r; m; N) ?to go
( G2 }" K) m+ h& i0 e move-turtles7 X3 t2 s1 j( C5 k5 r( S% g. p
eat-grass
) a2 d3 l# t3 i7 s6 P reproduce% a1 ^4 U! D2 g9 }- f" v
check-death1 T7 q' s2 v" e
regrow-grass
# ]: i# b2 {. L( s/ h: ~( w3 |6 r do-plots
/ f) K; O$ o. A7 xend6 ]1 o- Z7 k* `
to move-turtles1 T2 u( T6 v' H8 s! z
ask turtles [
9 i V0 x6 }9 m# O0 A H& N right random 3604 i8 S8 V$ Y, E3 Z9 ~. l
forward 1$ i$ Z9 ]6 V5 A6 x# O ]& n$ S
set energy energy - 14 V2 [7 O) x. h
]! w, B& O0 X6 e
end/ D& Z k/ h y
to setup-patches$ n. {$ {7 K! ^' t4 b
ask patches [ set pcolor green ]
. b; t8 I0 w) Eend
' w; g; ~! y; { n1 s' qto setup-turtles3 R6 u m, a$ D3 e; g
create-turtles 100
7 f! t; O6 Z5 W* `& j1 r$ Y3 F ask turtles [ setxy random-xcor random-ycor ]$ t8 @$ J' ]+ p0 O& p/ S4 Z) y
end% f3 Q$ l5 S0 z
to eat-grass7 m6 w. k- r: z \) s, X
ask turtles [3 u2 w. c4 l" K
if pcolor = green [
% ^5 y F) e% i) {9 }) _ set pcolor black
4 t( j3 V# ?4 r% q1 D& Y set energy (energy + 10). n+ w" Z4 I' B) g
], a- t% ]1 b& U. A+ }
ifelse show-energy?
# m- ]! _9 h3 S( Q0 g+ l. X2 K [ set label energy ]. t7 d, l* s! @1 O& G
[ set label "" ]" c* U7 e9 C) K4 e$ d# M6 r) n; o4 m
]
; f7 z- O _* O) v3 aend- D/ z5 L4 o. f" e6 W! `
to reproduce
/ D* \) f9 f$ F; [9 L ask turtles [. _2 a, [) M' x0 z9 @
if energy > 50 [, e8 r4 g/ \& d! U# F7 V$ X
set energy energy - 50. L# V% J) `6 y3 ^1 |% Q
hatch 1 [ set energy 50 ]
6 Y+ N, e9 Y" |& [- | ]: r9 z+ k- x9 g+ u+ k R
]# C+ x5 g. f6 R& G: w
end
; ~5 F. |, u+ n) r$ sto check-death
) r* g% w3 {8 {! D* b ask turtles [, t$ {: K) i4 p8 q0 Z' A
if energy <= 0 [ die ]. R6 w) ^+ |6 Y' ]! X
]3 H/ g# I K2 U2 j% U B' D
end; t6 _% r+ r* E4 w
to regrow-grass r2 Y7 s6 _9 C+ S `9 Y
ask patches [
- K. E, L( t/ ~- c if random 100 < 3 [ set pcolor green ]. r+ s6 O3 x( L+ M% ?
]
. ~1 ~- e( ~/ xend
0 f8 V* h# g# |2 `7 rto do-plots3 e+ \6 y# a5 k4 i# ~8 s
set-current-plot "Totals"/ }" O$ L+ y h* i! [# u E
set-current-plot-pen "turtles"
' X7 O# R% R3 D N plot count turtles
$ R9 H) O! f. w0 D9 e& b set-current-plot-pen "grass"- B6 U2 o+ g, V. x/ |( D( D# m
plot count patches with [pcolor = green]* r$ g' l! r& t% I* p9 j& [, G- c
end2 l/ v9 ^; l# p x, x) j) b% i8 N
可是运行时提示no such plot: "Totals"
* z, i/ p, B2 N ?, Xerror while observer running SET-CURRENT-PLOT
V, ?" s* g" [- \ called by procedure DO-PLOTS
$ y9 X! R( [6 y1 h D/ q called by procedure SETUP
! M/ i4 @" @. H, U called by 按钮 'setup'
* u+ p Q6 i4 `* A& K0 C求大神解答啊 |