我编的程序如下turtles-own [energy]
) s0 O, Z) h3 ]/ ?* Kto setup6 b$ Z3 A8 e+ V9 c. ~
clear-all4 J4 a- |; Z3 ]
setup-patches( i. Q2 k* E! y8 Y6 h/ E5 a
create-turtles 1008 s8 E0 @) J' D2 {1 R% Y
do-plots5 U+ Y6 Y' X9 _9 o# l9 b0 z# [
ask turtles [ setxy random-xcor random-ycor ]
- n8 |( R, Y/ d' t, B# fend
* W7 Z! W8 j) J; [9 S3 i, Xto go
( R) ^4 D5 S* t8 x' M) g$ W% ~# b move-turtles
' b, b8 k. \4 ]5 S) ]; J eat-grass8 N z+ I, O. x: ~" ]
reproduce
8 U6 N( f& v) x- r check-death
0 X& l5 i. b- y* Q4 S regrow-grass3 p6 o3 M: O; ~. X: `" k
do-plots. k( l0 `8 t r3 c
end- t# y4 [5 Y8 O/ j7 _. @ e
to move-turtles
j/ Z' f+ e" B8 Q ask turtles [) _# @8 d1 D$ D# L# c
right random 360
3 ?- ?( J* a* _. r. [# M7 e forward 1
9 m2 [3 Z$ }: y# K2 R set energy energy - 1+ ^( S& W) ?. ~" D1 f
]
+ L4 i; c5 b5 iend
0 x; H' b% p- V7 u3 D$ ~# \to setup-patches
- j3 ~9 t$ ]6 ^ ask patches [ set pcolor green ]
& b2 b) |" i3 V( P4 ^) M7 V' K! dend
: V2 ~$ M D' X; y1 v: Y0 @. A$ `to setup-turtles) u ~3 A2 y* ~9 q7 K% o) ^
create-turtles 100: C) w1 b8 E1 W# O
ask turtles [ setxy random-xcor random-ycor ]4 Q2 [8 j2 J ^+ }& T7 V
end
! K$ U/ I, s8 @- |) U4 W! G: ]to eat-grass+ ?& E9 f D# l
ask turtles [
p, a2 C5 g& [' Q if pcolor = green [
' k, N) A$ w8 e# X ?; X, d4 h- M6 F set pcolor black2 Z7 C& R1 M$ k) Z5 F- s' O' J4 w
set energy (energy + 10)! G/ @$ ^& l( R
]
. F7 L8 L% v/ n) c7 _7 a1 r" w ifelse show-energy?
! }3 P' O/ A L; q) g% U [ set label energy ]
7 T' @, K. U! ?# J \8 W. y [ set label "" ]
" C0 u# j% S. }1 g ]& e) i9 a; i* n" F4 j
end
" a0 W8 C6 n, w0 q, K4 vto reproduce$ y. V( B% p3 ^
ask turtles [
3 w# E2 \4 l' S l. y; @: s; y if energy > 50 [! w$ y! z9 f _' {7 b6 j4 p: }
set energy energy - 50
8 f6 W3 y1 j: v3 A2 G# A p hatch 1 [ set energy 50 ]
3 o: r8 w" s ?, x7 [$ ]! x ]# q+ N) M& Q7 j* y1 I$ d8 h
]& B- L, }3 s9 m' B1 m. E8 U% A" [
end) a) E. \2 X: G8 \- d
to check-death! r6 x, |$ ?+ j" B
ask turtles [
! p4 p5 O5 g2 i9 p8 X if energy <= 0 [ die ]
0 {$ Q; c0 V6 U. L f" o0 b4 X% K ]: J* N* o$ v& {: b7 e
end% I' ~& v- ?# a; [' D9 q3 W
to regrow-grass) e9 R& h+ J0 V
ask patches [
1 I* ^# g/ b. P# ?; O if random 100 < 3 [ set pcolor green ]
3 T5 B! c( j# z ]" |" O: s# P' a4 ^1 l
end! p% c" E% n* t
to do-plots
7 }- Q+ e# x7 C$ B set-current-plot "Totals"
7 G% |5 T* }1 P( D4 L set-current-plot-pen "turtles"
$ s# N8 V7 ^ q4 B9 r* H; X4 E& S plot count turtles. t. Q" D: F* y/ b. @6 N
set-current-plot-pen "grass"3 w; v% ~& L+ c0 O( ^ x
plot count patches with [pcolor = green]- q& B! |! c; l& m/ @- X7 f0 H1 p Q2 D
end, `" o4 ?4 ?8 m4 E
可是运行时提示no such plot: "Totals"+ Q; _ R1 q* v! E; I! Y
error while observer running SET-CURRENT-PLOT; u* C, [0 X& Z$ U/ ?5 ]( Q
called by procedure DO-PLOTS: B: ? K1 B' a; }* F) R& n4 `
called by procedure SETUP
9 y* D) F8 y: S- J, n called by 按钮 'setup'
! x, |1 n8 X- E( Q求大神解答啊 |