我编的程序如下turtles-own [energy]6 j' g% X' b6 [4 b0 k# w6 W
to setup- h6 x2 S( O5 ^; N; ?
clear-all
0 H" S6 n7 P' l6 A7 g+ | setup-patches
' [8 k M: N' A: k0 g' i create-turtles 100
& P9 d7 Y, K8 n5 x c do-plots
& k3 S0 P5 b+ N& C$ j+ P4 l ask turtles [ setxy random-xcor random-ycor ]; J m6 K3 x3 x4 K; y
end/ _2 G: D0 n' i" t
to go! g8 B/ a1 _$ n. T% T, F' t
move-turtles
7 v- F& l& i& y' w eat-grass
) R9 ^! t# p+ Q, L8 r7 F reproduce# t8 r. W/ Z" z8 i
check-death
8 W8 B7 I8 f3 l; `9 J1 K" H. W regrow-grass4 J' q( c9 `( G( W4 r' t
do-plots
( \; @; x: i3 e) L" Tend2 ?( K- ]' P: h' U
to move-turtles
) {% n9 y4 p# b ask turtles [) r- f9 P+ o0 T9 y- H
right random 360- r5 ~9 b) m3 m0 }
forward 13 h9 M6 x4 q2 Q2 U) K
set energy energy - 1
2 O3 h6 i5 t% ?" e' E! l ]
1 Z# w" n/ n) F+ K, w5 Dend
" m9 v9 K' U8 g' r: X9 O: Ato setup-patches* D. n3 F# S- E7 m X7 `6 G
ask patches [ set pcolor green ]
( d( O0 R6 X) x. N6 @- Zend, M; c0 Y8 L4 E; U/ S
to setup-turtles
2 {" G! k8 _* @) { F/ ` create-turtles 100
& E5 J1 A5 ^7 O) N& ~( s1 b8 P, w ask turtles [ setxy random-xcor random-ycor ]
; ^. R! r# R$ v M e# m: {end
^* e4 k d! F' _& @to eat-grass, Z; M5 g1 w. S! `5 a* f2 m8 f
ask turtles [
! G4 f7 d& a# W/ ^) l* Q: J) A if pcolor = green [
- j- k) h$ A7 i: p& d set pcolor black, E0 \4 J" c- t' g- T9 _
set energy (energy + 10)
% S1 ?- i5 m$ ~* L$ J8 h6 i, V& ^0 q ]
( X# M! r2 e0 p! L7 F+ J! n* j. s ifelse show-energy?
# s' E+ ?$ f2 p* k! d [ set label energy ]
3 k) ?. U: @; h$ z* X [ set label "" ]
' D0 h: V5 o0 J' }, H ]
7 `" o p6 z; U' ^# o$ Gend ]9 V0 u" e3 ~( ^2 f3 I. i
to reproduce
7 T% T% H! a; W, p$ H& E ask turtles [' `( }: N \% V. y
if energy > 50 [* E' f; }' M+ F" C# x3 P
set energy energy - 50
$ O0 I/ A: g6 u9 l; n2 p+ a hatch 1 [ set energy 50 ]' l6 P5 t7 x3 z; Z- |3 c7 S
]
, ]( N: d0 x" \8 t ]
4 o7 b' |6 t$ _5 b" Jend
, Q( u$ |- O$ \8 i' W. d) s" nto check-death% l6 k/ q& ^2 H* ?, X" h( }
ask turtles [
$ p7 V2 _$ ^0 v9 V# E0 h if energy <= 0 [ die ]: Q& V" G# P4 q, U6 V n* L
]
6 a! [* M9 t0 D' `, qend
! i8 d/ o5 c+ u! q% ^to regrow-grass [* F2 H, n3 [) H# \0 P+ B
ask patches [, f2 h8 _2 x) x( `: X8 K: b7 d7 E
if random 100 < 3 [ set pcolor green ]
7 Z3 }) G/ |8 n2 h+ ?3 j( Z$ m2 R+ } ]: @+ p/ W2 p2 P/ _, n
end
. z7 |4 I7 G& B* Wto do-plots) x+ z$ ^% o o
set-current-plot "Totals"+ u; E$ P; {+ y/ a( q
set-current-plot-pen "turtles", U, P! X7 T, m# S
plot count turtles) C+ ]5 F6 B: V6 I$ u! {
set-current-plot-pen "grass": q* q1 u# r& V
plot count patches with [pcolor = green]
, O% p) T% }) D5 ?0 l, j- xend( y- H: I/ c! J S: y- e- q! b& n
可是运行时提示no such plot: "Totals"6 N! N5 U" Z; Q9 D
error while observer running SET-CURRENT-PLOT7 f9 ~* e4 z5 J# Y1 q
called by procedure DO-PLOTS7 K4 P* B: |5 V" e) _$ D
called by procedure SETUP+ D% M4 w. }, S* e) \$ `
called by 按钮 'setup'/ C& _# X0 H8 i% | o9 F
求大神解答啊 |