我编的程序如下turtles-own [energy]& `0 G/ m0 c1 X/ M3 w' H& e
to setup
8 [8 I) z8 m- m5 h# u0 i clear-all
8 ~2 ~9 I4 u: z o0 C setup-patches8 h5 A9 f: ]$ H) w; g! T) n
create-turtles 100" U# y* [) g$ \- K* {
do-plots' H6 d/ f5 Q5 F% t/ P5 E( d7 ]
ask turtles [ setxy random-xcor random-ycor ]( U% e! o" _6 R I( w T% w8 y
end
* `, v9 G& t( A2 w# ^to go
3 O9 r& ^3 O A6 N, D/ F( C move-turtles. f% ], g) z2 |$ W
eat-grass3 I% _! X: L4 n1 m# ?: o/ k
reproduce
( }4 V- ?1 b( v1 m8 M check-death _+ u' k% [9 {1 w! R
regrow-grass0 y* U( y1 @7 |* ~
do-plots
- o# `3 i' a% x$ h$ g) i/ Yend
% Y" p$ b9 ?9 n- A) t7 {to move-turtles
3 Y+ Q, J' i$ ^; v6 h ask turtles [& p: ?( M6 l# y! v: ], k' N! w) @
right random 3606 Q0 n8 {2 u, W5 C% v4 n
forward 1( W! C% N! I( T4 K0 o9 L3 W
set energy energy - 11 E0 N$ }* i9 Q/ k- q
]/ q% e/ z) J4 C( T
end- Z( l+ Q5 r4 P d9 o3 O' h$ L
to setup-patches
2 B6 x! r) l, y" ?6 p0 \; J8 N4 V ask patches [ set pcolor green ]. F- P( L. B3 W9 H/ A3 K
end/ D+ v- C( d+ c: Y) p3 R
to setup-turtles& x V4 P! c9 [- f, W1 ^3 n
create-turtles 100; U5 g7 K* y% A; P0 z
ask turtles [ setxy random-xcor random-ycor ]+ J* }8 E7 ?# I P4 T' {
end6 I; u7 j: V/ B- B4 A' \
to eat-grass
I2 p3 Y5 b K& B ask turtles [
3 i9 k& S4 N& T# x if pcolor = green [5 X) [% y9 r0 D. z- e; m- A4 }
set pcolor black" V% `1 K8 x, r8 H
set energy (energy + 10)) S% _1 @! X% [, G# a- _
]
* J3 e/ C3 e" w- V$ l0 X6 B7 R) M8 ~+ K ifelse show-energy?
* p! Z5 }1 z1 S! w1 W [ set label energy ]
0 r1 l9 Q& W. T' d, y* J. P [ set label "" ]& s2 y7 K, c$ h' H- J0 C2 f
]1 b+ s6 {' _( O. W
end2 N% w) y" t. _0 d
to reproduce6 P/ e/ P" c4 ~& V3 r
ask turtles [. h' Z- P% J8 o. S9 W
if energy > 50 [2 Q. ~) ?% g4 _' r0 ?) B- \
set energy energy - 50
6 F- p6 {1 v: K hatch 1 [ set energy 50 ]3 i. ~5 @1 c; Y- {" }
]) r8 M& O& `: D6 z# l
]
: p, j* ]* R9 L- d$ j1 c6 F, Mend0 |5 g% b$ p! L. i4 ?3 r0 W1 y
to check-death
2 j' V5 `. J) y- I {: v* Y ask turtles [
$ C/ J( A5 U: |& O$ T, H) C if energy <= 0 [ die ]* Z: i' J1 G) U" k9 _1 |- R
]9 @3 |; t% E" x0 |, g& G
end+ C6 q3 F1 h+ P- M
to regrow-grass
) W( R+ T/ p& P( ?5 ~4 V ask patches [
$ f% s8 ^8 V: M if random 100 < 3 [ set pcolor green ]: F9 [- a7 I( B; G
]& U4 J$ N% D4 ]: y. k3 x" B
end
% y6 F% I' P' l! _9 yto do-plots. A' u1 y% {8 `9 {' b9 v
set-current-plot "Totals"% }0 J! f7 T; E+ [
set-current-plot-pen "turtles"# I: z; P2 W6 R2 @4 k
plot count turtles
- R# k9 L+ I/ c4 U9 Y, c1 a set-current-plot-pen "grass"7 |" p- e1 s7 v; v$ _
plot count patches with [pcolor = green]* e# C6 t: q! p# Q
end
4 f+ V( N O' R# t' o% A6 |* g; A. K可是运行时提示no such plot: "Totals"
& Y( k3 o0 Y C/ verror while observer running SET-CURRENT-PLOT
" L5 R4 b% ?8 i# b$ z9 j called by procedure DO-PLOTS% ?" d" Q& W8 r: o+ K7 H
called by procedure SETUP
( F% G% A5 w2 A j called by 按钮 'setup'
3 l5 D3 X6 |6 P. j5 `# @# ]% G求大神解答啊 |