我编的程序如下turtles-own [energy]0 S& F6 D" s9 `7 U
to setup ~% y5 s4 K! V) q/ S; o
clear-all
% G( `! Y5 x9 g' `1 X& \/ G setup-patches
$ b9 K" d* U- ]: K+ X" H create-turtles 1001 A" \" d0 ?8 R! G% C- t: R
do-plots0 f7 @6 V3 Y& n! G; ?9 f; Y, b
ask turtles [ setxy random-xcor random-ycor ]
/ O% I; a( x5 ^0 L" pend8 t4 u& M5 }4 r- p9 {7 l
to go
5 W% b& L9 B, { move-turtles
, l2 n' {$ p7 e8 ` eat-grass' m" |/ i! p5 ~- F5 ~ G
reproduce
1 m" B. W! v$ X/ s3 e check-death! K5 U3 ~, Q! E$ {4 b& E
regrow-grass- f x7 B d+ X4 K8 O o
do-plots% s$ G# z; Z( f$ ]
end8 L- K: G `- }+ n9 F% c
to move-turtles8 a$ {8 @0 _' {4 L3 `5 f# S4 U& L
ask turtles [9 I+ h; @6 H7 {) Q' ]6 X
right random 360
9 b. F& j6 V) K7 i# s forward 1& I# J0 Y& B% H; E: j1 b" b
set energy energy - 1
" R* [: V0 f9 R( G6 T( `9 Q) | ]
' n2 e7 Y) E& c/ B0 W+ F8 i# aend
6 l+ {3 i, k. ^8 ]7 ]" ^to setup-patches
: A U V4 {7 E ask patches [ set pcolor green ]
4 H& n3 O: j) F$ Iend
3 N2 M/ W+ w/ z% ^* \; c. i0 Tto setup-turtles
- ?! f+ h) ~! q* t. Y1 l create-turtles 100
2 A. ]0 G* Q* B D6 a ask turtles [ setxy random-xcor random-ycor ]
3 P% B. j' F" }" m0 d7 f- j% vend
" ]2 Q6 x( w% Z5 c' l% W( ato eat-grass
2 I2 d$ t' }( c9 t ask turtles [
$ n/ o4 _& ^* I1 a7 u v# G if pcolor = green [0 Q* z4 Z. G1 \) u
set pcolor black
2 ?% d* U+ P# Z3 A! D# i set energy (energy + 10)
% W8 {2 Y3 ^3 ?" o* E% Z% Q8 R ]
; H2 B# K5 h# ?+ T* V( A8 p ifelse show-energy?5 ~! @ b, Q5 ?' y3 _+ V8 s
[ set label energy ]+ K: w; x# G8 d8 n" }) a
[ set label "" ]" J3 c7 @6 a. g0 B+ h
]
, ~& p J* C C Fend
9 |) c" Z8 D) b9 S3 Z: r- W! hto reproduce
5 U' v1 C( c& v3 k9 @ ask turtles [" B; F) e2 ], p2 d/ J
if energy > 50 [! H* R9 C3 x3 Z' j
set energy energy - 50$ j4 ^! _8 C; A" P
hatch 1 [ set energy 50 ]
1 B0 y; M; z. P- F/ J# H ]5 i% q, g! x5 L8 C* _( i. @+ ]0 |
]- w/ F0 I/ ]2 y! `% _5 D) `
end9 \+ `$ }1 S: k5 ^' ?% G" N' ~
to check-death
4 R; R; @* j% M+ k$ \8 o" B ask turtles [) a" U4 V" r' u, d
if energy <= 0 [ die ]
, U- L q6 \; f6 f7 @# k+ p: `$ l ] Y& y4 v$ i$ D! s4 Y# `& U, D
end" r# q/ u, y. I$ B6 Y* z
to regrow-grass
( Y& W, q% N: E ask patches [# H7 N) R" X) d5 t# J
if random 100 < 3 [ set pcolor green ]+ E# z% D% y3 ~# H* Q e
]
6 v/ u7 k: ?+ z; V5 H Jend
5 j2 U6 o* d0 Q% _% rto do-plots! f, ^' K+ l. @, S. {
set-current-plot "Totals"; n; k- O: L* B* I! [' m) H
set-current-plot-pen "turtles"; U. [( C* W6 j' t
plot count turtles, y- r- Z! H# l: W9 }
set-current-plot-pen "grass": i9 h5 @' A4 V2 L3 A
plot count patches with [pcolor = green]
4 C' O, s" Z f0 t _2 h; Hend
) n1 P* O9 a0 j2 _6 D) j+ I1 ?可是运行时提示no such plot: "Totals"
0 ]. g3 Z/ `0 S( |& i0 G! f# ]error while observer running SET-CURRENT-PLOT
! D6 M( i2 Z1 g. z4 f called by procedure DO-PLOTS& p0 D7 S* G$ f7 R9 N/ x6 h
called by procedure SETUP1 t) P* N% W1 r& e0 Y3 H- S* T
called by 按钮 'setup'
7 @$ F) M4 N* o# |3 F求大神解答啊 |