我编的程序如下turtles-own [energy], B1 P& [# n8 ~) b- U% e: M8 M
to setup" G/ ]; ^% I8 ^+ o" h4 m
clear-all
* B1 A }) I4 G$ @# A5 P& n8 E setup-patches! ?: Q% V- R- Z. u
create-turtles 100. r/ X7 r: H/ y% {* S y
do-plots
- y1 A4 x& @ w# i1 Q( S ask turtles [ setxy random-xcor random-ycor ]; r; H* G; Y6 i
end: W! d' w+ y1 `( T+ d' |8 T7 \2 X, ]8 h
to go6 q+ i1 L- v, J+ N# E1 z
move-turtles4 T9 ^7 ?: l2 z9 p8 G( b c
eat-grass
+ W. E8 S. |: d0 h reproduce+ ?& ~# j' p* g
check-death
5 Q |0 j, i5 M, U regrow-grass
5 A8 n+ x( i* _/ M: ^1 Z do-plots, w ^/ x- C4 |$ ]1 {
end" _" G k3 S1 O( N" j
to move-turtles
- [ R* a L7 r9 L r' I: n ask turtles [4 M Q/ R7 u' W% T) {# ]
right random 360
' _* T: |8 }! s7 z6 }7 X- k( G3 V forward 1% d9 j& d) `, G1 b" ^6 C
set energy energy - 1
4 s: g; h; { z6 Z) P- @5 Q ]/ \' l& J3 n" m( u% j8 Q
end
, L5 ^" h7 L* K; O6 Cto setup-patches9 ~# Z6 z9 E( b* q
ask patches [ set pcolor green ]: o! {5 D2 p) ^9 H* a( J
end
7 d5 N$ n6 M$ P0 o, oto setup-turtles, j3 }! e8 u, [
create-turtles 1002 D ?0 m6 H D' o. [- c& n
ask turtles [ setxy random-xcor random-ycor ]/ [5 i, ~# Y. c4 f; l
end
3 ~8 J6 W- J! ^) B0 Hto eat-grass l( N! g- S2 E3 B( T
ask turtles [
* n) J$ {' h5 h7 M, j0 K# T; @ if pcolor = green [
+ D) L! A# t9 I& F4 j8 V( Y set pcolor black5 k( x3 E8 R" T. x4 r5 y3 z
set energy (energy + 10)% Z) ]6 I- _3 Y' B+ C7 k
]# l! W2 \! g; p
ifelse show-energy?0 N! m$ ]) V) {" t2 i, E1 l2 |
[ set label energy ]" y/ S9 @' ]- R2 k1 M
[ set label "" ]
1 ^5 e) J; A" e2 K9 q ]
& G2 ] U& a4 v' O; p* n, p. yend
1 v& S) [0 {2 J9 p' |0 Oto reproduce r6 t# k' D l i5 Z
ask turtles [
9 {" r9 n6 y( w8 A L4 R; U if energy > 50 [
+ J- `: ~, P* P/ s9 Z* t set energy energy - 50
6 s1 f7 j& Z# u7 X3 H. X% y& P hatch 1 [ set energy 50 ]/ i: H! K3 L( N6 q
]
3 b- ?+ \9 B: U" z3 h- I ]
0 }, @; ?% N' L$ `! }( [9 Lend
' |- P+ X+ `( h8 Y$ V! Fto check-death
" F' m8 { H7 r ask turtles [
( o+ f+ ]9 @0 V9 _8 O% g" s; r if energy <= 0 [ die ]$ ?6 g% ^/ e: L; p) B2 A/ A" B% A4 m
] {0 _, D, A3 S
end5 d/ P2 ^5 K8 d
to regrow-grass
`9 b( ?' e& y( f& L ask patches [
! H) B1 t2 C/ `$ H- K0 F if random 100 < 3 [ set pcolor green ]5 e! w( E, S+ D4 v& o2 \
]
/ m z! P0 E) k/ H5 L# {end6 }4 K, R& o/ m
to do-plots5 f4 a( u! b# c$ I- T
set-current-plot "Totals": d7 Q" \3 k) t7 s$ z
set-current-plot-pen "turtles"
) }8 `5 u' v: b0 h6 C plot count turtles
3 m: O( y3 W9 q. w2 P set-current-plot-pen "grass"
* ^; f- b! `4 q9 B plot count patches with [pcolor = green]
( Z) V8 ^7 n4 e/ ?4 W8 |. Send
* o! j$ N5 f# o7 m& D# V* ?可是运行时提示no such plot: "Totals"
+ v5 @( R! {6 c) |error while observer running SET-CURRENT-PLOT( X' E2 |- L @9 B; U
called by procedure DO-PLOTS
& j! Y, T9 r [5 ] called by procedure SETUP, w( N) f1 g* _+ s- o" Z
called by 按钮 'setup'
! R; m, H' y# V$ e求大神解答啊 |