我编的程序如下turtles-own [energy]# l: b4 x2 I: [/ @
to setup" T5 H2 H5 N5 I+ E; \; O; ]
clear-all
$ `6 q2 x( u3 e setup-patches
- h, T4 k, @- G create-turtles 100
$ R7 C0 K8 R5 [, i" W do-plots( I- d9 w1 R* J$ M: }6 {- L
ask turtles [ setxy random-xcor random-ycor ]
2 V. ]+ g4 T# @2 V; p2 o5 f- eend- X9 |! o# n+ U, C+ Z+ K8 g2 x, s
to go/ v7 u8 Z9 T4 s. |
move-turtles
( L% J/ v- `0 j# j( [& e eat-grass
; c3 s* g% R! {/ m( a- i( M5 m reproduce/ }6 G- M, f( V3 S) r
check-death
- C6 \# m R0 {+ s. Z' D. f+ d0 C3 E regrow-grass
9 p4 d9 [6 ^2 e- D# Y4 K$ l7 h$ z do-plots
0 G1 f- a$ |/ [/ u6 ?! _; W: eend
* F, h Y9 {6 n; B( q7 H0 W: {0 F6 o5 Oto move-turtles: T. k' h! z9 l4 Z
ask turtles [
. C- O; k- I2 g right random 3609 o! X$ L5 Y- F6 k n
forward 1
1 V2 E% T, P& k0 j! M& o5 d set energy energy - 14 Q1 S/ E, V3 `6 H# m; ], Q
]# c" U; b) l! l) ]$ U
end
* d) V5 o( p. G8 Bto setup-patches0 G1 x3 c) P! }/ l! \# ]
ask patches [ set pcolor green ]1 @9 s% @6 A& D7 k
end
; C/ a! e2 f$ X6 n' l+ U$ F& Vto setup-turtles8 ^" N" ^7 C( `6 ?7 K
create-turtles 100
' o+ v' F3 t5 @; q9 o+ k4 B ask turtles [ setxy random-xcor random-ycor ]
' e' R2 h4 r1 U, L' Y2 `! m& rend! e2 `- ?% C7 ]
to eat-grass
7 s3 `9 X+ G+ t S% c ask turtles [; l& z6 ^; ^8 l z: O
if pcolor = green [
) a0 `6 d" K1 B0 J set pcolor black" z, g7 L! U5 v) r- ?
set energy (energy + 10), ?! Z2 c* W+ N. @) ~
]
7 u7 M/ y X' u4 t1 r9 l ifelse show-energy?
$ Z, q: B2 K$ D0 I2 R, q0 R7 |2 z) v9 S [ set label energy ]2 S$ j9 o) h" p
[ set label "" ]
$ \& o- J1 V2 ]$ K1 b ]
! U- y& e e; P1 Z0 ^$ tend
o2 j8 I1 {/ n8 p( uto reproduce
) d! U' H% i, ?* ~# q; O5 @" v ask turtles [. O* ^& F6 n! U
if energy > 50 [* O& A# t$ D% L
set energy energy - 50& M; L% E) m5 x! ~( }8 f9 S N
hatch 1 [ set energy 50 ]4 n) p! X9 s, f, | K. n
]
: s. ~% h3 x: ^7 ^: D& `% A ]
5 z! O6 R8 t( m' Bend" G( Y+ e1 ?" M7 p# w5 h
to check-death3 z$ H8 [* h+ `8 |2 W
ask turtles [
! i, U8 ^+ D" s if energy <= 0 [ die ]4 y' e+ A9 f( F3 w
]+ k( q0 L% f) Y0 O
end
7 I$ W! o! E% vto regrow-grass- Y( x( ]3 @& R9 T
ask patches [
5 J. ^1 ?. L8 ?2 D3 l! e- @. ^ if random 100 < 3 [ set pcolor green ]
6 |$ x; G7 n/ }+ p d D; o7 _6 T ]
' q o) A) c- q: Z% ~1 Z: Nend$ H* j6 U$ U6 ^6 q2 n) F
to do-plots4 {2 K4 Y5 s! d, `5 F4 R! T/ }
set-current-plot "Totals"9 K3 ^4 O2 }& T U) v1 Z
set-current-plot-pen "turtles") Z: Z) p2 o; q5 X5 C4 [
plot count turtles
7 n" Q! K! i2 _7 u I7 h set-current-plot-pen "grass"
/ E; J, B0 x) ~1 G plot count patches with [pcolor = green]. U' ?& b6 T! }6 i
end7 b. y( h+ N: P9 j* R6 F8 |
可是运行时提示no such plot: "Totals"& r3 R0 P! @+ { X
error while observer running SET-CURRENT-PLOT
$ V! w c6 R$ m9 K called by procedure DO-PLOTS
+ A% @, ?1 H1 K/ T called by procedure SETUP
" I8 f8 W* A' f, b called by 按钮 'setup'
+ v4 N2 _+ t) M4 [( s求大神解答啊 |