我编的程序如下turtles-own [energy]
2 s# t; A: ~% Cto setup
. S7 ]/ y0 J' R clear-all
8 g1 u/ I$ ], n- p2 o# L/ P4 M setup-patches6 m0 s9 T+ V1 O0 Z, ~
create-turtles 100
. p: ~5 [, q1 {4 H i) f do-plots
* K! a1 A Q G/ {& g( i ask turtles [ setxy random-xcor random-ycor ]% @1 ?, C# N! }9 n/ G4 A* n; r% i
end
4 g0 k8 a/ L" J' x Dto go
2 O6 T- k: w& M( B0 ~( \ move-turtles9 J* C3 C6 w8 X# c' f; O
eat-grass& d; o" S" S: V6 P5 P
reproduce. G3 h$ w3 S9 n
check-death
; }6 u7 Z1 M& u, s regrow-grass; p8 a2 | H, `# R) r
do-plots
7 E( ]$ G" Q' ^ i; g7 cend
; H; G6 V9 z- z: vto move-turtles
/ ^# b) K! H9 A z# N ask turtles [ L) N! F& V& C3 K" R8 J8 }3 ]
right random 360
8 L6 U$ W3 W5 ^# O# ? forward 1
# @) ^4 H6 C, \ set energy energy - 17 {. K" m: Y2 F0 `! Y/ j& C+ w0 h
]4 h0 E l' I0 }9 b
end
5 `7 K1 f2 w1 Y. x( O8 jto setup-patches
, s1 M; T0 y. E& M2 p% w ask patches [ set pcolor green ]6 G! U) W p8 a( F2 Y
end3 f4 `: L7 \, A; }
to setup-turtles
# U0 m; ]1 q$ Z/ @/ \ create-turtles 100
( U, g6 l2 R& C5 n ask turtles [ setxy random-xcor random-ycor ]6 m8 j$ W! O+ g" B4 V
end- B& n) x- t' I
to eat-grass9 [# P3 C4 t: D% q
ask turtles [9 C* i! k8 d1 v& L3 u: P7 E1 ?. k
if pcolor = green [
0 E) K/ z# `4 H: E: b3 V set pcolor black
( h6 J4 Q; o! h8 i$ _ set energy (energy + 10)
5 D3 @5 W8 M% \! ?$ I0 w# V2 b ]" K+ \) {! t3 u1 T* `- g
ifelse show-energy?+ e0 _6 k. y) L2 i# R) Y, x1 d: j
[ set label energy ]
% ]& B% q& Q$ y7 V: ]0 R [ set label "" ] g/ V$ M+ y q* a
]
& z Z D, e& S* w' ^9 N/ Iend
) n5 f9 W) B$ P3 D) F0 lto reproduce
* T+ z2 i3 d0 D. A' w ask turtles [' _) x0 x5 M3 N; _) s1 W; H3 t6 {
if energy > 50 [; r9 C8 d" R; P: F K
set energy energy - 50
! N/ w3 H9 c$ D9 U9 H hatch 1 [ set energy 50 ]
( d0 Z5 H, f. r5 D ]3 q0 E# w7 c( \: r; G- X
]0 a! F$ J: [: @5 o" l6 p1 @
end
5 z3 ^+ h1 I1 q8 X+ m9 Kto check-death
1 P$ a8 N$ V3 K; @, U ask turtles [
4 \0 M U4 u6 M% x if energy <= 0 [ die ]
6 a/ g* E+ ], r( I! p# n ]8 c3 q% P: s6 c$ \
end. n3 E$ l. X- u2 t
to regrow-grass
' j8 r3 P' C8 D; k ask patches [
! T! A" g7 c, ^" @0 M if random 100 < 3 [ set pcolor green ]
, c9 }1 L7 _) }' D- T0 N6 F! O ]% U x; C% C' h
end
5 N9 k+ w& n5 W, p# y2 n2 ]to do-plots
; i/ c. s. S) U, I q* L4 N$ ] set-current-plot "Totals"3 }3 U! g# ]# Z2 o" u7 A
set-current-plot-pen "turtles"# U" c1 _6 [% z" k2 p
plot count turtles7 U6 ?( |4 b/ W& N q Q
set-current-plot-pen "grass"
9 T6 f. B* ]$ A- L8 Q plot count patches with [pcolor = green]2 v6 R$ A1 S2 Y/ J {, y
end- Q/ B- `! c+ I* p1 L$ N8 U
可是运行时提示no such plot: "Totals"
7 v, i. N$ `* x5 `error while observer running SET-CURRENT-PLOT3 A) N" k* S. u
called by procedure DO-PLOTS
9 ]3 z# v' g% {% J/ R called by procedure SETUP) |! W7 e: X" n2 _4 K' N" x, r5 d
called by 按钮 'setup'
9 @3 y, A+ G6 g6 l% `9 S求大神解答啊 |