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

Standardized Error Messages #67

Merged
merged 17 commits into from
Jan 4, 2022
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
7 changes: 5 additions & 2 deletions src/main/java/edu/rpi/legup/model/rules/CaseRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import static edu.rpi.legup.model.rules.RuleType.CASE;

public abstract class CaseRule extends Rule {

private final String INVALID_USE_MESSAGE;

/**
* CaseRule Constructor creates a new case rule.
*
Expand All @@ -24,6 +27,7 @@ public abstract class CaseRule extends Rule {
public CaseRule(String ruleName, String description, String imageName) {
super(ruleName, description, imageName);
this.ruleType = CASE;
this.INVALID_USE_MESSAGE = "Invalid use of the case rule " + this.ruleName;
}

/**
Expand Down Expand Up @@ -103,8 +107,7 @@ public String checkRule(TreeTransition transition) {
*/
@Override
public String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement) {
// System.out.println("Nurikabe case rule check reached here");
return "Invalid use of a case rule";
return this.INVALID_USE_MESSAGE;
}

/**
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import static edu.rpi.legup.model.rules.RuleType.CONTRADICTION;

public abstract class ContradictionRule extends Rule {

private final String NO_CONTRADICTION_MESSAGE = "No instance of the contradiction " + this.ruleName + " here";

/**
* ContradictionRule Constructor creates a new contradiction rule
*
Expand Down Expand Up @@ -84,7 +87,12 @@ public String checkContradiction(Board board) {
return checkStr;
}
}
return "Does not contain a contradiction";
return this.NO_CONTRADICTION_MESSAGE;
}

public String getNoContradictionMessage()
{
return this.NO_CONTRADICTION_MESSAGE;
}

/**
Expand All @@ -96,4 +104,5 @@ public String checkContradiction(Board board) {
* otherwise error message
*/
public abstract String checkContradictionAt(Board board, PuzzleElement puzzleElement);

}
8 changes: 8 additions & 0 deletions src/main/java/edu/rpi/legup/model/rules/Rule.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public abstract class Rule {
protected ImageIcon image;
protected RuleType ruleType;

private final String INVALID_USE_MESSAGE;

/**
* Rule Constructor creates a new rule
*
Expand All @@ -30,6 +32,7 @@ public Rule(String ruleName, String description, String imageName) {
this.imageName = imageName;
this.ruleName = ruleName;
this.description = description;
this.INVALID_USE_MESSAGE = "Invalid use of the rule " + this.ruleName;
loadImage();
}

Expand Down Expand Up @@ -140,4 +143,9 @@ public ImageIcon getImageIcon() {
public RuleType getRuleType() {
return ruleType;
}

public String getInvalidUseOfRuleMessage()
{
return this.INVALID_USE_MESSAGE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,25 @@ public ArrayList<Board> getCases(Board board, PuzzleElement puzzleElement) {
public String checkRuleRaw(TreeTransition transition) {
List<TreeTransition> childTransitions = transition.getParents().get(0).getChildren();
if (childTransitions.size() != 2) {
return "This case rule must have 2 children.";
return super.getInvalidUseOfRuleMessage() + ": This case rule must have 2 children.";
}

TreeTransition case1 = childTransitions.get(0);
TreeTransition case2 = childTransitions.get(1);
if (case1.getBoard().getModifiedData().size() != 1 ||
case2.getBoard().getModifiedData().size() != 1) {
return "This case rule must have 1 modified cell for each case.";
return super.getInvalidUseOfRuleMessage() + ": This case rule must have 1 modified cell for each case.";
}

FillapixCell mod1 = (FillapixCell) case1.getBoard().getModifiedData().iterator().next();
FillapixCell mod2 = (FillapixCell) case2.getBoard().getModifiedData().iterator().next();
if (!mod1.getLocation().equals(mod2.getLocation())) {
return "This case rule must modify the same cell for each case.";
return super.getInvalidUseOfRuleMessage() + ": This case rule must modify the same cell for each case.";
}

if (!((mod1.getType() == FillapixCellType.BLACK && mod2.getType() == FillapixCellType.WHITE)
|| (mod2.getType() == FillapixCellType.BLACK && mod1.getType() == FillapixCellType.WHITE))) {
return "This case rule must an empty cell and a lite cell.";
return super.getInvalidUseOfRuleMessage() + ": This case rule must an empty cell and a lit cell.";
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement);

if (!(parentCell.getType() == FillapixCellType.UNKNOWN && cell.getType() == FillapixCellType.BLACK)) {
return "This cell must be black to be applicable with this rule.";
return super.getInvalidUseOfRuleMessage() + ": This cell must be black to be applicable with this rule.";
}

if (isForcedBlack(parentBoard, cell)) {
return null;
} else {
return "This cell is not forced to be black";
return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be black";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement);

if (!(parentCell.getType() == FillapixCellType.UNKNOWN && cell.getType() == FillapixCellType.WHITE)) {
return "This cell must be white to be applicable with this rule.";
return super.getInvalidUseOfRuleMessage() + ": This cell must be white to be applicable with this rule";
}

if (isForcedWhite(parentBoard, cell)) {
return null;
} else {
return "This cell is not forced to be white";
return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be white";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
}
}
}
return "Board does not contain a contradiction";
return super.getNoContradictionMessage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
}
}
}
return "Board does not contain a contradiction";
return super.getNoContradictionMessage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
LightUpBoard lightUpBoard = (LightUpBoard) board;
LightUpCell cell = (LightUpCell) lightUpBoard.getPuzzleElement(puzzleElement);
if (cell.getType() != LightUpCellType.BULB) {
return "Does not contain a contradiction at this index";
return super.getNoContradictionMessage();
}

Point location = cell.getLocation();
Expand Down Expand Up @@ -66,6 +66,6 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
return null;
}
}
return "Does not contain a contradiction at this index";
return super.getNoContradictionMessage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
return "This cell does not contain a contradiction";
}*/
if (cell.getType() != LightUpCellType.EMPTY || cell.isLite()) {
return "This cell does not contain a contradiction";
return super.getNoContradictionMessage();
}
Point location = cell.getLocation();
int ver_count = 0;
Expand Down Expand Up @@ -74,6 +74,6 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
if(hor_count == 0 && ver_count == 0) {
return null;
}
return "This cell does not contain a contradiction";
return super.getNoContradictionMessage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
if (finalCell.getType() == LightUpCellType.EMPTY && initCell.getType() == LightUpCellType.UNKNOWN && initCell.isLite()) {
return null;
}
return "Cell is not forced to be empty";
return super.getInvalidUseOfRuleMessage() + ": Cell is not forced to be empty";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
LightUpCell finalCell = (LightUpCell) finalBoard.getPuzzleElement(puzzleElement);

if (!(cell.getType() == LightUpCellType.UNKNOWN && finalCell.getType() == LightUpCellType.EMPTY)) {
return "This cell must be an empty cell.";
return super.getInvalidUseOfRuleMessage() + ": This cell must be an empty cell";
}

Point loc = finalCell.getLocation();
Expand All @@ -60,7 +60,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
numberedCells.add(lowerLeft);
}
if (numberedCells.isEmpty()) {
return "This cell must diagonal to a numbered cell.";
return super.getInvalidUseOfRuleMessage() + ": This cell must diagonal to a numbered cell";
}

