我编的程序如下turtles-own [energy]
+ @2 a, y( x" Y- L2 j: ]to setup
$ G# {; p) ]/ j clear-all! v, l Q9 D, w* L% q: l
setup-patches$ G2 O; t6 X" G9 E
create-turtles 100- p9 V! J5 E9 U7 p* E
do-plots
8 h2 l! p+ T$ D2 f0 D ask turtles [ setxy random-xcor random-ycor ]7 Y8 e3 x% m. G' L* X: ]7 t
end' W3 m' h* C* `0 I6 N, U5 V
to go
) F6 P! O# D: p# a) ` {8 L2 } move-turtles, w( R5 ?# M3 k+ |
eat-grass
$ R, N4 s3 n5 v( t$ j8 H' } E reproduce
0 }8 `/ d5 ~) L5 A check-death
( u- J1 V! C/ j4 ~6 `* J& M( E1 V regrow-grass# L6 P8 h. E" `' x/ }; I" o
do-plots
' C4 Y3 x5 l. p$ ]3 v) Aend; X6 D, ^, J9 z3 v
to move-turtles
' a7 g6 O5 ^* \) X* ]" K" z ask turtles [+ `' u4 b6 G6 A" s0 Z
right random 360% A; U' J8 D% u/ x5 \9 s$ b) g' M
forward 1
* w) W& W! z5 K- C set energy energy - 1' @$ K0 b9 v g% y0 Q0 C* p U( c
]
$ J' D5 B. z/ ]' P* |end
- O) a; z* _4 a+ p/ Ato setup-patches
. d3 Z h/ W& n; g5 l# e+ b* Z ask patches [ set pcolor green ]
( a2 Q8 g$ Z, f, bend7 [6 ^# R. s! v1 Z C' ?
to setup-turtles4 J5 Z. j: T; T. f8 ]( P0 i
create-turtles 100
- V/ z5 |5 Z% r5 i! V' e$ I ask turtles [ setxy random-xcor random-ycor ]3 x* D$ t! r, W0 o" o3 ?
end) F1 Z9 `& W8 S. S1 x0 k X
to eat-grass
3 e: y+ C& T+ K4 h ask turtles [ K9 u1 }0 ?- v' ~
if pcolor = green [
0 u" j& D' p5 G; l+ x set pcolor black
- s: X0 s# O3 v2 ^& t/ B/ R$ N set energy (energy + 10)
$ h. p+ I$ {* e6 U2 w! u) n. _ ]) ^3 N" p3 D& k( R! r
ifelse show-energy?' {6 S. w5 M1 q* s/ f
[ set label energy ]1 f" L; F6 k/ X) H6 i: T* d& C
[ set label "" ]* F, H/ P6 Q+ I
]+ E% M4 p. Y# Z5 w, l
end( _; G5 C; @; x$ }6 e
to reproduce( ~+ e* {; [+ f# G+ E" E
ask turtles [$ z. q. f: T9 D1 Q- b M e
if energy > 50 [$ D" z! O+ h K
set energy energy - 501 \3 H: @% k0 c5 T0 {: k
hatch 1 [ set energy 50 ]5 s$ Q! Y+ E) p2 M- w3 e! k& V
]
3 W4 ^4 Q1 \4 i( n6 u# z* @ ]1 k& p( Z, ?5 |( @! `4 G2 x" \3 `
end8 G3 H! b5 O2 }1 |" |6 R6 l
to check-death# n: x q+ X# h+ O7 }
ask turtles [
* B; \7 L7 y7 F: {, A+ K2 ~ if energy <= 0 [ die ]6 q7 h3 B8 X2 r0 q; O
]
, r2 W7 B: A- U3 _0 |, aend
v" v! f$ P h7 r- Rto regrow-grass
0 f0 w. q: A" v9 p2 @+ K ask patches [
* j3 k! c1 u+ k if random 100 < 3 [ set pcolor green ]
* k1 R. r' v3 g6 r1 b6 _ ]
P% z' h! _" n, B R+ zend
: r" U- j$ ]9 o- q8 n$ Ato do-plots7 r: K1 r$ ~- x k" H' S Z7 J3 a
set-current-plot "Totals"
0 C- c# F: [- v2 } set-current-plot-pen "turtles"
' M" v v$ H9 S. } plot count turtles! R5 o2 ^3 `( v9 Z
set-current-plot-pen "grass"- A5 w2 h9 p# ?2 a, ~9 U% g
plot count patches with [pcolor = green]
; b' e6 d- k, ~) O& C# |: `end6 D: \) S. w6 A/ T- `# {' n8 L' _
可是运行时提示no such plot: "Totals"0 Z& S$ \2 A. B
error while observer running SET-CURRENT-PLOT
( d* w! A- O1 A( {& N, d called by procedure DO-PLOTS
& J7 y$ v- B G/ B called by procedure SETUP" `: P# }" ]& O4 p$ U
called by 按钮 'setup'
. | q9 ]/ V3 \3 @) ]( q9 r; f求大神解答啊 |