我编的程序如下turtles-own [energy]
+ f, o9 x0 I8 Q" o$ F2 M5 }) D! V; t4 Pto setup! X2 J6 x& s$ l% n3 j, M
clear-all
: B$ q5 b7 J4 x- w- ]4 z4 O setup-patches& i- F( A7 V5 P: l$ w5 X& P. i
create-turtles 100: K/ U) Q0 C0 Z2 A$ H$ A Y9 i
do-plots) [& g( \: y- y
ask turtles [ setxy random-xcor random-ycor ]
3 u5 J# q9 H( Z" r: a3 L: u' o6 Dend# s I2 T, x* V" s
to go+ k+ ]4 K0 B! |0 A
move-turtles
5 l! t1 r# F6 ~/ \0 s. G eat-grass
/ U+ o0 Z) t9 I* P) @ reproduce
) M1 f# c+ H: w) I' e( Y. h' A: Q check-death
! W& g. p7 z& S: Y" Z regrow-grass
" }4 l2 E1 `) |( F do-plots
& q7 {* v. c. A: w! `! send) [; O4 M! K m1 J, N0 C6 _; \
to move-turtles
( M) M3 e& {1 L( |! o ask turtles [
, I( Q' W) y. Z. t9 ? right random 360+ s1 Z* ?/ L( o/ q
forward 1
1 t2 @8 P5 U; u' X# f set energy energy - 1
! @; C9 q9 }! L' C/ [3 U4 { ]
' _ b$ F! R# K6 c' I/ Oend
8 w% N( W+ a/ Xto setup-patches" v6 \& {) v q1 a5 b# ]1 Z
ask patches [ set pcolor green ]5 ]- S1 h: {( F; G
end0 A0 ?1 H% E, C. p9 E
to setup-turtles
/ E! P( d" I( \7 W- K: o8 K create-turtles 100
5 @/ W% T9 c6 ^2 R' Z0 ? ask turtles [ setxy random-xcor random-ycor ]
) v# T/ h8 F' I8 z4 oend8 l9 @ L2 F+ L2 q3 V" V* F
to eat-grass
% l9 c a5 ~; P0 U ask turtles [0 y1 g+ x; F$ b3 q4 M
if pcolor = green [
3 H/ m3 z" l- K! |) _ set pcolor black8 v7 \. z* s5 l
set energy (energy + 10), {7 u, H: ]) c0 i; k/ S
]
3 p4 P2 T1 q* @% H& e ifelse show-energy?
3 H- y2 s) b, O, E- H8 l5 t [ set label energy ]- L6 [; p: }- R& }5 u/ C8 U! g4 |
[ set label "" ]
8 ]+ w7 ~ I/ J ]
; ]6 [; o/ V: U1 S2 V. U5 F2 Eend
$ u% Z+ V( r2 n- W& q. rto reproduce
- G8 m/ u1 L( ?3 I; L5 o! c+ p ask turtles [( f% X) Q6 e% s5 d3 c; G L
if energy > 50 [# @) U, i! Z& S+ O% a
set energy energy - 50: f' k* Z6 s0 F5 P* C% `. r- R7 j5 \
hatch 1 [ set energy 50 ]
* D0 D5 x) T" `6 | ]& I7 B. {) j; ~# i0 x
]8 V. ^- b4 F( [! m+ T# i8 U1 T1 A
end
: O5 V `9 n. Y, W, Nto check-death) P, h" Y; n; r# V2 F/ x( T. z( n
ask turtles [- S. ^3 o* h, G: ^
if energy <= 0 [ die ]
& B8 [$ b7 L, N9 ? ]: g$ i* ]0 |# r! V
end" z% r* k" k) m( |8 M
to regrow-grass
# f% A' F" O ` ask patches [: @% ~, b o3 y2 i# v- M8 W" x4 H+ J
if random 100 < 3 [ set pcolor green ]
! T2 r$ O. H( J( r8 F8 T! J; c ]: q6 D8 I& @- C6 e$ B! f
end
$ q# Y# \4 G' X$ a+ Z6 Pto do-plots+ o, E8 R& x6 I2 }$ [" Y/ e% P
set-current-plot "Totals"' T6 M- ~6 ]& d* |: s4 D1 x
set-current-plot-pen "turtles"
% h6 g8 A( ^& r) ? plot count turtles$ N+ @ v* V# A6 K6 X
set-current-plot-pen "grass"
8 m/ l# q5 ?6 P! n2 @# X plot count patches with [pcolor = green]
# M3 X' [# o5 w3 A& j- A, qend& l* K; z. n! s7 Y% f K6 M) K
可是运行时提示no such plot: "Totals"# }) [$ q- N* w, ~0 L6 A
error while observer running SET-CURRENT-PLOT
8 ]2 K( t, w& x called by procedure DO-PLOTS
! H* |! `+ R/ p% v4 K. L* ]1 s called by procedure SETUP
( z: K) j! D+ s) a/ V H! i2 ` called by 按钮 'setup'
+ }% U* Z- b8 G0 W2 ]求大神解答啊 |