我编的程序如下turtles-own [energy]) r$ b) a9 [3 z. J9 z p2 U, n6 n
to setup) Z+ W6 D! H6 ~
clear-all- y% [$ @2 N/ G3 Q5 Q* H* I) {
setup-patches6 h# K' f( Z6 D$ x& \) v% ]5 a
create-turtles 100, |# Y4 G ^$ R
do-plots4 Q8 O o3 s9 n5 ^8 N& S0 m5 ~
ask turtles [ setxy random-xcor random-ycor ]2 h H& x5 H) k2 E. o' e
end
4 \( F1 `& m* u8 j. Lto go/ { X; { [( }+ ~2 D; i) l
move-turtles
% s/ x7 G0 I3 C) R7 E* m eat-grass
; y/ r# r' E7 \7 _+ Z, l reproduce
% A5 S* q' K+ y) e check-death2 x* D' m3 P k6 S
regrow-grass
) w0 |! f. A& G4 ?; \ do-plots2 g: o2 A+ [, W6 a7 M9 J
end N% h8 {8 p7 W1 t; z
to move-turtles3 |8 h& x! S9 s) p
ask turtles [
; }( m% T- Z- K9 X* d right random 360
8 J( D( w$ x: Y6 Y$ N forward 1. I$ d- U6 x3 [2 ~, }
set energy energy - 18 i) p0 \/ L7 i, R
]
; L8 b6 L s2 w2 Qend* ^) U/ U1 n. Y7 ]* ]
to setup-patches
5 y9 w& J) T( | ask patches [ set pcolor green ]
! y& ]7 N3 {; l% ^9 o' ]end
T' z1 K3 g5 w8 I! ^5 o" m& C" Ito setup-turtles
( e2 v' t3 A$ z A1 J! U create-turtles 100. M* J/ h; O% x9 V; ~ d" ^; O' b
ask turtles [ setxy random-xcor random-ycor ]2 E9 ]0 k! \2 B& ?
end
6 S1 P- }9 ~3 H* t9 L2 @9 Qto eat-grass% l8 W) l/ i W9 @
ask turtles [
6 F- O) d9 s0 ~( h! q+ s- W9 W$ g2 ? if pcolor = green [
% [) b- G6 B2 ?- _ set pcolor black1 j% \3 s# a; V \+ ?9 I6 G
set energy (energy + 10)) g' B6 b) o$ b }. {8 Z
]$ M2 Q. ^+ d! ]/ `% s2 `. o
ifelse show-energy?
- m* {& N" t, r, f1 R' b [ set label energy ]0 F6 z1 w' @) {' i
[ set label "" ]1 b% m- q- g$ ?6 B4 u) k8 c
]
8 L9 e! k% E% {- Send3 g9 Y$ Q d4 v
to reproduce u# k/ k& O; n. N3 b+ B
ask turtles [
" P% N2 L6 o0 m5 g; F. P2 C- B if energy > 50 [& O: {/ g- E% {. P2 R+ r) s, S
set energy energy - 50
% @! v) h' K+ O# y9 H. k) P( S/ V5 B hatch 1 [ set energy 50 ]5 f5 r6 U9 o' z4 g& s( D
]8 ` O$ a, i d5 t1 l
]( h9 @1 o* ^, @
end
, V, r/ j' _. {4 K% ^6 Gto check-death
) N' t) Q6 v9 ^( r ask turtles [" ]2 [( H! o. g! q m0 A) u% h
if energy <= 0 [ die ]1 N0 Q: d( v; w- i! C
]
9 j* {5 @" I7 v0 \: Cend
" c+ l+ Y" C5 |to regrow-grass: c1 d6 V5 N C) N) c2 V
ask patches [
2 C" R8 H% }1 T5 a0 c; H7 i if random 100 < 3 [ set pcolor green ]) _. M- l @" I2 V1 }) D! l
]
, o! e) X( { Q. fend
\# M" D- m; o H6 C% U# ito do-plots
6 U& C: x9 L Z7 K$ X4 L set-current-plot "Totals"# f7 `# K' _$ c% u. `* Y
set-current-plot-pen "turtles"; c0 C% ~2 @8 y' X* r' G; T
plot count turtles. \6 V K4 n* V; e2 K/ O
set-current-plot-pen "grass"
3 G# c4 F/ F- z- m6 t plot count patches with [pcolor = green]% `8 d/ b v9 h
end
' ?$ X1 F6 z' v可是运行时提示no such plot: "Totals"
& E" A2 {- J1 y1 gerror while observer running SET-CURRENT-PLOT
+ A/ |! B$ `1 v H' t8 l! \ called by procedure DO-PLOTS4 d2 V' f. ~9 E6 E) i
called by procedure SETUP
$ L1 x# T. m- u1 @* [ called by 按钮 'setup'
" E) J9 ^4 x! S8 f- _% i: w求大神解答啊 |