Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sudoku #833

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
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.ModelSudokuBoard;
import edu.rpi.legup.puzzle.sudoku.SudokuBoard;
import edu.rpi.legup.puzzle.sudoku.SudokuCell;
import java.util.ArrayList;
import java.util.Set;

public class PossibleCellsByXWing extends CaseRule{

// Board math for translating indexes to numbers
private ModelSudokuBoard model = new ModelSudokuBoard();

// Old board for caseBoard reference
private SudokuBoard lagBoard;

public PossibleCellsByXWing(){
super("SUDO-CASE-0005",
"Possible X-Wing Cells.",
"If in two rows and two columns, four cells exist that will allow for the same number such that they form a rectangle," +
" that number must ocupy either one of the vertices of the rectangle.",
"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();
lagBoard = (SudokuBoard) sudokuBoard.copy();
CaseBoard caseBoard = new CaseBoard(sudokuBoard, this);
for (PuzzleElement puzzleElement : sudokuBoard.getPuzzleElements()) {
puzzleElement.setData(model.getModelRegionNumbers(puzzleElement.getIndex()));
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 = lagBoard;
SudokuCell sourceCell = (SudokuCell) puzzleElement;

Set<SudokuCell> group = sudokuBoard.getRegion(sourceCell.getGroupIndex());
for (SudokuCell cell : group) {
if (cell.getData() == 0) {
Board newCase = sudokuBoard.copy();
PuzzleElement element = newCase.getPuzzleElement(cell);
element.setData(model.getModelRegionNumbers(sourceCell.getIndex()));
newCase.addModifiedData(element);
cases.add(newCase);
}
}
return cases;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/main/resources/edu/rpi/legup/legup/config
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
fileCreationDisabled="false"/>
<puzzle name="Sudoku" qualifiedClassName="edu.rpi.legup.puzzle.sudoku.Sudoku"
fileType=".xml"
fileCreationDisabled="true"/>
fileCreationDisabled="false"/>
<puzzle name="TreeTent"
qualifiedClassName="edu.rpi.legup.puzzle.treetent.TreeTent"
fileType=".xml"
Expand Down
Loading