我编的程序如下turtles-own [energy]
: a, w0 R9 E4 }% J" lto setup
3 {" F+ ^" F0 d1 ^7 ^ clear-all
- a. ^7 N. z, C setup-patches* W: @# |) T* d% m7 Y+ Z" h
create-turtles 1000 g& a4 J6 T H/ M" O; E( i/ L
do-plots
, p. i5 R I' s% f ask turtles [ setxy random-xcor random-ycor ]' D B: v, C# g9 V. H
end
3 L! a4 J4 X" G, Ato go
2 Z' {- h2 e4 ]" U# ~1 f move-turtles
$ q- `( c* t8 I$ Y n. s/ X! ? eat-grass
6 @" x0 q+ T# n: z- a) c# |4 u" e reproduce
Z% m0 z, z" ]( `2 J- [ check-death9 @' e3 \2 r) G8 C
regrow-grass5 ]; |/ m8 d3 s" I ^) _
do-plots
4 G, X" T+ }/ E9 t- Wend
% X0 P2 @ ]' z* w1 Wto move-turtles+ X' q' x6 O4 G# y
ask turtles [
* g9 c# p9 }) M9 I right random 360( \9 S6 H! d. D" k1 `3 G
forward 18 w! J, H- Q: i4 s( _! c
set energy energy - 1
5 h$ Y: S6 y3 O( s4 c' W/ t) ~5 \ ]
% }- r3 X2 S% I6 l2 zend
( |( G( O7 V" Y5 ]to setup-patches
$ s; k1 o; B \) |6 C0 f2 n ask patches [ set pcolor green ]6 g% f+ P2 \, V" C8 V* A" R8 i
end
0 L" a$ w! t0 ]( cto setup-turtles
4 G% n0 x$ m& I6 n& m create-turtles 100
* _, p2 D" _: [/ i: ?; i4 G0 T1 F ask turtles [ setxy random-xcor random-ycor ]
|* q/ o/ h: [* Xend8 C9 v V( ` ^5 ?9 L+ o* r
to eat-grass: y* l V f8 c4 Z+ [ U5 R! H3 h
ask turtles [
% N$ b' C( _" A1 b if pcolor = green [
- d5 V9 ~1 T6 G# K. c set pcolor black
5 s5 f7 ~$ \: i' y& I" j set energy (energy + 10)
7 {) W7 L4 O0 i9 l) w ]* r/ w7 _. B2 `4 S& Y3 h" E& x
ifelse show-energy?6 ?8 I' }6 [ z& G0 o
[ set label energy ]
3 p k* c4 `1 C# K8 G7 [# ` [ set label "" ]; `! a" } _% b
]
& t5 N2 B1 S% A& r& L% w' n( fend
+ I( J9 U! X" r }to reproduce
A1 n9 _* r6 g ask turtles [
" D$ M. A8 t# H" B if energy > 50 [) _3 p4 d8 Z5 i
set energy energy - 50: i; t$ C7 p4 R0 o4 R$ b
hatch 1 [ set energy 50 ], n1 Y$ @4 R5 J9 q# Z
]7 n5 ^3 |7 \0 h1 a
]0 P6 T* s: f+ `
end4 j ?, x( m. }7 F* ]! S& Z
to check-death1 w/ @; b9 P4 C( H
ask turtles [
* U' l* L: l' v2 y if energy <= 0 [ die ]7 h4 Z1 J& Y g# W1 y
]' P6 \5 _ o& h$ n' X. ?
end
_( t$ }9 @6 i' oto regrow-grass
$ R a5 ~( T( I5 }7 A ask patches [6 w, i: {; `4 ?0 _* F& u# G
if random 100 < 3 [ set pcolor green ]" ^" D5 G) w8 m/ _" d
]
/ F) ]. @( ]" e: x4 c- G' uend9 n/ v* ?; ~' D
to do-plots
w" P# }; {. V0 Z$ a \7 ~ j+ C' p2 l set-current-plot "Totals", A5 w( ^6 g7 p( E0 m( I! k; b
set-current-plot-pen "turtles"4 v$ n0 X5 ]1 {% x; c9 [+ a
plot count turtles
# Y2 x( S6 d4 W, y! S! ^0 e set-current-plot-pen "grass"
+ G" Z7 T4 p# `. I& \! j+ G7 Q/ t plot count patches with [pcolor = green]
4 K- n/ x* {% G& ]: i8 Lend0 D' b- H. f; I" k0 c
可是运行时提示no such plot: "Totals"; D: ^, B! M' w- G2 w0 g
error while observer running SET-CURRENT-PLOT
' @2 o0 {/ r# `/ d called by procedure DO-PLOTS
, ?/ I* G3 b1 B% Q4 x, Y5 j called by procedure SETUP
! |6 |0 G; G( g5 `$ `* @ called by 按钮 'setup'
, N) y. ~* {& x求大神解答啊 |