protected override bool updateSurroundings(int squareNum, PuzzleNumbers puzzle, PuzzleStructure grid) { bool used = false; if (candidateCount.Count == 1) { used = true; char answer = ' '; foreach (KeyValuePair <char, int> pair in candidateCount) { answer = pair.Key; } puzzle.squares[squareNum].number = answer; for (int i = 0; i < row.Squares.Count; i++) { if (puzzle.squares[row.Squares[i]].number == '-' && puzzle.squares[row.Squares[i]].candidates.Contains(answer.ToString())) { puzzle.squares[row.Squares[i]].candidates.Remove(answer.ToString()); if (puzzle.squares[row.Squares[i]].candidates.Count == 1) { SingleCandidate temp = new SingleCandidate(); temp.Solve(row.Squares[i], puzzle, grid); SinglesUsed++; SinglesUsed += temp.SinglesUsed; } } } for (int i = 0; i < col.Squares.Count; i++) { if (puzzle.squares[col.Squares[i]].number == '-' && puzzle.squares[col.Squares[i]].candidates.Contains(answer.ToString())) { puzzle.squares[col.Squares[i]].candidates.Remove(answer.ToString()); if (puzzle.squares[col.Squares[i]].candidates.Count == 1) { SingleCandidate temp = new SingleCandidate(); temp.Solve(row.Squares[i], puzzle, grid); SinglesUsed++; SinglesUsed += temp.SinglesUsed; } } } for (int i = 0; i < block.Squares.Count; i++) { if (puzzle.squares[block.Squares[i]].number == '-' && puzzle.squares[block.Squares[i]].candidates.Contains(answer.ToString())) { puzzle.squares[block.Squares[i]].candidates.Remove(answer.ToString()); if (puzzle.squares[block.Squares[i]].candidates.Count == 1) { SingleCandidate temp = new SingleCandidate(); temp.Solve(row.Squares[i], puzzle, grid); SinglesUsed++; SinglesUsed += temp.SinglesUsed; } } } } return(used); }
protected override bool updateSurroundings(int squareNum, PuzzleNumbers puzzle, PuzzleStructure grid) { bool used = false; char solution; if (puzzle.squares[squareNum].number == '-' && puzzle.squares[squareNum].candidates.Count == 1) { solution = (puzzle.squares[squareNum].candidates[0].ToCharArray())[0]; puzzle.squares[squareNum].number = solution; used = true; for (int j = 0; j < row.Squares.Count; j++) { if (puzzle.squares[row.Squares[j]].number == '-') { puzzle.squares[row.Squares[j]].candidates.Remove(solution.ToString()); if (puzzle.squares[row.Squares[j]].candidates.Count == 1 && puzzle.squares[row.Squares[j]].number == '-') { SingleCandidate temp = new SingleCandidate(); temp.Solve(row.Squares[j], puzzle, grid); SinglesUsed++; SinglesUsed += temp.SinglesUsed; } } if (puzzle.squares[block.Squares[j]].number == '-' && puzzle.squares[block.Squares[j]].candidates.Contains(solution.ToString())) { puzzle.squares[block.Squares[j]].candidates.Remove(solution.ToString()); if (puzzle.squares[block.Squares[j]].candidates.Count == 1 && puzzle.squares[block.Squares[j]].number == '-') { SingleCandidate temp = new SingleCandidate(); temp.Solve(row.Squares[j], puzzle, grid); SinglesUsed++; SinglesUsed += temp.SinglesUsed; } } if (puzzle.squares[col.Squares[j]].number == '-') { puzzle.squares[col.Squares[j]].candidates.Remove(solution.ToString()); if (puzzle.squares[col.Squares[j]].candidates.Count == 1 && puzzle.squares[col.Squares[j]].number == '-') { SingleCandidate temp = new SingleCandidate(); temp.Solve(row.Squares[j], puzzle, grid); SinglesUsed++; SinglesUsed += temp.SinglesUsed; } } } } return(used); }
protected override bool updateSurroundings(int squareNum, PuzzleNumbers puzzle, PuzzleStructure grid) { if (used) { for (int i = 0; i < puzzle.squares.Count; i++) { if (puzzle.squares[i].number == '-' && puzzle.squares[i].candidates.Count == 1) { SingleCandidate temp = new SingleCandidate(); temp.Solve(i, puzzle, grid); SinglesUsed++; SinglesUsed += temp.SinglesUsed; } } } return(used); }