我编的程序如下turtles-own [energy]
# e: F! A" J( kto setup
( B: y- ]* E5 Z, _ clear-all3 N- w5 t) J: g+ {. H8 _/ A
setup-patches
& J0 i$ r1 S/ z4 I" h: V- ? create-turtles 100
( |3 L% n9 ]; E% u6 p0 m do-plots1 h0 C1 K; H6 j O; N0 Y
ask turtles [ setxy random-xcor random-ycor ]
( ?& O# I2 S" Wend& X3 A$ p. i$ z' \# c2 E4 O
to go3 ?& l% y7 T/ y1 U
move-turtles, S& I8 R7 j5 o: d5 I0 B' o
eat-grass, K* R$ L% @5 u/ Z; P/ H+ k
reproduce# ]8 @+ z1 e6 U, v: W4 ^( z- f
check-death
9 S4 y7 H' M( t+ | regrow-grass
6 v, a" e# P) e; |- o5 B do-plots7 `, n# h! M" h& b7 [( M
end
+ }% B! }+ q- nto move-turtles
: A, Z8 x9 w: ?) E1 q' R: L$ O0 f( g ask turtles [2 Z4 f, f$ ?7 k9 P
right random 360- D4 v* g# C. r
forward 1
; b% L8 v! H4 ]; Y; Q8 x set energy energy - 1' |7 C* k: B+ [8 Z* K* y
]
0 n% S0 n- W T( u& Q5 kend) U0 V/ O% o$ u# z' R$ \
to setup-patches) W- ?0 ], g5 H1 }4 \4 X& D$ E: m
ask patches [ set pcolor green ]% Z8 p2 _8 ^6 Z ~1 Z8 A4 f
end
" R0 L/ l/ P L6 @ Qto setup-turtles. F3 n% ~) z$ A: J; s
create-turtles 100
4 ]1 b+ t4 k$ v ask turtles [ setxy random-xcor random-ycor ]
2 r3 [) U* v. t; Gend0 O7 f+ o, G1 C& U! A
to eat-grass
' N9 ^2 H/ d: `; C+ }1 [# A ask turtles [
% t$ d' x+ S& P, ^ if pcolor = green [
2 X( ~! E7 X3 @" L+ T5 Z set pcolor black
% `/ t2 r2 C, L. V/ i set energy (energy + 10): o+ G1 M/ _# a! e# i, R8 Q
]
7 {! ~7 D+ F( E, U- C ifelse show-energy?$ N1 d4 i9 x# @: w( z) Z5 q4 F
[ set label energy ]) e4 ?* y' V f# W' I
[ set label "" ]. {: {0 V2 _0 g( ?) M0 d# {
]
. {6 F3 [ B n# ]7 kend
- v1 x/ x5 B9 H$ B$ l, C( e% pto reproduce
: p) o0 I) A# g; p3 J ask turtles [1 y+ b" }; n9 x$ t
if energy > 50 [# t" X( C7 E% m+ ?$ C# C; }
set energy energy - 50
[, Y) }; t/ [8 d7 p% l hatch 1 [ set energy 50 ]4 h* H& }) C) x" X i$ P9 I
]
% Q' R& x- R' [8 H. k1 E ]
: f( g% @, \& g6 y9 Vend
2 c" _- y4 b5 n( ~* z+ @: z# Tto check-death
8 b. {, \5 W- R8 s1 L: G ask turtles [
' `2 s4 h7 a ]# j# h if energy <= 0 [ die ]$ e$ f/ {& D/ z% z3 R3 G( X
]% S+ S- I9 l# [
end% @" j- l5 M9 X* [
to regrow-grass
! f! n* K. i$ E2 z2 y! {! y ask patches [, I1 t: ]+ Y; h. u/ E9 i
if random 100 < 3 [ set pcolor green ]
4 ^; \/ o$ t( N9 V ]
3 H/ ]- L' Z* B% z% Bend
. z. I% j& f6 p$ Qto do-plots b4 @: m# S$ c! @* w! k8 U! D
set-current-plot "Totals", s# U8 j5 u, u1 |3 |" N
set-current-plot-pen "turtles"
+ V3 A' ]% k& r8 K/ |. Q plot count turtles% S0 W' s+ ^9 o' ]
set-current-plot-pen "grass"
8 y! D7 {# x; Q& q- q plot count patches with [pcolor = green]0 A6 u J+ d. f' N( l: F8 P
end
9 s- q6 e# N: w# N9 L m# a6 c可是运行时提示no such plot: "Totals"
/ U2 R5 \( ]1 C3 s7 n5 merror while observer running SET-CURRENT-PLOT
( J- w1 ~" F7 ^- S0 n7 J- @ called by procedure DO-PLOTS7 Q* Q4 b' r0 @, v2 N& Y7 f
called by procedure SETUP
& Q; J" t2 F+ B" ^& l. b- o called by 按钮 'setup'
$ c! i( d- F& T, B+ B求大神解答啊 |