我编的程序如下turtles-own [energy]
: a. s: `, D' {: gto setup
9 ^0 X" U m0 e5 n5 O2 V clear-all
- C) w. E. \1 g5 l: Y setup-patches
0 O7 I( Y2 M8 A' p7 L; H create-turtles 1002 F, b0 \- r( e j
do-plots
, Y( p. o1 t8 }( E- z# \ ask turtles [ setxy random-xcor random-ycor ]( H' ?) m$ W5 j& m6 K7 |
end
q7 f* @4 f2 c7 L2 [to go
" m" ~0 o% }9 q& s% ^* T ?7 A move-turtles5 u$ u# U% O+ F+ a f
eat-grass" }+ q! a* \4 E
reproduce' o; l& n* P( ^9 Z9 D
check-death
( S/ W/ H# s0 \3 t6 k regrow-grass9 {1 _/ j* o+ g3 W+ f: @9 X
do-plots
% N8 V+ s) I+ R% Aend
9 n( w0 s3 T' O# w* C: G3 n* xto move-turtles. `, `/ [ Y( [ Y5 M. I
ask turtles [
. \8 E/ B3 P) r7 ^7 s/ N! O1 t right random 360
j, \( j4 {" x$ F$ D9 o forward 1% }+ |- x6 C0 h' r: H4 k
set energy energy - 11 H3 B. [6 c) r0 b% h2 W
]
0 o/ V7 F+ `) V6 N4 lend
}- {& E) a- uto setup-patches2 @6 k2 Q+ ~" L* y* n
ask patches [ set pcolor green ]+ ~4 m, x# x( k$ E! G+ l
end
1 Z' l$ q, q) }1 y" b, v, _) wto setup-turtles
: E" M F* }- b' R+ q create-turtles 100
+ [; }9 ] J2 d( E& l/ p ask turtles [ setxy random-xcor random-ycor ]* }- @0 e3 D2 p$ H
end* F1 _8 a% x1 l/ L2 L/ E: s8 R
to eat-grass
. d: f' ?, e! s7 h ask turtles [4 G8 [; C H5 M, {8 m* Q9 [. C
if pcolor = green [9 i& n& m% V3 W$ s
set pcolor black/ T) P6 M; Y3 N- y8 r
set energy (energy + 10)
9 M- D0 _+ z! n7 \$ S6 V( j6 m1 T ] ]. d# n. }' J! |3 s- p8 W/ t" f
ifelse show-energy?% ?. m' d& X6 a# j8 @0 c
[ set label energy ]( {* u4 @! M# \2 y5 d' h
[ set label "" ]7 n- Q: I% X8 }3 \2 K! |
]
0 C# j& l# n! ]/ g4 P% I; i) e: Uend
1 g j% ]" `3 q: G6 Oto reproduce- \& x$ y- y# a& A5 @ q/ N
ask turtles [: U% y/ ?: E( N" w
if energy > 50 [
7 [' `8 @, ^0 B2 D7 r! a set energy energy - 50
- ]( I1 k( M1 R U5 I- b# G& N* ]8 Q hatch 1 [ set energy 50 ]7 [1 u/ O# ], F0 N# [$ }5 ?
]* O" n( g5 T, G$ U" P
]3 x6 V) k5 p+ H8 k, b8 E% m, Q
end
/ B: p0 j: ]2 M7 q' [$ c( j' Nto check-death
; |0 ]/ I. W$ q- u0 r ask turtles [
0 S* v; R" ]( @% Z if energy <= 0 [ die ]8 F+ c/ F) `, W8 ]
]
+ s3 V$ s# U; Q0 I/ K2 I! f: Aend
7 i5 _* B. y9 r$ |0 ato regrow-grass
2 p5 h5 d9 `. k# i( {; `& r$ m ask patches [
1 K; s4 u( t9 G5 X0 i$ a3 e if random 100 < 3 [ set pcolor green ]4 h% n% S! Q2 M
]
, r5 }! C9 Q# i3 `' s" J- Tend* k7 `. U6 |3 l, S! R# [9 X
to do-plots) V: X- I0 Z2 r5 P# W
set-current-plot "Totals": U$ B$ \" u+ ?% N! }- F! S
set-current-plot-pen "turtles"
: T1 I/ S& [+ H3 G9 k/ X! u# P plot count turtles
: `8 ]' s" ?& ]' D* x! Y2 D set-current-plot-pen "grass"
1 x9 I, R# X6 a3 l2 t8 y/ w plot count patches with [pcolor = green]1 l) _" ?0 @+ K& H
end, D1 u9 T9 \1 a3 z% j
可是运行时提示no such plot: "Totals"/ ?! B. e+ D4 o0 e
error while observer running SET-CURRENT-PLOT
, w1 ^! P8 v6 O# v' b1 | called by procedure DO-PLOTS
( F/ N/ L9 j! q, t" u called by procedure SETUP
& y" ^0 m0 d/ w% v, y called by 按钮 'setup'
& s& {- U* m: p: B求大神解答啊 |