我编的程序如下turtles-own [energy] R/ B" L5 S( \- B7 D& U4 [
to setup" p0 M- d2 | y' t. G: s
clear-all {7 Y* I0 E6 x( {: v& n+ p5 O4 m
setup-patches* h) S; A+ u5 O) T9 ~4 @3 v) B
create-turtles 100
: O8 [. F/ L4 G V; N, W. e do-plots6 H; L6 y1 K: U# ?4 c3 ~* S
ask turtles [ setxy random-xcor random-ycor ]
( [' g. N9 ?; B! f1 S4 wend
3 u5 A: e+ k% u2 w/ |6 S) D. Gto go
; a" g( G6 ?; u9 V% D4 q& _ move-turtles
1 g# i2 D( X/ Q# W: _* q3 k% w5 d+ y+ D eat-grass7 {/ t" [6 d9 s* D( y6 |7 u
reproduce" Q6 s" m& S( @* Z; p
check-death! t' s( S* b2 c3 J
regrow-grass
2 w$ y; x9 H0 N" ~, | do-plots5 Z9 a9 z' Q/ K8 r5 Y+ K- a, @5 B
end
) _! B, z; m7 s! e5 V, `to move-turtles- ^- G1 h: X' t. e& K/ b
ask turtles [
5 }) g4 v" N. H$ y- W right random 3602 G) y7 q+ P7 n4 _ F. W7 u, ~) V) \
forward 1; v3 u/ A3 W/ u- G
set energy energy - 16 Z& ^- T$ g/ ]9 ~1 V" v) n$ q
]! F3 e' F! S( C" M8 v- ^, Y
end
- C. y6 q5 U q( ?" j/ |# p* _to setup-patches" Y3 ]! L$ Z/ }" Z
ask patches [ set pcolor green ]
) j! o( v: f( U- y7 mend+ D1 W& I8 \$ e" i# s$ K# X
to setup-turtles
. r0 V( P% v+ @' f% V+ @ create-turtles 100$ Q/ [9 g1 R% Q4 E1 D, ?" K+ r# i
ask turtles [ setxy random-xcor random-ycor ]
4 N7 S7 N0 _0 Hend& q2 R5 y7 c, U: b) Z
to eat-grass
) p8 A1 ]. O/ T" N* D ask turtles [/ H/ j: \) T2 b% X5 Z' O" V1 ^$ W
if pcolor = green [
( ]5 C3 J$ C, l" Y set pcolor black
; a! X1 y/ B* ]: t0 {* o set energy (energy + 10)
4 ^* E- s1 y$ u/ }7 p ]
7 q G* o) V K3 [( |4 D8 V ifelse show-energy?
) K: S6 K( Z9 c) J6 C4 v [ set label energy ]
# n, }% k; }! ~* R, K( K [ set label "" ]: D5 r' E" }% U8 a6 |/ M5 N3 X
]2 h0 C7 E, S" r' _* u$ P
end% h$ @% f+ W1 Q; \* E: M
to reproduce
, f. n) D' l9 y* Y9 G2 ^% g; u ask turtles [1 A& R/ L/ w% q% D3 P
if energy > 50 [: `7 I5 `' ~, [9 w" L8 x
set energy energy - 50
4 k \! F$ n" `) B hatch 1 [ set energy 50 ]- Q/ o: s) G0 E
]
- p$ v) T [7 P0 l; u9 Q ]+ | g, d1 t5 A/ ^9 u% n; b1 j8 f5 J
end
, b+ n9 y( y* {& u* tto check-death
, W2 I8 P8 [! ^, L ~ ask turtles [
3 g3 x- m* f1 V- [/ |+ L- n if energy <= 0 [ die ]
' W7 B, P' X- F8 t ] t$ K/ A* _) m* D/ R, ~7 H6 Q
end3 A# v* s$ I0 C9 N. O
to regrow-grass
, o; f. a( c& {/ X% Q ask patches [* O/ Y2 ]0 y7 x8 @, y; S& V
if random 100 < 3 [ set pcolor green ]# k8 i: f; Q' H$ V" v* f. ?
]) N" h2 S' V9 O: o
end
5 {/ s$ j, Y4 z# p' wto do-plots; Z- ~1 @, e6 g1 O
set-current-plot "Totals"- @+ r; `, K Q
set-current-plot-pen "turtles", \( w& w& \) U" _
plot count turtles: i7 o+ [6 c+ H, N o6 M% Q! R0 @
set-current-plot-pen "grass"- u% o9 H& O7 k& O' ~( B8 Z
plot count patches with [pcolor = green], i9 Y/ [2 E+ h0 o$ ?
end" s: r- F s9 s
可是运行时提示no such plot: "Totals"; U q9 m8 W: ^4 C( D% j M
error while observer running SET-CURRENT-PLOT
) ^% M( o" T" ^/ l called by procedure DO-PLOTS
7 Q2 T% j, G: J+ a0 I called by procedure SETUP: M' {6 B+ V6 O1 T5 T( e
called by 按钮 'setup', j: E- S" J" g: M4 O! x
求大神解答啊 |