TooFewBulbsContradictionRule tooFew = new TooFewBulbsContradictionRule();
Expand All @@ -76,7 +76,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
if (createsContra) {
return null;
} else {
return "This cell is not forced to be empty.";
return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be empty";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
LightUpBoard finalBoard = (LightUpBoard) transition.getBoard();
LightUpCell finalCell = (LightUpCell) finalBoard.getPuzzleElement(puzzleElement);
if (!(initCell.getType() == LightUpCellType.UNKNOWN && finalCell.getType() == LightUpCellType.BULB)) {
return "Modified cells must be bulbs";
return super.getInvalidUseOfRuleMessage() + ": Modified cells must be bulbs";
}

Set<LightUpCell> adjCells = finalBoard.getAdj(finalCell);
adjCells.removeIf(cell -> cell.getType() != LightUpCellType.NUMBER);
if (adjCells.isEmpty()) {
return "This cell is not adjacent to a numbered cell.";
return super.getInvalidUseOfRuleMessage() + ": This cell is not adjacent to a numbered cell";
}

LightUpBoard emptyCase = initialBoard.copy();
Expand All @@ -52,7 +52,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
return null;
}
}
return "This cell is not forced to be a bulb.";
return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be a bulb";
}

private boolean isForced(LightUpBoard board, LightUpCell cell) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
LightUpBoard finalBoard = (LightUpBoard) transition.getBoard();
LightUpCell cell = (LightUpCell) finalBoard.getPuzzleElement(puzzleElement);
if (cell.getType() != LightUpCellType.EMPTY) {
return "Modified cells must be empty";
return super.getInvalidUseOfRuleMessage() + ": Modified cells must be empty";
}

