我编的程序如下turtles-own [energy]
5 ~" ^! j5 x* bto setup( D: Z) J O7 U2 H6 P9 S1 s% b
clear-all
0 Y8 c- Z/ F. C* R7 T* r$ |0 l setup-patches
4 v$ d' U; _+ n( h create-turtles 100
% M) j. ^: O2 | do-plots( D9 n7 t; H$ a8 c2 \' I# O
ask turtles [ setxy random-xcor random-ycor ]
/ s: N" q4 f+ |- l/ T5 g$ ?end
7 N; A5 ~3 g% ^$ n4 N! Eto go8 C) _- X5 J8 _' ~+ M9 K, h0 K y+ Q
move-turtles
% o+ f* z5 e' }0 U9 A1 X! \ eat-grass/ _( n, N5 o' U/ n: X' a) l/ R" k
reproduce5 m: O8 }) W* J8 E0 m- g- K1 G5 |
check-death: k; }0 |& |6 u$ m5 x
regrow-grass
% X7 w1 @" F: O. l; o0 D do-plots$ W; Y. G9 Z7 x- W# w
end
) d/ F. N2 |- d( E% [to move-turtles/ {1 |" A3 N; J- d3 f
ask turtles [
* c R+ m" c4 Q, s0 @" x: L2 G$ c right random 360
: }! z n5 L) ` forward 1
) U/ P" t$ D: v set energy energy - 1
! h8 N: ^! h+ F. [ ]- K( a6 g# f( q
end
. E7 R% S& F$ C. Q/ Kto setup-patches4 M' Y% \9 e: K* D
ask patches [ set pcolor green ]# Z, ^' }) K! n2 Z
end
3 V2 j6 H! _8 R! j" P; eto setup-turtles8 ]: H' r% q" H8 ^
create-turtles 1004 |: L% a ?, `* h- ?
ask turtles [ setxy random-xcor random-ycor ]
0 W8 }. f& Q+ w: Hend( R4 J9 j# |- ]/ x/ [
to eat-grass& o* e7 R( Y$ x
ask turtles [# u t* h9 @1 F4 `. @
if pcolor = green [9 G- e6 r5 P+ r$ B# m
set pcolor black
7 {7 J8 ^/ s& O set energy (energy + 10)
7 D$ u2 ^0 ~5 N g' @. K5 K8 `+ B ]
& W" ]$ W; \# d, s, M& _, ~" ?5 J8 s ifelse show-energy?
+ D; K/ Z) }* L) V3 R8 f2 H [ set label energy ]
' h4 O! i9 e8 Q/ F- ? [ set label "" ]
, |4 t5 Z* [3 {6 G ]
+ n$ ? W7 }' x e8 ~: Nend
- {# U3 ~' X- @' d. S5 R% k/ f4 rto reproduce: k2 \9 @7 k$ ~+ w4 u7 l
ask turtles [/ q2 V6 _1 V3 L. B9 L* F
if energy > 50 [
' V- j7 _* @+ ]& E! w! I a( s set energy energy - 50
! z8 i# @4 w' p* I7 U; D4 m4 \7 H- Q R hatch 1 [ set energy 50 ]. u2 C' t( K- K/ q; o/ O b; ]
]
: A; @7 e9 r$ h$ g9 G) a ]
0 r6 J1 Z- G3 fend
+ \6 Z/ V% H6 \' U) c eto check-death% I$ l+ Q! H1 b* v2 s) D) s( O
ask turtles [
Y, k& G! {% ^4 ^ if energy <= 0 [ die ]. z$ M9 d" N) ]* A1 g
]
) W; F& _9 \6 Rend" B) v! |# i! y: |) |$ X
to regrow-grass
% G2 o' F( a M2 P: n ask patches [( @- o6 ^2 e& z0 i$ B$ y0 F! `
if random 100 < 3 [ set pcolor green ]0 N/ R5 H" d6 n. v% v- s
]
7 Y9 T+ z- @4 Y% A- {end
' Q9 r# S) B. G& m tto do-plots) Z! Q& ~2 k8 b3 Z; j+ y) E: S
set-current-plot "Totals"7 q$ I( O/ p# H- e# a3 i
set-current-plot-pen "turtles"
" C% B# l4 ]7 B1 W: @* s1 u( h plot count turtles
9 X1 a/ C3 c! u set-current-plot-pen "grass"
9 x6 k g1 h$ Y plot count patches with [pcolor = green]% J2 ^: z+ a" b- b
end0 `% \- `) f! V q, n" u' M
可是运行时提示no such plot: "Totals"; h/ F5 |* J* V# v
error while observer running SET-CURRENT-PLOT4 y$ B5 O" g& I1 O
called by procedure DO-PLOTS7 @. ]- |9 G' N) r/ x& |
called by procedure SETUP" L7 J2 p: W$ \7 u5 z
called by 按钮 'setup'
3 Y7 w6 Y, R/ _1 |8 W求大神解答啊 |