我编的程序如下turtles-own [energy]
7 y" u) k4 q9 O2 o3 b/ Yto setup
8 \! W# Z2 Q5 W7 L5 e& o; A clear-all
[$ G5 Q8 p7 `3 M. V p! U0 r setup-patches: J0 j8 G1 t# [$ T$ _ z
create-turtles 100
e/ u) e7 d2 c; ?/ G' R do-plots6 p3 z% o5 `9 ^( ]7 z- i
ask turtles [ setxy random-xcor random-ycor ]
, {8 ?) C# i9 {8 R' X3 k1 i4 Mend
P! K' j: f6 s8 D8 e, Q1 p' Bto go Q) Z" E/ G( Z% c" H0 a) `
move-turtles/ P( T1 i0 h( c8 z
eat-grass0 ^" C' z& ?2 J8 g3 P0 ?- f! d* X0 @; l
reproduce
9 f* K, {0 J X9 s2 Y( K check-death
+ [! z" ~/ O) O" b X- n regrow-grass
" t- R( y% H. o+ B do-plots5 a' z' |/ `0 m/ P+ t) m' ?
end$ U5 Q* V( |+ t* s& P% a, A4 r! q
to move-turtles+ U5 X/ d9 J/ k+ Z& m6 C
ask turtles [6 ^2 k; g' T: y+ S3 N Y
right random 3604 `4 L8 X- H. _7 i" D% B0 [7 d
forward 1
- G1 N y) z# i' i) {3 `6 d4 ] set energy energy - 12 w7 t$ u: J' j8 s0 y: n* k4 Z/ h7 S; U
]
) u4 q3 f4 }! Fend
5 }6 h7 T! z3 }, A1 c# {' x7 Z rto setup-patches; ^$ w6 W2 G0 ^1 n# b3 a* \/ B
ask patches [ set pcolor green ]
) ^$ \4 V2 }/ yend" `7 N& Z1 O3 U
to setup-turtles
( P% \' s6 x: ?+ ?: K2 { create-turtles 100
2 s @/ y, ?% `8 Q) d ask turtles [ setxy random-xcor random-ycor ]5 l8 Z6 w8 a1 _, w
end
/ u" p& e3 w0 @% C, r. ~. Mto eat-grass- e |: _: Z; w7 b, w2 P! g
ask turtles [# T, I; l( C" ]# d
if pcolor = green [* ^% l- R# s6 t! {. I
set pcolor black) C7 g+ I$ M9 B
set energy (energy + 10)
1 G+ e4 K. i/ C/ ~# R ]- M! [3 {; O Q7 n% u
ifelse show-energy?. r _4 v$ K- ]/ {1 i0 V" u
[ set label energy ]
4 f5 p3 ~2 I4 b9 F: m9 M1 W [ set label "" ]8 X% O! ~; [4 k+ n4 ?- e1 H
]
; k# R! _ X4 Wend
0 Y1 S- n, V- V% G" Nto reproduce: _; X) C. v' p4 P& v! X
ask turtles [; r$ a. e! g0 f( f5 k
if energy > 50 [2 Z! P* V2 a* a2 n
set energy energy - 50( ?0 ?4 G' t* J6 t$ |
hatch 1 [ set energy 50 ]
1 _ @5 l! L5 d: ]+ R ]
* J {- V3 K+ [* q ]
% X2 C+ m1 m7 u( k6 Kend
$ S6 @* l& c9 l* y$ x; vto check-death
7 }/ z- ]0 V3 K ask turtles [
' M4 s2 H* p; L9 U0 S7 O% P if energy <= 0 [ die ]
& {2 g/ o! D8 E4 m. N! \ ]
$ B- @( E' J( @' Zend: u6 g, J: J/ e
to regrow-grass
1 Z* U9 C3 q6 `6 C+ ^! N; B ask patches [
! P0 B' _3 r. s" ^# G( J! E& x' ^ if random 100 < 3 [ set pcolor green ]$ P0 x: d h2 ?0 C
]
$ }/ g; ]% e) ~, V8 ~! aend$ G6 a$ x. b% I0 \
to do-plots
' X: v' Y0 \3 P3 t- M) A set-current-plot "Totals"
8 k& j7 f; d# p g set-current-plot-pen "turtles"
; l/ d" L5 j% m4 o% z9 ~+ L4 l" \ plot count turtles
8 [/ z% [5 S, I, ]% m1 k set-current-plot-pen "grass"* ^+ W8 [6 I! k; @/ f" W, S) N n% B
plot count patches with [pcolor = green]
9 t$ o+ X+ d9 rend) g9 X: h+ R2 B' o }: N; \; D
可是运行时提示no such plot: "Totals"* q- O7 I6 X7 }, ^
error while observer running SET-CURRENT-PLOT
3 H! _" x- @( U% a6 @ called by procedure DO-PLOTS4 E8 X* `# C x8 B1 e4 [4 i
called by procedure SETUP
5 @3 Z2 D. p4 f8 G" A called by 按钮 'setup'
5 z+ g" @: X# d# L) M& v( x( D求大神解答啊 |