我编的程序如下turtles-own [energy]( ~) h B$ e7 r; P o# E
to setup
! D6 p/ v8 I U" a clear-all
3 a% h/ x" |) x0 P4 F/ I) k setup-patches
% B! c$ E9 u7 ~6 t+ E8 V create-turtles 100/ d1 Y6 E2 D, Q* c4 `
do-plots
, a1 j5 } e) ?. R) X1 L ask turtles [ setxy random-xcor random-ycor ]# E1 V( _8 v" v2 K% s. H
end1 W( o) T& k. c2 D& `
to go! r7 K( D/ k a6 N, ] `
move-turtles
0 Y5 S. K, p6 F* B; T4 y4 M Q eat-grass
" Z& @( f1 }5 @1 z9 H reproduce
9 W. L$ z* y E* |. t% z check-death: m. V7 s6 t8 c. j$ v
regrow-grass& N/ u. ?* O& \ ~" p
do-plots
' E% K5 ]; @$ ^" t/ oend4 G- P# O8 O1 s% Y2 b
to move-turtles, u* ~- N; c G* d7 S, |
ask turtles [
/ _9 X5 J0 z/ N! Y8 B5 W. l6 A right random 360. ^2 m$ b: ^7 b0 r& J
forward 1
3 w7 i, w+ n' Y set energy energy - 1
) ]6 c; Q- s+ ~! y2 O ]
0 _1 \% F( X& A. ?end" N& O" C S% b3 ^( C. i" r1 I
to setup-patches
" N7 B; }2 H( F4 Q ask patches [ set pcolor green ]
7 L0 L$ k& Z) g+ N( Cend0 x/ @$ s3 Q. s. m" _# S
to setup-turtles/ R* H- r/ r3 y3 K1 C) `4 _+ s
create-turtles 1001 l) r* ^- D: ]0 O7 K; ?4 O$ j
ask turtles [ setxy random-xcor random-ycor ]6 X8 F; Y: A) d4 V- x
end+ [; s2 ~$ l3 K2 m) D0 V( [
to eat-grass$ }2 k( {3 M7 a) H) E
ask turtles [
' Y. x7 B, r' s+ Z if pcolor = green [1 U, M4 _/ S5 j6 I
set pcolor black
+ U1 N8 y9 g; D set energy (energy + 10)
! ]0 ]# z( g9 c/ h ]9 A* G+ d# O/ m2 A' b5 Y
ifelse show-energy?. `7 `* c9 w2 t% {" i
[ set label energy ]6 o$ B s$ ~/ Q- I# W3 c4 j4 o
[ set label "" ]5 o, h- g; D3 e$ i2 x5 G) C3 H
]
) d, V5 `7 y- F; y3 x& }# iend
$ v6 S- M O) u) ato reproduce
9 O% ^4 o- U# u/ i ask turtles [2 y4 @9 q# h% r) Q& G
if energy > 50 [: \+ F2 ^1 U7 b) {
set energy energy - 50
, ^ |6 W) g' L, z- t7 I9 Q6 z/ h hatch 1 [ set energy 50 ]
2 b, d. X& y% r. }1 x9 r% b ]
, z4 K* n! a9 V9 `( E$ p ]
$ u$ H) ?2 @+ s. `6 gend
4 A& A$ o2 N' b' b( O w/ _! m" Mto check-death) [; S. W( k$ G2 z- U
ask turtles [& K1 z7 c' d' T" X! a5 k3 C
if energy <= 0 [ die ]
: a- ^' Z* ~' d8 r& m0 X- p ]
9 t& [% M) D$ oend
! P5 z3 V8 H& n5 P) Lto regrow-grass! E. s5 X6 ~3 ]
ask patches [
% i% y& k( w4 o; i* f if random 100 < 3 [ set pcolor green ]$ l1 u& h' R# h9 ? R5 r" f
]
6 V* \- L3 F: M! p& }3 s( u: S) Iend
; q( f5 v: S) @9 X+ x5 d) P. jto do-plots& v$ L$ J0 y) i( D: A& ]
set-current-plot "Totals"8 M' ~% i# M4 ]8 [
set-current-plot-pen "turtles"9 \$ w, b* v: ?. t- p/ @' `+ B
plot count turtles0 o; i4 `# Y+ b
set-current-plot-pen "grass": n9 ^, `7 ~/ b
plot count patches with [pcolor = green], S# S- y. d2 I: m6 [; s
end
1 S2 h( l% I! e8 Y/ Z$ W( b1 w6 ]. t可是运行时提示no such plot: "Totals"
" v$ ~9 S* Y# X+ a0 Y0 l E! u* ^error while observer running SET-CURRENT-PLOT
' N# A6 d5 [, J ^ called by procedure DO-PLOTS" y6 n" R) Y) M/ k
called by procedure SETUP" ~! Q% Y2 [; R" |8 l
called by 按钮 'setup'
* f8 t" Y4 N% E9 @7 h! W& v求大神解答啊 |