我编的程序如下turtles-own [energy]
7 S4 \1 n( ^8 d3 J4 o( M# h. L# zto setup( W9 x& ^' R6 W% F( z" ?: q, [6 v; m
clear-all
7 |5 A b8 `2 l3 b5 e! r0 [0 Z setup-patches
* u% f' }8 I2 ~3 p4 m create-turtles 100( J' O: C' Z& m& L. `4 _
do-plots
- H- A1 o: A$ E6 x% B ask turtles [ setxy random-xcor random-ycor ]1 h0 W! r9 P1 P6 P" a
end5 |9 L& w' u$ Z' H7 z
to go
3 }- m! ~+ {2 s6 D' S move-turtles6 }9 M9 k* N/ q# Q- X/ U6 `
eat-grass- H* u8 A8 o) N$ O! P# Z
reproduce
! x8 R' o/ f3 U! s check-death
6 n8 ]8 e7 \0 q regrow-grass& x ~4 a* ]" |$ B0 @
do-plots
1 \4 {$ M4 ^1 G* U/ Fend `( n; A* C# x
to move-turtles& v+ I: t- Y5 P( ]# @! y
ask turtles [% I# c' e) d. a, C! h
right random 360
* {+ P/ d& U# `3 o forward 1
* i4 U: `3 |1 \1 Z% i8 E set energy energy - 1( i! x% v; O5 s! u
]
! t S- M B' ]* f% Tend; t% b% \" X0 i3 g( H5 `
to setup-patches
" Q( k2 e* U' H9 [ ask patches [ set pcolor green ], G& Q5 b/ N. p! y0 E
end1 f. _4 M d9 q/ s, u) z o; Y
to setup-turtles; p( A8 z9 W3 q3 Q2 U0 Z
create-turtles 100
- [, ^/ i) j8 x" {2 ~) _ ask turtles [ setxy random-xcor random-ycor ]. Q% l% I7 _) V ~
end: ~- h! J0 V7 W, {$ H2 ~8 z& Y
to eat-grass
- ~ u; C8 N0 O h$ l' V ask turtles [. K6 Q) `4 _" U2 Q4 ^
if pcolor = green [
v/ F, [" Y. `! d5 v' V) m set pcolor black
[6 U- Y V5 G; o: Q set energy (energy + 10)! p' z0 O, a* i0 ?3 D: d5 P, d |: a
]+ e* X$ V, `, Y- M5 ]& y
ifelse show-energy?+ ]& \: S" f( r! v7 T- V, ^" D
[ set label energy ]! G6 U* W i, S# M6 A& B
[ set label "" ]; j+ L4 i/ T( m/ \/ i9 C
]
9 K! v( ?' P: r- k+ O9 Send, \8 d( K- }. L3 F
to reproduce
3 ^; b u) O# I2 a8 \6 G ask turtles [
) h* f \7 O) r# I) ^ if energy > 50 [
3 g7 Z- q4 k K; ~- f: O9 O9 X set energy energy - 50. E- P$ m, C) R8 K: h: @
hatch 1 [ set energy 50 ]
" `/ h* r# L1 f0 ] ]
( A" p& _: t( _) ^4 m7 J ]
% |, X! b/ ^' K/ Mend: a3 K2 S( s5 X0 u
to check-death
! j) u" O+ D& c: L, r ask turtles [) a! ~9 [( \0 w9 J1 c9 G
if energy <= 0 [ die ]
8 Q, I2 h k& @) m1 }# n3 V ]! L; L0 }- u5 x: \, S# O8 L
end A H& e2 ^% s$ z. S- i9 X
to regrow-grass8 w% S2 G+ l- u) s' S8 \' @1 d
ask patches [7 G: B& d5 q1 w* U
if random 100 < 3 [ set pcolor green ]
5 n1 h3 {) ]2 D8 Q; G7 A ]' Z* G( {7 U) q3 X9 y# T. p
end
: z5 q5 x' Q- {$ Oto do-plots
T( H& l: F7 h/ R set-current-plot "Totals"2 k5 w5 ^/ O, ~# E8 ~! U2 o* v
set-current-plot-pen "turtles"
# s: _! P2 H0 V: m plot count turtles
- w" B( t9 q. m& O1 Y set-current-plot-pen "grass"2 c. ^9 K9 ~9 @ |
plot count patches with [pcolor = green]
5 C3 J* y, t; _ t$ k+ Xend* Q: i* C% `' T; c- B$ b7 z
可是运行时提示no such plot: "Totals"
. T, f. U9 c8 i. Kerror while observer running SET-CURRENT-PLOT h' Y `( G+ G' l: [) v+ b
called by procedure DO-PLOTS" V' {; S' m" q! s
called by procedure SETUP
0 ^8 S% G$ w+ \4 ]- G. A) V: C" z# ] called by 按钮 'setup'
0 k2 m6 E3 h2 J! T2 V0 {) B8 s求大神解答啊 |