我编的程序如下turtles-own [energy]% @3 l( m$ U+ o0 G1 B y& G
to setup
& ?0 u# r4 O% H) D9 y/ c$ R# M clear-all
8 A. Z* ^5 N( ?1 v setup-patches" n' Z+ W7 u _" Y9 B, e3 U9 V2 q
create-turtles 100
) U, |; ?7 x+ D( F- l+ d do-plots: T! D! _8 p7 C, V+ ]
ask turtles [ setxy random-xcor random-ycor ]+ a! b4 {: B' M/ h/ ~. n
end
! n9 D/ E2 \. ~3 R: H: bto go: v7 w j2 K3 ]
move-turtles
i9 b, n) r) c eat-grass
1 w: N7 N r4 _6 n$ `. q4 F! Q+ b4 A reproduce3 I4 T7 |+ J* A% f; d. S8 [
check-death5 d- q7 z- V4 T0 F9 Q' b- I
regrow-grass6 X( ^8 u$ f3 i0 r7 ^
do-plots
& A% r& B2 `& N! I; f& O$ Zend; |4 `! _0 G' ?% K- ?% c$ F
to move-turtles8 F$ B& h, J, o! e$ c6 D
ask turtles [4 O0 p3 i$ K9 R2 v, F) {
right random 360- H. k5 }9 M- Q0 R' z4 ^6 m2 \9 a5 A
forward 1
; P( F) k6 a% \" q/ ~ set energy energy - 1
+ G* D7 l5 ?, n/ } n, b ]' Y2 f6 j' B J6 `8 v# o- p" _
end8 J! J; ~" Q9 `3 U" R3 X/ Q8 l
to setup-patches- a. x1 w- J ]; u, q
ask patches [ set pcolor green ]0 t& D5 T3 m. A1 e. x
end
$ I6 G: k& r. a) k' Q; vto setup-turtles& C7 m. |7 r& H8 r& L) Z
create-turtles 100
# N1 e% e7 q6 z$ b ask turtles [ setxy random-xcor random-ycor ]
- d7 i( z4 H$ c% Qend( m/ u, W7 m# g4 r+ |; u$ B" }/ r
to eat-grass
- B8 a% Q9 {, P6 Y+ p( b3 y2 U ask turtles [" z! B" p6 R! A
if pcolor = green [
* x' o1 Q2 P' i9 E. b) Q# X" N set pcolor black
/ t$ x5 j* e( }9 c; \) N& ] set energy (energy + 10)
& e: G% M3 W0 g. ^ s ]
4 Y1 }% Y9 ?. E& e5 s; g$ J ifelse show-energy?5 \4 M# f1 T* N. M' `* c* ~$ N, B
[ set label energy ]7 G# i: q: v" e) s8 p
[ set label "" ]
& {- u3 \3 `5 u C ]
3 S* m/ H1 x* qend
6 }( j( p6 A# z; H# T+ I% c( Mto reproduce( j1 X$ z) c3 P
ask turtles [& h5 |: [" }: G5 A2 k3 y; S
if energy > 50 [" J! [ t+ r, U6 w- i
set energy energy - 50
8 A- u3 G( y$ y6 Q# d hatch 1 [ set energy 50 ]1 |( t& v" T, b; h0 R: ?
]
' b5 K2 K8 P. H0 z* f ]
7 z0 t1 }+ o* \$ L; _( B" s' Lend- j% M5 [+ O! e( \5 x% I- z# ?
to check-death
' x% l+ ?0 U2 P4 U) Z ask turtles [
; q9 X: M( h* X0 D5 ]7 E if energy <= 0 [ die ]+ j% N c$ N' K7 Y) t
]9 Z3 ^* H5 f" m& T3 P
end
, y3 U( L7 K, n8 c! Fto regrow-grass9 i" v. G# f4 ^. A0 E* a7 h: ~0 _
ask patches [
& W& e# `8 S5 `5 ^' w5 r if random 100 < 3 [ set pcolor green ]
4 z6 o+ B5 x R0 o8 I ]. g; \& D7 `5 i
end
- Y2 S. ~. V# }1 R( Oto do-plots8 y* u# S: g2 |) C3 l
set-current-plot "Totals"5 l3 `, `' B$ S r0 r' X
set-current-plot-pen "turtles"
' |( S; u! ^8 c$ l$ w plot count turtles1 M8 k+ t5 _; I2 N4 `4 h4 O/ Z
set-current-plot-pen "grass"; |- n! x* v' l e
plot count patches with [pcolor = green]7 g$ H9 c7 f5 O/ z8 E% i \
end e; n' b4 [/ K( C( Y
可是运行时提示no such plot: "Totals"
2 L! q: f; ?, rerror while observer running SET-CURRENT-PLOT
1 Q1 G: h1 X( r% s7 p called by procedure DO-PLOTS' f3 d5 u* S- }2 a1 p0 ^
called by procedure SETUP
D) |: H& D" c6 K% y& s/ k ? called by 按钮 'setup'
; m [# S. v. p+ W4 {; ~( b4 i求大神解答啊 |