我编的程序如下turtles-own [energy]- G, T8 ^5 W1 e. d% @( T/ m
to setup; [4 ^3 o' W$ q+ g; Y
clear-all
$ u3 u3 V7 g: g) B: k% w+ W2 G# y8 W setup-patches, X! P5 q2 t0 a/ Y
create-turtles 100
; _0 L9 f7 e' X$ [! o: r do-plots
& y% `9 G" Q/ F0 ?% e2 o+ ~ ask turtles [ setxy random-xcor random-ycor ]
' }* J4 U; Q' {9 C( d" J# eend, a7 I. p7 D# b! P
to go U" K+ F9 l) T8 w
move-turtles
1 \' m% l- ~9 D7 \/ x eat-grass9 G) d/ R L* t S3 Q8 E
reproduce5 D# B4 F- t& o6 R+ |2 L% Q( x
check-death
, p9 F z& h- V& h4 _6 e regrow-grass
! l* l2 E: k8 x do-plots
?6 i; ^9 d; N, B' x8 f) lend
$ O8 Y' k& a# y! N; mto move-turtles. T v1 }$ J1 k7 C
ask turtles [
: b1 `$ L4 ^+ `8 A9 D, ^ right random 360
; n( k' _* V! B& W4 Q, [3 l+ t forward 1
; u/ O V J' E set energy energy - 1
# Y3 b7 ~* Z/ z& L* D ]4 A/ ^' Q5 h3 t! M' F) \0 Z
end2 Q- W1 }1 ~3 X% r7 n
to setup-patches: Q" n, P6 z3 X" X
ask patches [ set pcolor green ] L( \$ ~4 y. r3 _2 R
end
4 ~# ]1 R D" E9 N$ {( W6 q2 s Uto setup-turtles u! C1 f) U9 m4 v" m
create-turtles 100' f* l8 i5 e6 J4 i: d# Z1 c% N, m2 Y, Y
ask turtles [ setxy random-xcor random-ycor ]
. d; X/ Q- `% R: B- Dend
0 b1 u9 L2 I6 u' X: e1 I. ]* c- `3 bto eat-grass# N. _0 A! Q% T5 G
ask turtles [- a* ^" r) C) `
if pcolor = green [+ H! C/ r; p; y2 @; ?5 v2 K' x
set pcolor black8 _: ^5 V, `& L5 N
set energy (energy + 10)! x5 h5 S1 c0 h
]" K0 G$ V( V, \9 k- e1 Y
ifelse show-energy?
* p3 S4 X$ U: o [ set label energy ]: J, O/ s5 s% F3 ^1 b
[ set label "" ]% K* Z7 |% Z/ N; f" ^* a
]2 q% A: Q7 K/ d' b ?9 h P" w
end) s! S2 l7 p( w- O( U* x9 @
to reproduce
' t1 q8 h. ~7 p( o9 m) k* h ask turtles [# `$ K4 v8 @. n6 Q7 o
if energy > 50 [- ~% q F+ C' W. m( O* H3 T
set energy energy - 50
1 O' r+ o: Q- u; o. b3 J& t: x hatch 1 [ set energy 50 ]
* w( \) h6 v# a5 v/ | ]# I1 }% o# ~4 O" b
]
2 h0 P$ O6 ]: h/ gend
! p+ L+ a3 i0 Pto check-death0 @! [* c. }% a8 `* S
ask turtles [
: ~* H& q1 I0 y if energy <= 0 [ die ]6 x& z" [; D% }+ X3 V$ R' f
]
- z2 X3 b( P7 m' T9 l8 G( g8 Dend
" N, @( x4 B- Ato regrow-grass
. P+ Y( n/ D* K1 D4 k$ R ask patches [
- n2 `" R, v3 `. y if random 100 < 3 [ set pcolor green ]. ?4 Y8 G1 `% Q8 l% e! B6 g7 c
]
7 y1 S2 j6 }, a% z8 T6 `end
/ e, R) u+ I: d2 r' E1 Zto do-plots* A! M4 }8 p! N
set-current-plot "Totals"+ t. X* m; h' `+ H1 ~
set-current-plot-pen "turtles"5 l8 X8 h7 I5 j+ x
plot count turtles
6 Y+ @& {+ E- e" | set-current-plot-pen "grass"
/ V& ^3 k) p" E# D& U plot count patches with [pcolor = green]
' f M! `; S [4 i Y- ]) @1 qend3 R! {+ U( ^! C' U
可是运行时提示no such plot: "Totals"4 w+ w t. W( H- |& j1 y
error while observer running SET-CURRENT-PLOT# n6 c, l ^4 {, I
called by procedure DO-PLOTS( c% @1 |3 R$ a; r. w
called by procedure SETUP
1 D1 ~( g) N/ {; m( b; w called by 按钮 'setup'
6 r6 L) A$ P8 q; |* p6 A, V求大神解答啊 |