我编的程序如下turtles-own [energy]
; d5 D% w. A! K; @to setup8 {. g* Y2 _* E' M; W$ |
clear-all
) a9 C7 N5 Q! \+ t" l2 { setup-patches
' E) _/ ^( C" ~5 W create-turtles 1002 |7 U0 _5 |0 S8 ]5 @+ W0 Y
do-plots
# j1 l0 I; S) S+ I; }7 h ask turtles [ setxy random-xcor random-ycor ]
' {$ T/ n1 `. E4 x- Q$ | }end
9 J2 P- X( z# ?1 L1 _2 R$ ^3 Vto go) e- l6 x; r4 Z2 K1 z
move-turtles. ^! Q# X! Z% d/ d" R
eat-grass
$ F: y3 d: t9 y- T) X% X) b reproduce
& Q2 d% N* G2 {# E$ K1 _ check-death6 B% L. O, d5 z" |
regrow-grass8 B; c* `# z& Y0 o, r) w
do-plots1 g0 i$ h; a) d* T/ I) m1 Q
end
/ ?. [( H1 k* J. ]( Y0 Eto move-turtles. U9 D$ ]9 s" [+ v- s" S7 G
ask turtles [1 ?$ X: v* F& L
right random 3602 [/ w9 a1 x8 c
forward 1
& W6 K2 e+ O+ W7 ?: I! F7 K set energy energy - 1
+ V, t9 R4 O# L ]
( `# s" D& C2 v. c% ^6 Cend
0 @* W. M" P7 z6 C$ ~4 A4 Mto setup-patches. D# \( B* s! o
ask patches [ set pcolor green ]8 G ~/ a/ } Y, \. P/ U
end
) ^1 L1 W4 U, m, Uto setup-turtles
$ ?6 M9 V5 ^/ a create-turtles 100
. n, r0 N8 X* g% P ask turtles [ setxy random-xcor random-ycor ]
- c4 b! s* j) [9 Y7 s) D4 Lend
# J, ~0 ^- K8 O5 I% y {to eat-grass
9 [3 y7 O4 Z; I, o8 k& ?$ T' j$ q- F ask turtles [2 O% U4 Z# |0 R7 U) K# s/ U
if pcolor = green [
! j' j0 @3 d. N3 F u set pcolor black
; E! Y# H& H& f+ V: X1 {7 U M set energy (energy + 10)
6 e! w7 i4 F5 `) C* P8 d: e1 e: M# O ]
$ w1 P1 ]. [# x( f: M/ S! [( N" N ifelse show-energy?6 w5 M% q( b6 \, k1 p; I
[ set label energy ]
% X5 v3 r. \8 P# n) J# f6 } [ set label "" ]
) O! I- U% }: E4 @) M' s ] R5 O* w' O( y5 S3 t: [
end
- y1 {1 I: G* B3 Fto reproduce
4 S0 c* S& ?6 F$ X; h ask turtles [
! x5 `+ i/ s0 R! q. n+ T1 E: z if energy > 50 [9 Q3 Q1 y% X' V& Y* _+ v% @1 w/ D. ^
set energy energy - 50" r8 x! e& s6 Y; i2 V: q
hatch 1 [ set energy 50 ], S- N, b. S, V% z/ [
]9 ]6 c4 @, r) _0 Z2 @: U) v
]
9 B+ V5 b: E$ c7 C! N! Q$ Q' A) @end
$ L; V- f H5 g$ X( u6 mto check-death
" w2 }! c% O5 @$ L1 F! P ask turtles [
/ b; J# q6 K% } if energy <= 0 [ die ]/ o# R" B* V( i6 U; U# v( m7 {- Y
]
9 M& J- K' U6 }* z* j( kend
5 f0 [! n3 v6 r, I# {to regrow-grass+ f) p/ Q$ D) \# o" @% J
ask patches [- j9 S4 |1 f9 f2 k$ i1 R
if random 100 < 3 [ set pcolor green ]& s4 z* B* F4 S
]# X/ k- N/ Y2 q8 D
end2 f% o9 F' n; _5 B4 [8 B! E5 ^
to do-plots
5 o3 T; K/ N* _2 l6 ? set-current-plot "Totals"' A5 [2 {, F7 s0 I& T( [) W( s
set-current-plot-pen "turtles"
( E/ h2 L6 z5 \% _) | plot count turtles0 E& m" k2 Y5 U8 ]4 G X/ ] s5 j
set-current-plot-pen "grass"% ~3 M0 q5 }! C/ T# z
plot count patches with [pcolor = green]4 R5 c! P `! e0 U
end% d0 i) G E7 Z
可是运行时提示no such plot: "Totals"
$ s. M( v1 A1 P, lerror while observer running SET-CURRENT-PLOT
- d& u! j- p3 F% Q1 B called by procedure DO-PLOTS/ w6 n7 s' ]6 Y! ^, h
called by procedure SETUP
. @' t+ C$ _, N6 v4 x3 e called by 按钮 'setup'' `3 B9 `8 S( M8 N
求大神解答啊 |