我编的程序如下turtles-own [energy]
5 _, ?; h. U* ~% @4 c% M) ~to setup2 p) [# h7 ~; z2 w) P) j
clear-all
4 K @' ^$ ~, h7 E, t4 o) n9 [ setup-patches7 ^% j4 D# R6 j. B% I3 U, L: x+ @& N
create-turtles 100
2 I1 F2 Z! b0 V8 m do-plots
0 x1 v; w9 i$ [, F$ p% F) R5 F$ q ask turtles [ setxy random-xcor random-ycor ]
8 O4 y' s% ~: Z! Rend+ _# o4 v% h: S0 T, O
to go
4 `# h0 M4 q& a# { move-turtles
3 s0 }7 }& g1 u7 v( M( K! R eat-grass: i& ^( {* t' m( ~
reproduce
1 e" @/ |. z4 T check-death) v( u. i; R- x3 [( c' L
regrow-grass$ b. C- x1 b! R/ G
do-plots3 [8 D7 `- u3 f6 o/ x. J
end8 u# R0 W7 c! G
to move-turtles" g! ?- z2 R" H7 u
ask turtles [
$ r D7 Z1 O1 a* c! c right random 360# v8 h1 [; G& O; K; N7 f) m
forward 1
$ z( F2 \+ }1 ^4 Z3 V set energy energy - 1
. {% [ A5 z) E$ I. ~ s+ \! W1 _ ]* [6 [: B5 y) M# Z( g
end
6 ^: f0 S9 {* [/ y* y0 dto setup-patches2 I8 M" d+ L* R8 e% g0 t- E( H
ask patches [ set pcolor green ]- a& V- m1 }) X
end u M2 S) v7 O; W8 e
to setup-turtles' f# T2 O# `1 A6 z, D& r: {
create-turtles 100
9 E8 u: r# {7 A1 ` A6 n) `4 C ask turtles [ setxy random-xcor random-ycor ]
. k6 o$ @0 ?" s2 Iend
8 _; _ i- o# b( v" E M9 Yto eat-grass4 C4 c$ J9 _$ d2 `4 y# P) J2 U( I
ask turtles [- b0 m! T2 x4 r0 ^8 T9 {: y
if pcolor = green [: V/ S& h+ Y/ r# D- C
set pcolor black
' m3 l8 ]4 n* H) ^1 v set energy (energy + 10)
7 u, }$ {6 ]( L- q4 @" L4 y ], B, o) Q% W# c0 [. t
ifelse show-energy?4 I2 u- O) N& {: N% T
[ set label energy ]
' S- g! p' V3 y4 I, S. \0 { [ set label "" ]8 S. k5 |, `9 s+ ^* k- F
]1 I5 x8 R$ s( `% i0 G" ?2 o
end
. K, a8 F) }# Z$ N0 Rto reproduce
/ n5 Y. ?2 ^4 f2 B" b0 ~( T ask turtles [1 @# H/ M. h) u: c5 N- J( _1 h
if energy > 50 [* D: C, e& ]# @: B6 S! a6 g
set energy energy - 50
# U( f5 [' \2 u5 B4 D M5 I hatch 1 [ set energy 50 ]
3 }" p' b) W$ F k ]( G' q# C( ^- v, u$ R8 A! \: e0 i
] S+ k5 e" H1 Z6 {. P
end; s/ G: |1 X( |8 e m
to check-death3 r, L$ X4 G0 y4 i$ _$ ~; U6 P6 k
ask turtles [
2 R1 x5 R% v9 E( n if energy <= 0 [ die ]
U5 i# W$ z2 H& g* s+ c1 p3 }7 g ]) H; \; K6 I, C- A
end6 Y, T: H& r- [$ b. E/ _
to regrow-grass
7 P Y* B# l, X% Q8 u+ ~# b ask patches [1 Q8 M' x& k: F0 z0 N
if random 100 < 3 [ set pcolor green ]
( e, P4 m' w# J n9 M ]
1 R! T9 J+ D+ q( Eend; U# c* v/ Z$ j6 A% d" h
to do-plots1 U+ M8 I* i" w/ P0 r% u
set-current-plot "Totals"
) f7 a) k7 Z/ G% k set-current-plot-pen "turtles"
% X5 l% [* c- Z4 k! T plot count turtles4 ^; h5 b4 D7 d# { n, M
set-current-plot-pen "grass"
* m& \% E* Y) j; e! P plot count patches with [pcolor = green]
1 W" _# ]3 q/ M3 xend6 x3 {0 r2 G4 M: z! g& O
可是运行时提示no such plot: "Totals"
& Z3 t$ C# \& Uerror while observer running SET-CURRENT-PLOT9 V. C, F" `& n5 C
called by procedure DO-PLOTS' M: m0 Q9 I+ N+ w4 A$ ?
called by procedure SETUP1 Y% n" {4 H% G( c! D' C
called by 按钮 'setup'
0 y3 \' |9 v6 z( _求大神解答啊 |