How can I write two functions, each of which have as their argument an array mat of 0s (no trees), 1s (trees), 2s (burning trees), that can determine the trees that survived a forest fire, which run from initial state mat and spreads from a burning tree to its von Neumann neighbors only and then a second function that determines the number of trees that have no trees, burning (2s) or not burning (1s), in their von Neumann neighborhoods? For the function determining the surviving trees, I have the following code:
survivors[mat : {{_Integer ..} ..}] :=
Count[FixedPoint[nextState, mat], 1, {2}]
where nextState is the following function:
i = 5;
mat = RandomChoice[{0, 1, 2}, {i, i}];
moveright[j_] := Prepend[Rest[RotateRight[j]], 0 j[[1]]]
moveleft[j_] := Append[Most[RotateLeft[j]], 0 j[[1]]]
nextState[
mat_] := (mat1 =
MapThread[
Max, {moveright[mat], moveleft[mat], moveright /@ mat,
moveleft /@ mat}, 2];
MapThread[If[#2 == 2 && #1 == 1, 2, #1] &, {mat, mat1}, 2]);
For a 30x30 matrix and varying values of parameter α, which is used to determine the probability of 0s and 1s in an initial state of mat, as shown in the code below, how can I calculate a number of iterations for the two functions and then get the average of each, for the different values of α?
ClearAll[initialState]
initialState[[Alpha], dim1, dim2_, pos_ : Automatic] :=
ReplacePart[
RandomChoice[{1/(1 + [Alpha]), [Alpha]/(1 + [Alpha])} -> {0,
1}, {dim1,
dim2}], (pos /.
Automatic -> RandomChoice[Tuples[{Range@dim1, Range@dim2}]]) ->
2]