我编的程序如下turtles-own [energy]% ~& d' l ^8 X
to setup9 K- \9 Z# }; Y4 x; n) X2 P8 T2 h4 ]; v
clear-all1 E/ k7 Z3 G3 z7 O/ u' j6 y
setup-patches
! z' `8 Z. f9 ? create-turtles 100# z+ }2 L0 F& s3 ?
do-plots
7 R, u' A% H3 r y ask turtles [ setxy random-xcor random-ycor ]3 @3 G( U! I, U9 @
end5 D/ c! }; y$ X. \4 M! f
to go
$ L3 S* f$ W6 D9 V1 s4 S move-turtles5 V( R% z( q/ g! j: i
eat-grass2 m3 v. X; g/ |% q
reproduce
& n( a4 r u! N) Z/ R check-death
4 J6 a5 O6 H! ]# _+ x. i9 O regrow-grass
M( P( r# T" S0 _ do-plots3 v4 a- z. N* u! t. Y, V
end
" u b" r6 i+ o9 L% zto move-turtles9 I. O3 k1 G0 R7 H5 g- y
ask turtles [
# u5 B. K- K( Z" K+ L! n right random 360& j8 L0 ^* d: a+ U6 T- a' m
forward 1
. w' x& I7 }( D! h set energy energy - 19 a8 k9 s4 ~9 C
]1 g8 w( K3 k$ n3 j( ^) r
end
. V/ W: b- f W0 S2 O. [& mto setup-patches
. u+ H. O0 m0 u" o9 y ask patches [ set pcolor green ]' y7 `% \+ }+ U. a% u: s
end
: ?" o5 q# C' R0 l4 O$ O/ [to setup-turtles
/ A9 c# y3 F0 L* r8 k create-turtles 100$ `% c9 l/ Y1 t: x
ask turtles [ setxy random-xcor random-ycor ]% X5 a$ V2 K" {. g& ^" a" q% D
end: q) c8 h" X, z Z4 V
to eat-grass. }4 u2 Y7 \% f- e4 F$ O. J* W1 U
ask turtles [# S+ s v% u5 i/ S, z
if pcolor = green [
! g& D* R& l; l set pcolor black
: I" G; p. o# Z4 m& | set energy (energy + 10)
; K1 |+ L) @0 u9 f7 q! M ]9 e- j1 b4 G" |9 A# _
ifelse show-energy?
1 D7 \% H* ~4 J* R [ set label energy ]
! q# I, m# |: l4 I4 { [ set label "" ] s9 _( c, k# s0 D
]
2 E0 V* f1 O( Z$ u0 n* h' W6 ~end7 Y L" y8 e, [
to reproduce/ l; N. H* X" [- M0 t
ask turtles [
5 l* w+ M7 b; Q! W6 q if energy > 50 [
" J5 y* v! n3 X set energy energy - 50% U! Z1 c' j7 N1 t6 d+ r8 K1 m
hatch 1 [ set energy 50 ]
7 a L% L- Q" H* ^3 h' l( e ]
3 N$ C. i9 X( ?* z* _! Z) j8 v9 [0 a ]) m" E" \) `$ J- g9 T
end N- P/ l0 C: j4 D* G/ _0 \2 j& v
to check-death
* B' R1 C' i" s) R8 O1 C' e, v3 C ask turtles [' Q& o* c$ {0 _- f
if energy <= 0 [ die ]
$ s' ], A" O' v ]
6 D+ m$ O; b: h& s4 p5 d- ~end
2 ^+ h" M6 b) Oto regrow-grass( v7 F" e, }6 [
ask patches [: n2 p6 }/ ^ T% u6 m
if random 100 < 3 [ set pcolor green ]
+ X- H1 W7 o' e ]
) I' _* z3 U, Send, J! W' V5 i, v# I5 _
to do-plots6 `% K p' V" y8 g& [
set-current-plot "Totals"( N( V; S% J9 Y$ l& w$ U
set-current-plot-pen "turtles"
4 n j8 e; U9 S# Q' C3 E8 Z" F plot count turtles
- L( d1 Z* R- S6 n8 Z, r set-current-plot-pen "grass"
) _2 W* K, p$ Z% q: }. o8 B plot count patches with [pcolor = green]
6 b( f) _4 O- s; A( p- Pend. A, I9 ^# q% O
可是运行时提示no such plot: "Totals") O% h P( V& |* @: ?* J: o
error while observer running SET-CURRENT-PLOT0 b" y$ v; Q9 r) b8 d/ ?' ^: y
called by procedure DO-PLOTS
' x4 {7 |8 Y+ [( F9 Y called by procedure SETUP
- \; Q+ |* O! a" |$ W: V called by 按钮 'setup'
5 k% F' O1 D/ x+ {$ m0 W求大神解答啊 |