我编的程序如下turtles-own [energy]! x; |! t0 Q. S5 D* T
to setup
. ?" t" L& g; n/ O3 ~ clear-all0 {+ {; M. L- r( R7 o% d4 N
setup-patches0 U U- x* Y/ L; ?; S. Z+ a8 `
create-turtles 100
2 ?% r# w3 k5 Q2 p, Z; e do-plots
: f3 A" F' v3 s, A ask turtles [ setxy random-xcor random-ycor ]
" f `. i# q* j/ J* jend0 \( o2 s7 f: Y
to go
3 ~' x$ j! g# O' f' J; L* Z; K move-turtles" q# Z1 I8 W( d. I' H( R, n- V( E
eat-grass6 b8 l/ A4 t8 o( K8 x
reproduce
5 b* z5 |& f5 S# @& o check-death
- e: K2 h& P! Q6 O( T regrow-grass
# m' m4 T. S. z, F4 r/ E do-plots
8 L, V3 P" x* z- iend
X3 [- c. i7 A# d8 Yto move-turtles2 z/ B1 t0 y, s( M# A
ask turtles [
7 P4 H1 S e7 z( U/ ]& F" ~ right random 360
$ f: I2 F* `0 Y* m forward 1
$ F% l3 G- ^" b set energy energy - 1& X; V1 t3 F3 `: X3 u$ X8 ]$ R
]
. {" R$ R- P- Vend
" I) _2 t9 |$ z: p. s9 g4 Jto setup-patches
$ O4 E6 P0 z7 D6 R7 T ask patches [ set pcolor green ]1 I' B0 A% o% j0 h/ n+ p. |
end
9 z% R2 f0 A& [4 Y& P* Mto setup-turtles
+ w9 a5 W2 P3 ?+ d; _! u% w( a/ S5 ?. U create-turtles 100, p( C( {+ U7 l9 C, u2 ^
ask turtles [ setxy random-xcor random-ycor ]
" G# i2 `) w/ f6 F. H3 lend$ n5 S. w% P; A
to eat-grass
: k. g; J# i3 u ask turtles [! c9 a/ a) i4 y* N O/ x+ p
if pcolor = green [
1 E G" g( \7 h9 u set pcolor black
4 m, Y; B9 X$ d" u set energy (energy + 10)# u/ b: U. M& A& R" Y. O
]- T" S8 h+ P/ ~4 E
ifelse show-energy?
: B3 T5 m2 S' m/ e6 S4 `. J5 F+ f/ e [ set label energy ]# T+ ?3 b" X0 |$ \
[ set label "" ]
+ x T3 F$ y" C; K ]2 L0 P* D7 S$ A& W& K
end
* d) b2 K* G* dto reproduce
! W; ]( K2 o$ v- l# f6 d! u ask turtles [
) p% `( r6 \9 P& Z if energy > 50 [
. K5 t, b! u: u0 _ set energy energy - 50
8 p; m( V, q% C8 F3 T# P hatch 1 [ set energy 50 ]' Z3 e. d% q$ V2 x7 U+ q8 A9 u+ Z9 B
]
1 P4 i6 s; Q& B, l ]3 o: A |7 l+ q1 l1 y& Z+ W
end4 r8 R8 e8 O" Q# u. o0 v
to check-death
- ~: b( U( W6 @* B6 c6 n/ c4 P ask turtles [, E6 U( Z; ~4 a- E7 I( L- a6 y
if energy <= 0 [ die ]
! f: a M, y0 W3 w* Q ]" }& z" D: P2 ~
end
* }% R+ k2 z) ~) V+ @) s2 Ito regrow-grass
$ V [8 E& a' D' g! C ask patches [
. M [: w3 `) a7 D. Y. L if random 100 < 3 [ set pcolor green ]
/ F: ]% e4 o/ |1 \% P ]( H6 J; i/ C% ?. F6 N
end! _0 }% z1 b E- m* `
to do-plots4 S6 w, U( i \6 v( j* C2 {9 w
set-current-plot "Totals"
- \& J" ?6 Z* H+ Y, z* ` set-current-plot-pen "turtles"
% P' A, w2 b1 f- F plot count turtles! Q# ^6 V* P$ U+ k% `
set-current-plot-pen "grass", w# O" G) A9 v0 Q: o
plot count patches with [pcolor = green]
* ?) N5 e4 K2 g( Qend' y% ~3 a0 l8 A! e& A
可是运行时提示no such plot: "Totals"& L& P: ?6 E; i; f2 ]5 F
error while observer running SET-CURRENT-PLOT
3 b; q+ c. k$ k1 K6 \& o2 d) _/ Y called by procedure DO-PLOTS
5 S O8 z! x9 W& t called by procedure SETUP
/ ]9 C; i3 A7 q6 [" X9 V called by 按钮 'setup'
; z( N' C1 m8 T$ i) _求大神解答啊 |