我编的程序如下turtles-own [energy]: \1 `7 m( g9 N2 _8 U* d
to setup4 a* e; q6 E) |9 J7 C
clear-all
3 l; c5 I' F2 a# l* |8 D' K setup-patches
. ?1 E3 D0 {2 X create-turtles 100
& O( u: s* l" a1 s/ A: @, J do-plots& E& }& u5 F+ i. c+ O/ R
ask turtles [ setxy random-xcor random-ycor ]
5 Q, j( T+ B4 ]5 s# g3 Yend9 }! ?: e; G' Q' z" u+ Y9 \
to go
( n6 F# J3 u: |$ W move-turtles
6 s4 l( b7 H2 N' | eat-grass
) g/ I5 E- \ f3 h0 F* p4 I( ~9 c reproduce
% b; e# O$ o- y' [) ]% h' k check-death
( Q0 C ~+ w# p/ e" M# G3 n regrow-grass& J; Y8 x) M) q
do-plots# [0 [3 ~. |2 U, y
end
- m) n6 j I4 S# u& J" {' d" [to move-turtles
) b2 E; l$ u* _7 c ^# H2 F ask turtles [
- B: I Z% R$ S k, ]! L t/ Y right random 360
. R+ a( k5 F0 B# `1 V% M forward 15 j5 V( e) e$ A; [
set energy energy - 1& ?" T. \+ R6 Z: y) R# o; d
]
/ A3 T: E; ?) w, bend
; L6 \4 ]( o) V- |" v! u" e, E8 mto setup-patches
8 G2 Y! [& Q5 i0 y0 F) P ask patches [ set pcolor green ]
3 ~1 f& P2 v) N5 Pend2 i$ a k. |% w: [* _ h
to setup-turtles
$ w% y, L& l. n4 v' w create-turtles 1005 W# M* @7 x5 U% o
ask turtles [ setxy random-xcor random-ycor ]
) r. v) ? x% o" c* Kend9 A1 Q) u* M% Z9 n+ i" R( a
to eat-grass
( e5 Q: W& h& R/ R/ ^ ask turtles [) Z$ M: d+ l5 i
if pcolor = green [
. N g' T6 j. c1 o# C m% ]' c set pcolor black: q- W0 o4 ~/ f. s' n
set energy (energy + 10). n; ^; z4 i1 M7 l" ^! I N
]
+ w( O e$ u9 G( \, [ ifelse show-energy?
" O8 r% J0 J- x/ ^1 p [ set label energy ]
4 O u+ \& n" P+ l3 K- _ M [ set label "" ]
3 g' M$ m7 Z5 m" G- e: }" r6 j ]0 u9 M5 `7 u8 o; t1 |2 K
end
* d1 ?' \+ [% @: L% ?. tto reproduce1 L& P! T. a- p# a% i
ask turtles [
3 \- U/ b' ^$ i8 |- \4 l if energy > 50 [/ _ d/ E5 e7 d1 {% ]3 Q+ v
set energy energy - 50
N+ t% v& [) M4 Q; f hatch 1 [ set energy 50 ]
! P& q/ }: a) ?6 q# d ]
# l* b W) e" }# f8 v ]* a" n3 h8 s0 Z; L
end4 [" Q. q; a: Q+ L# H: h& ]; i
to check-death
" h8 ~6 p! |; c' b: ^2 C) e ask turtles [" f6 _. G7 z4 ~- q9 ~
if energy <= 0 [ die ]& U5 `+ c3 G8 y1 r) B( E
]5 |! b: C" J4 ^5 A' c; f
end4 p4 F, r+ o( i* M% g) Q
to regrow-grass" j" ~3 y' m- j
ask patches [
1 K r0 Q7 s, i5 G0 W8 x$ N if random 100 < 3 [ set pcolor green ]0 H/ a+ W# y, s1 g& P- ?9 p' b
]6 i! L4 W* p! @! d6 B1 [
end
) P( U4 _: n% mto do-plots
# |' D ]" X) i8 f: b8 L set-current-plot "Totals"
3 f. q1 Q: V. g+ N set-current-plot-pen "turtles"
+ W' x! ~' h* r2 @( |8 J1 Y# a plot count turtles
) b' Z& p0 }9 q. @3 Q set-current-plot-pen "grass"0 N: \9 b% w0 b6 e o+ l
plot count patches with [pcolor = green]
5 D7 C+ h7 @9 g& J3 send
. E/ U$ b8 N& B9 R; ~8 ]可是运行时提示no such plot: "Totals"
2 P# C/ l4 N1 x4 {1 x8 aerror while observer running SET-CURRENT-PLOT
# P2 x' k/ `( Q: y8 {2 F' S2 y+ p called by procedure DO-PLOTS
. ?" a, ]6 [9 H3 Z$ _& H6 Z$ m called by procedure SETUP
# s( Y6 F) t( i5 A' w( G1 \ called by 按钮 'setup'
1 \7 H, L" @# n% e# d" H$ i( d求大神解答啊 |