我编的程序如下turtles-own [energy]
+ F }; I0 G. x0 sto setup
b% `! p8 P& M$ t. D) Y clear-all# V) b3 _% K. y: H2 L' N
setup-patches
- F7 Z9 l4 u4 m1 \: S/ U3 t create-turtles 100; c, e' @4 q$ ?% x5 G+ a3 r' F: s
do-plots: K r; J, c: Z: w( N J( y
ask turtles [ setxy random-xcor random-ycor ], i2 U2 K- ]% |% k
end0 Q2 ?) n( |' ^: V1 t
to go
- c- h. r$ e+ _" X move-turtles
1 Z7 y# I: ^" u! t2 w! Q eat-grass
/ r1 Q, e6 G% h6 h' b! n4 G reproduce
8 s. t% k6 R8 z" E' M check-death
) j- T3 X5 z5 M+ _! [7 `/ k regrow-grass
0 H$ }, J4 I. u8 ]* d2 H B do-plots9 x- y# j2 P/ c2 R( V5 G
end9 v' T& l8 `' P1 a ~4 n
to move-turtles
$ Y% g# ^9 e" g p ask turtles [
4 }2 p; _# `" _9 z% _: P! w right random 360
3 T! V# N- j' E# ]; f' I forward 1* J. K2 o3 I( w) l7 J
set energy energy - 13 f. d7 J; U2 [+ |; i: x
]
, D, P# j3 |- @9 lend ^/ S! n7 ]6 ~( f3 W
to setup-patches
: u `: f7 Q6 ] ask patches [ set pcolor green ]
) v. h' {3 t; H" v* ]6 hend' |, q+ v# p' r
to setup-turtles/ a( `' v3 G+ F5 l$ K2 z
create-turtles 100
3 h; x# ~ O7 o/ o- } ask turtles [ setxy random-xcor random-ycor ]: P; [# U+ H, H! C3 F
end. K0 b# t6 \; X! B, @
to eat-grass
5 R8 r8 u/ C+ x+ \$ s! Y5 c ask turtles [9 n" }9 d. z0 x+ h$ I
if pcolor = green [
9 z& k- o2 J% w8 W set pcolor black0 J# o/ D* Z4 v6 i! N9 P
set energy (energy + 10). E, E9 q$ |4 o) j2 Y
]
+ R) A6 y! \8 K' |! t7 _ ifelse show-energy?! t5 F) T( b5 o9 p+ M
[ set label energy ]. g$ S% R" Y1 d2 v
[ set label "" ]: o! L1 ]2 ^3 X5 x6 f+ _
]
7 {; t5 K4 `- ^( c" k. ~end
! }5 J2 B2 A& dto reproduce( q4 j: ]& a% x. S' x y
ask turtles [+ L; ^0 w. x1 r4 y* c. Z# d/ I
if energy > 50 [- x9 a3 @( z; u$ i
set energy energy - 50! _8 T s: W3 [* ?: a3 }
hatch 1 [ set energy 50 ]
- i* J% [0 b' ^. k4 I" G ]1 @+ G2 b9 p- @$ ^" f3 c
]
d9 Z8 D& a. I! N% F' mend( W8 s: D3 B/ W9 n5 f
to check-death+ ?" a& ~( x# i R R8 t
ask turtles [5 l `/ a1 S, M, [2 e e2 a, X! c
if energy <= 0 [ die ]/ n8 k3 S1 I: L" R1 I! p) T
]
* Q, d/ F7 f/ Q3 A7 {7 lend
& [8 l( R2 K9 E* o- e6 Y0 gto regrow-grass
. J! L9 a; e8 [0 U! I7 r) ? ask patches [9 C8 H& e( \( S; r3 W" F
if random 100 < 3 [ set pcolor green ]
: X; K# p9 M) W4 ` ]
) y1 X6 L1 a& j7 l' Z% S# Iend
* x# z; k* u+ C; f3 ~to do-plots
" X! C, p1 Y/ D, s# X% z set-current-plot "Totals"
" J5 q5 b6 d, f" `4 T2 k0 C2 o set-current-plot-pen "turtles"
& _& v" H: p S* J. n/ g2 \$ | plot count turtles
3 G0 q! @; f U) l3 \9 C# a set-current-plot-pen "grass"
7 w* i' K' b8 y: c+ q3 ` plot count patches with [pcolor = green]
) W7 S/ S, t2 t# |% F2 ?end8 R. v5 D8 G e: b/ d
可是运行时提示no such plot: "Totals"# i4 j+ b( f/ q
error while observer running SET-CURRENT-PLOT. j. ^" O2 K1 m- |! |* [
called by procedure DO-PLOTS" y+ O- n# j! N
called by procedure SETUP
: D3 k1 f. @2 Y called by 按钮 'setup'
" B- ]0 ^* K9 g# [' b) o/ y求大神解答啊 |