我编的程序如下turtles-own [energy]: N& [. x T( Z8 `8 n* I5 S+ t
to setup$ I# g1 k2 S, ]+ q8 x
clear-all" t9 X# r8 f9 E3 J+ ?# q* j, x' s
setup-patches3 Y) k2 D+ M2 o
create-turtles 100
! i8 \- W S7 K do-plots! J8 z( ^; x0 p" x
ask turtles [ setxy random-xcor random-ycor ]
4 ^' C: R$ Z- jend' e7 c: U% v, K$ f$ r5 p
to go
5 I Z) I" o- I* N move-turtles
# y0 q e6 W: C9 G eat-grass0 A ]. R. A$ Q& d3 O
reproduce
' c( T/ w/ M5 h" K/ ?( ^ check-death
9 Z. C) {3 A, j. {7 w regrow-grass/ A- s. b$ V& X* {& _# K
do-plots0 C; A/ C# \7 _& ]. `3 t
end" Q: z1 t a, m9 ?/ S1 {# K
to move-turtles/ L' b, x$ E' O, \, g; A9 K
ask turtles [
1 n) D; o8 t* s. ` right random 360+ l1 {. ^! P, j& m2 K! }6 C1 U) n8 K
forward 1
1 X& N, i; _, x" z6 Q& w+ H set energy energy - 1; U/ W1 A& D. U+ {. F
]8 M/ w% J/ i3 W. b0 e X, y
end
" n( D, }) V- k8 F- t# Mto setup-patches
_ P4 @9 U% I" }3 t ask patches [ set pcolor green ]
6 D) A* n8 ]$ b, [end
! r& {* t" M9 x/ T6 H5 t& @to setup-turtles
% o5 e6 K2 P( N/ T; ^9 b5 {1 _4 ~ create-turtles 100' @8 }" B) f5 x8 t
ask turtles [ setxy random-xcor random-ycor ] x4 i: f4 @9 y; w* U
end2 u2 h' r9 {/ K/ E2 U* y
to eat-grass
& U; S Q+ s; P. G3 M( q4 _) @ ask turtles [2 J. P+ q, ~6 E1 U
if pcolor = green [, h/ C( h/ Y8 t6 Z- W9 r/ g, B: {+ t5 W
set pcolor black
: o# a8 ?! m, Z* l. ~ set energy (energy + 10)
9 Q8 w0 N# B" j3 @9 V ]- Q1 T2 C1 ?, C% g0 ]) A
ifelse show-energy?6 K& o8 |- G7 g6 b* D5 r0 f
[ set label energy ]9 e+ C E% |. p- b8 J
[ set label "" ]2 ]9 ]1 f6 }7 v& k
]5 W5 l) Z4 b4 q F
end+ q: X9 G- \/ g, D' ?; b+ K. Q
to reproduce
" ?9 ?0 Q: C' K% U6 F6 e ask turtles [
4 ~3 G2 C( d7 y* V& k& z+ B* f if energy > 50 [
: U2 v9 f* Z# f' p: N: A' k# B" V/ {! Y set energy energy - 50
" o, m$ m, ^7 F. i hatch 1 [ set energy 50 ]
; L, Z& U( u- k) K9 f" W ]
, u; |) q6 a% j* v/ ~0 M" R* V. A ]0 c9 k; Q$ ~$ U" H: x, U
end# I% k! T! L2 w7 Z$ ?; g
to check-death5 w% G. Z) T& N5 u4 c
ask turtles [# C: u& O. K' n- U' y: X( `
if energy <= 0 [ die ]) c& r/ q8 {% d
]" p+ r0 E3 s8 [
end& X' o& P; h* ^
to regrow-grass
5 z$ `2 O6 n2 t1 z ask patches [
/ {: E% W* u/ u& N+ H4 B5 S if random 100 < 3 [ set pcolor green ]
, A8 o' H! F }( F. N ]2 m0 C6 [% K$ k# F8 a
end' G4 I- Y* \8 D) q Y Z9 D8 L3 Y8 {
to do-plots
1 ?8 w# L: G" D; v set-current-plot "Totals"( X' f$ }0 h. B6 t
set-current-plot-pen "turtles"
0 F L5 ~4 q% ~& G- G plot count turtles) t: I3 E0 p- g/ p: \" ?' e
set-current-plot-pen "grass"
- d/ V" w ~+ M/ M plot count patches with [pcolor = green]
9 b [6 s+ F$ Vend
! b7 F6 \* c/ n# [4 ?可是运行时提示no such plot: "Totals"
( u. F! m2 [3 v" {' xerror while observer running SET-CURRENT-PLOT
S' [2 X4 [; L6 |$ W9 _$ H called by procedure DO-PLOTS# g @2 m- \5 u$ h+ s
called by procedure SETUP$ Z! l6 ?- o: ]2 s
called by 按钮 'setup'
+ S2 K. |1 ^( |求大神解答啊 |