Skip to content

Commit

Permalink
Bug Fixes
Browse files Browse the repository at this point in the history
The colored tiles weren't generating off of number case rule, so I fixed that.

Now correctly generates 9 branches.
  • Loading branch information
kchiu1 committed Feb 13, 2024
1 parent 1598cf2 commit 2d607d3
Showing 1 changed file with 8 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,15 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem

@Override
public CaseBoard getCaseBoard(Board board) {
SudokuBoard sudokuBoard = (SudokuBoard) board;
PossibleNumberCaseBoard caseBoard = new PossibleNumberCaseBoard(sudokuBoard, this, null);
for (int i = 0; i < sudokuBoard.getSize(); i++) {
caseBoard.addPickableRegion(i);
caseBoard.addPickableRow(i);
caseBoard.addPickableCol(i);
SudokuBoard sudokuBoard = (SudokuBoard) board.copy();
CaseBoard caseBoard = new CaseBoard(sudokuBoard, this);
for (PuzzleElement puzzleElement : sudokuBoard.getPuzzleElements()) {
if (((SudokuCell) puzzleElement).getData() == 0) {
caseBoard.addPickableElement(puzzleElement);
}
}
return caseBoard;
}

/**
* Gets the possible cases at a specific location based on this case rule
*
Expand Down Expand Up @@ -86,41 +85,9 @@ public ArrayList<Board> getCases(Board board, PuzzleElement puzzleElement, int v
List<SudokuCell> caseCells = new ArrayList<>();
SudokuCell cell = (SudokuCell) puzzleElement;

Set<SudokuCell> group;
if (groupType == GroupType.REGION) {
group = sudokuBoard.getRegion(cell.getGroupIndex());
}
else {
if (groupType == GroupType.ROW) {
group = sudokuBoard.getRow(cell.getLocation().y);
}
else {
group = sudokuBoard.getCol(cell.getLocation().x);
}
}

for (SudokuCell c : group) {
if (c.getData() == 0) {
Set<SudokuCell> blockableCells = sudokuBoard.getRegion(c.getGroupIndex());
blockableCells.addAll(sudokuBoard.getRow(c.getLocation().y));
blockableCells.addAll(sudokuBoard.getCol(c.getLocation().x));

boolean repeat = false;
for (SudokuCell bc : blockableCells) {
if (bc.getData() == value) {
repeat = true;
break;
}
}
if (!repeat) {
caseCells.add(c);
}
}
}

for (SudokuCell c : caseCells) {
for (int i = 0; i < 9; i++) {
Board newCase = sudokuBoard.copy();
PuzzleElement element = newCase.getPuzzleElement(c);
PuzzleElement element = newCase.getPuzzleElement(puzzleElement);
element.setData(value);
newCase.addModifiedData(element);
cases.add(newCase);
Expand Down

0 comments on commit 2d607d3

Please sign in to comment.