我编的程序如下turtles-own [energy] F, L% z4 \! K- Z
to setup
' w6 d$ ^) @; j* U8 ^& w clear-all, p0 N( Z0 a# v+ c
setup-patches9 k& {9 p6 m0 j
create-turtles 100
4 Q( E d$ l4 f* w4 m d L do-plots
$ r8 x+ P+ L$ c' m3 c ask turtles [ setxy random-xcor random-ycor ]* }& v1 p# C/ y# a
end
$ @ F7 s5 t3 k, E" G- T: b' |to go
3 u* y! b3 f+ S, F move-turtles9 S- `4 V4 v! {0 y5 g
eat-grass) E# L+ n4 z. l) \+ B
reproduce+ z8 I/ l) [7 K4 w6 J% v
check-death
( V4 Q0 ?: q3 Z3 _# E. N2 s regrow-grass
5 e& @6 k {: V9 E/ _, Q do-plots
( j' x+ T: d& f7 o% Zend) w! L6 q: ~7 X; b9 v' s
to move-turtles ~- L# p: g& R7 v7 J$ X- O: _1 s
ask turtles [: a( ]2 {3 y4 a4 \) i
right random 3604 L5 T) b) H, Q# W L9 P
forward 1( f7 n) ?, p4 ~, G1 ]0 L* b6 x9 V) I
set energy energy - 1
+ R) q' M1 @6 C/ m4 M7 q ]
0 q; o. {6 E6 r4 F6 L& S8 J" pend
. ~. W! p* O- k! w: A7 @to setup-patches9 P/ Q- M6 ?/ G8 [$ y, t4 }5 H
ask patches [ set pcolor green ]6 l4 M) {7 w u1 k1 h
end
: k+ a6 H* y- @' b3 fto setup-turtles
2 n4 }6 U/ z1 g create-turtles 100: z& E2 X# w) P" G0 [4 T
ask turtles [ setxy random-xcor random-ycor ]; e8 W) l1 [0 o; a
end# E" F3 ?, [5 h
to eat-grass
$ G7 O$ I% b4 Y& s$ K0 e ask turtles [) r" r7 ?1 Q* ?0 H9 H1 ?- H7 _) L
if pcolor = green [! u& a4 R% ]/ R; u
set pcolor black. e. I( b6 ~ s+ T1 S& a
set energy (energy + 10)% e7 }" R, i9 L+ z8 [" V' q$ a( A- P
]
* G% j7 x/ p1 O ifelse show-energy?
* H0 A* e0 k# p6 i9 g- L5 b [ set label energy ]
9 D( P, W( S3 e3 Y L6 h [ set label "" ]
* W# P" T3 }' @5 z ]
& S3 K9 w3 t! z1 \" Kend8 Z/ j' o( v+ m' I/ |: t o
to reproduce$ \ i0 n* k. I% y2 a- i
ask turtles [
+ @1 a7 `, I$ `/ q9 T7 G) K4 T' | if energy > 50 [/ _1 `- t& n0 x, Y, W% r: t
set energy energy - 50 d; |: i0 v7 M) ?2 R- G
hatch 1 [ set energy 50 ]- C& H [+ S7 v# ^
]7 D9 n/ [+ D) k( _" [0 a* v" W7 Z
]2 b9 G: A2 A* ^3 x7 W% y( i
end
/ q* ]3 Z7 e$ ?) V+ A8 A/ p) \& Bto check-death8 N/ x' o5 [: D/ n
ask turtles [+ R2 f( o" X3 I5 i
if energy <= 0 [ die ]
7 p! n# D8 N& m! c I ]
2 A& ?6 f& P! J" l* \# Bend
0 y+ ]1 o2 S' [5 ]( n3 bto regrow-grass+ q4 p% _- F3 [& F2 W% n; e
ask patches [
: }- j& s" u: \% G if random 100 < 3 [ set pcolor green ]7 ~3 H4 W& x+ O8 e/ r( v5 C) R
]
6 ]: e% X% \& `0 G) B4 R0 Nend0 r6 N/ G' [ n7 R; n
to do-plots
9 Z4 J7 w% C( V5 N9 W set-current-plot "Totals"
' |: E, v# @1 J3 s h set-current-plot-pen "turtles"
. L. Z; j* J6 j- P/ a. c4 n plot count turtles3 k) V0 X+ m" l6 M6 Y! F; p
set-current-plot-pen "grass"
' \+ m. ]% H3 i) r$ `7 N, P plot count patches with [pcolor = green]9 r, c. L% T* j1 y ~
end- L) t0 m0 Y- R: s
可是运行时提示no such plot: "Totals"
2 S: ]: M8 X9 Ferror while observer running SET-CURRENT-PLOT+ K# J+ z" {$ x' `: j5 u
called by procedure DO-PLOTS
0 `2 I1 o6 y' A called by procedure SETUP
* s& ~* D: |' X3 H called by 按钮 'setup'
1 ^0 }0 @2 U0 |" M& x求大神解答啊 |