我编的程序如下turtles-own [energy] n) ~/ H! n$ V0 h
to setup
7 A4 e8 L6 T5 |9 N! T! w clear-all
) [7 d' A4 \+ e" L* F' K setup-patches1 D$ z# p5 Y7 E8 g4 F7 N
create-turtles 100; G( @3 M# m3 \$ x1 u
do-plots2 \: n6 U# t3 T# t& Y
ask turtles [ setxy random-xcor random-ycor ]
- y0 E' _& s" {3 _" Zend8 X# e: g0 ?1 s5 _, n; ~
to go
8 I0 C% v5 L! f3 w0 e- ?" a move-turtles
W2 e" M3 T/ U r+ c8 Y2 E eat-grass9 E _7 m7 I5 o
reproduce, g$ d/ o8 u* X; K S% u' d, i
check-death. [* E8 ^+ \! _) N8 ^" k/ Q
regrow-grass
% k( o) [/ D/ U/ d do-plots
1 S- ^* l* v& R3 Z3 gend
6 x. n8 y& w; y* N xto move-turtles% d6 L: b* V" m- B1 @( Y
ask turtles [# ?7 R" K# D# e7 F( N, N
right random 360$ r& Y! h- r, N* X! L( ?- g$ x
forward 11 s, k: g! d3 V+ p" b3 j! S
set energy energy - 1
" g% ~" [: a; H7 B4 f9 n ] `9 m) `6 p1 ]& w( }( ~* ]
end
; O, z; B9 l( rto setup-patches9 X6 k+ y6 a. x( c
ask patches [ set pcolor green ]
1 C+ n4 [" a3 m- M% l# y' @! ?end6 C* G0 V, r* q& O2 c* y
to setup-turtles4 ]. y/ ]2 Y( z# k' {& }3 U( H
create-turtles 100* M# e( {4 o* |
ask turtles [ setxy random-xcor random-ycor ]
" N% A# c; [8 U6 W2 Wend
5 i2 E. h7 f3 _; Z/ E% w2 ?to eat-grass$ Q4 A. ?4 P- n$ G* [" h( G8 V1 g* ?
ask turtles [
) P7 L8 L: S* u! d2 K" @ if pcolor = green [
% Q- d$ @6 D0 b8 R7 Y2 |( r9 ^ set pcolor black8 t* A% f# f$ z5 A' `3 ?" U+ R' {
set energy (energy + 10)
9 n3 ?. j2 Y# H ]
* `# _4 x/ w2 M ifelse show-energy?2 g, v* y3 B% L2 Y7 c2 t
[ set label energy ]
/ W. j/ i1 L2 |9 n [ set label "" ]6 V' |) H0 k5 Z) x" f" e
]
+ g+ @6 @3 d/ Q9 Vend! `9 j9 {9 K7 }& ?
to reproduce
) x# ~4 ^# W+ W! k ask turtles [
4 }* s$ f% G# b$ T! a. f if energy > 50 [8 j, ^( V2 g G1 k# Y0 N% w
set energy energy - 50
1 q* s* V0 z8 W8 a* W+ Y hatch 1 [ set energy 50 ]. x. `1 C8 u6 X( s. N
]
L, _" _) j% u$ a+ p: F$ t: \ ]+ b& r$ u2 h8 K. p* t
end
1 A/ a' \ h( e7 b7 n7 xto check-death
c: S) F( y% w' _& N3 `( F0 x' X- H ask turtles [! _. ~; n- @- g5 S! F7 F
if energy <= 0 [ die ]
# i$ I- \0 \2 X0 \! z ]
' R5 q5 b; t4 Send4 b* t- p8 X& ]# n% E9 L, P
to regrow-grass
& w) l0 `# a( d' U( L ask patches [
% c% P9 ?1 L4 t* d Y2 k if random 100 < 3 [ set pcolor green ]0 K' b8 H: G% ^6 Y( m! g1 \
]
: D- `; I; ?: M+ S5 p1 Kend: t( K J+ T6 l3 E$ ~: n
to do-plots
/ ?" d5 y8 _0 c5 \+ f4 b5 V) r" N$ _ set-current-plot "Totals"
7 G2 S/ T" O8 G1 m set-current-plot-pen "turtles", a+ c3 w- ^+ h) p& M" l. U7 W
plot count turtles) F1 a& C9 B& ~8 a" e+ U; |
set-current-plot-pen "grass"# Q1 I Y* z( ~! q7 k; e# b0 j
plot count patches with [pcolor = green]
7 C8 a @8 u, A4 Xend: I' G! v2 `2 n
可是运行时提示no such plot: "Totals"2 `7 Z& p0 \/ ?' J! [9 e j
error while observer running SET-CURRENT-PLOT
: b) o& Q. r* J. E; B6 {8 L called by procedure DO-PLOTS
- q$ o6 ?) ^" N8 u: n# n called by procedure SETUP
* r; \& U# R& h4 Z7 Z+ E6 D called by 按钮 'setup'
8 I5 N' A% o9 P7 |8 J9 T求大神解答啊 |