我编的程序如下turtles-own [energy]! {8 \6 i, Y& Y9 M1 }4 x
to setup3 ^; f1 V- `. u% ~9 O
clear-all
3 \8 d+ T& }) `% z$ y/ ~) {; M setup-patches
d0 t$ H9 Q0 c" w create-turtles 100
# T& h$ ^9 R0 S1 d$ g- T6 E* s do-plots
( T) J# ?" } M) B5 q ask turtles [ setxy random-xcor random-ycor ]
; t9 D" v+ }! f: F: o9 N. O2 Oend0 s) z. k" @ M) y) f. Z5 \
to go
$ E; m9 R, b9 J% b+ ~* W move-turtles8 Q# J% Y- l( q0 M+ w% ?; U( j
eat-grass5 h+ b1 B4 u, Q( S' Y* D0 Z `. B
reproduce8 |6 u& @& \" T2 H
check-death
3 ^: h2 s% d) ^! K j% { regrow-grass
4 S5 e& _2 t8 L, W do-plots3 D v% _# o' N% l# ]
end# g# n/ a' f; k6 E' }
to move-turtles& c* I0 f5 a; [* D5 R
ask turtles [- C1 {/ u, N/ ?0 ~1 W
right random 360
5 S: t2 h- W2 u+ V) H) n forward 1
# C& Y/ ^5 q& { set energy energy - 1! ~* r/ Q1 ?: J$ k( F
]9 l! K+ C5 d- b- ~/ E
end
5 L z$ t& @1 ^1 jto setup-patches3 n, X1 H/ ~9 F s* X3 |7 l
ask patches [ set pcolor green ]
8 b6 I/ L7 r6 c4 d/ wend
( [" s) y- V. ~" ~7 p5 T& P! `to setup-turtles! o$ w/ k1 d* S. g2 E
create-turtles 100
! [/ @' B1 {; M* u( N' r$ c ask turtles [ setxy random-xcor random-ycor ]/ g7 U7 H/ R1 q0 |1 f
end4 {. Q8 q9 s$ ]- Y$ u* p
to eat-grass
; m8 ^0 ^/ B8 V9 B2 K$ {0 e* p ask turtles [% D9 }. C: I4 I5 n8 I
if pcolor = green [
4 }. Q: r6 i* } E) @- l7 d$ [ set pcolor black* S9 u# y2 _( h" E
set energy (energy + 10), G$ X- f5 }' |% @
]
6 P: F) i5 }9 @" h ifelse show-energy?
2 U* w# F. l; l [ set label energy ]
, y' G& P& O' e7 F( M } [ set label "" ]
+ G, d) C0 Z- V2 f, X ]
( j: O4 V c x% T/ h" O% ^: mend" o: o+ E; L. { `2 z
to reproduce
. ^0 @ [7 Q7 b* y+ g6 m3 |2 a ask turtles [& R$ g( Y. {. B( g4 G
if energy > 50 [+ k' {( e6 b& x& D m8 e
set energy energy - 50
2 M4 m. _, y8 K+ d hatch 1 [ set energy 50 ]6 l5 D" `. N( |- J5 C' W% m
]1 N+ u; w. S& C8 b1 b' D5 x: F( D$ W( F" [
]5 P. ~% M8 J- w/ W) P
end1 N6 P# s4 ?2 j9 d2 ^4 L$ M$ |' C
to check-death
# [# A3 m/ D" A+ y) `0 V1 D ask turtles [
0 _+ c) L! e: x if energy <= 0 [ die ]
* L1 j- ~, w1 z! F3 S ]
/ [* \7 ^, N5 J/ Mend! M' F1 K' h2 _1 K: k8 x7 `
to regrow-grass
+ X* s# U3 }% i% M6 m ask patches [
4 n( e& S0 E; W Y1 H ` if random 100 < 3 [ set pcolor green ]& x) p& m6 {, h3 B ~' b
]. }6 Z: a' w9 Z/ t) \1 ]: P4 ]5 S
end
6 _( M5 v ^1 q k' Xto do-plots
! B7 k1 t0 M( ~6 ~# _ set-current-plot "Totals"5 g0 }2 Z/ H$ N3 C# e2 g- P
set-current-plot-pen "turtles"
* F$ \* M9 A x- O7 U/ A: i: K plot count turtles* p. E$ o, {6 [2 s1 Q5 F# U
set-current-plot-pen "grass"9 |- I9 O+ c; Z4 O O
plot count patches with [pcolor = green]5 V% _+ b2 a. Q8 B: F! S
end8 `$ V3 J' p, E
可是运行时提示no such plot: "Totals"
/ f6 s/ m1 p' O7 t1 j0 Oerror while observer running SET-CURRENT-PLOT
% y. D# V% I$ ?! O called by procedure DO-PLOTS8 q& v. e/ \+ B4 `$ L8 P
called by procedure SETUP8 s8 N3 P1 j# p. G" V5 P& Z8 r
called by 按钮 'setup'
, A- J) }, ?- u" e4 V求大神解答啊 |