Exemplo n.º 1
0
        // TODO: rename - doesnt make sense. Should be single responsibility
        public static void SearchRowForSingleCandidates(this Grid grid)
        {
            // 3. Searching for Single Candidates: ROW
            // "is there a value in any row that is only possible in one location?"

            for (int row = 0; row < grid.GridSize; row++)
            {
                for (int value = 1; value <= grid.GridSize; value++)
                {
                    // that value already exists in the row
                    if (Array.Exists(grid.GetRow(row), element => element == value))
                    {
                        continue;
                    }

                    int result = grid.CheckRowForValueInOptions(row, value);
                    if (result != -1)
                    {
                        grid.SolveCell(row, result, value);
                        grid.UpdateNeighbours(row, result);
                    }
                }
            }
        }