我编的程序如下turtles-own [energy]
, U3 D( @5 y0 A4 T# Qto setup
3 l9 u/ j" o8 b8 \$ H8 |( E clear-all
( L& v8 s4 I* W# R; j0 K setup-patches3 C5 V; S" L) y+ R' h$ N4 |
create-turtles 100
/ w5 ] n: F$ P7 s' w" F$ m do-plots
/ j+ t3 ]4 w/ l% e4 i1 \2 K5 U3 L* ` ask turtles [ setxy random-xcor random-ycor ]
N7 q3 p: l5 k$ F0 b/ N( hend
4 e+ W4 O" a, v7 k4 M; Dto go. Z; t6 b" H; G& Q
move-turtles
, r0 p o) j& B; S+ s( m eat-grass
1 B: @" v+ Y% |/ i( v reproduce
/ Q* u& [. Y m( `- U# b6 R/ o8 a check-death+ x% ~5 M: E/ w1 b' Z: n7 z7 `
regrow-grass
& e7 Z; N+ }; ~9 T do-plots
5 ]/ B* d* ]) _0 l# p1 K3 ~end
6 V3 g5 p0 ]6 U L( r/ Gto move-turtles
4 B4 ~3 R) |; }+ t! ~ ask turtles [! c1 `6 L: ^7 z U
right random 360
9 V* B% T+ ^+ l forward 1
# w) |4 y6 }; a0 @' \3 ?! { set energy energy - 1
" P: h3 a. B5 d% l2 g2 A1 l# O ]
1 K( p2 C: Q7 x0 @. e9 Q, Rend
4 M/ D# w8 p) J2 oto setup-patches
$ e* ]# t" j; h7 ^/ i ask patches [ set pcolor green ]+ I: @7 u6 w3 h* P4 R* U
end* T! V" a8 s, ~; o& C0 G( _3 |# q
to setup-turtles9 y% y4 V- Q! v* f6 V4 d. Y
create-turtles 100
8 a6 p# M) V0 T ask turtles [ setxy random-xcor random-ycor ]
8 t9 A/ f$ N! U6 l$ @& aend9 f' h1 ^1 q* Z$ q! H
to eat-grass. f4 F7 W% J I9 Q
ask turtles [3 r: s% e, U/ N
if pcolor = green [
) [0 z+ O8 y) }% K set pcolor black% l: ?! |8 _: n
set energy (energy + 10)8 F/ D, @0 {3 @
] h, N' ]6 ]& f a! M; J
ifelse show-energy?: n3 Y4 R7 J) X' f5 S( L
[ set label energy ]; Q) ]6 ~$ y: ^
[ set label "" ]
! J* T6 d) ^0 q1 l ]
5 E" W4 F& O5 _# y9 W9 s& G) Nend4 j" i. t8 K4 C
to reproduce- _) H8 Q2 ~/ a0 V# H
ask turtles [8 y% d5 d9 u T# l
if energy > 50 [
4 g7 W6 r6 m5 s( q+ d$ i set energy energy - 50" w1 @0 K* w% @; U7 F
hatch 1 [ set energy 50 ]6 s1 x+ }8 n7 L6 n9 j) ?
]0 v* f# `) [8 R- K% \
]2 `3 C' I& |: q& a
end
* \9 Q7 M3 I$ fto check-death
8 A1 u) [$ P$ u* z9 B% ^6 W& b ask turtles [
4 z1 T- L% }; e( e/ C) C9 L. J+ y3 F if energy <= 0 [ die ]9 Y X+ h ~5 ^
]0 O* P8 w( R' n* G, p
end2 ]9 E5 X- Q1 \& X r, `
to regrow-grass
& e- F5 _# ^2 h0 q& E5 Q. [ ask patches [
' g0 `. G- ]1 ^$ }6 P9 D if random 100 < 3 [ set pcolor green ]
/ p6 S) ?: p7 L3 c6 f; N ]
+ y: v1 O% n6 E% `end
* O8 r6 X$ M+ g$ y" e O# ^* V$ S6 Jto do-plots9 D+ U: z% K! |; K; W
set-current-plot "Totals"
& E: G# t$ q2 C6 D* W( q set-current-plot-pen "turtles"
" `. C4 V# N# G& B" P plot count turtles
2 a' B# f0 I8 y. Q% O* L set-current-plot-pen "grass"
3 W: E6 y5 E3 V; |7 k plot count patches with [pcolor = green]8 N3 u d3 T$ W$ I
end6 W4 S8 F7 c& G
可是运行时提示no such plot: "Totals". r* D8 G8 A5 c# O" Y S
error while observer running SET-CURRENT-PLOT) n9 k H+ n" }/ d* o3 ~" s/ \
called by procedure DO-PLOTS. e5 T! [ d" _2 T x! b$ ^/ l
called by procedure SETUP: J' d! N" w9 O4 Z. r0 o
called by 按钮 'setup'$ `+ V, n% p7 c2 H. H; z. B
求大神解答啊 |