我编的程序如下turtles-own [energy]% h" a. F' c1 q
to setup& d B" N( B& x, o: ~
clear-all
: |3 r3 M0 h/ f" G; t* T' @ setup-patches' S$ Y: S- A% b" D( ?. ^
create-turtles 100( F+ L6 @3 d% S& ~7 o
do-plots
) `3 ~0 `5 y' W/ h0 v' [ ask turtles [ setxy random-xcor random-ycor ]6 L% U4 a+ h, A7 u/ h1 M
end, X d$ c5 e: m2 T2 j" q' `
to go
. U: k1 V+ [5 T move-turtles
" u+ w! [ K) c7 H; I3 r eat-grass
/ ~; R8 g! d* N& N, c* J reproduce6 a% E. p5 x: n/ O8 v" t
check-death
2 E. t( T8 t. s2 e l) [) J* {( V regrow-grass& t }& l+ f. d
do-plots$ L1 _4 k) `6 e; V
end/ f) z% ~, t% D9 m T6 I! R+ w6 u( i- Z
to move-turtles
1 V. @+ q/ w5 `; m$ X% ~$ Y ask turtles [# A& H; H( D2 ]! z7 H
right random 360
; Q( y* y7 ?2 c3 u forward 1
" v) y, Q. r9 x/ l( p$ M' m+ U* A9 _ set energy energy - 1
1 a3 Z7 I$ }- I4 b ]
4 G- X+ g) d4 f m* r. \8 @0 E7 Rend
- s& u- ^+ ?5 d& B* Eto setup-patches9 \: i' X; ]5 I7 u
ask patches [ set pcolor green ]4 @- D% @0 x5 Q4 _0 c7 D
end) \, k+ ?) }5 h) T
to setup-turtles
( ]$ s, A! N) P+ s) F# u4 L; ^" X create-turtles 100 e' O9 m- g P5 d/ H* X
ask turtles [ setxy random-xcor random-ycor ]9 W7 \' j. C7 w9 V8 i
end2 y4 u; a( e; h' B# r
to eat-grass1 W* |! S! {# r& B h" M8 j. y
ask turtles [, |' g. v' v9 r0 K8 p
if pcolor = green [7 R7 x# c' h8 ~ |2 N0 u7 R( @/ i
set pcolor black/ w& O0 G6 Z0 v' X
set energy (energy + 10)
' J* Q6 |3 D' M/ E! Z8 g+ O ]) e9 X5 P/ f8 Y
ifelse show-energy?
; R' H/ W E* L' Z: N9 B$ ]: H [ set label energy ]" ?- k% V ~9 V8 N6 o2 ^
[ set label "" ]
9 y, j1 x* [9 u. G8 S) Q' a ]! Z3 V; K& m/ d7 X" `$ B
end
: ^+ o' d' R7 nto reproduce
) n& y/ u3 o V ask turtles [
: l, \% L' j4 V! J; Q q; E7 J if energy > 50 [& T# H. [$ X* N3 @) T8 W2 M- o
set energy energy - 502 S9 G8 o; v# V# A8 @7 ]" \: F3 Y( e% P' B# b
hatch 1 [ set energy 50 ]5 H8 w2 T) p* e$ Y1 F
]
G" o/ G. u% W {% L' n" m% q% y ]2 z& V+ ]4 f7 i: [% }. b; |
end
' [3 S$ {( N; M9 Q7 L/ T8 tto check-death% @/ |; p+ R' j* ~! T- M
ask turtles [
$ T: y, p( }6 g! q+ ] if energy <= 0 [ die ]2 T9 G/ \' ]7 |7 {% {( g/ f) a6 j
]
- i" A2 O d: R2 O2 x. Q! a U! `end
: q' b/ [, V z2 M/ uto regrow-grass
) }9 a( _, r9 D) b6 ^. S ask patches [! d* n* n# `" s/ |$ `! y" E
if random 100 < 3 [ set pcolor green ]
0 L2 \: B9 p9 S8 d ]
9 H' Q; ?6 [. |; K; Lend% m$ A( P' X! s" ^7 Y; O; [4 d( j8 j
to do-plots
3 T. p: Y: _! C set-current-plot "Totals"
8 \7 u v J3 H- @, h set-current-plot-pen "turtles"
$ S0 X/ z# v4 W4 F' q plot count turtles5 b2 i( c0 m6 [3 z6 k, ^: N7 f4 t" M
set-current-plot-pen "grass"
) K! |) K7 g: g: k+ R8 }! X plot count patches with [pcolor = green]; Y: _: ~: c+ b0 {
end) A' W' j/ a/ E4 c, X
可是运行时提示no such plot: "Totals"# k: N! I( X2 f) w& q
error while observer running SET-CURRENT-PLOT; {; q# K' I4 `5 k( J6 Z
called by procedure DO-PLOTS
9 g# ~; u6 N% G$ x called by procedure SETUP3 f* a. v" w2 \
called by 按钮 'setup'
" I8 A' C% N! i* w( C- ] i. u: K求大神解答啊 |