我编的程序如下turtles-own [energy]
' U% {6 n3 t4 i! Zto setup; q3 Z, j9 M) N
clear-all9 g2 Z. `+ B$ E2 r
setup-patches2 d& c. Y6 R- W$ @( R4 @
create-turtles 100
/ O" {( Y7 L* H/ l- b0 V. H2 e do-plots7 o' t! @- ], s) t, q. t
ask turtles [ setxy random-xcor random-ycor ]
/ O c4 m, {8 n& bend
2 w3 R: W1 s4 m- c; Bto go
/ N) D& l' a. V& J! L' Z+ e Y move-turtles
& O) A- _! x: z1 y eat-grass
2 q! _5 ]' Q* T q) t reproduce( C$ S0 ^5 ~; O4 J
check-death' S& [5 k3 l% v' E: z- R
regrow-grass9 r# q o5 L" u3 k+ S! Q6 L5 ?% g
do-plots
. F) z, O5 C. N% Wend% T+ H5 r* b1 C- Z* J8 _. [
to move-turtles# F/ o* N- z2 }
ask turtles [" ^3 y' S! w( y( _& }" e
right random 360
E* R- [( Q' W$ s: n forward 1
( I+ }8 u5 \- ` set energy energy - 1
* ^$ I/ w. e% V0 D( e6 X4 C/ g6 R ]
- k9 B8 e w9 E6 p/ cend( F Q7 D) N: Q3 h
to setup-patches% G4 c8 |: f6 X( \: X! x
ask patches [ set pcolor green ]
8 R6 `8 \2 v# i1 l, A: eend
- p6 P5 d/ e i( qto setup-turtles
, l3 S# v: p2 K, V create-turtles 100: m3 X* M) P4 C9 S
ask turtles [ setxy random-xcor random-ycor ]9 ]0 V' x2 b4 r8 j2 \% `6 r$ F
end; ^) f& u4 I$ @( P: h" f2 N
to eat-grass, k$ f R" @+ q' ]( R
ask turtles [/ }' N7 \2 H3 v5 x( l1 R8 ?3 J
if pcolor = green [3 }* l, ?6 v' z8 K% g. E9 G9 ^
set pcolor black+ [4 m$ C" `/ e* \' M# e4 d) h
set energy (energy + 10)
' Q" p0 ]# h( L: l ]. H4 a$ @2 U7 j7 [8 e
ifelse show-energy?
! V- t% R/ d" J% e$ C- v2 P [ set label energy ]( a8 ^( x, U. b V0 Y* |
[ set label "" ]
1 ]/ P+ t! K! v, h! W" h ]
: s8 V; @) X* E' nend, V ?4 `, o3 x
to reproduce; y' N& [, G1 f9 X! r9 y
ask turtles [
( g7 I P# X( w9 x if energy > 50 [
0 B8 c' j+ y& l# S ` n, l6 r& H set energy energy - 50
2 f9 s) S0 o) r2 W% X2 I4 B hatch 1 [ set energy 50 ]. N# U, x2 s# r* B
]
3 X- z2 i$ y! C! h, ^ ]2 t2 t6 s5 v( w2 ]; a
end) E* w( M, `* u! q5 e# V% D- d
to check-death/ S9 P( d L4 B" Q; A, P* o
ask turtles [
9 t3 \7 l2 ]- P# k8 Z( e" e0 R if energy <= 0 [ die ]3 W( W; M. j: g9 q. `+ b' g( R
]# B$ B- J. D% I) S. Q
end
/ a& L+ X, a+ g/ b" ^to regrow-grass
`9 d: m8 s& }+ A: k ask patches [) m4 H" |, c, b) X' z H$ [
if random 100 < 3 [ set pcolor green ]
4 X7 B9 [; n' \5 A- ?4 T# t ]
+ S% S# h% Z4 z0 O3 L* v! hend
% M {/ X, p7 Z4 t! |to do-plots
: w3 I7 Q. f- O' e% `( O) g# l set-current-plot "Totals"2 Z0 X5 b0 v p0 q
set-current-plot-pen "turtles"
- `1 U& u; [. B% v plot count turtles6 o' G( f/ A9 {% Z
set-current-plot-pen "grass" ?! O, l3 O( p* E- L8 r
plot count patches with [pcolor = green]/ }+ Z: h7 D9 v, ~
end/ E2 j8 C$ Y, o9 o3 N) j. w. I9 @
可是运行时提示no such plot: "Totals". Y: @8 E, P$ e0 S4 i
error while observer running SET-CURRENT-PLOT
7 A! A2 G+ |& w y4 c called by procedure DO-PLOTS
' [) E0 G( H& ~& Y" m9 ?) s called by procedure SETUP0 T W9 p+ V4 C+ l7 x X
called by 按钮 'setup'0 f) B4 ^. T( c
求大神解答啊 |