我编的程序如下turtles-own [energy]; L' t0 F6 ?2 y4 @! r: }# O
to setup( X/ B& x5 P% F$ t
clear-all
+ B! r' _# C& G; ]' d setup-patches% l# F; |. S1 i2 z2 E, A
create-turtles 100
$ p! h3 |& x! N9 W" r3 o do-plots
7 c' i w1 h: S5 x ask turtles [ setxy random-xcor random-ycor ]- M1 B, p& D) S1 v$ V6 d3 G
end
8 |* i. I \% d5 Rto go
: O4 [+ I* V6 D* n* h0 P& d7 v3 L move-turtles
" Q9 m# x9 N. K eat-grass/ G. e5 o8 G2 M! x$ p& ?9 T
reproduce
" w% e8 \; p& F check-death1 ^8 K7 C( m1 Y1 m
regrow-grass
9 L# T+ y$ J6 B1 `* Y! \( Z) v" V. K do-plots) I8 e$ d& o3 K6 j5 s' b$ C$ Z
end* V" `; z* q; s |1 B
to move-turtles$ h2 v9 n* X% t( X# s' J9 S
ask turtles [
7 {6 F; {1 N2 c/ ? k3 { right random 360
: Q1 ]7 e+ B* [3 m5 Y7 m; R forward 1
+ x k$ Q [& X% t1 a; H/ i set energy energy - 1
! e! }% [9 ?: E- s% T- j! Z ]2 e6 A( h8 G. r$ \9 c* C) j! m
end7 u+ M& z3 \# K' @$ l/ K
to setup-patches4 ~7 [5 u/ k& u0 @4 f" O+ b" f
ask patches [ set pcolor green ]
" j' a$ B/ f Cend
, f1 ?8 u4 s+ Tto setup-turtles4 m$ M8 r+ @+ [
create-turtles 100
# K/ {) x3 b( w9 J/ n" [4 l, @ ask turtles [ setxy random-xcor random-ycor ]7 f3 b/ B% K% p# Z2 \
end6 S' f6 @6 E' n. t- s+ m" ]! p
to eat-grass
, u) {0 k5 |, r; E& ~3 ]; N# f! H ask turtles [
; K, [8 }, [ Y7 C0 u) z. @ if pcolor = green [
$ q4 b2 ~$ Y% F g2 D0 J set pcolor black
: o- B/ y8 V1 F$ @5 x set energy (energy + 10)
% P; O2 ]( [1 w9 d9 D2 J. S ]
( c. v' `0 F; [$ P ifelse show-energy?! \9 Y) V% A) L0 l8 p( @
[ set label energy ]
; A0 f0 t2 Y1 R* w [ set label "" ]
* |8 J- z1 {5 y9 |# E. V. ]# ? ]
5 T0 T! L4 W4 cend5 w9 c. O4 F& O6 Y8 W
to reproduce
% W3 G6 S/ R; n" @, D( ~/ ~ ask turtles [, ? K# E' n3 @/ F: U
if energy > 50 [. Q! i1 T8 m& ^4 Y7 f9 V- U1 s
set energy energy - 50" a9 j7 p" {6 f
hatch 1 [ set energy 50 ]- b0 k( R- g" ]
]7 q6 P" b4 S# ] W+ G
]5 Z8 K# |8 I1 x3 L- i- R
end
" h) D( w" W0 o1 |to check-death
6 ~: z& \4 G! x- q; B& f ask turtles [
4 K. H1 _. A: S if energy <= 0 [ die ]+ H) Y3 q5 n: m4 r2 M$ ?( s4 H
]7 c4 J: ^$ N! f4 J* K1 Z8 }
end& |* ]% N E- \6 P5 R; B9 x7 t. f
to regrow-grass+ |+ o# O: T! C }, w' X9 F
ask patches [8 N1 O; N6 @( B5 _5 {. L) {5 \
if random 100 < 3 [ set pcolor green ]
! T! u* ~' w/ h4 w3 [; L6 L( I7 C$ w ]9 ~* }8 U* J0 Y' {0 Y
end' L' n" H& F) p0 n; \8 ~( G
to do-plots4 L8 l( e0 V0 n) _
set-current-plot "Totals"
( m" G8 E8 Q n set-current-plot-pen "turtles" ~$ j* y |# N: e, j; z
plot count turtles
" K0 i* v: ?- y. c* }6 G8 f set-current-plot-pen "grass"" Q% x* p9 `+ J0 K7 n8 [0 B! D$ j* a4 x
plot count patches with [pcolor = green]
G+ K! p7 X4 z$ Z" d- A- _end% Z7 t9 w# F; j/ M+ E; ~
可是运行时提示no such plot: "Totals"# L% {+ M+ L9 D& d
error while observer running SET-CURRENT-PLOT
, g% f! q" {# ?1 M called by procedure DO-PLOTS8 l/ d, v0 r4 |: V
called by procedure SETUP! v2 k# F* \! s: |; W Z9 S
called by 按钮 'setup'
: j9 Z. o* |+ l8 ~求大神解答啊 |