请问:7 n% s; Y- \% `# M$ d4 A& |
随机产生的turtle 已经在patch的坐标上上下左右一格格运动,当turtle碰到一个随即分布的patch以一定概率粘合,patch变色,其他turtle经过也还是以一定概率粘合的,粘合后turtle的能量就会转变到patch上,并且以一定速率消耗它,怎么编写这个过程?下面是我编写的,运行时就出错了。怎么改正呢?' G3 L7 z$ t: a* w( d
! W" q# _2 @6 b+ l$ Z7 w" V- ? 7 ^& r9 t* _9 p+ B
turtles-own [ energy ]6 B, m+ M9 c/ H! h L7 w
to setup
( g7 j1 t. `8 s( M! Oclear-all0 i( }$ ?1 M0 z$ x' _2 I
set-default-shape turtles "square"
; `, ]3 W8 o" H7 \7 F4 Gcrt nutrition
6 U$ y7 j$ o' l+ C( [ask turtles[
0 t8 e8 K8 [. t4 k9 }2 K$ Q' F set color white
. S" Q3 v% c; z$ P/ j- F; v, s setxy random-pxcor random-pycor]
9 X7 V3 M' P9 ?
) K: M8 }6 _: P0 O% v- Iask n-of microbes-initialization patches
: W3 X, V1 d2 }6 d* g* K [ set pcolor green]
0 A- l8 O ~ P) L0 [& b# ~, A ask turtles [set energy 1]
) F: Y4 [/ Z3 l/ Q8 V5 }: lend
; D6 A' [! X: A c* A2 u. E. l' H, R( G5 [# G( `
to go
/ [: }5 w% i3 g2 e1 j ask turtles [set heading 90 * random 4 fd 1]$ l8 o+ _0 x1 D3 F; b3 O) B" v
ask patches with [ any? turtles-here]" g8 t$ _- w2 Z; ?4 j0 Z' N4 w
[ if pcolor = green and random 100 < chance-of-congregating [tt ]]" Y# B6 U* E- c2 T& I0 a
ask turtles [ if energy = 0 [die ]] l, U# H6 p+ o: u2 p
end
& ?7 Q0 Y$ u2 o( A# C6 O4 M. y% t$ Y E2 X \
to tt
' q( K) f0 T: @7 `/ l+ m! qask patches [set pcolor gray ]
( D6 m0 H& J2 e% G% b; b$ {( l! V$ Bask turtles [set energy energy - 1]
: Q# r. D, o5 C8 O( Q/ {end% \. ]# w) @9 m/ v
9 J y4 J8 m( P& ~! F1 V
|