Ejemplo n.º 1
0
        public static void CheckCellForSingleOption(this Grid grid, int x, int y)
        {
            if (grid.GetCell(x, y).Solved)
            {
                return;
            }

            if (grid.GetCell(x, y).Options.Count == 1)
            {
                grid.SolveCell(x, y, grid.GetCell(x, y).Options[0]);
                grid.UpdateNeighbours(x, y);
            }
        }
Ejemplo n.º 2
0
        public static void SearchColumnForSingleCandidates(this Grid grid)
        {
            for (int col = 0; col < grid.GridSize; col++)
            {
                for (int value = 1; value <= grid.GridSize; value++)
                {
                    // that value already exists in the col
                    if (Array.Exists(grid.GetColumn(col), element => element == value))
                    {
                        continue;
                    }

                    int result = grid.CheckColForValueInOptions(col, value);
                    if (result != -1)
                    {
                        grid.SolveCell(result, col, value);
                        grid.UpdateNeighbours(result, col);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        // 3. Searching for Single Candidates: Square
        // "is there a value in any square that is only possible in one location?"

        public static void SearchSquareForSingleCandidates(this Grid grid)
        {
            for (int s = 0; s < grid.GridSize; s++)
            {
                for (int value = 1; value <= grid.GridSize; value++)
                {
                    // that value already exists in the col
                    if (Array.Exists(grid.GetSquare(s), element => element == value))
                    {
                        continue;
                    }

                    Tuple <int, int> result = grid.CheckSquareForValueInOptions(s, value);
                    if (result.Item1 != -1 && result.Item2 != -1)
                    {
                        grid.SolveCell(result.Item1, result.Item2, value);
                        grid.UpdateNeighbours(result.Item1, result.Item2);
                    }
                }
            }
        }
Ejemplo n.º 4
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);
                    }
                }
            }
        }