我编的程序如下turtles-own [energy]
' N& P0 ?% D! |to setup
* B* ^# q8 u* z: p& q clear-all
) A" g6 Z: n+ b1 S setup-patches
" y1 ?* v& }) e create-turtles 100, T! o4 Q- L( W& M2 R) l z7 v
do-plots' E0 I& a, R H
ask turtles [ setxy random-xcor random-ycor ]" N6 W5 h8 a7 n/ K7 O7 O3 i
end2 F. [' g6 H# t# J
to go
/ s! z. Z; Z. M6 K move-turtles2 Y( h) |. p* F0 ]& v$ U' D
eat-grass
* f$ r( Q0 b5 N reproduce
+ q$ @; y5 a% y3 [. K check-death& | v8 e$ ^ R* w1 F- n. E3 F
regrow-grass
* X6 T6 c3 s$ E0 q do-plots
- w v' u& M/ {: }end7 Z" z8 e: L, O/ c* X
to move-turtles- |3 n$ w! w6 g* B$ U
ask turtles [
+ Q( |1 M4 A1 E right random 360& N% T5 C2 `( B5 `+ d' @/ R
forward 15 h4 ]* X) k7 U
set energy energy - 1
1 Y( i7 o7 y5 P+ b4 l. l0 j# j ]# ?1 }" e" E+ w6 n9 X
end2 a7 f. d! E J4 f& e( c- d, Q
to setup-patches) E7 S% i: x) Z$ j' A, O
ask patches [ set pcolor green ] F; J6 W! G( } m; s
end
: I1 x C( X6 i% ?to setup-turtles
% x; _3 x' v3 G! a# N create-turtles 1006 k; s5 Z6 U6 b# S: e" x
ask turtles [ setxy random-xcor random-ycor ]
) S3 |. g3 k. R. mend6 H6 {' {; Y, n0 d
to eat-grass- S! Y2 _6 a" P0 U1 \) R% |
ask turtles [
% }2 o/ x$ F& x if pcolor = green [
; z8 v8 Y/ J5 T9 y set pcolor black
1 J% d& N. l8 _/ f5 W$ l i set energy (energy + 10)) s" t8 s2 R$ S) \
]' ?2 `( u/ |$ ^( U) n, w) C
ifelse show-energy?
; |& A- N# N* e# q& g. o% D! C [ set label energy ]
! s, O/ H5 l+ T7 G6 M- |5 } [ set label "" ]( @. {* ]& L: }: T% w+ c( x5 h
]
+ A3 D7 e# J0 ^- Lend! ^8 l, t* \9 e5 O0 U4 p
to reproduce
9 {' `! B; H, t ask turtles [
: t4 g! p8 ^9 J c if energy > 50 [
2 t7 C, p- t! n+ P- i0 a2 x set energy energy - 50
- k$ s. J: U% A& m hatch 1 [ set energy 50 ]
/ s8 [0 N5 n$ I7 ^2 C ]
! J" t# ^! L y ]
7 B# n( l& S( G8 vend
2 u8 ~8 d* l. bto check-death
/ B0 [* S7 ?- [6 l' x5 l# s; b7 a ask turtles [" s/ I4 {8 i2 X1 m8 q% Q
if energy <= 0 [ die ]& ~/ {0 `* y$ J' @7 Q% v; P" x
]) d: P% Q4 n1 b: q5 Q2 n
end' \4 k5 ^0 q3 @
to regrow-grass
. v* K, u G* z3 ] ask patches [, H3 t- S% H2 E; s; ?& j
if random 100 < 3 [ set pcolor green ]2 u, F: q1 e7 Q: j5 P
]3 z$ d( \. D: k( D1 z
end6 h/ H7 G( m5 G5 N' |
to do-plots3 s' @) h" D/ L: q# T. X4 `
set-current-plot "Totals"/ ^7 p# q+ C/ Y+ h! x9 Z
set-current-plot-pen "turtles"1 v% Q. J. c m) Q; z
plot count turtles7 S( S0 f$ J5 z, l/ w
set-current-plot-pen "grass"
3 m4 ]$ _& `2 D( |# I2 s( c- [ plot count patches with [pcolor = green]
8 U& l& d' E( b0 _end
3 p6 ^9 U, K8 \7 w3 q' w$ l' {& z4 H( @可是运行时提示no such plot: "Totals"6 }1 i3 L( W }( y o/ ?* g, d
error while observer running SET-CURRENT-PLOT c* h2 \: O2 Z) g% u. W/ y
called by procedure DO-PLOTS* q5 w% f8 i. F
called by procedure SETUP
. i2 v5 N/ ~& v: ]3 I: Q called by 按钮 'setup'
1 S4 e2 d: ]+ q8 N, |求大神解答啊 |