我编的程序如下turtles-own [energy]$ r; S2 a$ {. [
to setup u7 P' e, ^$ Q! D. w% Y, I7 v
clear-all
1 e1 p0 o* K* L n m2 g setup-patches
2 d2 R7 z$ Y3 h* u& |/ @5 e create-turtles 100- l7 @6 v1 V" p# r1 ~
do-plots
3 D$ z2 l& k! ^* T3 k& \+ V) b ask turtles [ setxy random-xcor random-ycor ]
# J" l2 w6 l4 F0 N; |2 _, Wend+ ^8 |1 d4 L1 e- V) g5 d' e/ q8 s
to go. d# a8 l' R. z2 P) k \
move-turtles
& q( J( D3 t' B1 u( m H0 K eat-grass# Z% @. m) Q5 @" P* F
reproduce. Y4 r+ [) f+ ~! K: z# y
check-death& v6 E* P7 o! x( [6 L1 Y0 B
regrow-grass
* G& ^' A# v, w" ^3 N. h. R: Q do-plots7 V9 D" H( d0 X5 ?+ y H
end( D0 n5 v, i+ z; _* u4 t# X7 X7 w
to move-turtles; a% g2 @( S& @
ask turtles [
9 Q4 R: _4 q6 I: i right random 360' s' \1 z6 m. ^: R" K% A) J& \+ B
forward 1
+ y( r/ D, S) }9 ]6 ^. ~ set energy energy - 1+ A- E/ L# Q4 y, @
]! E' p) Z6 m. a8 h
end
7 q1 c, x- m0 m9 Gto setup-patches
i6 p# S% E) i: O7 e. n ask patches [ set pcolor green ]* ~0 V( F/ |% P w( y, }6 m7 X& Y
end" w, D8 A5 x& e
to setup-turtles2 p2 r! `1 u# M0 _7 y
create-turtles 100
( S0 q) {8 P/ ` f+ r) o! [ ask turtles [ setxy random-xcor random-ycor ]$ p# ^5 j2 ]* _ T( H
end3 V* X; ]- L V# L' Z1 A5 |
to eat-grass
6 n+ m5 J/ P4 m) L( ^% ]7 K" p ask turtles [
& ]* `. q0 y# |# ~ if pcolor = green [
; L7 }, t2 l. ] set pcolor black* Q* b! E, k0 q0 R
set energy (energy + 10)
% O( E% |6 X P6 |8 t ]0 M, ]% v i) f+ s+ E8 M+ i
ifelse show-energy?
2 y! j6 ?2 f/ e4 G: E [ set label energy ]
2 P- H$ H: ]3 u' [# O [ set label "" ]" O" }9 S; Z2 K+ }3 x' k
]
7 T. _6 R B' `" u$ Uend/ \' p) g* w9 O& W6 c7 W: p! E+ s
to reproduce
2 P# k6 u8 G% P# y ask turtles [/ B" |. k6 y7 U
if energy > 50 [
1 O3 D6 B6 i* v" N8 `0 ^ h set energy energy - 50# A" R4 ~. I+ A
hatch 1 [ set energy 50 ]5 C+ `4 n, j3 j) D, N
]
% T% A1 H: U6 P* ?, b( [; u! D ]" G( R6 a; G0 f
end
+ a5 d2 D& X+ Z, ~to check-death
) u- M+ d: {) W! f- G" r0 o ask turtles [
9 @0 d7 H0 {2 x; e/ j |# X8 B" r if energy <= 0 [ die ]
! g6 j) Z! ~4 N4 N! n/ A ]
/ ^) R, Z2 s" f: Q) H* \5 ]end) P) ^3 {! w0 q
to regrow-grass# G A; p; C( [/ `( k5 Y, b! E5 W. v' ~
ask patches [* t. h2 b* M' n7 C6 s
if random 100 < 3 [ set pcolor green ]0 P/ |% w7 ]* F9 B( V7 D- w
]
2 [) j. [5 J" S: Bend
1 m4 }2 m# ], Hto do-plots3 ]0 q8 ~2 Z: M) o% p; U$ p
set-current-plot "Totals"
/ i0 ?; k, V: E) c" B! \ set-current-plot-pen "turtles"
* Q( p7 S& L1 r' h1 T; c plot count turtles& n# L$ b4 W( b" E! h/ d' V% ~
set-current-plot-pen "grass". x5 J! u% A+ R* O% O
plot count patches with [pcolor = green]
4 n1 w* n( Y6 D) J! U" xend
+ Q- r- `5 T! G9 p/ _5 j" u可是运行时提示no such plot: "Totals"$ D6 Q A/ H6 \4 c* k! Q9 w
error while observer running SET-CURRENT-PLOT' d% k% o5 a( t
called by procedure DO-PLOTS
3 B- f; w/ {7 Q1 A0 g0 q: f0 ? called by procedure SETUP; p6 Z/ M: W! s) Q/ F
called by 按钮 'setup'
% y! |6 C5 Y% u, o& H求大神解答啊 |