我编的程序如下turtles-own [energy]
# Z9 }& p+ T* D. K, lto setup
# O& J, a( E( j$ g5 z! s4 h2 ? clear-all
5 X7 J& l6 {3 F2 J setup-patches% E& J0 Q/ U# P' {) A* }7 I! h
create-turtles 100
) w& z2 o) n- Y do-plots( H; [2 w+ W2 ?1 i) E: ?, F( v: X
ask turtles [ setxy random-xcor random-ycor ]7 w) P4 D7 | H4 r" B' }/ |
end4 G+ u9 F8 j- F/ s7 P
to go
' _. X% d) N* {; U2 U4 o6 s8 V* C move-turtles
9 u6 K8 N: D& Q4 ?2 P* ~ eat-grass
6 o$ m) b) N @& ` reproduce
. O: p- y9 {1 `" m' ?" G2 u3 b8 \, A check-death2 T3 w$ P) r6 J3 d( h% X5 _# ~% S
regrow-grass7 P7 I" _: q! \( u
do-plots( }) `7 i1 \: k. t8 n; I
end
/ k, S1 f/ v% V$ G* Vto move-turtles
+ J6 w; R% ^" \; i; T ask turtles [2 t6 ?$ v. e! n* |. Q
right random 360
' ?! X- E( @/ A1 r0 @ forward 1" {8 s! O; U" M) c
set energy energy - 14 L! I# X2 G0 G- @5 `0 O2 J
]
& s' ^9 t2 e- s5 g4 gend9 J# v; y$ H& {5 y+ f& G
to setup-patches
/ n9 j% u1 |; x0 {( `/ f5 }! e' d ask patches [ set pcolor green ]+ j8 P5 ^( |+ ?3 p; I$ i* a
end
0 O7 m0 }8 |, A- v+ ?7 z" [to setup-turtles
0 S# v* y; P+ b, j7 a' U; J! d( h create-turtles 100: A2 h8 Y. u q& e5 \
ask turtles [ setxy random-xcor random-ycor ]. }) ~2 B) C- w+ t n
end
; p4 E- D H% o: Jto eat-grass
: {* H4 s8 |, W2 C6 O; I ask turtles [
1 ~. Z2 W* i3 r9 Y if pcolor = green [+ L. t$ j/ d: D I
set pcolor black
( p2 O( |# z R+ v8 g# d x set energy (energy + 10)$ i+ d% t5 y0 H# s# y" C
]# o5 X1 k: t5 f8 U' V0 T8 M
ifelse show-energy? {% I6 C2 G) T( B
[ set label energy ]
; L& a$ ]" Z M5 D. h) k [ set label "" ] U9 b% P! `; y/ H) G S# A1 u
]% O$ y8 s4 b; z
end, ]3 {; Q7 V" P
to reproduce
1 }! h- P% o' c, B, a7 r ask turtles [
0 x5 J: d1 ~4 P! D3 V+ t if energy > 50 [
# z; C% M/ y; I4 k set energy energy - 50
, V) ?8 D% G% g5 @4 l. r; t hatch 1 [ set energy 50 ]4 q* X$ D! W9 c" T" T! f
]. d5 |1 B" A% P" y+ V2 [# o/ G
]
4 b. g7 K) ]' e2 o, Kend5 M, B2 z) g8 W1 I2 v, F- }- ^
to check-death
" ~8 l- @% b0 D5 {1 S' W# v ask turtles [
- p7 C3 j3 i& Q9 _ if energy <= 0 [ die ]$ n9 c4 Y2 h# d% P: G9 l, c
]
) g3 B" ]" y6 T1 ]* `7 g% fend
& S3 K. z5 Y* |# H# h% m( zto regrow-grass& T: Z1 I* H+ _( O' z
ask patches [
7 u% N5 K2 g; X8 v if random 100 < 3 [ set pcolor green ]. E- }# f% I1 g" X2 y5 J! G
]) }, K" d# T' \. W1 }
end& A% S/ A1 u- q- W& A1 `
to do-plots* |) B# u) Z2 F( ]
set-current-plot "Totals"& L. Q6 Z& }8 i2 F
set-current-plot-pen "turtles"
7 p% Y2 a- N3 ~& q- Q1 }+ S plot count turtles
- z0 h/ j5 a0 E- x: Q5 v set-current-plot-pen "grass"6 `% [) {8 j7 N" t0 E3 O
plot count patches with [pcolor = green]" {1 o7 R! G; a
end0 g3 M8 U9 K3 ?8 {
可是运行时提示no such plot: "Totals"
8 V- L4 j# C# eerror while observer running SET-CURRENT-PLOT
/ i' x9 @: ~& d8 C$ k9 f0 d! \ called by procedure DO-PLOTS6 S+ x+ Q, c8 X+ O
called by procedure SETUP
" V$ |. c/ G Q& d& x called by 按钮 'setup'
( E" Z. ~+ L* |; i+ E/ j求大神解答啊 |