我编的程序如下turtles-own [energy]% m- _5 `. b/ h# e! y( t% f
to setup% ]! }0 P4 g' I, a
clear-all
5 F; E6 y' P9 ?" \$ V% w setup-patches$ ~ z0 n& u: H9 C
create-turtles 100
4 a# ]1 n0 [ z& O9 x4 J ^" c do-plots
# T; M* T0 U- H" Q ask turtles [ setxy random-xcor random-ycor ]' P/ x% h1 R* G( ~. |; u
end
; |& ]. S P9 |9 tto go2 S. r1 E5 d" c- g4 A
move-turtles
& u3 u% |0 j# C8 O eat-grass2 }$ h' P# B7 h L. x& _7 o
reproduce5 r" l% Q+ g5 D# Q8 T3 k+ \/ E- g9 K0 O
check-death
/ J, M' E, O+ T) _, K ~" ]$ H regrow-grass
& A1 _" l- ^! w2 G- V w! N3 D4 I do-plots! a/ L- ]! A. N- F5 g
end
3 c+ R d& K) d5 ^1 ]to move-turtles- c! V5 Z, j7 E. a" s
ask turtles [- F* V" n( a7 G+ |. i4 L0 w$ D0 g
right random 360
/ @& e ?3 n% G9 s$ ` forward 18 x9 L; ?( E! M( j2 Z
set energy energy - 12 C0 ]+ W: w' O7 W9 l" U) b" Y
]
& N: I) M/ K1 xend" s* \3 z* _8 p2 }0 ^
to setup-patches9 x& f* c. b4 l9 z
ask patches [ set pcolor green ]* ~& G7 E' g1 W3 H
end
. X _ c# E! e7 {0 ^0 A7 Ato setup-turtles
" E" Q8 T% W+ k create-turtles 100
# H& F) X' Z! @4 i* N7 r ask turtles [ setxy random-xcor random-ycor ]
1 E u0 w1 I6 \8 t" I9 z8 A7 }end e, ^ x# O& L. b: Q. E
to eat-grass5 x2 m- y" r: e l
ask turtles [. j8 c& {2 @3 @5 q" s" U
if pcolor = green [* P; i- y% c/ p& v: i/ C2 i
set pcolor black( T" v* p/ t/ m- {
set energy (energy + 10). x- B, D% h1 N9 f$ B; q0 j% j
]
v6 e! K; e# M ifelse show-energy?
9 a j# Q0 `" D+ q, F+ m [ set label energy ]7 s: c' A2 ^3 n4 [
[ set label "" ]
4 ]! I8 A6 h% X0 q" S3 L! s: r ]
: y2 v) x* a2 f8 \3 wend0 W& b" z9 ^5 X3 b6 A- O
to reproduce
/ n+ F r, L& s ask turtles [' t: V5 ~- Q% s7 D/ I
if energy > 50 [0 _) \) N4 Z" V( }+ s5 f
set energy energy - 50
Q% s+ H# S) _" @ hatch 1 [ set energy 50 ]
% [+ u. n% U0 q8 X0 N# `" V ]
7 q4 z2 |! C7 k0 S. h5 a ]
1 O ]5 ]+ Q" [end
* T7 Z, R- k8 P K0 Z6 sto check-death9 [% C. W% M- V; N: f
ask turtles [4 k8 Q9 S) N5 a( e9 ^5 K. J
if energy <= 0 [ die ]
8 r6 s8 a, F: l5 u: x6 g3 ^ ]
5 S" J, K u. V5 n% jend9 G) Q9 |& {" R+ c- ]2 ]
to regrow-grass
; C `) E3 g8 f% V. h+ x6 s ask patches [) f6 v' k% `0 @: S5 M
if random 100 < 3 [ set pcolor green ]
% k2 P7 K& @9 I: Y) A$ K+ ^ ]# O8 j$ Y' W8 ]1 ~
end
; B. t) _4 B2 {/ }3 ?2 F" yto do-plots
7 A9 F* w$ D1 G set-current-plot "Totals"
+ f3 b) b5 c. {- }. ]7 W- W8 J set-current-plot-pen "turtles"
3 E0 F( M5 O' `. r plot count turtles
6 L- J0 l6 y# i set-current-plot-pen "grass"# d) o: O- i( x9 h5 u
plot count patches with [pcolor = green]% c3 N0 C# w0 k
end( a, X. {& T( m/ z' u* C7 m
可是运行时提示no such plot: "Totals"& f/ @ T8 B' s- o7 ^. t
error while observer running SET-CURRENT-PLOT
: @+ A7 d( W9 k# Y( [0 A$ d. U2 l! a called by procedure DO-PLOTS
' S: k O0 c) D called by procedure SETUP
; u# ^8 H/ E; f' P( d2 A$ P called by 按钮 'setup'$ n5 b$ @! R# N9 T: y) m
求大神解答啊 |