我编的程序如下turtles-own [energy]
$ W1 e# W$ Z% Pto setup8 \2 d2 p+ S4 C8 H+ [) t
clear-all6 w4 Q( u5 A; F7 q* |1 K
setup-patches
; L# o* Y( `3 l6 n0 G: O9 P create-turtles 100
3 }. d I( O/ o4 F! V4 V* T) o do-plots
0 w7 |* ~6 X; @ i ask turtles [ setxy random-xcor random-ycor ]7 P+ ^$ f: ?( ^9 n: E6 H( Y7 X" _
end
! m6 i7 H; U- D$ B; N! X) ?8 wto go& O! X/ ~3 ?" O& Z
move-turtles- P) G$ V5 H+ c0 F q: N. J
eat-grass
, ~' @3 M; C& w/ v" i& m reproduce' I# C, W" s, p* y5 g
check-death
7 J* n4 j* w; H+ _( z regrow-grass
; v9 H% q" X7 e0 J do-plots
8 U! }# M! Y" Y# I2 d& f' X% Aend& b6 N; P" q X3 v+ d3 y
to move-turtles
& b1 N, Y! |! b3 j2 N ask turtles [
G& O) Q7 W9 c, [ right random 360
$ B! m s! S# U& D$ b forward 1
. q8 U$ g( x% @, ~8 Q" O N5 ?% F set energy energy - 1
2 E6 Q5 G2 e# u' ]8 [' d# b" t* h ]
1 g) ]$ I0 ~' z+ O& Oend
- V- N; X2 R' Lto setup-patches( j, H2 A x- l% J. E! L
ask patches [ set pcolor green ]3 Y0 h2 q' D" o' A9 n- G
end- l, v+ p W$ r+ @5 D
to setup-turtles3 L' w* r6 K* a9 a
create-turtles 100
, i' h: Y" l8 l% o+ M# w ask turtles [ setxy random-xcor random-ycor ]" o8 e4 d, i% a9 O9 n/ ?# V
end @* ?5 S# o3 {5 P, n
to eat-grass
/ K& `# i0 {. X8 s ask turtles [
: r4 X, W; P3 Q5 z6 u2 j0 R if pcolor = green [. M0 y& H2 A' c0 Q. f7 X
set pcolor black' d- ^: i2 ?) q$ ^: z% |7 i
set energy (energy + 10)
' T) ~1 e4 \6 k- C7 n ]/ X3 K# y1 }9 }7 `1 ^, R% H
ifelse show-energy?2 g9 K1 Z: i+ L( b9 s: N5 r
[ set label energy ]% o' @8 K! f, [' M. F' k/ e
[ set label "" ]* g4 @: T% W, W
]* {1 V% V4 g& {. ]% a
end
) Q3 g% x9 a, q1 ]+ u$ g- B) S1 @to reproduce
! Q) `4 V( g9 k; v$ ]: ]* R ask turtles [* X6 D/ U& |0 i+ A
if energy > 50 [
. r1 \, A+ @# j/ W9 f set energy energy - 50
) P3 {! Y9 _8 [# c# i0 I hatch 1 [ set energy 50 ]
1 C! b6 s$ b" L ]
% I% e# ]& ~9 V" B3 H+ {" e ]; E- s% c% w. S
end9 S- U; ]: n3 u
to check-death
* z" _/ Q0 J4 h# P ask turtles [
$ e* g5 L. L7 t% M( j. C if energy <= 0 [ die ]
8 d5 J3 Z. W. B; P ]
. N9 Q/ o0 l/ _5 b% W9 ~+ k2 ^; wend
4 _) P6 R/ G- g* w0 Dto regrow-grass
- J8 P; k$ d$ K* B/ r3 L% C ask patches [
, N% E0 b: a$ @* { X) U! h) U if random 100 < 3 [ set pcolor green ]
7 ?. H- |; \. C0 O. O- s ]+ g) k0 D. R8 E* \6 K' T/ O2 y# C
end# q2 I( V* L& U
to do-plots# Z; F9 ?( T% G+ Q) Z
set-current-plot "Totals"
+ j9 P2 n1 }2 k8 O. k; M, I set-current-plot-pen "turtles"
5 c6 w; N+ N, \, z2 ^2 R" I# L plot count turtles
1 o! Z+ H9 d& N% l# E2 `; N set-current-plot-pen "grass"
0 a# c5 p6 c$ H0 [, ~ plot count patches with [pcolor = green]( C7 G6 }4 }& a( V+ @
end
5 |: b( ~! ^) j& j可是运行时提示no such plot: "Totals"
) [7 N$ T, M, a8 ~1 }$ ?error while observer running SET-CURRENT-PLOT
3 F7 Y7 x( n$ D" q0 L, @ called by procedure DO-PLOTS
% B' k5 A: F0 z$ A# @ called by procedure SETUP
! h* c( N |4 G# } I8 K called by 按钮 'setup'7 |0 U6 b. r) w( @. \9 ?; q
求大神解答啊 |