我编的程序如下turtles-own [energy]0 \( p2 E0 }$ X2 t0 p' w
to setup8 B% w8 }6 z1 l( [( A- P1 d
clear-all6 _ r, u$ \9 W3 [% d: Y
setup-patches
( L8 v: X$ z7 W. X: ] create-turtles 100
9 o3 n s* l$ u% K8 r- q6 R! c. g do-plots
5 S z! Z" d: P8 z, D1 e# S/ `8 {1 G ask turtles [ setxy random-xcor random-ycor ]4 L. F7 s: v3 d
end
/ A/ V+ `# q) {to go
. H1 W' b& I$ J. _) g' W- N7 Y5 x move-turtles6 p- z! `4 {' W$ @
eat-grass
: [$ a# ?! D: ?! Z$ f& ^ reproduce( e4 y3 q4 [2 c( A; l1 `
check-death
7 c/ `# t& N2 X- t! a regrow-grass( k7 q: C$ a2 j7 ~
do-plots8 ?5 P, W/ q* }" u. M
end
]; `: B" p) u2 s1 pto move-turtles2 c7 d4 a. m" |
ask turtles [
6 T2 U- _3 K7 `. u& [ right random 360
& s- T/ q( J& h# n4 e forward 1
3 i; c/ s: i7 q) \, S+ R set energy energy - 10 D$ z7 }( m$ _6 w( j8 k$ Y
]
2 s8 ?2 _& f; m+ Rend
. I* Z" S& N% z. Rto setup-patches
/ Z3 @% ^' o( S: ~2 _2 M ask patches [ set pcolor green ]" _8 H, ^, f4 s- m9 ]
end
3 H0 A& u; ~) w+ m& `, P' ?6 J- ~. mto setup-turtles
. B: m6 K2 l! t' [$ y create-turtles 100
4 V* Z& R& _" a# J) Z8 I) ~ ask turtles [ setxy random-xcor random-ycor ]
6 h1 b, U' ?* z# x9 Gend
! z3 g6 @/ N% c& |+ ]to eat-grass* S# k: o- H* V, j8 V5 S5 Z
ask turtles [
8 [/ a' e v2 v+ f if pcolor = green [
; k) B2 K n( M# Y$ f set pcolor black
) J- s9 @( g% u& A0 W' ^3 w7 y! k set energy (energy + 10)( ^/ X( _( e# n' h
]
# ?$ x7 L; {" |) H6 @9 s( W: a' @ ifelse show-energy?9 W4 J: Y, l+ |3 V0 ]- H
[ set label energy ]
1 g& p' r; x8 C7 D- f1 V [ set label "" ]* X" S' w/ ~- }7 |/ V
]% o! R. d- _2 {' s. [6 L( d
end# f" S K7 ^$ q5 M9 I) x
to reproduce* b3 P" `$ i/ P1 t" D) O
ask turtles [
: K) h+ \5 W: x1 B+ f6 u4 i if energy > 50 [* g& D+ B0 f& N) l: e
set energy energy - 50
, W. w" n+ s( P* d' C. x& o0 S hatch 1 [ set energy 50 ]2 i; \' ^! N2 J* R
]) N5 ?8 I3 l" z8 z. f$ B2 a# w
]
) D* c* p9 S' H# \end
& c n# ~, w( X, y$ \0 y7 J) Qto check-death9 L+ A8 i* u$ [$ @" k8 w+ |
ask turtles [$ u6 x+ |! r$ V; R4 Q
if energy <= 0 [ die ]* ?4 x, W T$ b5 R1 o+ V2 }
]
3 L; N& h6 b) Q, i& v' _end
* c ^" }# A0 lto regrow-grass
i1 ], z _ R: F6 _& m+ v& H ask patches [1 j6 g z+ ~6 A& V: B) G0 \; f
if random 100 < 3 [ set pcolor green ]* G2 m9 c/ h3 [: c' [5 Q5 l
]# X# g1 Y3 {+ v, N7 z& ] Q8 A. v
end
" `. j* W+ z( k* jto do-plots5 @# F. v) O& W# w" n$ L
set-current-plot "Totals"9 v* X( U- B" `; `: i
set-current-plot-pen "turtles"+ V) w9 s0 z! ]6 w; f0 j, q5 N, F& k; z
plot count turtles. [2 Q9 g/ p8 J L; D7 W5 ~
set-current-plot-pen "grass"* K }1 Q4 \) v& V" S
plot count patches with [pcolor = green]
7 X0 H+ n2 Z$ X7 xend
% Z1 X8 d% D; o* s可是运行时提示no such plot: "Totals"! o- O4 Z0 I; q
error while observer running SET-CURRENT-PLOT
, z6 N J" } B* G% L& ~ called by procedure DO-PLOTS
- b$ U% |9 i- Q- S, z1 q called by procedure SETUP, A1 G% v+ w5 W( l, h5 P
called by 按钮 'setup'
- W6 Q0 x/ I9 p( K& |求大神解答啊 |