我编的程序如下turtles-own [energy]0 n5 i7 y" f7 X
to setup
% @: f+ q' s/ r' }* W$ |2 I N clear-all
# X1 u; A5 d2 a& K5 A. T) i1 v* T setup-patches; z7 x; F( S {5 X i! Z( n
create-turtles 100
# y0 \4 E0 b' M1 P+ x% I9 @4 d do-plots; P# o- _/ ^* V7 g; ~- J% V. K
ask turtles [ setxy random-xcor random-ycor ]
# g% d. x% K2 ?8 h nend4 ~( _: F2 x% ?9 G, B
to go8 J* O% w% `1 K( _: O3 S
move-turtles3 s; r/ K* A Q. y1 I
eat-grass. u' c/ U" p$ c2 v, h
reproduce7 D# Y% \9 a( c! s
check-death
: p& J+ T5 [6 R$ a, M$ q! F regrow-grass
& F( U" W6 b; Q V do-plots
0 e, j4 e; c! lend
, o; w! B" R, Nto move-turtles( ?9 t! ?2 c; V3 D9 g+ Y
ask turtles [; J% Q; W7 X5 t# p( c( f6 F
right random 3605 Z8 l+ c7 u+ d! M, ?1 E
forward 1" D* f5 N, m+ h: e5 e
set energy energy - 1, V; l) `- S6 p7 o
]9 J% c/ o; X6 t
end
3 |: f0 I7 Z2 K% M; R/ lto setup-patches
# u5 F3 k- J% _) o/ \! V ask patches [ set pcolor green ]
5 s$ |3 Z7 n4 G6 n7 ]& iend
, c0 U- Z( a1 Tto setup-turtles
9 o3 Y0 U6 n U create-turtles 100. f3 T1 {" T5 k8 }, b$ {
ask turtles [ setxy random-xcor random-ycor ]
7 o# f/ q( C6 r( P6 \% zend+ t5 B2 _7 r$ d- d& f" c/ g, z
to eat-grass2 G6 M# I1 R7 N; c2 Z* Q
ask turtles [* _/ T: G7 N& Y# b/ [& _+ y
if pcolor = green [" X- P) N& i' d6 e" a# h W+ }
set pcolor black
! y/ U6 D# B! k7 Z set energy (energy + 10)% l# \( B! d0 _3 R( j
]
$ @0 C8 w% O8 F- V [" V ifelse show-energy?
0 f b8 b* d' \# ]( J5 N [ set label energy ]
% q/ `& H2 j; a' t- ^' u1 v7 t [ set label "" ]% `- \0 P9 J# [4 Z" n
]6 D7 C- P d5 g6 C) @
end
( a$ P4 c7 A9 o2 t3 Jto reproduce
+ F2 B8 f% c+ ]4 \& r8 k$ L ask turtles [! L+ U v# C" q+ C& _* K
if energy > 50 [
% `0 `6 V: u0 g7 Y8 W! Y set energy energy - 50
4 D$ B9 V3 S# M: X hatch 1 [ set energy 50 ]! j, P" e9 J; K8 c; l5 w; J+ H
]' @' |4 w+ I3 n
]* d" m* H" i, z5 T1 O" Y
end8 A6 @) W+ ]5 k9 ^$ Y1 L) w' k7 X
to check-death8 e& R9 m" R; `
ask turtles [- z- o& j* A5 |( r3 P) u
if energy <= 0 [ die ]
4 V8 O& U/ P- ~& o, ] ]
+ |% A$ ^* h5 eend" X) X7 j+ h: J
to regrow-grass; H4 j! V. |# v- f" V
ask patches [
% A9 b# G/ B; C7 D; Y0 c9 p* e if random 100 < 3 [ set pcolor green ]4 h* v( f- G9 U
]/ Z8 S, X& ]4 o, q+ x6 P7 q# w% v
end
3 }6 A/ Z$ V/ gto do-plots- r3 D! p/ W4 _
set-current-plot "Totals"
9 ?2 `2 K# D9 v1 m6 v set-current-plot-pen "turtles"
/ P( [5 c) E8 U9 G" y: T plot count turtles
1 W6 ~7 x2 I0 D$ F& O$ m set-current-plot-pen "grass"
6 P. Z6 @$ B1 u% a! e/ u plot count patches with [pcolor = green]
5 M) v! g5 e- ]5 B5 ?/ ]& I( send, s& L+ D' ~+ w1 `' X; R
可是运行时提示no such plot: "Totals"
8 c/ N K1 V6 d9 @/ ~/ |error while observer running SET-CURRENT-PLOT& t& U) C; { r* ?
called by procedure DO-PLOTS
4 ?3 J2 a4 z' N. C% U called by procedure SETUP& Y W/ l) U( l. g, L( i+ Z" R
called by 按钮 'setup'
7 {2 x# T" T" O求大神解答啊 |