我编的程序如下turtles-own [energy]6 j, ~; c) L" f5 M* D, ?
to setup; p5 T. Y# m! p1 O5 A$ ^8 ?
clear-all
4 R) P* r a. l) N+ V L8 Q setup-patches
4 Q/ u8 f. l; t( \" P create-turtles 100
: V8 k1 P: |+ x9 Q do-plots! f2 D: {+ v) N) ?7 Z' Y, Y# }+ [
ask turtles [ setxy random-xcor random-ycor ]( J6 L- J% e- k
end, i* o* P' H2 c: ~5 n
to go
6 Z( l+ W$ l- z5 f% o move-turtles
1 E t& q/ V3 |/ h eat-grass6 U# Y. D& e. k* T
reproduce
X a" `% p( W0 J5 j- G( q, Y' ~$ n check-death
& p9 F3 @# Q, h" b9 H9 A. @8 N/ T regrow-grass \" {! y9 P7 _" \! |8 _7 [# L: O) a
do-plots5 ?+ M* x6 \6 d) B- z
end4 Y c6 a1 O5 S3 t
to move-turtles8 T! p0 }% X3 b6 \% d! c* J& k
ask turtles [
6 i2 c8 S/ |/ t: D" Z* a right random 360* d% j+ X4 Y& h( \
forward 1
% C U; [4 ~7 v8 i$ V9 _ set energy energy - 1 A/ p+ A+ u& @. W$ |' B U4 c
]
+ |: ]& z7 w0 Q1 oend
) ]0 T. G5 `8 j& q" @to setup-patches. B; ^1 t% n; b* e
ask patches [ set pcolor green ]3 }% t) c; J3 _ a
end" K) X* O' t& @ P Q# ]. [
to setup-turtles
) |: w+ e' q+ Q% y$ Q create-turtles 1003 @; y; Z8 n) g% ^1 @; D
ask turtles [ setxy random-xcor random-ycor ]; A. x$ ~( |# }+ _8 \! o) I
end d4 ?; F: N7 @' E. R# e- s/ U
to eat-grass
& ?" x C- H( X, P* { ask turtles [
& r' u; _. w) x1 x0 |) D2 p if pcolor = green [
1 z! c$ l6 G9 |% P3 Y1 s9 F set pcolor black
1 V9 K4 c f( z set energy (energy + 10)
r3 {! C1 i# l; |: p5 a' b9 A ]
2 F6 F+ ^& @7 H( L: ] ifelse show-energy?+ a s# P5 g1 p3 l; a- i4 E& e0 ]
[ set label energy ]9 c3 t8 i; P% N/ e& V4 U$ Z
[ set label "" ]$ s: q p! P0 [3 F7 ?) c
]2 q% O1 l4 @+ z2 n
end* e6 ?5 A! E' D
to reproduce+ S/ C& d( r1 i8 g
ask turtles [5 `2 W# E" T% T0 N* x l1 h# b
if energy > 50 [3 j- g/ B: |0 a4 H
set energy energy - 50
6 j( f' {1 q8 U hatch 1 [ set energy 50 ]! e5 v( e0 }8 e7 b4 [
]% K! _6 B0 P2 F! q( e- Z* f/ i
]" } k3 Y& ^8 R
end4 b% Z4 F' Q8 G" ^) K
to check-death
O9 ^ W& h T# Z. x8 T) { ask turtles [
; g7 ` P; W" S c, i. C, s5 O if energy <= 0 [ die ]
& i% c' F7 ?' ~( |5 E% ^ ]' c' i2 E7 h; P
end
3 \) L2 T3 k+ d( P0 [to regrow-grass9 B" p& Q" R1 a% r* f
ask patches [3 \( B, h: P+ V( A1 R
if random 100 < 3 [ set pcolor green ]
4 _6 ~9 s$ K4 l9 U* _ t* x9 b$ q ]
: [* O% d( W& ~7 k. S. _' q5 _end9 Z$ G7 m, B3 P
to do-plots
# V3 ~2 }; Z$ E% a6 I) W7 \ set-current-plot "Totals"
+ U* Z3 Q1 i0 D* G$ h4 } set-current-plot-pen "turtles"
+ W% ?& u/ I2 \8 s# X) c plot count turtles
& @$ y" U* R( w7 s set-current-plot-pen "grass"
& a' Z1 l0 B/ i) O: u. k7 l8 C plot count patches with [pcolor = green]7 ~; O3 z' C( A/ Z; U% x1 q
end
' M' K# e) h1 s* i1 z可是运行时提示no such plot: "Totals"
+ Z) @9 S9 V: Cerror while observer running SET-CURRENT-PLOT2 \3 B- |6 S w, j# F
called by procedure DO-PLOTS
6 {/ K- Y8 O' J2 `$ y3 u2 q: w called by procedure SETUP0 K% D# q: q. \& a# l5 a# P
called by 按钮 'setup'8 E; t. y2 {# C0 w, |* T
求大神解答啊 |