我编的程序如下turtles-own [energy]8 r/ a- X4 m& Z
to setup* I6 x; Y. o8 v) \% [2 W+ a
clear-all
0 Q8 l4 S. E, O y5 n J' g setup-patches
! v3 ?! c9 y3 Q2 F# ^3 w create-turtles 100
3 V( X0 K) b% g& N" K- ~ do-plots; |. ]" {1 Q2 S" U& ]
ask turtles [ setxy random-xcor random-ycor ]
( r5 {6 m# d( j' n1 Dend
/ U8 o, f* Y3 r6 |to go" y! W/ f3 x2 _1 {- a" \+ @
move-turtles
5 s0 \* P$ Y [* B2 r eat-grass$ S. y5 R* |" \1 g' S1 f
reproduce' M& M# J. Q* m y( F
check-death6 N4 a6 S2 U# A ]
regrow-grass
9 F* [- E: M: h# Z: I) L& o6 v' `; J do-plots. q$ ~: ^. K+ U- w; {
end
9 ?6 {0 |' ]" E; e( I8 X8 Uto move-turtles
) w& x" D+ S. Y2 x* K& k ask turtles [8 B$ T! q3 {* t/ p& \9 E
right random 3601 a, z9 B, @. U& N
forward 1
$ W( _& v$ K% q0 x6 y set energy energy - 15 ]- f$ s- ?: ^/ C( K! h n
]
, Y0 _" _: t: ]6 z- |end* r) C! d! t/ o) D% I& _& e
to setup-patches
: @3 A, w* \* E5 ?5 b ask patches [ set pcolor green ]
- h) r Y0 N: ] t0 o, b+ w; _end
. `$ w( _( M# gto setup-turtles6 ?8 _3 I$ L* z
create-turtles 100
* v" ^4 `8 r0 a! V8 E# J- P# | ask turtles [ setxy random-xcor random-ycor ]
% n9 H0 y I5 P+ l+ q7 A- q/ l; Bend% J2 y7 W& E8 A" l
to eat-grass& D$ c9 z2 l. r) B
ask turtles [
0 r$ R8 O( @! k; C ?0 r if pcolor = green [
' u# d( `/ `4 {$ ^+ `+ ]9 m4 s9 G7 o set pcolor black1 l: o; [1 o6 T, |2 Y, V
set energy (energy + 10)
7 P$ u- k8 K* c0 \ ]
% a9 R y6 \( e8 @ ifelse show-energy?
! V8 G6 ?" D. v$ P9 n- l [ set label energy ]+ S7 F, T+ G3 J4 h0 P6 d" I
[ set label "" ]
7 M5 O3 @$ d. x# z+ ? ]- I4 r3 V6 w$ N7 S6 A3 S# X
end
* `6 }) [ i M" G( Zto reproduce
a& [4 M0 V; G& o ask turtles [
8 t- M1 `: ~# h! S. Z( R if energy > 50 [1 A4 E0 s, u4 j9 q
set energy energy - 50# h' x) O# v2 |. V$ @
hatch 1 [ set energy 50 ]4 b* \7 l4 G3 T* x0 @- Q3 k
]3 U1 ]/ @0 d1 c1 L4 r1 ` l7 ^
]
& r6 u& ?8 C P' ^' Y$ Zend1 \# h' _& j$ v5 K4 B$ ?
to check-death' n3 [ A$ |# h$ m
ask turtles [5 q# b0 c3 b* I0 Z! v! L
if energy <= 0 [ die ]
& I7 U, u" ?8 K, e6 j ]$ |. L( b" n. z6 q% S
end
! E7 l1 k* v/ I+ Nto regrow-grass
" n; B/ _" j& F2 n/ V0 n, | ask patches [2 T! w) I& @7 T% a# K9 _0 Y
if random 100 < 3 [ set pcolor green ]$ h8 ^; p* B9 O4 T4 g0 J
]. }: W5 c% q: i5 g
end
3 V5 M3 B/ @8 ^to do-plots
2 A* F; b+ L! s' Y0 `7 I, v( { set-current-plot "Totals"6 Y# O" g) {- M$ B- _, p
set-current-plot-pen "turtles"4 ? D d/ r+ h% R# n) |# K
plot count turtles
/ U5 l4 U# v+ ~0 P' _ set-current-plot-pen "grass"8 I+ D1 g% n0 k0 }6 s
plot count patches with [pcolor = green]: y0 C* t$ }$ j( ^3 |# X
end
1 ]& U. x* z; }! S$ x$ s可是运行时提示no such plot: "Totals"
! C, v& X: [# F: h5 oerror while observer running SET-CURRENT-PLOT
5 n* b1 @0 J9 \& @9 \6 B called by procedure DO-PLOTS
?6 h& L: |& \6 P* I called by procedure SETUP" n! s/ c; T8 e' i* t6 a
called by 按钮 'setup'
( d5 R, `0 V6 G7 d求大神解答啊 |