我编的程序如下turtles-own [energy]
' @ i8 n' t: H j uto setup% I( ~4 i9 f5 P y1 Q. v
clear-all2 F; Q. @( I1 | U1 |1 l1 G- _
setup-patches1 R9 ]( I4 _. ^- `. g+ ~+ H
create-turtles 100" R8 U+ l" D8 C$ k- ] g. e z4 R
do-plots: C' a2 ~/ }3 [7 A8 z
ask turtles [ setxy random-xcor random-ycor ]
I* t" Q( w9 Q. o/ Mend( X4 v8 G$ s+ {; @; R' b, w* q# C
to go @$ ~3 O4 m* M. d
move-turtles
* z; p9 i' o0 x$ u eat-grass2 t' P4 r$ ^2 F6 t" c' x l; Y
reproduce
6 z5 g2 y" q9 S2 Q' I/ _; \! p* a check-death; r$ t3 m7 ]+ i$ F p3 v5 q
regrow-grass
+ w/ X! W2 q5 f7 `0 R) A9 s+ ^6 q do-plots
) k9 C. { U+ v3 Q7 Q/ Dend
# l, u& F M9 tto move-turtles3 @' U R% i, N; a |/ E( D
ask turtles [
9 n9 I7 d5 O' J2 V! G/ ~ right random 3606 B9 d6 h) [7 x8 K$ b9 K$ `' C# t
forward 16 O) f0 h! _4 {' [; V# \
set energy energy - 18 [5 A0 Y% N' G8 x
]
# \ ] ^' t6 c; s# W* \" E1 iend
2 m* V3 s2 r$ c0 I1 Gto setup-patches
5 n% c: R! t- t2 I: u ask patches [ set pcolor green ]
/ v" ]' K2 v" M- o. ^end
, [0 `- v/ P9 F- Yto setup-turtles9 T. ] J& G9 ^2 x
create-turtles 100# X8 D; t$ g# `
ask turtles [ setxy random-xcor random-ycor ]
( z0 c7 I! B" y8 w f6 Z4 c3 cend, I. Q% ^6 c3 n u: @9 Q! I# X+ s
to eat-grass1 A, h0 H! j! `% S: r+ I) `
ask turtles [: y8 I/ O! G' p7 J
if pcolor = green [
( i. t" ]3 `& Z* \* ~ set pcolor black
$ V7 ~' A( J- K5 K+ U$ G set energy (energy + 10)
+ C. a0 g/ J- T/ ] ]
$ U5 V2 k" l6 e' r2 G ifelse show-energy?( \8 s" K: k% \5 O
[ set label energy ]! p W) K1 T$ |: H7 w! K
[ set label "" ]: A( E' ]" q4 V2 E( v
]* z9 d5 m. {! `0 ]; E
end
/ F& m, K t% ?9 R; ?to reproduce
) ^, G! s! M5 ]" \7 A2 ? ask turtles [
& E1 r8 K3 f6 j0 [ ` if energy > 50 [
% j: a6 F/ _5 \3 M: W set energy energy - 500 R% `8 l" T* U1 t) p% ?
hatch 1 [ set energy 50 ]) f9 o. z% m9 [. N/ P
]3 N2 w% ~3 ]4 z n" l& b8 @
]
1 [1 k, Z/ Y6 V% I- a/ Bend; F: h3 R# U, a B1 g" ^
to check-death
% i* x5 b& \2 R1 ] ask turtles [% K. D( n# p% I' _2 B) I* `: N) C
if energy <= 0 [ die ], h+ K2 `/ L' @% e9 G$ L3 j
]
0 e0 J, Q* C$ r6 v' e( Tend: Y- O& v6 r! X4 Y
to regrow-grass$ I, J- [* d8 D! H9 V# c
ask patches [
3 ?+ o# o8 R3 v: F if random 100 < 3 [ set pcolor green ]
' D0 M1 L9 Q+ j A+ c _ ]- g$ G5 R$ ?1 T& c
end
; [8 P' B$ Y1 t; y5 O$ h p. M; rto do-plots
" m' h# ]. p1 @, o( }# I0 p; I1 o set-current-plot "Totals". c% w9 D! `# p
set-current-plot-pen "turtles"! s( H" I5 V* a& w! w% o5 t3 s
plot count turtles' h" M* W) I- I6 {0 i
set-current-plot-pen "grass"
5 L# A5 U1 J0 j- t plot count patches with [pcolor = green]
_2 K" P6 ~6 K6 v- Tend1 ~! A( L# d2 X; n' x
可是运行时提示no such plot: "Totals"
& M- V: y7 {+ O* f4 M! Z8 S* \error while observer running SET-CURRENT-PLOT
& U* |; d- V, z2 k% v v called by procedure DO-PLOTS
! E6 z, {' Z- X1 l2 H* ^) l called by procedure SETUP" x( d5 Q! K+ g# a( W# l
called by 按钮 'setup'( s* M9 {3 ^& c) A6 \" `8 ? G
求大神解答啊 |