我编的程序如下turtles-own [energy]
! x9 j( u( I) f4 `) Qto setup+ a+ j. [5 h( z( ]8 J/ o
clear-all
( A5 J3 U9 z4 ?& N' A; {1 A setup-patches
9 u# J* d% E. l/ \+ x2 p3 u9 s' G create-turtles 1006 {4 |2 {. X2 w% q4 s
do-plots5 V8 [8 @0 d/ @1 R
ask turtles [ setxy random-xcor random-ycor ]
. |! ?% m4 p, v0 G: R2 z; {7 ^" Bend
7 S% X$ r7 A' J; t4 Wto go$ A! P) ^7 }$ o$ e3 o% G
move-turtles8 j" v9 U: N$ k! L: [' M* y; K
eat-grass8 V. s# R# n$ Z7 ]5 H4 j: c4 c8 O
reproduce7 U/ Z& W: A+ D% X% D6 M
check-death/ F! N; V/ t/ `" W- j- N( F
regrow-grass |. F/ ~& Y4 z& ]( x$ i4 h/ J
do-plots
/ S* [3 w* d& e9 u$ ~2 Aend U* r: R, @% j7 b ]3 ~
to move-turtles
& ]; B6 O6 a4 g t ask turtles [
5 q+ W, v: m$ V7 ?! G+ e ~ w+ O right random 360
y& G1 y. ~1 D- g) a2 C1 ] forward 1
2 a8 T' ]: u, C- o; Q) f. ^, y set energy energy - 12 M$ e' \' H6 e! j# u' {
]! O" [. Q$ t7 B' h5 e
end
4 N/ F! E8 d0 |. q9 O9 pto setup-patches8 T! j" `! R& [: X6 }* W. _6 w+ G0 f
ask patches [ set pcolor green ]1 B+ T) E& E; q
end
3 v' @$ ]9 ^# b' r, Lto setup-turtles* V! Y9 v3 `$ l2 V& @
create-turtles 100
$ r# e- v$ Q/ O) B# V9 x5 [, q ask turtles [ setxy random-xcor random-ycor ]
# P) x$ Z5 Z$ u+ v6 l) Oend
1 z$ b0 W$ C) V4 ?' Bto eat-grass
+ l9 B9 f! a' B, e+ S; v5 U ask turtles [
- H ]3 [+ Y: ?9 @$ \ if pcolor = green [
' n' T% o6 U! B0 C: B set pcolor black1 @* a& x( O" K8 ~& h+ }9 V+ E/ ~
set energy (energy + 10)
7 G/ q0 V5 B4 J ]
/ j2 B, j' W6 s; Z1 m ifelse show-energy?
6 S# G2 P$ T, W# ]" H0 S& F3 x0 C) } [ set label energy ] u2 B( B! f5 L$ {3 w5 z
[ set label "" ]8 Q$ P9 h2 P& u, D N0 C' Q
]
: @/ B6 D$ I# Y6 {2 Wend/ H7 F, v9 h. L9 k0 w/ ^5 ~
to reproduce
9 U' I5 ^( B/ W; M* a ask turtles [
7 }+ m7 ^1 b% L6 p: f# g3 S if energy > 50 [
5 p/ L. Q8 P% }' h# z set energy energy - 50
* @% M3 ]1 _4 F8 \3 b3 c( c hatch 1 [ set energy 50 ]
' o9 m6 f! l% X% u7 s ]& {4 \- H" p' K
]2 W5 L& n. K1 p# U
end( @) E5 T: C _* Q
to check-death% D4 }# P6 ~0 ?7 R7 W; f
ask turtles [
8 W+ D, P( _( @2 ?$ w) W if energy <= 0 [ die ]" O6 s( `8 ^8 _9 c; _& l5 {
]0 o8 T; N& W# E- u- ^% f
end
\. Z$ Y! M% x7 hto regrow-grass2 H2 s- J/ B8 D9 ]. V# v+ E7 g) f: r3 ~
ask patches [
8 e7 F2 T. c/ g- b! P if random 100 < 3 [ set pcolor green ]# l- @6 n+ c& [0 D2 t1 {
]5 I. v# a; J( J
end
, H7 y9 y5 @" ^0 n4 d; Lto do-plots
" k) ^5 _+ s4 d: F set-current-plot "Totals"
5 y) D% g' U9 w* ? k( t( G6 z set-current-plot-pen "turtles"& B) z/ u1 g2 L
plot count turtles
0 k' E: o, V7 m4 r1 M set-current-plot-pen "grass"+ w/ a! }( S* R& r( V2 g
plot count patches with [pcolor = green]) P) l6 c. y1 U" G( A: J! s
end% T5 N6 c( H2 u0 `* U- a# y
可是运行时提示no such plot: "Totals"" m; M; b5 Y( t$ v( K
error while observer running SET-CURRENT-PLOT0 I4 o# {1 e0 O, ]
called by procedure DO-PLOTS0 r8 F! s' W% g* M% @; y Z
called by procedure SETUP
, j# l& G$ X8 b2 |- P) x called by 按钮 'setup'
6 u- h% d0 `% F% O7 k4 a求大神解答啊 |