Skip to content

Commit

Permalink
I'm not sure what to do here
Browse files Browse the repository at this point in the history
I think this is right but we need to make 4 of the same method based on whether its cells or not not sure how we would do that.
  • Loading branch information
kchiu1 committed Feb 23, 2024
1 parent ff41f92 commit 2095987
Showing 1 changed file with 96 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package edu.rpi.legup.puzzle.sudoku.rules;

import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.gameboard.CaseBoard;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.model.rules.CaseRule;
import edu.rpi.legup.model.tree.TreeTransition;
import edu.rpi.legup.puzzle.sudoku.GroupType;
import edu.rpi.legup.puzzle.sudoku.SudokuBoard;
import edu.rpi.legup.puzzle.sudoku.SudokuCell;

import java.util.ArrayList;
import java.util.List;

public class PossibleNumberForRowCaseRule extends CaseRule {

public PossibleNumberForRowCaseRule() {
super("SUDO-CASE-0003", "Possible Numbers for Row",
"An empty cell has a limited set of possible numbers that can fill it.",
"edu/rpi/legup/images/sudoku/PossibleValues.png");
}

/**
* Checks whether the transition logically follows from the parent node using this rule
*
* @param transition transition to check
* @return null if the child node logically follow from the parent node, otherwise error message
*/
@Override
public String checkRuleRaw(TreeTransition transition) {
return null;
}

/**
* Checks whether the child node logically follows from the parent node
* at the specific puzzleElement index using this rule
*
* @param transition transition to check
* @param puzzleElement equivalent puzzleElement
* @return null if the child node logically follow from the parent node at the specified puzzleElement,
* otherwise error message
*/
@Override
public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) {
return null;
}

@Override
public CaseBoard getCaseBoard(Board board) {
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
*
* @param board the current board state
* @param puzzleElement equivalent puzzleElement
* @return a list of elements the specified could be
*/
@Override
public ArrayList<Board> getCases(Board board, PuzzleElement puzzleElement) {
return getCases(board, puzzleElement, 1, GroupType.REGION);
}

/**
* Gets the possible cases at a specific location based on this case rule
*
* @param board the current board state
* @param puzzleElement equivalent puzzleElement
* @param value value that the rule will be applied from
* @param groupType group type
* @return a list of elements the specified could be
*/
public ArrayList<Board> getCases(Board board, PuzzleElement puzzleElement, int value, GroupType groupType) {
ArrayList<Board> cases = new ArrayList<>();
SudokuBoard sudokuBoard = (SudokuBoard) board;
List<SudokuCell> caseCells = new ArrayList<>();
SudokuCell cell = (SudokuCell) puzzleElement;
//not sure what we would do here!
for (int i = 0; i < 9; i++) {
Board newCase = sudokuBoard.copy();
PuzzleElement element = newCase.getPuzzleElement(puzzleElement);
element.setData(value);
newCase.addModifiedData(element);
cases.add(newCase);
}

return cases;
}
}

0 comments on commit 2095987

Please sign in to comment.