我编的程序如下turtles-own [energy]
i e4 W( v0 O& ito setup o, u( B9 O8 v( I
clear-all8 i/ s: d0 S8 K& R
setup-patches. Z0 n9 r$ K' E9 ~5 X
create-turtles 100
/ O5 f0 U% E6 s8 u2 A8 I do-plots
4 S, m/ V6 N8 i4 f2 m5 T8 h# X ask turtles [ setxy random-xcor random-ycor ]1 W- `* }7 g$ `6 H* k- v! e
end ]) K \* X. }6 g& H7 V9 W3 \$ T3 g0 T$ t
to go$ _: _- R9 ?( ]" |' \1 J% r
move-turtles
4 u9 ~; B# [' K eat-grass( d. Y! [" j5 l1 p M1 N2 H5 ]: R+ D7 p# w
reproduce9 ]: W* b; r! g0 B V- b
check-death
5 f: L! ^ D! c& P$ j( \8 Y( b! U regrow-grass" [3 ^5 j4 ~$ I, W6 H% U
do-plots
5 w8 n( R* k7 send
" w) i5 H- b0 i7 dto move-turtles9 Z, f" @* _5 q! R5 C# G8 p2 W8 E& e
ask turtles [0 g5 J- ?* m6 i9 k. l* Z
right random 360
+ u6 W0 l& ?( I! y% k$ m% S& B forward 1
( N+ U" R6 ~/ O. | H$ z set energy energy - 1* L6 N# t+ T, V& s, D" j
]0 v, a* t* o6 R7 Y5 q
end
+ @/ i6 J4 b/ Z+ ^% D& S% e, |to setup-patches
3 R. O: E" m ~# E G! z' j ask patches [ set pcolor green ]
( e3 E# u5 i: f' X- m; Aend9 x( P; D' f& r1 w
to setup-turtles
7 P" G1 j/ q+ Q2 K2 ^4 `' t create-turtles 100
' L; x+ }" c. o& y! d; e h ask turtles [ setxy random-xcor random-ycor ]
7 d1 _7 A+ _+ Z# Z8 Nend+ l7 I, x+ Y6 ]* `
to eat-grass1 y3 k3 A, @9 _% i, U
ask turtles [1 b3 \1 c Z; u" ~# @" D R% g
if pcolor = green [+ W# {& N1 F- \6 H+ ?
set pcolor black; H& r# o$ P, y
set energy (energy + 10); S) T+ Z9 F+ s7 P( Z$ B, h
]) j* J. Y7 M) `4 p
ifelse show-energy? x9 U( f% Q; }+ m
[ set label energy ]9 f4 H9 J0 P. a3 @% Y
[ set label "" ]
9 q9 e% C; x6 N' \ ]
6 j( B! Z3 b+ H& N! Z" {end4 K! l) a2 R! I* s9 r5 V: R. b* z+ K
to reproduce+ M$ C; L# O7 c, U( E' t
ask turtles [
2 c5 t7 B5 _( P9 q. ?+ `- T if energy > 50 [
4 Y& \ U, {- E* [+ L$ L) k2 Y& x set energy energy - 50
) u4 P2 f2 `' ?' l1 s hatch 1 [ set energy 50 ]
b; k0 S( B3 n. j7 l5 r2 O. E ]" K/ D; _4 k9 d, |3 h$ @
]
; A# {$ N& e# K/ Bend
- @! B) [1 C* \' ~* v {. j ito check-death
; z s' u' h# U, D' K) t9 w ask turtles [% F- L& H- k0 a5 I3 Y
if energy <= 0 [ die ]
) D* P7 [: s2 | ]
$ q' _ T( V% }# D" M- j* g- B1 Rend
W/ `. f5 l9 pto regrow-grass+ i8 f, l- A5 R6 c0 X
ask patches [. S2 }& X/ o4 g S _; _9 _
if random 100 < 3 [ set pcolor green ]1 Y5 o$ P' S$ ~) o
]' C/ F( m6 M6 _3 Z% {$ o' n. B
end
- f- u( P. C7 B' ^! sto do-plots7 U: n+ G) D+ i- v. P) d1 x
set-current-plot "Totals"
: g& A2 E# g( K9 T# m/ k set-current-plot-pen "turtles"; O: R* C% D3 r W6 S* g, q% ]
plot count turtles- D7 g" l$ U _, J
set-current-plot-pen "grass"
5 m. A) F4 o7 H; C6 {" u plot count patches with [pcolor = green]- d; v* A! n& I2 y2 a& F' f! s
end' n s5 y: V% H! a- \: q9 E# D8 `$ t
可是运行时提示no such plot: "Totals"4 b9 }/ @: I3 P
error while observer running SET-CURRENT-PLOT
7 }& F9 c$ b2 K- e# m8 o called by procedure DO-PLOTS
6 i2 t3 j% z2 l" ^; }) M) J called by procedure SETUP8 B' k& c" |/ p8 j% l H
called by 按钮 'setup'
( l+ J; _; J; w2 V; y' S% \求大神解答啊 |