我编的程序如下turtles-own [energy]8 ^) K4 r# Q- [
to setup
; V, i: h, X# s0 V( x6 m0 v) d" J clear-all
$ f9 T9 M0 q) _: \3 a1 J" ? setup-patches
( l/ U( x, _$ a2 Q create-turtles 100; C" D- N+ s; o8 W/ j
do-plots$ Z' [4 I, {. m
ask turtles [ setxy random-xcor random-ycor ]
; n; f) ~5 E* ~( g; p7 h) F5 pend
) ~4 c% N! [ h6 Z- @, ^" h& kto go1 T0 q3 p1 N4 A2 ^, @
move-turtles
4 d! Y' \% T3 l% W& G# k; o eat-grass
" G! F6 p) S& x reproduce
5 J: a3 }# {2 P5 W6 T check-death
; C: Y: f9 T0 L5 r% `* P regrow-grass* X/ L, z' a( v' T
do-plots1 ]% W8 v8 {" x) y
end5 _2 M# x0 a3 e4 [2 I- D' Z! I
to move-turtles1 l& L N1 O) T
ask turtles [
2 ?. [3 j" z1 F" g5 c: ]; ` right random 3607 V* }: t" `3 Z5 s: d6 Q
forward 15 p" R' |: B7 a* ^
set energy energy - 11 }3 ~( w( ]2 [% n. \" J6 E, }2 B- i
]
# [: q$ c/ g! ?, w& _% eend
# m/ L4 b. R1 L9 D; Fto setup-patches8 R4 A* b; x- r
ask patches [ set pcolor green ]
- a! Z) b% o$ `% `1 [end8 r1 I0 ~6 Y# u* s, F# \
to setup-turtles5 l5 X: D" I( J- V3 L. q0 D
create-turtles 100
3 ?, J8 a f$ v2 b2 M ask turtles [ setxy random-xcor random-ycor ]
+ u8 Q c- F: R5 b, |+ Y& Mend3 j; C6 ^2 f; o0 y" }
to eat-grass
$ h: | ]5 T4 W1 ?1 O/ j7 Q, f ask turtles [* T& w5 h! x+ A7 f6 u
if pcolor = green [
& _. K, f& s' i1 p# k7 ~: F! } D set pcolor black4 O1 i4 D6 }. V" G( `/ q. l) } }
set energy (energy + 10)
. D `5 f2 l! s8 @) c ]
- o9 r4 Q7 o# ^ ifelse show-energy?! h8 h/ T# l5 |0 U
[ set label energy ]
0 P! d6 H7 G$ P8 T* U' f# V [ set label "" ]/ F3 l4 f5 _" }7 K, g( l
]
* A# r9 g. D1 T; m+ Wend
0 f1 r) p8 r1 o. e( ?5 e/ A6 i. Gto reproduce
. }$ |; _) H! J ask turtles [
, @ D7 K+ p+ D* v3 W if energy > 50 [
1 Q& X& i! l' C# W4 C# M0 l. g$ k ] set energy energy - 50
" E( m3 E: `0 R: n) Q5 E- y. ^ hatch 1 [ set energy 50 ]9 ^" f" `; Z! \9 a7 y3 p
]& e9 }% F# ]9 z' H
]1 r2 C! o9 u H/ u
end
0 E3 a3 B+ P/ ~$ {* w9 p lto check-death# |/ U4 [3 S% y2 i' S4 j& J5 L
ask turtles [
; ^$ b" z3 R% Y8 \! u if energy <= 0 [ die ]
& [: H! A% f5 U ]3 z2 Y5 }+ u4 g% S+ _; P) @# g
end
7 ~: E+ B( G; b, f3 x' K& b* K$ R! k4 |to regrow-grass
& f [3 l! E, m1 @2 s) q5 o ask patches [
1 L, w3 f* K7 U5 X4 z8 E; \7 T1 Y; w if random 100 < 3 [ set pcolor green ]
( B7 }! y$ y; p2 [) c" X! S ]
8 s( D. P6 \9 O5 U) O* ?0 }) g; iend
# r7 Q2 _: }8 h7 o! uto do-plots0 Q5 m) H- p7 y1 X% j
set-current-plot "Totals"( x8 E! \! k7 `" B0 V7 E2 k
set-current-plot-pen "turtles"
/ w: w$ n8 U4 ] plot count turtles5 h% e9 d& b* ^! D( {9 l
set-current-plot-pen "grass"9 j6 Z2 o: q; e/ o3 ~ @; Q
plot count patches with [pcolor = green]' T5 B/ [0 Y2 I5 ~; m
end2 }- a4 p! }! U5 i, X: z
可是运行时提示no such plot: "Totals"
5 b$ c2 a0 d4 u( b. Z; c* |error while observer running SET-CURRENT-PLOT) f3 x, E$ v# G; ^% U+ a
called by procedure DO-PLOTS
5 w' e+ S, @( L, M* U called by procedure SETUP3 A% q. D6 s; S u5 ?
called by 按钮 'setup'
+ P3 y# p6 q# n4 a( m1 m求大神解答啊 |