if (isForced(initialBoard, cell.getLocation())) {
return null;
}
return "Empty is not forced";
return super.getInvalidUseOfRuleMessage() + ": Empty is not forced";
}

private boolean isForced(LightUpBoard board, Point location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,25 @@ public ArrayList<Board> getCases(Board board, PuzzleElement puzzleElement) {
public String checkRuleRaw(TreeTransition transition) {
List<TreeTransition> childTransitions = transition.getParents().get(0).getChildren();
if (childTransitions.size() != 2) {
return "This case rule must have 2 children.";
return super.getInvalidUseOfRuleMessage() + ": This case rule must have 2 children";
}

TreeTransition case1 = childTransitions.get(0);
TreeTransition case2 = childTransitions.get(1);
if (case1.getBoard().getModifiedData().size() != 1 ||
case2.getBoard().getModifiedData().size() != 1) {
return "This case rule must have 1 modified cell for each case.";
return super.getInvalidUseOfRuleMessage() + ": This case rule must have 1 modified cell for each case";
}

LightUpCell mod1 = (LightUpCell) case1.getBoard().getModifiedData().iterator().next();
LightUpCell mod2 = (LightUpCell) case2.getBoard().getModifiedData().iterator().next();
if (!mod1.getLocation().equals(mod2.getLocation())) {
return "This case rule must modify the same cell for each case.";
return super.getInvalidUseOfRuleMessage() + ": This case rule must modify the same cell for each case";
}

if (!((mod1.getType() == LightUpCellType.EMPTY && mod2.getType() == LightUpCellType.BULB) ||
(mod2.getType() == LightUpCellType.EMPTY && mod1.getType() == LightUpCellType.BULB))) {
return "This case rule must an empty cell and a bulb cell.";
return super.getInvalidUseOfRuleMessage() + ": This case rule must an empty cell and a bulb cell";
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
LightUpCell parentCell = (LightUpCell) parentBoard.getPuzzleElement(puzzleElement);
LightUpCell finalCell = (LightUpCell) finalBoard.getPuzzleElement(puzzleElement);
if (!(parentCell.getType() == LightUpCellType.UNKNOWN && !parentCell.isLite() && finalCell.getType() == LightUpCellType.BULB)) {
return "Modified cells must be bulbs";
return super.getInvalidUseOfRuleMessage() + ": Modified cells must be bulbs";
}

finalCell.setData(LightUpCellType.EMPTY.value);
Expand All @@ -47,7 +47,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
if (isForced) {
return null;
} else {
return "This cell can be lite by another cell.";
return super.getInvalidUseOfRuleMessage() + ": This cell can be lit by another cell";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public String checkRuleRaw(TreeTransition transition) {

List<LightUpCell> spots = getPossibleSpots(transition);
if (spots == null) {
return "This case rule must have a valid spot for where it was applied";
return super.getInvalidUseOfRuleMessage();
}

for (LightUpCell c : spots) {
Expand Down Expand Up @@ -212,7 +212,7 @@ public String checkRuleRaw(TreeTransition transition) {
}
}
}
return "This case rule is not valid";
return super.getInvalidUseOfRuleMessage();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,15 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
LightUpBoard lightUpBoard = (LightUpBoard) board;
LightUpCell cell = (LightUpCell) lightUpBoard.getPuzzleElement(puzzleElement);
if (cell.getType() != LightUpCellType.NUMBER) {
return "Does not contain a contradiction";
return super.getNoContradictionMessage();
}

Point location = cell.getLocation();

int bulbs = lightUpBoard.getNumAdj(cell, LightUpCellType.BULB);
int placeable = lightUpBoard.getNumPlacble(cell);

if (bulbs + placeable < cell.getData()) {
return null;
}
return "Number does not contain a contradiction";
return super.getNoContradictionMessage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
LightUpBoard lightUpBoard = (LightUpBoard) board;
LightUpCell cell = (LightUpCell) lightUpBoard.getPuzzleElement(puzzleElement);
if (cell.getType() != LightUpCellType.NUMBER) {
return "Does not contain a contradiction";
return super.getNoContradictionMessage();
}

Point location = cell.getLocation();
Expand All @@ -57,6 +57,6 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
if (bulbs > cell.getData()) {
return null;
}
return "Number does not contain a contradiction";
return super.getNoContradictionMessage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement);

if (cell.getType() != NurikabeType.BLACK) {
return "Only black cells are allowed for this rule!";
return super.getInvalidUseOfRuleMessage() + ": Only black cells are allowed for this rule!";
}

int x = cell.getLocation().x;
Expand Down
Loading