我编的程序如下turtles-own [energy]
8 s! C6 y+ g4 mto setup5 T7 ^; ]. C6 T6 T0 R
clear-all
* f2 P; u6 p5 W0 O: M% l setup-patches
; K2 |/ [( r% @ create-turtles 100
, P" F) u5 m- x/ ^# _) |: B do-plots+ {2 \, n& c1 \1 R
ask turtles [ setxy random-xcor random-ycor ]1 g% C' P; X- ?, O$ l
end
1 s/ q Q4 M# lto go
5 Z5 O; y: I; z) y move-turtles3 Y% f) }" | r; N2 x
eat-grass
; y; H3 s" w) _1 V& @& F6 S reproduce
, t6 C; @+ \1 @/ z5 r- s: } check-death! R# _0 \! v' Q1 G' p$ f, Z c
regrow-grass- g; v4 `8 j; |/ R% Z \8 V
do-plots
1 e6 J! T$ Z- C- Fend7 } i* S$ j8 G& J
to move-turtles% Q: j% s6 M0 E0 J6 Y. D2 T+ p' N; `8 _
ask turtles [
) s0 o" U$ l& a9 \' K9 T right random 360. d6 {. n$ P# k& a9 e6 q
forward 1
" S2 b+ L9 y& p& \/ m+ m$ i. k set energy energy - 1
- i. s. h+ |" J ]' Q& a: }3 W% d) z# z, a
end* M- I5 ^ i# k, G7 `, i& E
to setup-patches
6 ?) ], ~) N+ \# _5 v/ U ask patches [ set pcolor green ]. ]# p# N! U0 g# O
end& m! d5 y6 I/ O r% W6 R. M7 E
to setup-turtles
' n5 h, {1 m$ i6 u: n create-turtles 100& M4 a1 z% p. y$ S% G7 B# _4 b
ask turtles [ setxy random-xcor random-ycor ]8 y6 N* E2 [, Z' m( Q
end! `, }; Y4 P2 }$ o! @! W
to eat-grass
2 f: @& L, o6 T6 I ask turtles [/ F; ^! G' f. M' y2 v7 h
if pcolor = green [# ?: N- S9 [- k! Z. D/ b% K2 W& A& {
set pcolor black+ B% S4 d4 ~+ `7 g2 n
set energy (energy + 10)
8 X6 f# A% P2 `7 e ]
1 W) v* O6 l7 l+ O4 v ifelse show-energy?6 D+ q/ I) }3 F* {& {" H
[ set label energy ]
1 A: M; Q$ o* x [ set label "" ]
0 G9 d2 j, p4 N ]
2 E. g8 r. R, m: @3 _end
, P9 t/ n' R( oto reproduce* @; S" {; F. L" O
ask turtles [
9 v7 R- |2 V5 f if energy > 50 [
% e3 h/ M; F- Z- z set energy energy - 50
) `* C8 o* G: e# | @& W hatch 1 [ set energy 50 ]
6 r+ l( u; g7 Q) `2 ?9 p ]
- q: f6 I1 G+ m. Y( O: C ]
: U& K7 C7 r9 P9 Zend
7 r+ o9 L+ f/ C7 l, J5 v% A9 qto check-death
_) J! f7 r7 I7 l+ k- ^ ask turtles [
. w2 E {, k& W+ t- w. x: E if energy <= 0 [ die ]: T* F- o/ N8 u* s2 r8 g
]" f: l, e& B/ G& }) G& y: g* B# N
end
9 _# C% x. x- ?3 @5 Nto regrow-grass
6 W, k% v- j* a* w9 H9 I ask patches [2 R5 ^7 l6 H% x5 ^! A
if random 100 < 3 [ set pcolor green ]6 ^5 P1 j% S. H0 l
]
! L& X# q6 ?% Q' a) I! z* s7 Bend5 a( |0 e7 u/ B* J" g3 n
to do-plots
, Q% [ c9 e* v, v set-current-plot "Totals"
% A; K, |2 O$ X$ V7 |' F. y! F set-current-plot-pen "turtles"
) `( ^4 G+ h5 r( y+ V0 { plot count turtles7 v; L T$ _: i/ v3 |0 @) W8 H
set-current-plot-pen "grass"% g/ }& V: S1 m: F, a% V* Z' c
plot count patches with [pcolor = green]
: n. t) v' O9 Y7 Xend
. Q+ x/ x7 K: [8 {1 t可是运行时提示no such plot: "Totals"
. J5 R% B) R7 werror while observer running SET-CURRENT-PLOT
L. l9 F. ~; n5 W called by procedure DO-PLOTS
1 R6 j( o: H4 m1 i* R) ^ called by procedure SETUP
$ r' a: M3 A8 n q+ ], Y0 ~ called by 按钮 'setup'
, q5 n1 L8 ~) n求大神解答啊 |