请问:) O- j: r& G. l6 N3 n) }
随机产生的turtle 已经在patch的坐标上上下左右一格格运动,当turtle碰到一个随即分布的patch以一定概率粘合,patch变色,其他turtle经过也还是以一定概率粘合的,粘合后turtle的能量就会转变到patch上,并且以一定速率消耗它,怎么编写这个过程?下面是我编写的,运行时就出错了。怎么改正呢?
: Y, g/ f" g# W7 h+ h( H/ B; [5 g3 k% |) A4 F/ N3 |
& v& H& x& }8 a5 ^2 ?6 qturtles-own [ energy ]; t# F- p$ ~* }) e7 l. x
to setup7 P. l. Q' C6 b4 h
clear-all
- [: V3 t( H9 g' B; _+ a& C8 v0 i1 u- gset-default-shape turtles "square"
3 ~4 F* r( q1 L$ S- v8 U( P( y) `crt nutrition
' f. r* @# ] \3 D7 dask turtles[; b0 X' d+ c. R8 A2 A
set color white3 y/ H0 U0 s" |7 e' V" g) I
setxy random-pxcor random-pycor]
& D% a" l6 T+ v, W: j
( V- g: |; F4 U* p+ W3 m2 \ask n-of microbes-initialization patches
5 H, u4 N: F2 n [ set pcolor green]) L- w+ r3 g% E- B' _# P0 p3 ^
ask turtles [set energy 1]
, G. |" p5 N |' Z bend
, E6 c4 v X/ t8 d2 r* x# F @6 y5 z( X& S% q
to go
5 h) ]) Y/ G) y. \: T: J ask turtles [set heading 90 * random 4 fd 1]( Z4 Z5 B) B- @" a- C P" e: j
ask patches with [ any? turtles-here]
! X1 z. ^/ A" a* ]" i4 X7 v [ if pcolor = green and random 100 < chance-of-congregating [tt ]]; Q8 e- Q+ f6 }! B7 G
ask turtles [ if energy = 0 [die ]]
2 P) J$ h& v! n1 w* l end
. Z# A5 i- J! D6 j. S2 `) n# y" L. g, {6 m6 D: t% Y! y
to tt
* U( Z/ h7 b! Mask patches [set pcolor gray ]0 \# Y, M3 B! W. n, r
ask turtles [set energy energy - 1]3 n7 O2 _$ _; S6 y0 _9 V
end
6 ?* C, S# n- }
# b! O* q# }- p: p O; \. [; l |