我编的程序如下turtles-own [energy]# X( b$ R. I2 p# @% J, d
to setup8 s3 w5 n. k2 \8 ?0 x, W
clear-all
; K- l9 l! k5 d, E5 i9 C/ d$ q) N/ \ setup-patches* s5 Y/ A; P+ i- H+ O! \; `, s
create-turtles 100
1 w' n! D) J' z. i" O" C( e( k do-plots
- r! G- K _; h8 B ask turtles [ setxy random-xcor random-ycor ]
* Z) }0 B r& ~! Zend
- ]% i. \) R* N" zto go
; Z' o, S: u7 ~0 V0 }! A Y move-turtles
% g* h2 D1 ]% T2 d+ H eat-grass1 _( s+ x* Y/ |
reproduce
# _$ A, _2 g8 a+ H! A0 g check-death
6 s o `# p9 F: l* m1 ^# t2 j% c regrow-grass
3 ~' P. i; Z+ h do-plots" O% L0 x1 C h9 |* a
end3 U6 ?3 O) W K+ k0 G9 s; L
to move-turtles/ S3 J! F. K9 f7 |, S
ask turtles [/ V" _/ S4 b" o) }- D+ Z+ d
right random 360
z; l% f/ s! [2 z forward 1
, E% l( y6 Q- G& ]( P% z! z set energy energy - 1
9 D5 I2 o6 d8 V9 B: X0 d' b; i ]
D: A$ A* e- ~+ S) I' r" y% Q% _3 Wend8 M' i' a& F7 n* x: u! P# O, R; ~( c
to setup-patches
" l$ d% I3 C5 s' k( G) V3 c, Q/ S ask patches [ set pcolor green ]
5 q' Y' C- E/ d+ O4 q; Iend
2 G9 A0 Q( D! y7 g. `& I4 Ato setup-turtles+ }+ U* d8 S- V( ]4 q) s
create-turtles 100
, W1 H) T# [$ W% h) I; N& H1 B ask turtles [ setxy random-xcor random-ycor ]) u/ d. {/ Y3 \. f! f
end
( z2 n+ J/ Z: q7 B# R, Vto eat-grass
+ b1 M- l, l# r7 k1 l; r ask turtles [
) l. Q% f$ y0 D0 P: T: o6 y! J9 S if pcolor = green [% M. K+ X# `7 [0 B) M* k
set pcolor black
% z ^, v4 O1 q C' J set energy (energy + 10)
! K7 i, _8 z" ~- h0 [ M ]
* `$ O3 ^: [! S5 M/ B8 e/ {% z ifelse show-energy?
/ J: m0 D L& W) s1 l1 w [ set label energy ]
/ q% {. m. T8 p8 O% x [ set label "" ] \% y, K- \# x1 A( i# R
]0 J0 h3 G3 L' o' t4 E
end; W3 D) ?2 A+ f" O4 Y
to reproduce
' C* `) m3 a0 u/ f" K. J3 ]4 | ask turtles [
# Y' L( C$ a* ]; } if energy > 50 [$ [. V% c! m/ U, R5 o* {
set energy energy - 506 H3 B* c0 s# F) Z3 w t9 W
hatch 1 [ set energy 50 ]
8 U6 L, e3 w, Y1 z; O4 T& c ]
; h1 }: x' \4 m/ e% N1 Q) E+ A ]
# t# x0 @" R- i+ M' dend
% ?% y- x8 k y; c) ito check-death/ d2 @* ^6 I; b. o: z
ask turtles [# Z- Z& o0 n* u( u& E5 n
if energy <= 0 [ die ]% k" h7 r3 B8 }& z1 X+ [: ?2 G& ~
]' Q1 X# C o# Z1 ?
end7 H* b+ h# O: D1 n4 C
to regrow-grass B; h5 }9 m# I9 b8 Y
ask patches [
0 \7 n. E: k9 n1 g" e# c if random 100 < 3 [ set pcolor green ]8 o* m9 W& e) O3 h% U/ m% w- Y1 C8 }
]/ e L% ~' U( x: l
end
! J4 \9 J' O0 o uto do-plots. z/ g7 d& F: g9 y9 ]3 @
set-current-plot "Totals"1 L+ N& s/ w- [# w6 e" R0 D
set-current-plot-pen "turtles"
, Z: i: b- x: R- a# E8 O2 B2 u. _0 K, X plot count turtles: D5 ^$ U W8 d( ^- [7 v
set-current-plot-pen "grass"/ O5 [) i9 _8 S' R T8 t
plot count patches with [pcolor = green]
. g3 K( f5 Y; Hend: J- s8 Z2 m# U# M0 e, j H' C
可是运行时提示no such plot: "Totals"
- R6 ^( r+ I/ n4 o0 k- |error while observer running SET-CURRENT-PLOT
2 }- `" S: R2 N/ g called by procedure DO-PLOTS
, _( d) F7 d: O called by procedure SETUP
6 a0 M" N/ I/ [: [& w g/ D called by 按钮 'setup'
& F( {, f, W# V( _求大神解答啊 |