我编的程序如下turtles-own [energy]
" O5 R/ W! P$ G Lto setup
# \+ \+ @1 M/ l clear-all) j2 W, a( [( |& x; h( ?& ]
setup-patches
9 D+ Y5 |* m! H create-turtles 100" a" C) ]! `4 |4 @9 n# H; V
do-plots
7 o1 c' s- d/ i+ K( u, U ask turtles [ setxy random-xcor random-ycor ]
- A- s! K& U" Y$ Yend
( b3 W& i }& m$ c$ p( z$ ?to go# [& p( }4 \, N3 t- C" o% w
move-turtles1 Q! N4 s! J# A7 {3 |
eat-grass% v, S9 n G8 k
reproduce
) X& ^" I1 w% Y check-death; {2 H2 Z, q. o) p) H
regrow-grass) l3 q. }, Y7 `9 ?+ @7 R
do-plots
* ?$ i3 q" u2 S5 Q- f& \3 e, Rend
0 e2 N; @: ^/ R; vto move-turtles. e: _. i# @8 u/ B
ask turtles [
! p# u$ K# d% d/ Y5 `% s right random 360
' ^8 _( g. Q, ~ forward 1" u b3 r" W8 t/ O" l
set energy energy - 17 X; |8 o0 \0 k: y9 `% v# U0 L
]
$ K6 G0 X6 h+ p. D0 a R4 nend8 _9 r6 w! I: ?0 P/ ~
to setup-patches: H+ h$ E# g6 Z- M! [
ask patches [ set pcolor green ]
}- f$ v% s9 T* g" J- eend t' Z0 F5 a2 v1 [( G
to setup-turtles
! C! B- f& o7 n! L; B5 R; ~ create-turtles 100
$ {* U+ F/ F, z' ]& N* P ask turtles [ setxy random-xcor random-ycor ]
$ i& }& U9 m: D3 M- }& o- eend5 e6 k% s' |% L8 p- r. t( f8 \/ [
to eat-grass" z/ q. u+ `% D+ M' r( u4 H6 q( F
ask turtles [. z: P" m, s7 M+ |3 {) }( \, s
if pcolor = green [
( X' w2 C# ]) T set pcolor black
# }! n" R* I' v7 Q0 q$ [- T set energy (energy + 10)' g: G' k$ l( F2 P$ d/ G T) }
]7 l3 p+ S* X9 y t3 M: n! u
ifelse show-energy?
# Q8 Z! |9 v l: t( x) f [ set label energy ]8 S ^9 W4 `7 b- n" O W* w
[ set label "" ]
3 q- y5 P& b. Y6 M7 s2 g5 n ]
2 U0 n: d A* O8 C' [end
# F2 }& z3 ~, ]9 P, {, Q; C% {to reproduce
2 r c. @& ~1 z: l ask turtles [
5 G2 j8 e9 h& i2 L! h* K) L if energy > 50 [
, F8 N! O" P' b+ |3 L2 K set energy energy - 50$ h+ R4 W W% q4 E4 K( `: w V
hatch 1 [ set energy 50 ]- r+ o/ D" X' c; w$ p
]
' p* h9 A F, m3 n0 F! H ]
! }, Z0 p, \" V$ s8 [. Send7 T+ f- X8 C& I" `
to check-death" ?3 |* M8 o8 L0 f* W
ask turtles [
: a2 n% Y( Z% I if energy <= 0 [ die ]: `: U5 Y( Z% L* t' e i# ^
]
M# f* f Y2 J7 ]end
+ a' M" n" L: I$ G+ tto regrow-grass
6 w2 ?: \. _6 C2 v- W1 ?0 R ask patches [
" E g" I8 W" } if random 100 < 3 [ set pcolor green ]
6 a, X7 ^0 a" c0 h$ o ]
4 @$ D, q" P& b7 w7 G4 ]end
( {* _8 s$ W1 c" @% Bto do-plots
0 P& K! T: _! |5 S set-current-plot "Totals"# p, R9 R& H1 @: P6 F1 a
set-current-plot-pen "turtles"
+ j8 s$ r, @5 B% N# o/ S' H/ m! u8 p$ W plot count turtles. X4 `: w' A3 f7 e
set-current-plot-pen "grass"
3 r8 t: K. {2 [8 {3 | J) |# L plot count patches with [pcolor = green]* B# ]3 `- p o% ^
end
& N- F+ n8 v* _% i9 J9 Q可是运行时提示no such plot: "Totals", C7 l0 |- X! H: c( J% ~$ Y4 b
error while observer running SET-CURRENT-PLOT
v9 |# | ?0 f6 F called by procedure DO-PLOTS
' w. q4 k9 k" u% {! p- y8 | called by procedure SETUP# q. |. c4 g- ^/ v
called by 按钮 'setup'
0 V1 S! N0 Z8 u* x @求大神解答啊 |