我编的程序如下turtles-own [energy]* D. Y$ m& A) k' d! X# J
to setup' k2 @: ` n6 D' h" X- x, [
clear-all
& A% }; A' f8 W i setup-patches9 c/ L, S6 W! Y, O: B8 |7 v* `
create-turtles 100
7 ^# \2 P1 b* d" p. c do-plots" q/ s$ K) I1 k
ask turtles [ setxy random-xcor random-ycor ]) Q' x1 i# w) J" P& W
end |4 R- V' f5 X' q6 K+ c
to go
# f' O& \8 w2 S* n) f) c# O) _. G move-turtles1 y; c2 {0 E6 e
eat-grass
0 Y* U1 N3 P5 H! J$ n reproduce
: n& C2 X2 ^" o# Z, D/ T; f& k" S/ A8 @ check-death! ]8 @6 N7 }: I6 w3 y
regrow-grass
4 p6 r% K4 W$ c% f* X9 ]9 | do-plots
7 r% R5 j' B, n3 L" _! i0 R8 bend
, m3 F [( I+ ^; {) ito move-turtles
$ }- j3 ?/ U/ T M2 |3 o+ g# }' ^. o0 ` ask turtles [
3 j8 j3 B2 @* [; t* A right random 360
6 D! K% M6 `2 d5 P- ~$ z% M forward 19 y0 z0 i8 t9 P
set energy energy - 1
0 k, {) T0 @* t ]
4 Q1 r6 L" C* j# Tend% [/ Z: }; ~9 k# i2 m. R
to setup-patches
' S( ]$ U7 U% W8 A& G ask patches [ set pcolor green ]
; g# z# o4 f( f! ]4 ?end( K! I3 |+ X) P+ z
to setup-turtles
3 e7 X0 S# a: S8 ~ create-turtles 100
4 n6 P& a+ N- ~ ask turtles [ setxy random-xcor random-ycor ]: X3 g$ ^' a! [6 F& s
end u& U( j* N- a' r& V* ~) s
to eat-grass' w: {+ c% {" Z' c. {+ R
ask turtles [
8 t% x4 q% Z* ?6 J2 \+ ^ if pcolor = green [7 s( ]. l2 ]$ u
set pcolor black
r2 N, ?$ q" E3 m" x* h6 j* L set energy (energy + 10), A- M$ |) X% `7 p! ~4 y
]
- k/ y* s8 X# @6 w9 |7 ^5 K0 A ifelse show-energy?
- q \+ T! n. ~. l& \! ^ [ set label energy ]
3 k( B5 Q* }, X8 o4 d: W [ set label "" ]
9 O6 g; b$ d+ t. E/ i8 m ]
7 X! [" F6 A6 Z" l& T: ^end& n4 w( s+ N; w2 ]$ L
to reproduce
2 A7 a5 n a' T ask turtles [
9 B% i; V* _( G6 `2 ]( E6 l* k if energy > 50 [
& M2 k; @( n& ~ ]. c7 d k' H set energy energy - 508 j) C1 Q4 _4 _# n+ p- R* B
hatch 1 [ set energy 50 ]/ b3 J( ^: r( v( H9 y1 S
]
3 P. M1 s+ e7 l8 P" b ]1 ^4 s1 E0 w, H- a
end
( p" f1 f5 T- \' R# U9 Sto check-death
) W4 s3 w4 c. f/ @& x' A: w9 \4 { ask turtles [
) p! J2 H+ }' s# E' F1 s if energy <= 0 [ die ]
/ ^# B7 B s8 S$ N t. a: O ]- T7 n: Q5 M1 M3 x* ]+ j( @
end
/ N" m$ I4 f, Jto regrow-grass3 o J, I) k9 W! i4 b) N8 H
ask patches [. Z8 E% P- e0 b) G" \
if random 100 < 3 [ set pcolor green ]
) e5 g6 |) `$ e8 B" w8 R ]
+ _) P. Z. K% f/ H* ?* `6 a* hend
2 B# R. T- P" Xto do-plots
% t" V& h; Y' Y6 {* S+ [ set-current-plot "Totals"" g: ]! D6 m2 b3 N9 I
set-current-plot-pen "turtles"2 Z* U; M6 t( F4 Q- @- B; j
plot count turtles
3 M) K5 A9 H: C v- t7 u set-current-plot-pen "grass"
( d% g8 Y. s, O D) g' c4 i6 W plot count patches with [pcolor = green]
- `, l6 s( |2 x$ J" Nend9 P9 E2 D9 w( Y7 `2 ?+ s3 P
可是运行时提示no such plot: "Totals"
; w8 \" x& y3 n& E, kerror while observer running SET-CURRENT-PLOT
. x, ]- z% H6 w% N8 e called by procedure DO-PLOTS
/ ?- _( r$ i& B called by procedure SETUP
; m( l" a1 w2 i# o: q# @! r: D called by 按钮 'setup'
7 {* T; z i/ e2 e; N求大神解答啊 |