From 7814d97182959f72f964a69378645d5c46908435 Mon Sep 17 00:00:00 2001 From: Charles Date: Sat, 25 Dec 2021 20:46:25 -0500 Subject: [PATCH 01/14] Prototype --- .../rules/basic/BasicRule_Generic.java | 98 +++++++------------ .../ContradictionRule_GenericStatement.java | 25 ++++- 2 files changed, 57 insertions(+), 66 deletions(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRule_Generic.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRule_Generic.java index 25eed0a85..286eded0c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRule_Generic.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRule_Generic.java @@ -12,86 +12,62 @@ public abstract class BasicRule_Generic extends BasicRule { - final ContradictionRule correspondingContradictionRule; - final boolean eliminationRule; + final ContradictionRule CORRESPONDING_CONTRADICTION_RULE; + final boolean ELIMINATION_RULE; public BasicRule_Generic(String ruleName, String description, String imageName, ContradictionRule contraRule, boolean eliminationRule){ super(ruleName, description, "edu/rpi/legup/images/shorttruthtable/ruleimages/basic/"+imageName+".png"); - this.correspondingContradictionRule = contraRule; - this.eliminationRule = eliminationRule; + this.CORRESPONDING_CONTRADICTION_RULE = contraRule; + this.ELIMINATION_RULE = eliminationRule; } - public String checkRuleRawAt(TreeTransition transition, PuzzleElement element){ + public String checkRuleRawAt(TreeTransition transition, PuzzleElement element) + { //Check that the puzzle element is not unknown ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); ShortTruthTableCell cell = (ShortTruthTableCell) board.getPuzzleElement(element); - System.out.println("Check Basic Rule Generic: "+cell); +// System.out.println("Check Basic Rule Generic: "+cell); - if(!cell.isAssigned()){ - System.out.println(" Only assigned cells"); + if (!cell.isAssigned()) return "Only assigned cells are allowed for basic rules"; - } - //check that it is assigned to the right value + // Get the original board ShortTruthTableBoard originalBoard = (ShortTruthTableBoard) transition.getParents().get(0).getBoard(); - //Use this board to check what would happen if the cell what the opposite value - ShortTruthTableBoard testBoard = originalBoard.copy(); - ((ShortTruthTableCell) testBoard.getPuzzleElement(element)).setType(cell.getType().getNegation()); - - //if this is elimination/introduction check the cell or its parent - PuzzleElement checkElement = element; - - //if elimination, check the parent - if(this.eliminationRule){ - System.out.println("Is an elimination rule"); - checkElement = cell.getStatementReference().getParentStatement().getCell(); - } - - //see if there is a contradiction - if (this.eliminationRule) - System.out.println("Parent check contradiction START"); - String checkContradiction = correspondingContradictionRule.checkContradictionAt(testBoard, checkElement); - if (this.eliminationRule) + if (this.ELIMINATION_RULE) { - System.out.println("Parent check contradiction END"); - System.out.println("Parent contradiction: " + checkContradiction); + // Strategy: If this is an elimination rule, simply check if there is a contradiction at the specified statement + + // This gets the operator of the parent statement, which is what we need for checking the contradiction + PuzzleElement checkElement = cell.getStatementReference().getParentStatement().getCell(); + + String contradictionMessage = CORRESPONDING_CONTRADICTION_RULE.checkContradictionAt(originalBoard, checkElement); + System.out.println("ELIMINATION RULE CONTRADICTION MESSAGE: " + contradictionMessage); + if (contradictionMessage != null) + { + if (contradictionMessage.equals("This cell does not match any contradiction patterns for this rule")) // <-- temporary, don't want to hardcode that string + return null; + else + return contradictionMessage; + } + else + return "Invalid use of " + this.ruleName; } + else + { + // Strategy: Negate the modified cell and check if there is a contradiction. If there is one, then the + // original statement must be true. If there isn't one, then the original statement must be false. + ShortTruthTableBoard modifiedBoard = originalBoard.copy(); + ((ShortTruthTableCell) modifiedBoard.getPuzzleElement(element)).setType(cell.getType().getNegation()); - //if there is a contradiction when the modified element is negated, then the basic rule must be true - if(checkContradiction==null) - return null; - - return "Negated Contradiction Failed: "+checkContradiction; - -// if (this.eliminationRule) -// { -// System.out.println("Elimination rule check entered"); -// // If the rule is an elimination rule, we can check if the statement contains a contradiction. If it does -// // contain a contradiction, then we know that the rule must be false -// -// String checkContradiction = correspondingContradictionRule.checkContradictionAt(originalBoard, checkElement); -// System.out.println("checkContradiction: " + checkContradiction); -// if (checkContradiction == null) // original board contains a contradiction: this is bad! -// return "This is not a valid use of " + this.ruleName + "!"; -// return null; -// } -// else -// { -// // If the rule is not an elimination rule, we can check to see if negating the modified cell will create -// // a contradiction -// -// // Use the original board to check what would happen if the cell what the opposite value -// ShortTruthTableBoard testBoard = originalBoard.copy(); -// ((ShortTruthTableCell) testBoard.getPuzzleElement(element)).setType(cell.getType().getNegation()); -// String checkContradiction = correspondingContradictionRule.checkContradictionAt(testBoard, checkElement); -// if (checkContradiction == null) // modified board contains a contradiction: this is good! -// return null; -// return "Negated Contradiction Failed: "+checkContradiction; -// } + String contradictionMessage = CORRESPONDING_CONTRADICTION_RULE.checkContradictionAt(modifiedBoard, element); + if (contradictionMessage == null) // A contradiction exists in the modified statement; this is good! + return null; + return "Negated Contradiction Failed: " + contradictionMessage; + } } /** diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRule_GenericStatement.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRule_GenericStatement.java index a2b9ed877..7fe36cfba 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRule_GenericStatement.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRule_GenericStatement.java @@ -19,11 +19,14 @@ public abstract class ContradictionRule_GenericStatement extends ContradictionRu private final ShortTruthTableCellType[][] contradictionPatterns; - final static ShortTruthTableCellType T = ShortTruthTableCellType.TRUE; final static ShortTruthTableCellType F = ShortTruthTableCellType.FALSE; final static ShortTruthTableCellType n = null; + private final String NOT_RIGHT_OPERATOR_ERROR_MESSAGE = "This cell does not contain the correct operation"; + private final String NOT_TRUE_FALSE_ERROR_MESSAGE = "Can only check for a contradiction on a cell that is assigned a value of True or False"; + private final String NO_CONTRADICTION_MESSAGE = "This cell does not match any contradiction patterns for this rule"; + public ContradictionRule_GenericStatement(String ruleName, String description, String imageName, char operationSymbol, ShortTruthTableCellType[][] contradictionPatterns){ super(ruleName, description, imageName); @@ -31,7 +34,6 @@ public ContradictionRule_GenericStatement(String ruleName, String description, S this.contradictionPatterns = contradictionPatterns; } - @Override public String checkContradictionAt(Board puzzleBoard, PuzzleElement puzzleElement) { @@ -50,13 +52,13 @@ public String checkContradictionAt(Board puzzleBoard, PuzzleElement puzzleElemen // ISSUE: IT SEEMS TO BE THAT puzzleElement IS EXPECTED TO BE THE OPERATOR if(cell.getSymbol() != this.operationSymbol) - return "This cell does not contain the correct operation"; + return this.NOT_RIGHT_OPERATOR_ERROR_MESSAGE; //check that the initial statement is assigned ShortTruthTableCellType cellType = cell.getType(); System.out.println("contra rule generic cell: "+cell); if(!cellType.isTrueOrFalse()) - return "Can only check for a contradiction on a cell that is assigned a value of True or False"; + return this.NOT_TRUE_FALSE_ERROR_MESSAGE; //get the pattern for this sub-statement ShortTruthTableCellType[] testPattern = statement.getCellTypePattern(); @@ -84,8 +86,21 @@ public String checkContradictionAt(Board puzzleBoard, PuzzleElement puzzleElemen } System.out.println("No patterns match. There is not a contradiction"); - return "This cell does not match any contradiction pattern for this rule"; + return this.NO_CONTRADICTION_MESSAGE; + } + public String getNotRightOperatorErrorMessage() + { + return this.NOT_RIGHT_OPERATOR_ERROR_MESSAGE; } + public String getNotTrueFalseErrorMessage() + { + return this.NOT_TRUE_FALSE_ERROR_MESSAGE; + } + + public String getNoContradictionMessage() + { + return this.NO_CONTRADICTION_MESSAGE; + } } \ No newline at end of file From c5184ef82d1374c203d61928e365eed6ce7175b5 Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 29 Dec 2021 15:39:01 -0500 Subject: [PATCH 02/14] Standardized contradiction messages; only Nurikabe messages adjusted so far --- .../rpi/legup/model/rules/ContradictionRule.java | 15 +++++++++++++++ .../rules/BlackSquareContradictionRule.java | 7 +++++-- .../rules/CantReachWhiteContradictionRule.java | 7 +++++-- .../rules/IsolateBlackContradictionRule.java | 7 +++++-- .../rules/MultipleNumbersContradictionRule.java | 7 +++++-- .../nurikabe/rules/NoNumberContradictionRule.java | 10 +++++++--- .../rules/TooFewSpacesContradictionRule.java | 7 +++++-- .../rules/TooManySpacesContradictionRule.java | 7 +++++-- .../rules/basic/BasicRule_Generic.java | 6 ++++-- .../ContradictionRule_GenericStatement.java | 10 ---------- 10 files changed, 56 insertions(+), 27 deletions(-) diff --git a/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java b/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java index 4ec5b9a57..36b15ec8d 100644 --- a/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java @@ -7,6 +7,10 @@ import static edu.rpi.legup.model.rules.RuleType.CONTRADICTION; public abstract class ContradictionRule extends Rule { + + private final String NO_CONTRADICTION_MESSAGE = "No instance of " + this.ruleName; + private final String INVALID_USE_MESSAGE = "Invalid use of " + this.ruleName; + /** * ContradictionRule Constructor creates a new contradiction rule * @@ -87,6 +91,16 @@ public String checkContradiction(Board board) { return "Does not contain a contradiction"; } + public String getNoContradictionMessage() + { + return this.NO_CONTRADICTION_MESSAGE; + } + + public String getInvalidUseOfContradictionMessage() + { + return this.INVALID_USE_MESSAGE; + } + /** * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule * @@ -96,4 +110,5 @@ public String checkContradiction(Board board) { * otherwise error message */ public abstract String checkContradictionAt(Board board, PuzzleElement puzzleElement); + } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackSquareContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackSquareContradictionRule.java index bcfdc78b6..62bca55e4 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackSquareContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackSquareContradictionRule.java @@ -9,6 +9,9 @@ public class BlackSquareContradictionRule extends ContradictionRule { + private final String NO_CONTRADICTION_MESSAGE = "No 2x2 square of black exists."; + private final String INVALID_USE_MESSAGE = "Does not contain a contradiction at this index"; + public BlackSquareContradictionRule() { super("Black Square", "There cannot be a 2x2 square of black.", @@ -32,7 +35,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { NurikabeCell cell = (NurikabeCell) nurikabeBoard.getPuzzleElement(puzzleElement); if (cell.getType() != NurikabeType.BLACK) { - return "Does not contain a contradiction at this index"; + return super.getInvalidUseOfContradictionMessage() + ": " + this.INVALID_USE_MESSAGE; } for (int x = cell.getLocation().x - 1; x >= 0 && x < cell.getLocation().x + 1 && x < width - 1; x++) { @@ -46,6 +49,6 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { } } - return "No 2x2 square of black exists."; + return super.getNoContradictionMessage() + ": " + this.NO_CONTRADICTION_MESSAGE; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CantReachWhiteContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CantReachWhiteContradictionRule.java index c2077ccec..00ef8a608 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CantReachWhiteContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CantReachWhiteContradictionRule.java @@ -13,6 +13,9 @@ public class CantReachWhiteContradictionRule extends ContradictionRule { + private final String NO_CONTRADICTION_MESSAGE = "Cell at this index can be reached"; + private final String INVALID_USE_MESSAGE = "Does not contain a contradiction at this index"; + public CantReachWhiteContradictionRule() { super("Cant Reach white cell", "A white cell must be able to reach a white region", @@ -33,7 +36,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { NurikabeCell cell = (NurikabeCell) nurikabeBoard.getPuzzleElement(puzzleElement); if (cell.getType() != NurikabeType.WHITE) { - return "Does not contain a contradiction at this index"; + return super.getInvalidUseOfContradictionMessage() + ": " + this.INVALID_USE_MESSAGE; } ArrayList> regions = NurikabeUtilities.getFloodFillWhite(nurikabeBoard); @@ -41,7 +44,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { for (Set region : regions) { for (NurikabeCell c : region) { if (c == cell) { - return "Cell at this index can be reached"; + return super.getNoContradictionMessage() + ": " + this.NO_CONTRADICTION_MESSAGE; } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/IsolateBlackContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/IsolateBlackContradictionRule.java index 846e486d3..56fcb6a83 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/IsolateBlackContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/IsolateBlackContradictionRule.java @@ -13,6 +13,9 @@ public class IsolateBlackContradictionRule extends ContradictionRule { + private final String NO_CONTRADICTION_MESSAGE = "Contradiction applied incorrectly. No isolated Blacks."; + private final String INVALID_USE_MESSAGE = "Contradiction must be a black cell"; + public IsolateBlackContradictionRule() { super("Isolated Black", "There must still be a possibility to connect every Black cell", @@ -32,7 +35,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { NurikabeBoard nurikabeBoard = (NurikabeBoard) board; NurikabeCell cell = (NurikabeCell) nurikabeBoard.getPuzzleElement(puzzleElement); if (cell.getType() != NurikabeType.BLACK) { - return "Contradiction must be a black cell"; + return super.getInvalidUseOfContradictionMessage() + ": " + this.INVALID_USE_MESSAGE; } DisjointSets blackRegions = NurikabeUtilities.getPossibleBlackRegions(nurikabeBoard); @@ -49,6 +52,6 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { } } } - return "Contradiction applied incorrectly. No isolated Blacks."; + return super.getNoContradictionMessage() + ": " + this.NO_CONTRADICTION_MESSAGE; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/MultipleNumbersContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/MultipleNumbersContradictionRule.java index 03c4647f6..41b560f0d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/MultipleNumbersContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/MultipleNumbersContradictionRule.java @@ -13,6 +13,9 @@ public class MultipleNumbersContradictionRule extends ContradictionRule { + private final String NO_CONTRADICTION_MESSAGE = "Does not contain a contradiction at this index"; + private final String INVALID_USE_MESSAGE = "Contradiction must be a numbered cell"; + public MultipleNumbersContradictionRule() { super("Multiple Numbers", "All white regions cannot have more than one number.", @@ -33,7 +36,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { NurikabeCell cell = (NurikabeCell) nurikabeBoard.getPuzzleElement(puzzleElement); if (cell.getType() != NurikabeType.NUMBER) { - return "Contradiction must be a numbered cell"; + return super.getInvalidUseOfContradictionMessage() + ": " + INVALID_USE_MESSAGE; } DisjointSets regions = NurikabeUtilities.getNurikabeRegions(nurikabeBoard); Set numberedRegion = regions.getSet(cell); @@ -42,6 +45,6 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { return null; } } - return "Does not contain a contradiction at this index"; + return super.getNoContradictionMessage() + ": " + NO_CONTRADICTION_MESSAGE; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/NoNumberContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/NoNumberContradictionRule.java index 446088988..f26c67308 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/NoNumberContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/NoNumberContradictionRule.java @@ -13,6 +13,10 @@ public class NoNumberContradictionRule extends ContradictionRule { + private final String NO_CONTRADICTION_MESSAGE = "Does not contain a contradiction at this index"; + private final String INVALID_USE_MESSAGE = "Contradiction must be a white cell"; + private final String NOT_SURROUNDED_BY_BLACK_MESSAGE = "Must be surrounded by black cells"; + public NoNumberContradictionRule() { super("No Number", "All enclosed white regions must have a number.", @@ -33,13 +37,13 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { NurikabeCell cell = (NurikabeCell) nurikabeBoard.getPuzzleElement(puzzleElement); if (cell.getType() != NurikabeType.WHITE) { - return "Contradiction must be a white cell"; + return super.getInvalidUseOfContradictionMessage() + ": " + this.INVALID_USE_MESSAGE; } DisjointSets regions = NurikabeUtilities.getNurikabeRegions(nurikabeBoard); Set whiteRegion = regions.getSet(cell); for (NurikabeCell c : whiteRegion) { if (c.getType() == NurikabeType.NUMBER) { - return "Does not contain a contradiction at this index"; + return super.getNoContradictionMessage() + ": " + this.NO_CONTRADICTION_MESSAGE; } } for (NurikabeCell c : whiteRegion) { @@ -50,7 +54,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { NurikabeCell bottom = nurikabeBoard.getCell(c.getLocation().x, c.getLocation().y-1); if (isEmptyCell(top) || isEmptyCell(left) || isEmptyCell(right) || isEmptyCell(bottom)) - return "Must be surrounded by black cells"; + return super.getInvalidUseOfContradictionMessage() + ": " + this.NOT_SURROUNDED_BY_BLACK_MESSAGE; } return null; } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooFewSpacesContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooFewSpacesContradictionRule.java index 2e211bcda..9eb5711ce 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooFewSpacesContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooFewSpacesContradictionRule.java @@ -13,6 +13,9 @@ public class TooFewSpacesContradictionRule extends ContradictionRule { + private final String NO_CONTRADICTION_MESSAGE = "Does not contain a contradiction at this index"; + private final String INVALID_USE_MESSAGE = "Contradiction must be a white or a numbered cell"; + public TooFewSpacesContradictionRule() { super("Too Few Spaces", "A region cannot contain less spaces than its number.", @@ -33,7 +36,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { NurikabeCell cell = (NurikabeCell) nurikabeBoard.getPuzzleElement(puzzleElement); if (cell.getType() != NurikabeType.WHITE && cell.getType() != NurikabeType.NUMBER) { - return "Contradiction must be a white or a numbered cell"; + return super.getInvalidUseOfContradictionMessage() + ": " + this.INVALID_USE_MESSAGE; } DisjointSets regions = NurikabeUtilities.getPossibleWhiteRegions(nurikabeBoard); @@ -50,6 +53,6 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { // System.err.println("Cell Value: " + numberedCell.getData() + ", Loc: " + cell.getLocation() + ", region: " + whiteRegion.size()); return null; } - return "Does not contain a contradiction at this index"; + return super.getNoContradictionMessage() + ": " + this.NO_CONTRADICTION_MESSAGE; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooManySpacesContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooManySpacesContradictionRule.java index d7be638ca..d6355f988 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooManySpacesContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooManySpacesContradictionRule.java @@ -14,6 +14,9 @@ public class TooManySpacesContradictionRule extends ContradictionRule { + private final String NO_CONTRADICTION_MESSAGE = "Does not contain a contradiction at this index"; + private final String INVALID_USE_MESSAGE = "Contradiction must be a white or a numbered cell"; + public TooManySpacesContradictionRule() { super("Too Many Spaces", "A region cannot contain more spaces than its number.", @@ -34,7 +37,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { NurikabeCell cell = (NurikabeCell) nurikabeBoard.getPuzzleElement(puzzleElement); if (cell.getType() != NurikabeType.WHITE && cell.getType() != NurikabeType.NUMBER) { - return "Contradiction must be a white or a numbered cell"; + return super.getInvalidUseOfContradictionMessage() + ": " + this.INVALID_USE_MESSAGE; } DisjointSets regions = NurikabeUtilities.getNurikabeRegions(nurikabeBoard); @@ -51,6 +54,6 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { return null; } } - return "Does not contain a contradiction at this index"; + return super.getNoContradictionMessage() + ":" + this.NO_CONTRADICTION_MESSAGE; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRule_Generic.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRule_Generic.java index 286eded0c..ba7988887 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRule_Generic.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRule_Generic.java @@ -14,11 +14,13 @@ public abstract class BasicRule_Generic extends BasicRule { final ContradictionRule CORRESPONDING_CONTRADICTION_RULE; final boolean ELIMINATION_RULE; + final String INVALID_USE_MESSAGE; public BasicRule_Generic(String ruleName, String description, String imageName, ContradictionRule contraRule, boolean eliminationRule){ super(ruleName, description, "edu/rpi/legup/images/shorttruthtable/ruleimages/basic/"+imageName+".png"); this.CORRESPONDING_CONTRADICTION_RULE = contraRule; this.ELIMINATION_RULE = eliminationRule; + this.INVALID_USE_MESSAGE = "Invalid use of " + this.ruleName; } public String checkRuleRawAt(TreeTransition transition, PuzzleElement element) @@ -47,13 +49,13 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement element) System.out.println("ELIMINATION RULE CONTRADICTION MESSAGE: " + contradictionMessage); if (contradictionMessage != null) { - if (contradictionMessage.equals("This cell does not match any contradiction patterns for this rule")) // <-- temporary, don't want to hardcode that string + if (contradictionMessage.equals(CORRESPONDING_CONTRADICTION_RULE.getNoContradictionMessage())) return null; else return contradictionMessage; } else - return "Invalid use of " + this.ruleName; + return this.INVALID_USE_MESSAGE; } else { diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRule_GenericStatement.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRule_GenericStatement.java index 7fe36cfba..0df5b7908 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRule_GenericStatement.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRule_GenericStatement.java @@ -89,16 +89,6 @@ public String checkContradictionAt(Board puzzleBoard, PuzzleElement puzzleElemen return this.NO_CONTRADICTION_MESSAGE; } - public String getNotRightOperatorErrorMessage() - { - return this.NOT_RIGHT_OPERATOR_ERROR_MESSAGE; - } - - public String getNotTrueFalseErrorMessage() - { - return this.NOT_TRUE_FALSE_ERROR_MESSAGE; - } - public String getNoContradictionMessage() { return this.NO_CONTRADICTION_MESSAGE; From 0172745ddaadad3a84dc3f4f2bbc8fd8fc1826e2 Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 2 Jan 2022 10:57:03 -0500 Subject: [PATCH 03/14] Generalized error message Moved the invalid use error message to the general Rule class --- .../legup/model/rules/ContradictionRule.java | 6 ---- .../java/edu/rpi/legup/model/rules/Rule.java | 8 ++++++ .../rules/BlackSquareContradictionRule.java | 2 +- .../CantReachWhiteContradictionRule.java | 2 +- .../rules/IsolateBlackContradictionRule.java | 2 +- .../MultipleNumbersContradictionRule.java | 2 +- .../rules/NoNumberContradictionRule.java | 4 +-- .../rules/TooFewSpacesContradictionRule.java | 2 +- .../rules/TooManySpacesContradictionRule.java | 2 +- .../rules/basic/BasicRule_Generic.java | 8 ++---- .../ContradictionRule_GenericStatement.java | 28 +++---------------- 11 files changed, 23 insertions(+), 43 deletions(-) diff --git a/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java b/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java index 36b15ec8d..e548f0b05 100644 --- a/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java @@ -9,7 +9,6 @@ public abstract class ContradictionRule extends Rule { private final String NO_CONTRADICTION_MESSAGE = "No instance of " + this.ruleName; - private final String INVALID_USE_MESSAGE = "Invalid use of " + this.ruleName; /** * ContradictionRule Constructor creates a new contradiction rule @@ -96,11 +95,6 @@ public String getNoContradictionMessage() return this.NO_CONTRADICTION_MESSAGE; } - public String getInvalidUseOfContradictionMessage() - { - return this.INVALID_USE_MESSAGE; - } - /** * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule * diff --git a/src/main/java/edu/rpi/legup/model/rules/Rule.java b/src/main/java/edu/rpi/legup/model/rules/Rule.java index bcec08dba..57fc345c7 100644 --- a/src/main/java/edu/rpi/legup/model/rules/Rule.java +++ b/src/main/java/edu/rpi/legup/model/rules/Rule.java @@ -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 * @@ -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 " + this.ruleName; loadImage(); } @@ -140,4 +143,9 @@ public ImageIcon getImageIcon() { public RuleType getRuleType() { return ruleType; } + + public String getInvalidUseOfRuleMessage() + { + return this.INVALID_USE_MESSAGE; + } } \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackSquareContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackSquareContradictionRule.java index 62bca55e4..dbf9ac89e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackSquareContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackSquareContradictionRule.java @@ -35,7 +35,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { NurikabeCell cell = (NurikabeCell) nurikabeBoard.getPuzzleElement(puzzleElement); if (cell.getType() != NurikabeType.BLACK) { - return super.getInvalidUseOfContradictionMessage() + ": " + this.INVALID_USE_MESSAGE; + return super.getInvalidUseOfRuleMessage() + ": " + this.INVALID_USE_MESSAGE; } for (int x = cell.getLocation().x - 1; x >= 0 && x < cell.getLocation().x + 1 && x < width - 1; x++) { diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CantReachWhiteContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CantReachWhiteContradictionRule.java index 00ef8a608..be680e7c2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CantReachWhiteContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CantReachWhiteContradictionRule.java @@ -36,7 +36,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { NurikabeCell cell = (NurikabeCell) nurikabeBoard.getPuzzleElement(puzzleElement); if (cell.getType() != NurikabeType.WHITE) { - return super.getInvalidUseOfContradictionMessage() + ": " + this.INVALID_USE_MESSAGE; + return super.getInvalidUseOfRuleMessage() + ": " + this.INVALID_USE_MESSAGE; } ArrayList> regions = NurikabeUtilities.getFloodFillWhite(nurikabeBoard); diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/IsolateBlackContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/IsolateBlackContradictionRule.java index 56fcb6a83..bc713f3ad 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/IsolateBlackContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/IsolateBlackContradictionRule.java @@ -35,7 +35,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { NurikabeBoard nurikabeBoard = (NurikabeBoard) board; NurikabeCell cell = (NurikabeCell) nurikabeBoard.getPuzzleElement(puzzleElement); if (cell.getType() != NurikabeType.BLACK) { - return super.getInvalidUseOfContradictionMessage() + ": " + this.INVALID_USE_MESSAGE; + return super.getInvalidUseOfRuleMessage() + ": " + this.INVALID_USE_MESSAGE; } DisjointSets blackRegions = NurikabeUtilities.getPossibleBlackRegions(nurikabeBoard); diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/MultipleNumbersContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/MultipleNumbersContradictionRule.java index 41b560f0d..1fcc72f25 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/MultipleNumbersContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/MultipleNumbersContradictionRule.java @@ -36,7 +36,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { NurikabeCell cell = (NurikabeCell) nurikabeBoard.getPuzzleElement(puzzleElement); if (cell.getType() != NurikabeType.NUMBER) { - return super.getInvalidUseOfContradictionMessage() + ": " + INVALID_USE_MESSAGE; + return super.getInvalidUseOfRuleMessage() + ": " + INVALID_USE_MESSAGE; } DisjointSets regions = NurikabeUtilities.getNurikabeRegions(nurikabeBoard); Set numberedRegion = regions.getSet(cell); diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/NoNumberContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/NoNumberContradictionRule.java index f26c67308..dfcf5aef8 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/NoNumberContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/NoNumberContradictionRule.java @@ -37,7 +37,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { NurikabeCell cell = (NurikabeCell) nurikabeBoard.getPuzzleElement(puzzleElement); if (cell.getType() != NurikabeType.WHITE) { - return super.getInvalidUseOfContradictionMessage() + ": " + this.INVALID_USE_MESSAGE; + return super.getInvalidUseOfRuleMessage() + ": " + this.INVALID_USE_MESSAGE; } DisjointSets regions = NurikabeUtilities.getNurikabeRegions(nurikabeBoard); Set whiteRegion = regions.getSet(cell); @@ -54,7 +54,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { NurikabeCell bottom = nurikabeBoard.getCell(c.getLocation().x, c.getLocation().y-1); if (isEmptyCell(top) || isEmptyCell(left) || isEmptyCell(right) || isEmptyCell(bottom)) - return super.getInvalidUseOfContradictionMessage() + ": " + this.NOT_SURROUNDED_BY_BLACK_MESSAGE; + return super.getInvalidUseOfRuleMessage() + ": " + this.NOT_SURROUNDED_BY_BLACK_MESSAGE; } return null; } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooFewSpacesContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooFewSpacesContradictionRule.java index 9eb5711ce..6593f8ea2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooFewSpacesContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooFewSpacesContradictionRule.java @@ -36,7 +36,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { NurikabeCell cell = (NurikabeCell) nurikabeBoard.getPuzzleElement(puzzleElement); if (cell.getType() != NurikabeType.WHITE && cell.getType() != NurikabeType.NUMBER) { - return super.getInvalidUseOfContradictionMessage() + ": " + this.INVALID_USE_MESSAGE; + return super.getInvalidUseOfRuleMessage() + ": " + this.INVALID_USE_MESSAGE; } DisjointSets regions = NurikabeUtilities.getPossibleWhiteRegions(nurikabeBoard); diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooManySpacesContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooManySpacesContradictionRule.java index d6355f988..95d706485 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooManySpacesContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/TooManySpacesContradictionRule.java @@ -37,7 +37,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { NurikabeCell cell = (NurikabeCell) nurikabeBoard.getPuzzleElement(puzzleElement); if (cell.getType() != NurikabeType.WHITE && cell.getType() != NurikabeType.NUMBER) { - return super.getInvalidUseOfContradictionMessage() + ": " + this.INVALID_USE_MESSAGE; + return super.getInvalidUseOfRuleMessage() + ": " + this.INVALID_USE_MESSAGE; } DisjointSets regions = NurikabeUtilities.getNurikabeRegions(nurikabeBoard); diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRule_Generic.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRule_Generic.java index ba7988887..3fe6b2185 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRule_Generic.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRule_Generic.java @@ -14,13 +14,11 @@ public abstract class BasicRule_Generic extends BasicRule { final ContradictionRule CORRESPONDING_CONTRADICTION_RULE; final boolean ELIMINATION_RULE; - final String INVALID_USE_MESSAGE; public BasicRule_Generic(String ruleName, String description, String imageName, ContradictionRule contraRule, boolean eliminationRule){ super(ruleName, description, "edu/rpi/legup/images/shorttruthtable/ruleimages/basic/"+imageName+".png"); this.CORRESPONDING_CONTRADICTION_RULE = contraRule; this.ELIMINATION_RULE = eliminationRule; - this.INVALID_USE_MESSAGE = "Invalid use of " + this.ruleName; } public String checkRuleRawAt(TreeTransition transition, PuzzleElement element) @@ -49,13 +47,13 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement element) System.out.println("ELIMINATION RULE CONTRADICTION MESSAGE: " + contradictionMessage); if (contradictionMessage != null) { - if (contradictionMessage.equals(CORRESPONDING_CONTRADICTION_RULE.getNoContradictionMessage())) + if (contradictionMessage.startsWith(CORRESPONDING_CONTRADICTION_RULE.getNoContradictionMessage())) return null; else - return contradictionMessage; + return super.getInvalidUseOfRuleMessage() + ": " + contradictionMessage; } else - return this.INVALID_USE_MESSAGE; + return super.getInvalidUseOfRuleMessage(); } else { diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRule_GenericStatement.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRule_GenericStatement.java index 0df5b7908..c723a4c01 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRule_GenericStatement.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRule_GenericStatement.java @@ -10,8 +10,6 @@ import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableStatement; -import java.util.Arrays; - public abstract class ContradictionRule_GenericStatement extends ContradictionRule{ @@ -25,7 +23,6 @@ public abstract class ContradictionRule_GenericStatement extends ContradictionRu private final String NOT_RIGHT_OPERATOR_ERROR_MESSAGE = "This cell does not contain the correct operation"; private final String NOT_TRUE_FALSE_ERROR_MESSAGE = "Can only check for a contradiction on a cell that is assigned a value of True or False"; - private final String NO_CONTRADICTION_MESSAGE = "This cell does not match any contradiction patterns for this rule"; public ContradictionRule_GenericStatement(String ruleName, String description, String imageName, char operationSymbol, ShortTruthTableCellType[][] contradictionPatterns){ @@ -43,31 +40,22 @@ public String checkContradictionAt(Board puzzleBoard, PuzzleElement puzzleElemen //get the cell that contradicts another cell in the board ShortTruthTableCell cell = board.getCellFromElement(puzzleElement); ShortTruthTableStatement statement = cell.getStatementReference(); - ShortTruthTableStatement parentStatement = statement.getParentStatement(); - System.out.println("Statement: " + statement); - //must be the correct statement - System.out.println("Symbol: " + cell.getSymbol()); - - // ISSUE: IT SEEMS TO BE THAT puzzleElement IS EXPECTED TO BE THE OPERATOR if(cell.getSymbol() != this.operationSymbol) - return this.NOT_RIGHT_OPERATOR_ERROR_MESSAGE; + return super.getInvalidUseOfRuleMessage() + ": " + this.NOT_RIGHT_OPERATOR_ERROR_MESSAGE; //check that the initial statement is assigned ShortTruthTableCellType cellType = cell.getType(); System.out.println("contra rule generic cell: "+cell); if(!cellType.isTrueOrFalse()) - return this.NOT_TRUE_FALSE_ERROR_MESSAGE; + return super.getInvalidUseOfRuleMessage() + ": " + this.NOT_TRUE_FALSE_ERROR_MESSAGE; //get the pattern for this sub-statement ShortTruthTableCellType[] testPattern = statement.getCellTypePattern(); //if the board pattern matches any contradiction pattern, it is a valid contradiction - System.out.println("Name: " + this.ruleName); - System.out.println("Testing pattern: "+Arrays.toString(testPattern)); for(ShortTruthTableCellType[] pattern : contradictionPatterns){ - System.out.println("Comparing to: "+Arrays.toString(pattern)); boolean matches = true; for(int i = 0; i<3; i++){ //null means that part does not affect the statement @@ -79,18 +67,10 @@ public String checkContradictionAt(Board puzzleBoard, PuzzleElement puzzleElemen } } //if testPattern matches one of the valid contradiction patterns, the contradiction is correct - if(matches){ - System.out.println("This is a valid contradiction: matches pat: "+Arrays.toString(pattern)); + if (matches) return null; - } } - System.out.println("No patterns match. There is not a contradiction"); - return this.NO_CONTRADICTION_MESSAGE; - } - - public String getNoContradictionMessage() - { - return this.NO_CONTRADICTION_MESSAGE; + return super.getNoContradictionMessage(); } } \ No newline at end of file From 32b3d43246b191cabda39b724b35951b03bbec2f Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 2 Jan 2022 19:50:59 -0500 Subject: [PATCH 04/14] Case rule invalid use error message --- src/main/java/edu/rpi/legup/model/rules/CaseRule.java | 2 +- .../puzzle/shorttruthtable/rules/caserule/CaseRule_Generic.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/edu/rpi/legup/model/rules/CaseRule.java b/src/main/java/edu/rpi/legup/model/rules/CaseRule.java index 1390997ca..e156d1c83 100644 --- a/src/main/java/edu/rpi/legup/model/rules/CaseRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/CaseRule.java @@ -103,7 +103,7 @@ public String checkRule(TreeTransition transition) { */ @Override public String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement) { - return null; + return super.getInvalidUseOfRuleMessage(); } /** diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRule_Generic.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRule_Generic.java index dd6a46417..c5c3c3d2a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRule_Generic.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRule_Generic.java @@ -31,7 +31,6 @@ public CaseRule_Generic(String ruleName, String title, String description) { */ @Override public String checkRuleRaw(TreeTransition transition) { - return null; } From 4820f6699282cbea13b188d251a0d7121fe6a11e Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 3 Jan 2022 12:57:36 -0500 Subject: [PATCH 05/14] Update CaseRule.java Adjusted the invalid use message for case rules --- src/main/java/edu/rpi/legup/model/rules/CaseRule.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/rpi/legup/model/rules/CaseRule.java b/src/main/java/edu/rpi/legup/model/rules/CaseRule.java index e156d1c83..e35af502c 100644 --- a/src/main/java/edu/rpi/legup/model/rules/CaseRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/CaseRule.java @@ -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. * @@ -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; } /** @@ -103,7 +107,7 @@ public String checkRule(TreeTransition transition) { */ @Override public String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement) { - return super.getInvalidUseOfRuleMessage(); + return this.INVALID_USE_MESSAGE; } /** From 4fceb23affb2bd883274ef4181f57e51d5b01f9b Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 3 Jan 2022 13:24:07 -0500 Subject: [PATCH 06/14] Nurikabe error messages Implemented Nurikabe error messages and adjusted global error message wordings --- .../java/edu/rpi/legup/model/rules/ContradictionRule.java | 4 ++-- src/main/java/edu/rpi/legup/model/rules/Rule.java | 2 +- .../lightup/rules/BulbsInPathContradictionRule.java | 4 ++-- .../lightup/rules/CannotLightACellContradictionRule.java | 4 ++-- .../puzzle/lightup/rules/EmptyCellinLightBasicRule.java | 2 +- .../legup/puzzle/lightup/rules/EmptyCornersBasicRule.java | 6 +++--- .../puzzle/lightup/rules/FinishWithBulbsBasicRule.java | 6 +++--- .../puzzle/lightup/rules/FinishWithEmptyBasicRule.java | 4 ++-- .../legup/puzzle/lightup/rules/LightOrEmptyCaseRule.java | 8 ++++---- .../legup/puzzle/lightup/rules/MustLightBasicRule.java | 4 ++-- .../legup/puzzle/lightup/rules/SatisfyNumberCaseRule.java | 4 ++-- .../lightup/rules/TooFewBulbsContradictionRule.java | 6 ++---- .../lightup/rules/TooManyBulbsContradictionRule.java | 4 ++-- 13 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java b/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java index e548f0b05..d56cd37db 100644 --- a/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java @@ -8,7 +8,7 @@ public abstract class ContradictionRule extends Rule { - private final String NO_CONTRADICTION_MESSAGE = "No instance of " + this.ruleName; + private final String NO_CONTRADICTION_MESSAGE = "No instance of the contradiction " + this.ruleName + " here"; /** * ContradictionRule Constructor creates a new contradiction rule @@ -87,7 +87,7 @@ public String checkContradiction(Board board) { return checkStr; } } - return "Does not contain a contradiction"; + return this.NO_CONTRADICTION_MESSAGE; } public String getNoContradictionMessage() diff --git a/src/main/java/edu/rpi/legup/model/rules/Rule.java b/src/main/java/edu/rpi/legup/model/rules/Rule.java index 57fc345c7..bd8eb13d3 100644 --- a/src/main/java/edu/rpi/legup/model/rules/Rule.java +++ b/src/main/java/edu/rpi/legup/model/rules/Rule.java @@ -32,7 +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 " + this.ruleName; + this.INVALID_USE_MESSAGE = "Invalid use of the rule " + this.ruleName; loadImage(); } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/BulbsInPathContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/BulbsInPathContradictionRule.java index 93e7ff03e..3b05552ea 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/BulbsInPathContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/BulbsInPathContradictionRule.java @@ -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(); @@ -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(); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/CannotLightACellContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/CannotLightACellContradictionRule.java index 88d2f8788..ef8f000f4 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/CannotLightACellContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/CannotLightACellContradictionRule.java @@ -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; @@ -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(); } } \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCellinLightBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCellinLightBasicRule.java index b488b224b..268f8d9ab 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCellinLightBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCellinLightBasicRule.java @@ -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"; } /** diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCornersBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCornersBasicRule.java index 9aa3cb19b..0cc02cf86 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCornersBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCornersBasicRule.java @@ -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(); @@ -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(); @@ -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"; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithBulbsBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithBulbsBasicRule.java index e378812eb..a2d6ed3d0 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithBulbsBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithBulbsBasicRule.java @@ -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 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(); @@ -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) { diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithEmptyBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithEmptyBasicRule.java index bbd68ec1e..292b3cfc2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithEmptyBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithEmptyBasicRule.java @@ -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) { diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/LightOrEmptyCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/LightOrEmptyCaseRule.java index 2dc7df88f..40a5f3a98 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/LightOrEmptyCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/LightOrEmptyCaseRule.java @@ -68,25 +68,25 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { public String checkRuleRaw(TreeTransition transition) { List 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; diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/MustLightBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/MustLightBasicRule.java index f545a80c1..685f380bf 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/MustLightBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/MustLightBasicRule.java @@ -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); @@ -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"; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/SatisfyNumberCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/SatisfyNumberCaseRule.java index 5f9d84287..ad9fac1ca 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/SatisfyNumberCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/SatisfyNumberCaseRule.java @@ -163,7 +163,7 @@ public String checkRuleRaw(TreeTransition transition) { List 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) { @@ -211,7 +211,7 @@ public String checkRuleRaw(TreeTransition transition) { } } } - return "This case rule is not valid"; + return super.getInvalidUseOfRuleMessage(); } /** diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooFewBulbsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooFewBulbsContradictionRule.java index 329b08e42..7f5fa6b9b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooFewBulbsContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooFewBulbsContradictionRule.java @@ -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(); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooManyBulbsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooManyBulbsContradictionRule.java index 658d016a0..0722ededa 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooManyBulbsContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooManyBulbsContradictionRule.java @@ -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(); @@ -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(); } } From c57d2c32614fa5b74fdeda2eca757ba54ecfde2f Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 3 Jan 2022 13:24:07 -0500 Subject: [PATCH 07/14] Light Up error messages Implemented Light Up error messages and adjusted global error message wordings --- .../java/edu/rpi/legup/model/rules/ContradictionRule.java | 4 ++-- src/main/java/edu/rpi/legup/model/rules/Rule.java | 2 +- .../lightup/rules/BulbsInPathContradictionRule.java | 4 ++-- .../lightup/rules/CannotLightACellContradictionRule.java | 4 ++-- .../puzzle/lightup/rules/EmptyCellinLightBasicRule.java | 2 +- .../legup/puzzle/lightup/rules/EmptyCornersBasicRule.java | 6 +++--- .../puzzle/lightup/rules/FinishWithBulbsBasicRule.java | 6 +++--- .../puzzle/lightup/rules/FinishWithEmptyBasicRule.java | 4 ++-- .../legup/puzzle/lightup/rules/LightOrEmptyCaseRule.java | 8 ++++---- .../legup/puzzle/lightup/rules/MustLightBasicRule.java | 4 ++-- .../legup/puzzle/lightup/rules/SatisfyNumberCaseRule.java | 4 ++-- .../lightup/rules/TooFewBulbsContradictionRule.java | 6 ++---- .../lightup/rules/TooManyBulbsContradictionRule.java | 4 ++-- 13 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java b/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java index e548f0b05..d56cd37db 100644 --- a/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java @@ -8,7 +8,7 @@ public abstract class ContradictionRule extends Rule { - private final String NO_CONTRADICTION_MESSAGE = "No instance of " + this.ruleName; + private final String NO_CONTRADICTION_MESSAGE = "No instance of the contradiction " + this.ruleName + " here"; /** * ContradictionRule Constructor creates a new contradiction rule @@ -87,7 +87,7 @@ public String checkContradiction(Board board) { return checkStr; } } - return "Does not contain a contradiction"; + return this.NO_CONTRADICTION_MESSAGE; } public String getNoContradictionMessage() diff --git a/src/main/java/edu/rpi/legup/model/rules/Rule.java b/src/main/java/edu/rpi/legup/model/rules/Rule.java index 57fc345c7..bd8eb13d3 100644 --- a/src/main/java/edu/rpi/legup/model/rules/Rule.java +++ b/src/main/java/edu/rpi/legup/model/rules/Rule.java @@ -32,7 +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 " + this.ruleName; + this.INVALID_USE_MESSAGE = "Invalid use of the rule " + this.ruleName; loadImage(); } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/BulbsInPathContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/BulbsInPathContradictionRule.java index 93e7ff03e..3b05552ea 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/BulbsInPathContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/BulbsInPathContradictionRule.java @@ -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(); @@ -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(); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/CannotLightACellContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/CannotLightACellContradictionRule.java index 88d2f8788..ef8f000f4 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/CannotLightACellContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/CannotLightACellContradictionRule.java @@ -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; @@ -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(); } } \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCellinLightBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCellinLightBasicRule.java index b488b224b..268f8d9ab 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCellinLightBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCellinLightBasicRule.java @@ -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"; } /** diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCornersBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCornersBasicRule.java index 9aa3cb19b..0cc02cf86 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCornersBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCornersBasicRule.java @@ -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(); @@ -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(); @@ -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"; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithBulbsBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithBulbsBasicRule.java index e378812eb..a2d6ed3d0 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithBulbsBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithBulbsBasicRule.java @@ -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 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(); @@ -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) { diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithEmptyBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithEmptyBasicRule.java index bbd68ec1e..292b3cfc2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithEmptyBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithEmptyBasicRule.java @@ -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) { diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/LightOrEmptyCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/LightOrEmptyCaseRule.java index 2dc7df88f..40a5f3a98 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/LightOrEmptyCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/LightOrEmptyCaseRule.java @@ -68,25 +68,25 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { public String checkRuleRaw(TreeTransition transition) { List 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; diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/MustLightBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/MustLightBasicRule.java index f545a80c1..685f380bf 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/MustLightBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/MustLightBasicRule.java @@ -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); @@ -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"; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/SatisfyNumberCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/SatisfyNumberCaseRule.java index 5f9d84287..ad9fac1ca 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/SatisfyNumberCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/SatisfyNumberCaseRule.java @@ -163,7 +163,7 @@ public String checkRuleRaw(TreeTransition transition) { List 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) { @@ -211,7 +211,7 @@ public String checkRuleRaw(TreeTransition transition) { } } } - return "This case rule is not valid"; + return super.getInvalidUseOfRuleMessage(); } /** diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooFewBulbsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooFewBulbsContradictionRule.java index 329b08e42..7f5fa6b9b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooFewBulbsContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooFewBulbsContradictionRule.java @@ -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(); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooManyBulbsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooManyBulbsContradictionRule.java index 658d016a0..0722ededa 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooManyBulbsContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/TooManyBulbsContradictionRule.java @@ -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(); @@ -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(); } } From fb9e99ec43cbf3a998bc26e7e6d8340cecdefd48 Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 3 Jan 2022 13:34:03 -0500 Subject: [PATCH 08/14] Fillapix error messages Implemented standardized error messages for Fillapix --- .../legup/puzzle/fillapix/rules/BlackOrWhiteCaseRule.java | 8 ++++---- .../puzzle/fillapix/rules/FinishWithBlackBasicRule.java | 4 ++-- .../puzzle/fillapix/rules/FinishWithWhiteBasicRule.java | 4 ++-- .../fillapix/rules/TooFewBlackCellsContradictionRule.java | 2 +- .../rules/TooManyBlackCellsContradictionRule.java | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/BlackOrWhiteCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/BlackOrWhiteCaseRule.java index 7d37a3c76..4d4715b39 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/BlackOrWhiteCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/BlackOrWhiteCaseRule.java @@ -56,25 +56,25 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { public String checkRuleRaw(TreeTransition transition) { List 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; diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithBlackBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithBlackBasicRule.java index e39fbd9ca..4fde78a81 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithBlackBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithBlackBasicRule.java @@ -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"; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithWhiteBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithWhiteBasicRule.java index 0fbc3826f..5cc015b31 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithWhiteBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithWhiteBasicRule.java @@ -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"; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TooFewBlackCellsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TooFewBlackCellsContradictionRule.java index 0a3b68e2b..5cc280984 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TooFewBlackCellsContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TooFewBlackCellsContradictionRule.java @@ -46,6 +46,6 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { } } } - return "Board does not contain a contradiction"; + return super.getNoContradictionMessage(); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TooManyBlackCellsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TooManyBlackCellsContradictionRule.java index b4cd2c31b..4ee1a96d3 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TooManyBlackCellsContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TooManyBlackCellsContradictionRule.java @@ -45,6 +45,6 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { } } } - return "Board does not contain a contradiction"; + return super.getNoContradictionMessage(); } } From 4088919b212d05368c786665dcf850af4abfa4fa Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 3 Jan 2022 13:38:23 -0500 Subject: [PATCH 09/14] Short Truth Table error messages fix Fixed one of the error messages for Short Truth Table --- .../puzzle/shorttruthtable/rules/basic/BasicRule_Generic.java | 4 ++-- .../rules/caserule/CaseRule_GenericStatement.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRule_Generic.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRule_Generic.java index 3fe6b2185..06e6b2809 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRule_Generic.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/BasicRule_Generic.java @@ -31,7 +31,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement element) // System.out.println("Check Basic Rule Generic: "+cell); if (!cell.isAssigned()) - return "Only assigned cells are allowed for basic rules"; + return super.getInvalidUseOfRuleMessage() + ": Only assigned cells are allowed for basic rules"; // Get the original board ShortTruthTableBoard originalBoard = (ShortTruthTableBoard) transition.getParents().get(0).getBoard(); @@ -44,7 +44,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement element) PuzzleElement checkElement = cell.getStatementReference().getParentStatement().getCell(); String contradictionMessage = CORRESPONDING_CONTRADICTION_RULE.checkContradictionAt(originalBoard, checkElement); - System.out.println("ELIMINATION RULE CONTRADICTION MESSAGE: " + contradictionMessage); +// System.out.println("ELIMINATION RULE CONTRADICTION MESSAGE: " + contradictionMessage); if (contradictionMessage != null) { if (contradictionMessage.startsWith(CORRESPONDING_CONTRADICTION_RULE.getNoContradictionMessage())) diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRule_GenericStatement.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRule_GenericStatement.java index 8b233c6e9..b591492dd 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRule_GenericStatement.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRule_GenericStatement.java @@ -20,7 +20,7 @@ public CaseRule_GenericStatement(char operation, String title, ShortTruthTableCellType[][] falseCases) { super(ShortTruthTableOperation.getRuleName(operation), title+" case", - "A known "+title.toUpperCase()+" statment can have multiple forms"); + "A known "+title.toUpperCase()+" statement can have multiple forms"); this.operation = operation; From 5f7d71146df6b1d13337fe4498a9bdab1b92e2aa Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 3 Jan 2022 13:47:17 -0500 Subject: [PATCH 10/14] Skyscrapers error messages Standardized error messages for Skyscrapers --- .../rules/DuplicateNumberContradictionRule.java | 2 +- .../rules/ExceedingVisibilityContradictionRule.java | 2 +- .../legup/puzzle/skyscrapers/rules/FixedMaxBasicRule.java | 8 ++++---- .../rules/InsufficientVisibilityContradictionRule.java | 2 +- .../legup/puzzle/skyscrapers/rules/LastCellBasicRule.java | 8 ++++---- .../puzzle/skyscrapers/rules/LastNumberBasicRule.java | 6 +++--- .../legup/puzzle/skyscrapers/rules/NEdgeBasicRule.java | 6 +++--- .../legup/puzzle/skyscrapers/rules/OneEdgeBasicRule.java | 6 +++--- .../skyscrapers/rules/PossibleContentsCaseRule.java | 6 +++--- .../rules/UnresolvedCellContradictionRule.java | 2 +- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/DuplicateNumberContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/DuplicateNumberContradictionRule.java index 82f08ce32..0e92bd9b7 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/DuplicateNumberContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/DuplicateNumberContradictionRule.java @@ -55,6 +55,6 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { } } - return "Does not contain a contradiction at this index"; + return super.getNoContradictionMessage(); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/ExceedingVisibilityContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/ExceedingVisibilityContradictionRule.java index 2e891d231..b7d6c1ebd 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/ExceedingVisibilityContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/ExceedingVisibilityContradictionRule.java @@ -118,6 +118,6 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { } //System.out.print("Does not contain a contradiction at this index"); - return "Does not contain a contradiction at this index"; + return super.getNoContradictionMessage(); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/FixedMaxBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/FixedMaxBasicRule.java index 269bd5359..a48717b2f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/FixedMaxBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/FixedMaxBasicRule.java @@ -38,7 +38,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); SkyscrapersCell finalCell = (SkyscrapersCell) finalBoard.getPuzzleElement(puzzleElement); if (!(initCell.getType() == SkyscrapersType.UNKNOWN && finalCell.getType() == SkyscrapersType.Number)) { - return "Modified cells must be number"; + return super.getInvalidUseOfRuleMessage() + ": Modified cells must be number"; } SkyscrapersBoard emptyCase = initialBoard.copy(); @@ -53,11 +53,11 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem System.out.println(south); if (north + south != max + 1 && west + east != max + 1) { System.out.println("111"); - return "Opposing clues must add up to max"; + return super.getInvalidUseOfRuleMessage() + ": Opposing clues must add up to max"; } if (finalCell.getData() != initialBoard.getWidth()) { - return "Modified cells must be the max"; + return super.getInvalidUseOfRuleMessage() + ": Modified cells must be the max"; } if (north + south == max + 1 && loc.y + 1 == north) { @@ -67,7 +67,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem return null; } - return "This cell is not forced."; + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced."; } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/InsufficientVisibilityContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/InsufficientVisibilityContradictionRule.java index 452ea1cc5..49f9ba689 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/InsufficientVisibilityContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/InsufficientVisibilityContradictionRule.java @@ -118,6 +118,6 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { } //System.out.print("Does not contain a contradiction at this index"); - return "Does not contain a contradiction at this index"; + return super.getNoContradictionMessage(); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastCellBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastCellBasicRule.java index fff63fb80..44210fcaa 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastCellBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastCellBasicRule.java @@ -38,7 +38,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); SkyscrapersCell finalCell = (SkyscrapersCell) finalBoard.getPuzzleElement(puzzleElement); if (!(initCell.getType() == SkyscrapersType.UNKNOWN && finalCell.getType() == SkyscrapersType.Number)) { - return "Modified cells must be number"; + return super.getInvalidUseOfRuleMessage() + ": Modified cells must be number"; } SkyscrapersBoard emptyCase = initialBoard.copy(); @@ -64,7 +64,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem if (it.next() == finalCell.getData()) { return null; } - return "Wrong number in the cell."; + return super.getInvalidUseOfRuleMessage() + ": Wrong number in the cell."; } candidates.clear(); @@ -86,10 +86,10 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem if (it.next() == finalCell.getData()) { return null; } - return "Wrong number in the cell."; + return super.getInvalidUseOfRuleMessage() + ": Wrong number in the cell."; } - return "This cell is not forced."; + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced."; } private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastNumberBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastNumberBasicRule.java index 609fcb1b8..994589d73 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastNumberBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastNumberBasicRule.java @@ -38,7 +38,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); SkyscrapersCell finalCell = (SkyscrapersCell) finalBoard.getPuzzleElement(puzzleElement); if (!(initCell.getType() == SkyscrapersType.UNKNOWN && finalCell.getType() == SkyscrapersType.Number)) { - return "Modified cells must be number"; + return super.getInvalidUseOfRuleMessage() + ": Modified cells must be number"; } SkyscrapersBoard emptyCase = initialBoard.copy(); @@ -76,10 +76,10 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem if (it.next() == finalCell.getData()) { return null; } - return "Wrong number in the cell."; + return super.getInvalidUseOfRuleMessage() + ": Wrong number in the cell."; } - return "This cell is not forced."; + return super.getInvalidUseOfRuleMessage() + ":This cell is not forced."; } private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NEdgeBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NEdgeBasicRule.java index f75953891..bdbe1d69e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NEdgeBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NEdgeBasicRule.java @@ -18,7 +18,7 @@ public class NEdgeBasicRule extends BasicRule { public NEdgeBasicRule() { super("N Edge", - "If the maximum number appears on an edge, the row or column¡¯s numbers appear in ascending order, starting at that edge.", + "If the maximum number appears on an edge, the row or column��s numbers appear in ascending order, starting at that edge.", "edu/rpi/legup/images/skyscrapers/NEdge.png"); } @@ -38,7 +38,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); SkyscrapersCell finalCell = (SkyscrapersCell) finalBoard.getPuzzleElement(puzzleElement); if (!(initCell.getType() == SkyscrapersType.UNKNOWN && finalCell.getType() == SkyscrapersType.Number)) { - return "Modified cells must be number"; + return super.getInvalidUseOfRuleMessage() + ": Modified cells must be number"; } SkyscrapersBoard emptyCase = initialBoard.copy(); @@ -59,7 +59,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem return null; } - return "This cell is not forced."; + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced."; } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/OneEdgeBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/OneEdgeBasicRule.java index 012c67e42..669ff5141 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/OneEdgeBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/OneEdgeBasicRule.java @@ -38,7 +38,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); SkyscrapersCell finalCell = (SkyscrapersCell) finalBoard.getPuzzleElement(puzzleElement); if (!(initCell.getType() == SkyscrapersType.UNKNOWN && finalCell.getType() == SkyscrapersType.Number)) { - return "Modified cells must be number"; + return super.getInvalidUseOfRuleMessage() + ": Modified cells must be number"; } SkyscrapersBoard emptyCase = initialBoard.copy(); @@ -46,11 +46,11 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem Point loc = finalCell.getLocation(); if (loc.x != 0 && loc.x != initialBoard.getWidth() - 1 && loc.y != 0 && loc.y != initialBoard.getHeight() - 1) { - return "Modified cells must be on the edge"; + return super.getInvalidUseOfRuleMessage() + ": Modified cells must be on the edge"; } if (finalCell.getData() != initialBoard.getWidth()) { - return "Modified cells must be the max"; + return super.getInvalidUseOfRuleMessage() + ": Modified cells must be the max"; } if (loc.x == 0 && initialBoard.getRow().get(loc.y).getData() == 1) { diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/PossibleContentsCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/PossibleContentsCaseRule.java index 0b6b36d4d..1fcbaa9bf 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/PossibleContentsCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/PossibleContentsCaseRule.java @@ -103,16 +103,16 @@ public String checkRuleRaw(TreeTransition transition) { TreeTransition case2 = childTransitions.get(i); if (case2.getBoard().getModifiedData().size() != 1) { //System.out.println("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."; } SkyscrapersCell mod2 = (SkyscrapersCell) case2.getBoard().getModifiedData().iterator().next(); if (!mod1.getLocation().equals(mod2.getLocation())) { //System.out.println("2"); - 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 (!(mod2.getType() == SkyscrapersType.Number)) { //System.out.println("3"); - return "This case rule must asign a number."; + return super.getInvalidUseOfRuleMessage() + ": This case rule must assign a number."; } } //System.out.println("no contradiction"); diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/UnresolvedCellContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/UnresolvedCellContradictionRule.java index 699c7509e..f24891470 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/UnresolvedCellContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/UnresolvedCellContradictionRule.java @@ -60,6 +60,6 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { return null; } //System.out.print("Does not contain a contradiction at this index"); - return "Does not contain a contradiction at this index"; + return super.getNoContradictionMessage(); } } From 8788d92fcce3a0718b0fdf1a8866e1990332065e Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 3 Jan 2022 13:54:08 -0500 Subject: [PATCH 11/14] Sudoku error messages Standardized Sudoku error messages --- .../puzzle/sudoku/rules/AdvancedDeductionBasicRule.java | 6 +++--- .../puzzle/sudoku/rules/LastCellForNumberBasicRule.java | 4 ++-- .../puzzle/sudoku/rules/LastNumberForCellBasicRule.java | 4 ++-- .../puzzle/sudoku/rules/NoSolutionContradictionRule.java | 4 ++-- .../sudoku/rules/RepeatedNumberContradictionRule.java | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/AdvancedDeductionBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/AdvancedDeductionBasicRule.java index e3eed592f..5ddeec8ec 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/AdvancedDeductionBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/AdvancedDeductionBasicRule.java @@ -43,7 +43,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem for (int x = 0; x < groupDim; x++) { SudokuCell c = initialBoard.getCell(groupNum, x, y); if (c.getData() == cell.getData() && x != relX && y != relY) { - return "Duplicate value in sub region"; + return super.getRuleName() + ": Duplicate value in sub-region"; } possible[y][x] = c.getData() == 0; } @@ -70,12 +70,12 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem if (possible[y][x] && !isForced) { isForced = true; } else if (possible[y][x]) { - return "Not forced"; + return super.getInvalidUseOfRuleMessage() + ": Not forced"; } } } if (!isForced) { - return "Not forced"; + return super.getInvalidUseOfRuleMessage() + ": Not forced"; } return null; } diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/LastCellForNumberBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/LastCellForNumberBasicRule.java index ae4d41437..93106f84c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/LastCellForNumberBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/LastCellForNumberBasicRule.java @@ -32,7 +32,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem SudokuCell cell = (SudokuCell) finalBoard.getPuzzleElement(puzzleElement); if (cell.getData() == 0) { - return "cell is not forced at this index"; + return super.getInvalidUseOfRuleMessage() + ": Cell is not forced at this index"; } int size = initialBoard.getSize(); @@ -77,7 +77,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem return null; } } - return "cell is not forced at this index"; + return super.getInvalidUseOfRuleMessage() + ": Cell is not forced at this index"; } /** diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/LastNumberForCellBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/LastNumberForCellBasicRule.java index 110da2033..ca751f156 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/LastNumberForCellBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/LastNumberForCellBasicRule.java @@ -54,9 +54,9 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem numbers.remove(cell.getData()); } if (numbers.size() > 1) { - return "The number at the index is not forced"; + return super.getInvalidUseOfRuleMessage() + ": The number at the index is not forced"; } else if (numbers.size() == 1 && numbers.iterator().next() != finalBoard.getPuzzleElement(puzzleElement).getData()) { - return "The number at the index is forced but not correct"; + return super.getInvalidUseOfRuleMessage() + ": The number at the index is forced but not correct"; } return null; } diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/NoSolutionContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/NoSolutionContradictionRule.java index 589a13a2c..0f12636da 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/NoSolutionContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/NoSolutionContradictionRule.java @@ -30,7 +30,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { SudokuBoard sudokuBoard = (SudokuBoard) board; SudokuCell cell = (SudokuCell) sudokuBoard.getPuzzleElement(puzzleElement); if (cell.getData() != 0) { - return "Does not contain a contradiction at this index"; + return super.getNoContradictionMessage(); } int groupSize = sudokuBoard.getSize(); @@ -57,6 +57,6 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { return null; } - return "Does not contain a contradiction at this index"; + return super.getNoContradictionMessage(); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/RepeatedNumberContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/RepeatedNumberContradictionRule.java index 36979f10a..d0e96a7bc 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/RepeatedNumberContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/RepeatedNumberContradictionRule.java @@ -30,7 +30,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { SudokuBoard sudokuBoard = (SudokuBoard) board; SudokuCell cell = (SudokuCell) sudokuBoard.getPuzzleElement(puzzleElement); if (cell.getData() == 0) { - return "Does not contain a contradiction at this index"; + return super.getNoContradictionMessage(); } Set region = sudokuBoard.getRegion(cell.getGroupIndex()); @@ -62,6 +62,6 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { colDup.add(c.getData()); } - return "Does not contain a contradiction at this index"; + return super.getNoContradictionMessage(); } } From cbfec2dd5461cc04cf862943ec94a76ce26fdf81 Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 3 Jan 2022 14:10:38 -0500 Subject: [PATCH 12/14] Tree Tent error messages Standardized Tree Tent error messages --- .../puzzle/treetent/rules/EmptyFieldBasicRule.java | 4 ++-- .../treetent/rules/FinishWithGrassBasicRule.java | 6 +++--- .../treetent/rules/FinishWithTentsBasicRule.java | 6 +++--- .../treetent/rules/LastCampingSpotBasicRule.java | 6 +++--- .../puzzle/treetent/rules/LinkTreeCaseRule.java | 14 +++++++------- .../rules/NoTentForTreeContradictionRule.java | 4 ++-- .../rules/NoTreeForTentContradictionRule.java | 4 ++-- .../rules/SurroundTentWithGrassBasicRule.java | 6 +++--- .../treetent/rules/TentForTreeBasicRule.java | 6 +++--- .../puzzle/treetent/rules/TentOrGrassCaseRule.java | 8 ++++---- .../rules/TooFewTentsContradictionRule.java | 2 +- .../rules/TooManyTentsContradictionRule.java | 2 +- .../rules/TouchingTentsContradictionRule.java | 4 ++-- 13 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/EmptyFieldBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/EmptyFieldBasicRule.java index 0d3e7dde0..21e2e0286 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/EmptyFieldBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/EmptyFieldBasicRule.java @@ -31,7 +31,7 @@ public EmptyFieldBasicRule() { @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { if (puzzleElement instanceof TreeTentLine) { - return "Line is not valid for this rule."; + return super.getInvalidUseOfRuleMessage() + ": Line is not valid for this rule"; } TreeTentBoard initialBoard = (TreeTentBoard) transition.getParents().get(0).getBoard(); TreeTentCell initCell = (TreeTentCell) initialBoard.getPuzzleElement(puzzleElement); @@ -44,7 +44,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem if (isForced(finalBoard, finalCell)) { return null; } else { - return "This cell is not forced to be empty."; + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be empty."; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithGrassBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithGrassBasicRule.java index 8b139478e..5b004ac83 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithGrassBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithGrassBasicRule.java @@ -33,20 +33,20 @@ public FinishWithGrassBasicRule() { @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { if (puzzleElement instanceof TreeTentLine) { - return "Line is not valid for this rule."; + return super.getInvalidUseOfRuleMessage() + ": Line is not valid for this rule"; } TreeTentBoard initialBoard = (TreeTentBoard) transition.getParents().get(0).getBoard(); TreeTentCell initCell = (TreeTentCell) initialBoard.getPuzzleElement(puzzleElement); TreeTentBoard finalBoard = (TreeTentBoard) transition.getBoard(); TreeTentCell finalCell = (TreeTentCell) finalBoard.getPuzzleElement(puzzleElement); if (!(finalCell.getType() == TreeTentType.GRASS && initCell.getType() == TreeTentType.UNKNOWN)) { - return "This cell must be grass."; + return super.getInvalidUseOfRuleMessage() + ": This cell must be grass."; } if (isForced(initialBoard, initCell)) { return null; } else { - return "This cell is not forced to be grass."; + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be grass."; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithTentsBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithTentsBasicRule.java index fe06c5d45..d51943dc1 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithTentsBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithTentsBasicRule.java @@ -33,20 +33,20 @@ public FinishWithTentsBasicRule() { @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { if (puzzleElement instanceof TreeTentLine) { - return "Line is not valid for this rule."; + return super.getInvalidUseOfRuleMessage() + ": Line is not valid for this rule."; } TreeTentBoard initialBoard = (TreeTentBoard) transition.getParents().get(0).getBoard(); TreeTentCell initCell = (TreeTentCell) initialBoard.getPuzzleElement(puzzleElement); TreeTentBoard finalBoard = (TreeTentBoard) transition.getBoard(); TreeTentCell finalCell = (TreeTentCell) finalBoard.getPuzzleElement(puzzleElement); if (!(initCell.getType() == TreeTentType.UNKNOWN && finalCell.getType() == TreeTentType.TENT)) { - return "This cell must be a tent."; + return super.getInvalidUseOfRuleMessage() + ": This cell must be a tent."; } if (isForced(initialBoard, initCell)) { return null; } else { - return "This cell is not forced to be tent."; + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be tent."; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LastCampingSpotBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LastCampingSpotBasicRule.java index 9fe91550a..a6aa826ce 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LastCampingSpotBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LastCampingSpotBasicRule.java @@ -33,20 +33,20 @@ public LastCampingSpotBasicRule() { @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { if (puzzleElement instanceof TreeTentLine) { - return "Line is not valid for this rule."; + return super.getInvalidUseOfRuleMessage() + ": Line is not valid for this rule."; } TreeTentBoard initialBoard = (TreeTentBoard) transition.getParents().get(0).getBoard(); TreeTentCell initCell = (TreeTentCell) initialBoard.getPuzzleElement(puzzleElement); TreeTentBoard finalBoard = (TreeTentBoard) transition.getBoard(); TreeTentCell finalCell = (TreeTentCell) finalBoard.getPuzzleElement(puzzleElement); if (!(initCell.getType() == TreeTentType.UNKNOWN && finalCell.getType() == TreeTentType.TENT)) { - return "This cell must be a tent."; + return super.getInvalidUseOfRuleMessage() + ": This cell must be a tent."; } if (isForced(initialBoard, initCell)) { return null; } else { - return "This cell is not forced to be tent."; + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be tent."; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LinkTreeCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LinkTreeCaseRule.java index 4485563ae..d8ade51c1 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LinkTreeCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LinkTreeCaseRule.java @@ -69,12 +69,12 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { public String checkRuleRaw(TreeTransition transition) { Set modCells = transition.getBoard().getModifiedData(); if (modCells.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"; } PuzzleElement mod = modCells.iterator().next(); TreeTentLine line = mod instanceof TreeTentLine ? (TreeTentLine) mod : null; if (line == null) { - return "This case rule only involves tree and tent connection lines."; + return super.getInvalidUseOfRuleMessage() + ": This case rule only involves tree and tent connection lines"; } TreeTentCell tree = null; if (line.getC1().getType() == TreeTentType.TREE) { @@ -84,14 +84,14 @@ public String checkRuleRaw(TreeTransition transition) { tree = line.getC2(); } if (tree == null) { - return "This case rule must have a tent cell."; + return super.getInvalidUseOfRuleMessage() + "This case rule must have a tent cell"; } TreeTentBoard parentBoard = (TreeTentBoard) transition.getParents().get(0).getBoard(); ArrayList cases = getCases(parentBoard, tree); List childTransitions = transition.getParents().get(0).getChildren(); if (childTransitions.size() != cases.size()) { - return "This case rule is incorrectly created."; + return super.getInvalidUseOfRuleMessage(); } for (Board caseBoard : cases) { TreeTentBoard cBoard = (TreeTentBoard) caseBoard; @@ -100,11 +100,11 @@ public String checkRuleRaw(TreeTransition transition) { for (TreeTransition tran : childTransitions) { TreeTentBoard tBoard = (TreeTentBoard) tran.getBoard(); if (tBoard.getModifiedData().size() != 1) { - return "This case rule is incorrectly created."; + return super.getInvalidUseOfRuleMessage(); } PuzzleElement tElement = tBoard.getModifiedData().iterator().next(); if (tElement instanceof TreeTentLine) { - return "This case rule only involves tree and tent connection lines."; + return super.getInvalidUseOfRuleMessage() + ": This case rule only involves tree and tent connection lines"; } if (cLine.compare((TreeTentLine) tElement)) { hasLine = true; @@ -112,7 +112,7 @@ public String checkRuleRaw(TreeTransition transition) { } } if (!hasLine) { - return "Could not find case"; + return super.getInvalidUseOfRuleMessage(); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/NoTentForTreeContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/NoTentForTreeContradictionRule.java index 803729ece..5bb1e836b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/NoTentForTreeContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/NoTentForTreeContradictionRule.java @@ -28,14 +28,14 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { TreeTentBoard treeTentBoard = (TreeTentBoard) board; TreeTentCell cell = (TreeTentCell) puzzleElement; if (cell.getType() != TreeTentType.TREE) { - return "This cell does not contain a contradiction at this location."; + return super.getNoContradictionMessage(); } int adjTent = treeTentBoard.getAdjacent(cell, TreeTentType.TENT).size(); int adjUnknown = treeTentBoard.getAdjacent(cell, TreeTentType.UNKNOWN).size(); if (adjTent == 0 && adjUnknown == 0) { return null; } else { - return "This cell does not contain a contradiction at this location."; + return super.getNoContradictionMessage(); } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/NoTreeForTentContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/NoTreeForTentContradictionRule.java index 42c7f0709..6eba5e6bd 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/NoTreeForTentContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/NoTreeForTentContradictionRule.java @@ -28,14 +28,14 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { TreeTentBoard treeTentBoard = (TreeTentBoard) board; TreeTentCell cell = (TreeTentCell) puzzleElement; if (cell.getType() != TreeTentType.TENT) { - return "This cell does not contain a contradiction at this location."; + return super.getNoContradictionMessage(); } int adjTree = treeTentBoard.getAdjacent(cell, TreeTentType.TREE).size(); int adjUnknown = treeTentBoard.getAdjacent(cell, TreeTentType.UNKNOWN).size(); if (adjTree == 0 && adjUnknown == 0) { return null; } else { - return "This cell does not contain a contradiction at this location."; + return super.getNoContradictionMessage(); } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/SurroundTentWithGrassBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/SurroundTentWithGrassBasicRule.java index 899045c87..6f7392595 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/SurroundTentWithGrassBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/SurroundTentWithGrassBasicRule.java @@ -32,20 +32,20 @@ public SurroundTentWithGrassBasicRule() { @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { if (puzzleElement instanceof TreeTentLine) { - return "Line is not valid for this rule."; + return super.getInvalidUseOfRuleMessage() + ": Line is not valid for this rule."; } TreeTentBoard initialBoard = (TreeTentBoard) transition.getParents().get(0).getBoard(); TreeTentCell initCell = (TreeTentCell) initialBoard.getPuzzleElement(puzzleElement); TreeTentBoard finalBoard = (TreeTentBoard) transition.getBoard(); TreeTentCell finalCell = (TreeTentCell) finalBoard.getPuzzleElement(puzzleElement); if (!(initCell.getType() == TreeTentType.UNKNOWN && finalCell.getType() == TreeTentType.GRASS)) { - return "This cell must be a tent."; + return super.getInvalidUseOfRuleMessage() + ": This cell must be a tent."; } if (isForced(initialBoard, initCell)) { return null; } else { - return "This cell is not forced to be tent."; + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be tent."; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TentForTreeBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TentForTreeBasicRule.java index 52a0f6d07..a23dad318 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TentForTreeBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TentForTreeBasicRule.java @@ -32,7 +32,7 @@ public TentForTreeBasicRule() { @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { if (!(puzzleElement instanceof TreeTentLine)) { - return "Lines must be created for this rule."; + return super.getInvalidUseOfRuleMessage() + ": Lines must be created for this rule."; } TreeTentBoard initialBoard = (TreeTentBoard) transition.getParents().get(0).getBoard(); TreeTentLine initLine = (TreeTentLine) initialBoard.getPuzzleElement(puzzleElement); @@ -46,13 +46,13 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem tree = finalLine.getC2(); tent = finalLine.getC1(); } else { - return "This line must connect a tree to a tent."; + return super.getInvalidUseOfRuleMessage() + ": This line must connect a tree to a tent."; } if (isForced(initialBoard, tree, tent)) { return null; } else { - return "This cell is not forced to be tent."; + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be tent."; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TentOrGrassCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TentOrGrassCaseRule.java index f49b4ad7c..300bc0fb9 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TentOrGrassCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TentOrGrassCaseRule.java @@ -69,25 +69,25 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { public String checkRuleRaw(TreeTransition transition) { List 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."; } TreeTentCell mod1 = (TreeTentCell) case1.getBoard().getModifiedData().iterator().next(); TreeTentCell mod2 = (TreeTentCell) 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() == TreeTentType.TENT && mod2.getType() == TreeTentType.GRASS) || (mod2.getType() == TreeTentType.TENT && mod1.getType() == TreeTentType.GRASS))) { - return "This case rule must have a tent and a grass cell."; + return super.getInvalidUseOfRuleMessage() + ": This case rule must have a tent and a grass cell."; } return null; diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TooFewTentsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TooFewTentsContradictionRule.java index 1e4aa4dce..eacd9626a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TooFewTentsContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TooFewTentsContradictionRule.java @@ -40,7 +40,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { colTents + colUnknowns < treeTentBoard.getColClues().get(loc.x).getData()) { return null; } else { - return "This cell does not contain a contradiction at this location."; + return super.getNoContradictionMessage(); } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TooManyTentsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TooManyTentsContradictionRule.java index d6445f0ee..d72eef721 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TooManyTentsContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TooManyTentsContradictionRule.java @@ -38,7 +38,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { colTents > treeTentBoard.getColClues().get(loc.x).getData()) { return null; } else { - return "This cell does not contain a contradiction at this location."; + return super.getNoContradictionMessage(); } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TouchingTentsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TouchingTentsContradictionRule.java index c6f7bd670..046124c38 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TouchingTentsContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TouchingTentsContradictionRule.java @@ -28,13 +28,13 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { TreeTentBoard treeTentBoard = (TreeTentBoard) board; TreeTentCell cell = (TreeTentCell) puzzleElement; if (cell.getType() != TreeTentType.TREE) { - return "This cell does not contain a contradiction at this location."; + return super.getNoContradictionMessage(); } int adjTree = treeTentBoard.getAdjacent(cell, TreeTentType.TREE).size(); if (adjTree > 0) { return null; } else { - return "This cell does not contain a contradiction at this location."; + return super.getNoContradictionMessage(); } } } From b1e8049b60bf71d4539bbfff00dead5127723c9a Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 3 Jan 2022 14:28:46 -0500 Subject: [PATCH 13/14] Finished Nurikabe error messages Missed some Nurikabe rules in the first go-around --- .../nurikabe/rules/BlackBetweenRegionsBasicRule.java | 2 +- .../puzzle/nurikabe/rules/BlackBottleNeckBasicRule.java | 4 ++-- .../legup/puzzle/nurikabe/rules/BlackOrWhiteCaseRule.java | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBetweenRegionsBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBetweenRegionsBasicRule.java index 71e460fa1..b7977150b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBetweenRegionsBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBetweenRegionsBasicRule.java @@ -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; diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBottleNeckBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBottleNeckBasicRule.java index 72cf0c587..131b592d7 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBottleNeckBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBottleNeckBasicRule.java @@ -37,7 +37,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!"; } NurikabeBoard modified = origBoardState.copy(); NurikabeCell modCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement); @@ -46,7 +46,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem if (contraRule.checkContradiction(modified) == null) { return null; } else { - return "This is not the only way for black to escape!"; + return super.getInvalidUseOfRuleMessage() + ": This is not the only way for black to escape!"; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackOrWhiteCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackOrWhiteCaseRule.java index 7251bb145..aec3c52ba 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackOrWhiteCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackOrWhiteCaseRule.java @@ -31,25 +31,25 @@ public BlackOrWhiteCaseRule() { public String checkRuleRaw(TreeTransition transition) { List 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."; } NurikabeCell mod1 = (NurikabeCell) case1.getBoard().getModifiedData().iterator().next(); NurikabeCell mod2 = (NurikabeCell) 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() == NurikabeType.WHITE && mod2.getType() == NurikabeType.BLACK) || (mod2.getType() == NurikabeType.WHITE && mod1.getType() == NurikabeType.BLACK))) { - return "This case rule must an empty white and black cell."; + return super.getInvalidUseOfRuleMessage() + ": This case rule must an empty white and black cell."; } return null; From 414493626e4ec0f55584a97148b4297005d6ef67 Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 3 Jan 2022 14:35:43 -0500 Subject: [PATCH 14/14] Update UnreachableBasicRule.java --- .../rpi/legup/puzzle/nurikabe/rules/UnreachableBasicRule.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/UnreachableBasicRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/UnreachableBasicRule.java index 3c75e7ded..b7e4e7d88 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/UnreachableBasicRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/UnreachableBasicRule.java @@ -33,7 +33,7 @@ protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleE NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard(); 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!"; } NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard(); @@ -50,7 +50,7 @@ protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleE modifiedCell.setData(NurikabeType.WHITE.toValue()); if (contraRule.checkContradiction(modified) == null) return null; - return "This is not the only way for black to escape!"; + return super.getInvalidUseOfRuleMessage() + ": This is not the only way for black to escape!"; } /**