我编的程序如下turtles-own [energy]1 o6 d, A+ f" N6 v4 \- f
to setup" O/ C' z. L" }# a z
clear-all, q7 f; ~, [1 u+ X! z4 u$ f
setup-patches- g0 X- e) U8 S
create-turtles 100
8 d- p; {0 c& G5 z: C$ W: ^ do-plots) F3 |; f5 W( W
ask turtles [ setxy random-xcor random-ycor ]' R7 [" _ Z( d$ P
end I L7 A: [. r0 B q4 F3 W
to go) T' r1 D( E" K: Q9 W4 \+ y
move-turtles
! y* J. s' K4 _$ n8 o eat-grass; H# i, x! ?! Y0 W5 ^5 z( N
reproduce
$ {5 f( ^. O( @8 _# a! \; x2 ] check-death
' T9 I' S- g. r; Q0 u) x; R regrow-grass. E# s6 ~+ Y D: j
do-plots
, Y+ C" a+ T% a/ q# Z2 \end. o9 u/ G+ ~( l: k# [# o
to move-turtles
/ Y( U) w, B$ ]* e ask turtles [7 D& @: c- S* J2 b
right random 360
* m: o: q& o$ q1 L4 { forward 1
6 U, Q! o9 Q9 L- B set energy energy - 1/ w& ]2 A$ c9 A* \, e
]
$ C" T6 y, ?8 h: }: P2 g& Wend
+ B; \1 L( w& `, a4 B* {" i9 N" bto setup-patches$ o6 x, P! ?- J* s: A7 K' B
ask patches [ set pcolor green ]
: e* C @# r7 d- k% C K' vend. z% R! r* A9 U3 A
to setup-turtles
l/ f% C6 |+ G4 U }4 z( S create-turtles 100
/ z" S5 V) E! u" [% g ask turtles [ setxy random-xcor random-ycor ]
9 j, ?& V. l6 T9 a! Uend9 P9 Q7 k2 U$ b
to eat-grass
; e3 T' a) p' y5 | ask turtles [7 u$ j4 w1 C+ a$ e' Y+ Q* |; D
if pcolor = green [$ C! g1 t+ H$ d5 S* y
set pcolor black9 X0 c4 \" i6 j# x
set energy (energy + 10)
$ Z) U9 @0 p1 L5 d) x6 {9 _ ]8 P. \4 Y0 a( f @( Z
ifelse show-energy?
, U/ H! A4 L% N+ V6 e J. Y+ S/ N [ set label energy ]
% t) B3 @4 X% F* o) @0 p+ G [ set label "" ]
2 |, R: e! Q+ j' q/ x+ h, Z, o ]
7 f/ n& v: q- \% Jend
9 y/ P, U* i- b' m# p5 Eto reproduce: U/ x& [* s1 A
ask turtles [, p8 L# ]; a2 c+ G/ T
if energy > 50 [
$ o+ `9 U) L7 g" n set energy energy - 50$ n3 {7 o. S" a' p0 P
hatch 1 [ set energy 50 ]
6 i* K' M3 k7 c) g7 K: E ]
- N9 S$ g7 B! B' k4 r$ _ ]
2 V8 U- F* X% u; H# J' k# {end1 }3 M& o% o* Z) u F
to check-death
. k, n2 c/ O, x# Z7 L: S ask turtles [
, }* L9 N' F# |" T* A+ a if energy <= 0 [ die ]
4 x% v& ^' d0 Y$ X ]" p m6 O6 ?9 X/ p+ q2 K, W! _
end+ D |/ q: w8 M% q& W
to regrow-grass+ H& K2 ?- ?0 i+ }
ask patches [/ F% a; q8 G. P* S" C. s2 W3 l
if random 100 < 3 [ set pcolor green ]
7 |6 i* V; v! _5 ]. \0 [ ]
3 N/ O4 q8 g$ q2 b' z1 ]5 Y4 vend( b0 ?( ?7 f; a0 {. M
to do-plots
: k. E$ d1 @. \+ i8 Z set-current-plot "Totals"0 {, ^' e+ W4 t Z {, K
set-current-plot-pen "turtles"( j/ y" a S6 O$ |2 O+ [: d
plot count turtles
, D5 Y6 C: a- d0 ~& s5 x7 z" o set-current-plot-pen "grass"( V# E( g3 o4 f1 P0 a/ R8 G. I/ T
plot count patches with [pcolor = green]
) B; p% f: q2 Y5 \ E+ Jend
]! e3 `: _( j. u3 B5 K& Q可是运行时提示no such plot: "Totals"+ E9 }2 S0 V% c) Y# j B2 f
error while observer running SET-CURRENT-PLOT: r4 `# a2 T2 y S% k( i! y; e2 @
called by procedure DO-PLOTS
/ Y; _+ H7 p% i7 {9 p' X& L; x! Z/ U called by procedure SETUP
: P. Q1 W/ j; u1 u called by 按钮 'setup'
% f& }" ]% H" h求大神解答啊 |