我编的程序如下turtles-own [energy]9 r9 e. F X/ B/ r
to setup I" J9 G( W, v# h
clear-all2 n: m( g% u" m$ ^4 w
setup-patches0 U' ~4 C1 y8 V/ [1 o
create-turtles 100
" l: g; W5 k3 B: L7 `0 c1 w do-plots8 V- M3 W+ v1 J& A
ask turtles [ setxy random-xcor random-ycor ]
0 z! d# D* }: O# A8 ~1 f7 X* T2 H, send& j. w" K5 r) h# {4 n1 _" Q: w' \: Q
to go8 N* T, S1 W% V
move-turtles
) G4 |( O1 g0 \" z/ U0 \ eat-grass
7 K5 F6 f# {! s) \ reproduce o: Q I& \/ S
check-death% R1 Y# j/ ?/ _! r8 @. R4 U
regrow-grass
7 c( k6 m$ q7 N9 p6 j1 c do-plots3 \7 o9 ~8 u$ z6 T8 d, c
end
6 X1 r9 g7 ?, f0 G( K3 F- l+ S) Fto move-turtles
$ V9 @* n& W. ?$ A4 ` ask turtles [" @1 E: }* \ J" e2 Z% Q. u
right random 360. L! ~3 u3 `( _
forward 1( B- J; \" I8 {+ s! u
set energy energy - 1
+ V' ^) F- J' ] N, x ]7 C$ U3 ?1 [$ @" C
end1 G' M7 `& t+ j4 _$ g
to setup-patches
/ x4 P8 z* B' R/ T, n" `* _ ask patches [ set pcolor green ]
$ }# _) U+ Q9 e% ^4 gend
4 g9 @# l; ~; \to setup-turtles
' O% g8 n& Y) h0 _" g% F5 h create-turtles 100, P& o4 i$ H/ W9 b5 V
ask turtles [ setxy random-xcor random-ycor ]! j% I% f! x5 j4 l, B; q1 D$ N
end* V5 Y& G# d5 p1 F2 y7 I
to eat-grass$ E* Y0 J4 L, C9 S
ask turtles [
4 G X" t* x2 j0 }/ ^ if pcolor = green [
# [1 t6 u& P" | set pcolor black b9 B+ k8 \. Z* l; Q3 A+ }
set energy (energy + 10)7 N) | m+ E5 s& F2 s' P* R
]6 v" n2 L/ I; p) q
ifelse show-energy?& R7 s" {, _4 H2 L2 D% E1 q+ o
[ set label energy ]2 F0 s1 N t6 i
[ set label "" ]
0 M$ N. S1 @) F, y3 H ]0 Q$ X$ x L3 W4 G$ U" |
end
& J4 [: Z4 V3 p% e( I; F8 a0 j3 Sto reproduce# L5 [1 ]+ @ G, W3 W( _
ask turtles [0 q7 T( ~7 A' I+ D# ^
if energy > 50 [
& Y. R, A$ c+ M- Q+ f$ u7 G9 F set energy energy - 50
. d6 G0 l+ \6 T4 O7 R! b4 s# J hatch 1 [ set energy 50 ]; Y( V- T! u' s$ H8 A- z6 k
]
3 U5 x, _) ?) j8 a% e( u& q ]
' K8 ^$ Q' l* d9 \% B" E3 Yend
' N+ @ S: X9 O( s4 Cto check-death+ C& ~, [ E- W0 V0 r/ J
ask turtles [
. Q/ n1 P: _- z# ] if energy <= 0 [ die ]
) I. j- F2 G) c' e, Q- Y$ X ]' p P# T n. W$ y' L/ w/ n
end
& v" r0 } m% t5 T: B/ {. K5 Lto regrow-grass
8 [( [) l2 Z- n8 n; ` ask patches [
8 e/ n8 m& r8 }( a1 [ if random 100 < 3 [ set pcolor green ]
2 b5 i! U/ S8 A6 ]% A4 { ]. V' y6 c7 _( d V
end
, U: ?- {' R& lto do-plots
+ T* w p. Y! }8 s; T set-current-plot "Totals": M# T2 R2 A( ]" x
set-current-plot-pen "turtles"
% S( F% ~) } V4 Z4 b Z plot count turtles" l1 c8 Q* P; p" \5 n/ S
set-current-plot-pen "grass"! s$ f( s0 `$ v0 Q4 @5 y P, s
plot count patches with [pcolor = green]8 V# a6 G$ f L3 e
end7 k6 o& ^# a5 }% V
可是运行时提示no such plot: "Totals"5 z% k7 A+ E( A7 G4 b4 b2 d* O
error while observer running SET-CURRENT-PLOT
7 P5 K! V7 {% @$ S# @! M called by procedure DO-PLOTS
$ g i( f- W- o* z called by procedure SETUP7 y: V9 [% j5 g' [$ R3 d
called by 按钮 'setup'
, H3 x3 Q3 `3 [0 e4 `+ w求大神解答啊 |