我编的程序如下turtles-own [energy]- R6 g. l2 k% K( v b1 D5 G( e
to setup. o" I& Y1 Y. ^ I
clear-all
) j8 u4 C. ]6 p. m2 Q+ H setup-patches
: a3 ]: A2 z( k8 @# Q* b create-turtles 100- i) Q' a& u3 E& O" c
do-plots& \9 L3 o. e/ E; m( s) i
ask turtles [ setxy random-xcor random-ycor ]
% C% }) |2 m& qend: l- t7 G( X5 ~
to go: i- K, K- Y& b3 Z3 ]
move-turtles
4 _7 V+ ^( W9 Q- x eat-grass
+ m2 @' o3 T4 [9 d' W reproduce
! g0 w; D7 f% c) {, I; j9 v check-death; P7 x! c: B+ D+ J& V+ Q
regrow-grass/ V0 U, G2 b+ T" a( D U
do-plots: ^ [0 i9 d p& M) s8 L
end' I2 ~( B" H4 @
to move-turtles' J- S/ I; i# k- z( B' B
ask turtles [2 b, z* e1 i& r' Q3 c
right random 360
" S8 }* n5 J t forward 1
" ~( x I; |1 g* X( m; _ set energy energy - 1
% K$ i6 p) M: @4 r0 |2 U" b ]) K2 |% z0 x2 U& w; ~
end1 A! e% R$ Q( V" i6 \. {
to setup-patches6 E& o3 I5 W& }1 p0 I( J
ask patches [ set pcolor green ]6 L9 T! ]/ S1 q5 b& P9 t' A
end3 h3 k4 k e) @/ ?9 b& d4 r
to setup-turtles/ J6 @7 g; P8 S/ b1 z
create-turtles 100
* \- R0 |5 q+ t( t9 z8 Y% L ask turtles [ setxy random-xcor random-ycor ]$ H+ p( m- h. u% G2 \2 J
end
) J1 U# F8 X# l; H+ ~/ Bto eat-grass
( N6 E0 L% a# S ask turtles [% `+ J, s7 V# N% d1 h& F
if pcolor = green [
% A2 [5 U! A6 I: Z" p set pcolor black. A7 B$ {8 w5 l# y A
set energy (energy + 10)
; B2 s4 e& t- W/ E ]. d O3 P4 Y# e* I
ifelse show-energy?
% P# `# ?; Y4 e; {1 o3 @4 { [ set label energy ]
) y' B1 _3 R0 D+ x& e# r/ y; V% i [ set label "" ]
3 P! m) F1 @5 `, P! O1 m ]
0 e3 @: f5 l+ n! j7 jend
0 }9 L% O: ?# F2 m& }6 }0 d+ dto reproduce: g' r ~8 C0 b% g
ask turtles [) s5 ^9 Y; Q6 o$ |
if energy > 50 [" H3 |! M) G/ @+ W( P4 u
set energy energy - 50# [. p ?/ H8 t; G0 L) s* [
hatch 1 [ set energy 50 ]
. `3 l: M" V0 D% T0 O P' S ]
& r$ J8 Z& f; b$ r ]
& J. S! [, c, N# @end. O3 H; M) a8 O+ P5 _' ?! c
to check-death" m& S2 N8 p4 W, d- ?4 b" Z5 O3 p
ask turtles [
$ S& T+ o8 J- A+ q, T: M9 X: K! T# A if energy <= 0 [ die ]. C. g* [- j& _ m! H. e+ o
]/ L9 K% `: \! m1 D( V
end
# T8 t- F' {8 r/ l9 q0 kto regrow-grass
5 D. R$ [1 J) ?1 B2 L ask patches [! ?/ c, Z' j+ \, x |, z2 b$ F
if random 100 < 3 [ set pcolor green ]
1 G% V0 W+ y5 L; r ]
' g3 e" @7 z1 ?# ~end& \0 u3 H& u% i% j+ V
to do-plots# {/ d( o# J/ J/ M4 b1 n
set-current-plot "Totals"% ^% H Z% l- B1 Y# c! u
set-current-plot-pen "turtles"4 d$ }/ S$ A0 R& d5 P" n
plot count turtles6 Y8 i6 B; Q3 `, G
set-current-plot-pen "grass"
) @9 X" B5 D1 h9 r& J3 b plot count patches with [pcolor = green]# Y8 R9 @) U2 I" ^
end: N' K: ], m! Z" K: a6 K
可是运行时提示no such plot: "Totals"6 W: r4 e4 ~: ]$ q9 N$ `
error while observer running SET-CURRENT-PLOT
; Y* O0 d; _' ^4 p% ] called by procedure DO-PLOTS. ?0 P- @+ p. d3 o' F( D3 w* A
called by procedure SETUP
& {0 s) B3 U: E' j' ?( m called by 按钮 'setup'
/ v. r% y; t, H$ P( T求大神解答啊 |