请问:0 d, Q1 L, K% k1 m, k, f
随机产生的turtle 已经在patch的坐标上上下左右一格格运动,当turtle碰到一个随即分布的patch以一定概率粘合,patch变色,其他turtle经过也还是以一定概率粘合的,粘合后turtle的能量就会转变到patch上,并且以一定速率消耗它,怎么编写这个过程?下面是我编写的,运行时就出错了。怎么改正呢?
1 A( Z( C/ Q2 `$ @+ z+ M1 L C# ~# R: n
8 S+ i& U* e& @7 l% @3 W2 x" h5 p
turtles-own [ energy ]2 q8 o8 t/ X+ _! c
to setup! j3 j2 ?+ n# ^ r7 @5 y+ {
clear-all, T4 I9 j6 N' r' }0 B* n
set-default-shape turtles "square"" o6 S9 [. `* U6 R
crt nutrition
; Q% r; Q: B0 P! {ask turtles[
; |) d, H) c# ]+ F% [7 x set color white
( Z$ Q4 n* U! H& c2 ]- h6 A setxy random-pxcor random-pycor]
! s; [8 u" n+ J) q) L, R0 c: F1 k ! K) T2 b( v/ C, K; g# e$ J
ask n-of microbes-initialization patches
+ w9 C' U) X7 M9 M, E [ set pcolor green]6 U" B3 I5 g; C
ask turtles [set energy 1]; a! {# A2 ~; g: v. V1 @& I3 J
end
1 n2 ^) w; O7 z' t' @! F9 ~; T) k
# X" A: n" R- R$ D& n6 Bto go6 k( _+ G) E4 Z4 \9 [9 {
ask turtles [set heading 90 * random 4 fd 1]; Z- q0 { O3 G8 m+ e
ask patches with [ any? turtles-here]
4 ~& l) n8 k6 n6 N, `0 }! `3 D [ if pcolor = green and random 100 < chance-of-congregating [tt ]]
* {4 I8 j2 J5 ^# | a2 L1 h' c ask turtles [ if energy = 0 [die ]]
1 Y, d5 u5 K! Q4 u c end
& b+ b$ c# s, d5 p' D* i5 K
3 k( z% E+ t# ~to tt# d3 ?# K) m& n& J. E
ask patches [set pcolor gray ]) \/ {1 { c; [, t
ask turtles [set energy energy - 1]0 {* s0 p! t8 O
end
5 V3 s- o C @* A& D
# p# ]/ p% l8 P" |" Z0 C& t/ v8 w |