private int CountNeighbors()

in GameOfLife/ViewModel/PetriDish.cs [151:165]


        private int CountNeighbors(int i, int j)
        {
            var count = 0;

            if (i != width - 1 && currentCells[i + 1, j].IsAlive) count++;
            if (i != width - 1 && j != height - 1 && currentCells[i + 1, j + 1].IsAlive) count++;
            if (j != height - 1 && currentCells[i, j + 1].IsAlive) count++;
            if (i != 0 && j != height - 1 && currentCells[i - 1, j + 1].IsAlive) count++;
            if (i != 0 && currentCells[i - 1, j].IsAlive) count++;
            if (i != 0 && j != 0 && currentCells[i - 1, j - 1].IsAlive) count++;
            if (j != 0 && currentCells[i, j - 1].IsAlive) count++;
            if (i != width - 1 && j != 0 && currentCells[i + 1, j - 1].IsAlive) count++;

            return count;
        }