countBlackWhite[a_, i_, j_] :=
With[{nb = Flatten@a[[i - 1 ;; i + 1, j - 1 ;; j + 1]]},
Count[nb, #] & /@ {0, 1}];
evaluateCell[a_, i_, j_] :=
Module[{numBlack, numWhite}, {numBlack, numWhite} =
countBlackWhite[a, i, j];
Which[numBlack == numWhite, 2, numWhite > numBlack, 1, True, 0]]
evaluateAll[A_] :=
With[{paddedA = ArrayPad[A, 1]},
Table[evaluateCell[paddedA, i, j], {i, 2, Length[A] + 1}, {j, 2,
Length[A[[1]]] + 1}]]
makeFrames[A_] :=
Map[ArrayPlot[#, Mesh -> False,
ColorFunction ->