我编的程序如下turtles-own [energy]
( P% j8 y# e, `; G8 w1 oto setup' N& q* k" m/ T" ?
clear-all
# I% |+ ^0 Z1 H setup-patches
|* N. {7 J* |# D8 n1 Q create-turtles 100
$ r6 ]* o" s3 P( b# G5 z9 n do-plots$ G# E& }4 k4 v
ask turtles [ setxy random-xcor random-ycor ]
% G S( e0 {, \* U2 z/ xend
+ K+ N9 V5 d/ G# L% D; _% a, u3 D( M6 cto go
' }( S3 X4 l. x# m move-turtles+ ?6 R& _& k6 m6 W
eat-grass6 \: q& k. a! w, L* A4 X
reproduce& q; j2 }- v5 b1 k/ h4 i m2 ~
check-death$ I' Y( [# i1 A' M1 Q7 e2 q
regrow-grass
3 n; F( n" J2 k: I0 u# E: i. x7 y. b do-plots
5 c; @6 U1 S- V, M- Fend
; w6 `# j# I' V5 _; O* j% o0 L8 ]to move-turtles
2 s k8 N7 P' E ask turtles [2 T0 r! W/ J! k2 l v- Y3 A' b
right random 360$ K' K9 k' y$ x3 v5 \' ?
forward 1
w5 C: t/ i$ A( [% Z2 j$ g set energy energy - 1/ A, u" M2 X) ~8 {& ^' x
]
* w( |7 I4 j) N) Y" n$ {end# r/ y; [5 E5 u
to setup-patches
2 ^, D0 l1 p/ G ask patches [ set pcolor green ]
; W) o6 B7 H0 t1 g cend( s& U* R" T- S
to setup-turtles
J" I0 ?5 L! R) m$ {$ ^ create-turtles 100; z& T+ j9 j5 G" e: @6 ^$ O
ask turtles [ setxy random-xcor random-ycor ]
3 V# W: p! t+ Tend
/ V# E1 I$ d5 I9 ito eat-grass2 z8 c" l/ J% ^5 x* Y
ask turtles [0 L: I$ x/ E) r; g" e" i7 o
if pcolor = green [; B7 E6 Y) D( M. I
set pcolor black
0 o H% l4 D+ V- T: V set energy (energy + 10)
0 z! q) H4 F$ Z/ h4 x6 Q" o+ w ]
; P3 D' k% U* ^ ifelse show-energy?: ]2 h* {/ ^+ X, j# _
[ set label energy ]
1 ^. W0 W3 Y2 s! V( x" k# G [ set label "" ]) D' Z( d" `; @8 n
]
5 s" \( l! v2 N, u& I6 X& q1 dend
5 G7 }* C$ r5 eto reproduce( n9 o! z5 E3 a) ]- b9 l
ask turtles [
' b; j& V. {6 \ if energy > 50 [
$ t" O% D, o9 B' p set energy energy - 502 e/ X% j1 ]% `7 s/ m
hatch 1 [ set energy 50 ]
3 g8 ~4 ~7 j( v/ n, f/ [ ]7 t2 A9 J( a0 y3 L
]) f* g, k3 Y( |, X# {' }
end
3 @6 M% d1 [. ?: ]0 m) Xto check-death, C) H$ l- y* p: N2 M# B& `! f& F
ask turtles [
3 D$ H, S9 @2 ~3 W" t' Z1 [# R* p- |% v if energy <= 0 [ die ]; R+ W! `( r5 l. ~( ^
]
( C3 F0 m/ {6 Z) F7 L' Gend
{" ~9 p( T8 ~ z7 Cto regrow-grass2 v% k) B1 `' E: n6 B. ^* q7 ]
ask patches [
% ?% }1 M1 M$ V, C if random 100 < 3 [ set pcolor green ]
0 B1 N- `3 ~# F ]% T+ E7 C3 ~' S, i5 R
end; o) y9 e9 ~) D* f9 l; C, I
to do-plots& F# f2 r! W3 Z8 Y7 Z$ b2 B8 `
set-current-plot "Totals" p3 v# I9 c( z9 \, a& ~$ X& E/ a" ?, ^
set-current-plot-pen "turtles"
# \+ `* G1 b8 P4 L2 b plot count turtles
6 R: E6 c+ c3 s* f8 r* M set-current-plot-pen "grass"
& n# |4 S( h" g8 @ plot count patches with [pcolor = green]* k' p& M- L" J, ~! L5 y' ?
end4 B! |. z- x A8 J; Y4 f: j4 L
可是运行时提示no such plot: "Totals"
! w5 I$ s# K) N( jerror while observer running SET-CURRENT-PLOT: N7 ^+ F4 z7 |* D
called by procedure DO-PLOTS
8 S I! X+ C: r6 H1 X3 T$ H( s; g called by procedure SETUP. {. c6 F N: g4 A$ y L
called by 按钮 'setup'
& Q; C& U- S- A: [8 Q+ a8 @; K求大神解答啊 |