我编的程序如下turtles-own [energy]. @! }4 L+ F: C! w. Z4 j
to setup
$ X8 i8 _& g! ]4 B& L G clear-all, f* c$ m% p4 Q+ `6 d" h, G z
setup-patches9 y; r( e' h+ g
create-turtles 100
& s5 `4 Z+ k7 T; W do-plots2 f0 n+ {( ]$ ~0 S
ask turtles [ setxy random-xcor random-ycor ]! p- b. |% g& n: ?! E" ?
end. B7 d# Y) B8 a1 @9 j& M2 F
to go
+ A h$ z$ F) h move-turtles
9 D+ S4 }3 w; ?# T4 M eat-grass
; T0 V* V8 c# x7 S! P) G/ ~ reproduce$ i3 h U( i3 ]( z
check-death$ R1 A3 v$ V8 R J! E3 O: q* ~/ p) J
regrow-grass
* D4 _! I9 g! b1 y do-plots0 [- a/ B* i8 l% |% D
end
$ d; h* y. {, \6 @9 l- bto move-turtles) O b0 P# ^5 E& F
ask turtles [
5 d" E( @8 @; h, ^9 W right random 360) o4 H' I: H9 x4 W
forward 1) ^6 X# t9 {9 G6 B( C
set energy energy - 1
9 L# M& |2 o3 u' p: B4 @, \/ O ]( T0 k! P' k( p; ~. |, `
end* z+ a: ^* l" _0 O- E7 V
to setup-patches" j* _; G1 E+ `
ask patches [ set pcolor green ]
/ B$ i& n! ^4 A3 Y( I' [. o; X( lend: K8 [9 Q1 a) `: w2 e0 o }
to setup-turtles
. f; w; e+ z2 p; E create-turtles 100
& k( v+ L; T, d# {- e6 S4 \ ask turtles [ setxy random-xcor random-ycor ]/ I! B8 d8 M1 s: n
end
- g" J! a5 a4 j, F# nto eat-grass% j0 ]# f+ ]/ Q& F7 x6 y
ask turtles [$ D4 f' ?; @5 M$ p; D; P0 x
if pcolor = green [$ K; E9 _5 W1 [; L
set pcolor black) F% j5 F. q: ~
set energy (energy + 10). A) q# I! n' C! R# b
]% \9 ^1 p" t) W. p) r
ifelse show-energy?- R# n3 D) {% h, k/ s! c7 ]& @9 J
[ set label energy ]5 E5 Z: X* Q# R' d
[ set label "" ]" M& X. M% `1 b! J% G
]
' s! f" M- i7 U- n9 I* _+ V0 zend
$ U! R2 }) G$ v+ D! ], Nto reproduce% c( q4 G6 ~4 C* V/ j
ask turtles [
; X5 H7 e/ @6 C' k if energy > 50 [, z9 t' \( p# e' a7 x
set energy energy - 50( ~; a: f: I2 M4 V% d3 J
hatch 1 [ set energy 50 ]
% |: c) I! O3 g A% ?; k Q ]* G& I5 Q# |6 h& B
]
. _9 w+ s, i/ D7 Wend
6 d1 T0 l& r! D Hto check-death" M$ Z' c0 B7 n
ask turtles [. y5 ^* t5 p7 o3 W- h" ^
if energy <= 0 [ die ]
# S0 _. L' u! _ ]
7 q) W/ @: n* z& r- |% [: oend
+ m# l* m- `- Bto regrow-grass) Y6 Y0 c0 k `) {6 b
ask patches [
6 m7 Z0 s3 y9 X( @) u- Z if random 100 < 3 [ set pcolor green ]
% c$ W V" K4 o( }& k: N ]* I" f. p+ V/ d- G* C1 j
end
{; V4 V Y. n: B5 T& a& Cto do-plots
" b# B9 h7 U1 @% g set-current-plot "Totals"
$ S: C1 Y! Q2 d# g set-current-plot-pen "turtles"
! N7 W2 y% D+ a8 G0 e* S plot count turtles5 _% P7 e; `5 U! X4 v' |2 T4 D
set-current-plot-pen "grass": V8 f5 [* y, a& {: Y
plot count patches with [pcolor = green]2 A4 x5 }7 f6 B; z' W$ j6 R B2 B
end
$ f3 `9 U& Q9 l6 k可是运行时提示no such plot: "Totals"- E% H1 N1 D- h' ]6 k" O
error while observer running SET-CURRENT-PLOT( b) K! k! X, h7 F* L T: N1 h- q
called by procedure DO-PLOTS# u4 Y8 G) B+ | {! S- A
called by procedure SETUP
3 c- {; t( F- O) D: a( V called by 按钮 'setup'
# P2 i+ A% y( z+ `8 m) |. n求大神解答啊 |