From e9fe310378721aa4b4fa358aa57ec44f21d086c1 Mon Sep 17 00:00:00 2001 From: Chase-Grajeda Date: Fri, 26 Jan 2024 09:26:53 -0500 Subject: [PATCH 01/11] Revert "Bugfix 549 (#682)" This reverts commit 5048ee69d958fdde9b1bb35854c56c9920068346. --- puzzles files/skyscrapers/1646651 | 31 + puzzles files/skyscrapers/easy1.xml | 47 + .../legup/history/AutoCaseRuleCommand.java | 1 - .../legup/model/gameboard/PuzzleElement.java | 20 - .../edu/rpi/legup/model/rules/CaseRule.java | 29 +- .../edu/rpi/legup/model/rules/DirectRule.java | 4 - .../rpi/legup/model/tree/TreeTransition.java | 64 +- .../lightup/rules/SatisfyNumberCaseRule.java | 63 - .../caserule/CaseRule_GenericStatement.java | 256 ++- .../puzzle/skyscrapers/SkyscrapersBoard.java | 11 + .../puzzle/skyscrapers/SkyscrapersClue.java | 5 +- .../rules/CellForNumberCaseRule.java | 53 +- .../rules/NumberForCellCaseRule.java | 35 - .../legup/puzzle/treetent/TreeTentBoard.java | 20 +- .../treetent/rules/FillinRowCaseRule.java | 25 - .../treetent/rules/LinkTentCaseRule.java | 15 +- .../treetent/rules/LinkTreeCaseRule.java | 29 - .../ui/proofeditorui/treeview/TreeView.java | 1640 ++++++++--------- 18 files changed, 994 insertions(+), 1354 deletions(-) create mode 100644 puzzles files/skyscrapers/1646651 create mode 100644 puzzles files/skyscrapers/easy1.xml diff --git a/puzzles files/skyscrapers/1646651 b/puzzles files/skyscrapers/1646651 new file mode 100644 index 000000000..847d8639c --- /dev/null +++ b/puzzles files/skyscrapers/1646651 @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/puzzles files/skyscrapers/easy1.xml b/puzzles files/skyscrapers/easy1.xml new file mode 100644 index 000000000..9d3135bff --- /dev/null +++ b/puzzles files/skyscrapers/easy1.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java b/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java index a4c157c77..331a3dddf 100644 --- a/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java +++ b/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java @@ -62,7 +62,6 @@ public void executeCommand() { board.setModifiable(false); transition.setBoard(board); transition.setRule(caseRule); - transition.setSelection(elementView.getPuzzleElement().copy()); caseTrans.add(transition); TreeNode childNode = (TreeNode) tree.addTreeElement(transition); diff --git a/src/main/java/edu/rpi/legup/model/gameboard/PuzzleElement.java b/src/main/java/edu/rpi/legup/model/gameboard/PuzzleElement.java index 3d84287e3..97c9205cf 100644 --- a/src/main/java/edu/rpi/legup/model/gameboard/PuzzleElement.java +++ b/src/main/java/edu/rpi/legup/model/gameboard/PuzzleElement.java @@ -11,7 +11,6 @@ public abstract class PuzzleElement { protected boolean isModified; protected boolean isGiven; protected boolean isValid; - protected int casesDepended; /** * PuzzleElement Constructor creates a new puzzle element. @@ -23,7 +22,6 @@ public PuzzleElement() { this.isModified = false; this.isGiven = false; this.isValid = true; - this.casesDepended = 0; } /** @@ -150,24 +148,6 @@ public void setValid(boolean isValid) { this.isValid = isValid; } - /** - * Get the number of case rules that depend upon the state of this element - * - * @return number of cases - */ - public int getCasesDepended() { - return this.casesDepended; - } - - /** - * Sets the number of case rules that depend upon the state of this element - * - * @param cases number of cases - */ - public void setCasesDepended(int cases) { - this.casesDepended = cases; - } - /** * Tests whether two puzzle elements objects have the same puzzle element * 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 efb96e21a..d9c7e73e5 100644 --- a/src/main/java/edu/rpi/legup/model/rules/CaseRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/CaseRule.java @@ -7,8 +7,9 @@ import edu.rpi.legup.model.tree.TreeTransition; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; -import java.util.Set; +import java.util.Map; import static edu.rpi.legup.model.rules.RuleType.CASE; @@ -78,7 +79,6 @@ public String checkRule(TreeTransition transition) { String check = checkRuleRaw(transition); - // Mark transition and new data as valid or not boolean isCorrect = (check == null); for (TreeTransition childTrans : parentNodes.get(0).getChildren()) { childTrans.setCorrect(isCorrect); @@ -125,31 +125,6 @@ public String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement */ @Override public abstract String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement); - - /** - * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid - * Overridden by case rules dependent on more than just the modified data - * - * @param board board state at application - * @param puzzleElement selected puzzleElement - * @return List of puzzle elements (typically cells) this application of the case rule depends upon. - * Defaults to any element modified by any case - */ - public List dependentElements(Board board, PuzzleElement puzzleElement) { - List elements = new ArrayList<>(); - - List cases = getCases(board,puzzleElement); - for (Board caseBoard : cases) { - Set data = caseBoard.getModifiedData(); - for (PuzzleElement element : data) { - if(!elements.contains(board.getPuzzleElement(element))){ - elements.add(board.getPuzzleElement(element)); - } - } - } - - return elements; - } } diff --git a/src/main/java/edu/rpi/legup/model/rules/DirectRule.java b/src/main/java/edu/rpi/legup/model/rules/DirectRule.java index 847764b7b..0465ca88c 100644 --- a/src/main/java/edu/rpi/legup/model/rules/DirectRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/DirectRule.java @@ -33,10 +33,6 @@ public String checkRule(TreeTransition transition) { transition.getParents().get(0).getChildren().size() != 1) { return "State must have only 1 parent and 1 child"; } - else if (finalBoard.getModifiedData().isEmpty()) { - // null transition - return null; - } else { return checkRuleRaw(transition); } diff --git a/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java b/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java index 72572ac72..e1d042626 100644 --- a/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java +++ b/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java @@ -2,7 +2,6 @@ import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.CaseRule; import edu.rpi.legup.model.rules.Rule; import edu.rpi.legup.model.rules.RuleType; @@ -13,8 +12,6 @@ public class TreeTransition extends TreeElement { private ArrayList parents; private TreeNode childNode; private Rule rule; - - private PuzzleElement selection; private boolean isCorrect; private boolean isVerified; @@ -29,7 +26,6 @@ public TreeTransition(Board board) { this.childNode = null; this.board = board; this.rule = null; - this.selection = null; this.isCorrect = false; this.isVerified = false; } @@ -91,42 +87,13 @@ public void propagateChange(PuzzleElement element) { } } else { - // Overwrite previous modifications to this element - board.removeModifiedData(board.getPuzzleElement(element)); - - // apply changes to tranistion - board.notifyChange(element); - - // mark first transition as modified - if (!board.getPuzzleElement(element).equalsData(parents.get(0).getBoard().getPuzzleElement(element))) { - board.addModifiedData(element); - } - - // propagate to children if (childNode != null) { - - // find starting board - TreeNode head = childNode; - while (head.getParent() != null) { - head = head.getParent().getParents().get(0); - } - Board headBoard = head.getBoard(); - - PuzzleElement copy = element.copy(); - // Set as modifiable if reverted to starting value (and started modifiable) - if (headBoard.getPuzzleElement(element).equalsData(element)) { - copy.setModifiable(headBoard.getPuzzleElement(element).isModifiable()); - } - else{ - copy.setModifiable(false); - } - - // apply changes to result node - childNode.getBoard().notifyChange(copy); - - // apply to all child transitions + board.notifyChange(element); + childNode.getBoard().notifyChange(element.copy()); for (TreeTransition child : childNode.getChildren()) { - child.propagateChange(copy.copy()); + PuzzleElement copy = element.copy(); + copy.setModifiable(false); + child.propagateChange(copy); } } } @@ -360,27 +327,6 @@ public void setRule(Rule rule) { isVerified = false; } - /** - * Gets he selected element associated with this transition - * - * @return If this is a case rule, the selected element for that rule, null otherwise - */ - public PuzzleElement getSelection() { - if (this.rule instanceof CaseRule) { - return selection; - } - return null; - } - - /** - * Sets the selected element associated with this transition - * - * @param selection selected element for this transition - */ - public void setSelection(PuzzleElement selection) { - this.selection = selection; - } - /** * Gets whether this transition is correctly justified * 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 cf7b70ccd..1f166685b 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 @@ -287,67 +287,4 @@ private List getAdjacentCells(LightUpBoard board, LightUpCell cell) } return cells; } - - /** - * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid - * Overridden by case rules dependent on more than just the modified data - * - * @param board board state at application - * @param puzzleElement selected puzzleElement - * @return List of puzzle elements (typically cells) this application of the case rule depends upon. - * Defaults to any element modified by any case - */ - @Override - public List dependentElements(Board board, PuzzleElement puzzleElement) { - List elements = new ArrayList<>(); - - LightUpBoard puzzleBoard = (LightUpBoard) board; - LightUpCell point = (LightUpCell)puzzleBoard.getPuzzleElement(puzzleElement); - - List cells = getAdjacentCells(puzzleBoard,point); - - for (LightUpCell cell : cells) { - //add cells that can light adjacents from any direction - Point location = cell.getLocation(); - for (int i = location.x; i < puzzleBoard.getWidth(); i++) { - System.out.println(i); - LightUpCell c = puzzleBoard.getCell(i, location.y); - if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { - break; - } - else if (!elements.contains(board.getPuzzleElement(c))) { - elements.add(board.getPuzzleElement(c)); - } - } - for (int i = location.x; i >= 0; i--) { - LightUpCell c = puzzleBoard.getCell(i, location.y); - if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { - break; - } - else if (!elements.contains(board.getPuzzleElement(c))) { - elements.add(board.getPuzzleElement(c)); - } - } - for (int i = location.y; i < puzzleBoard.getHeight(); i++) { - LightUpCell c = puzzleBoard.getCell(location.x, i); - if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { - break; - } - else if (!elements.contains(board.getPuzzleElement(c))) { - elements.add(board.getPuzzleElement(c)); - } - } - for (int i = location.y; i >= 0; i--) { - LightUpCell c = puzzleBoard.getCell(location.x, i); - if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { - break; - } - else if (!elements.contains(board.getPuzzleElement(c))) { - elements.add(board.getPuzzleElement(c)); - } - } - } - - return elements; - } } 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 0e25586a8..2a40bf45d 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 @@ -1,137 +1,119 @@ -package edu.rpi.legup.puzzle.shorttruthtable.rules.caserule; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.CaseBoard; -import edu.rpi.legup.model.gameboard.PuzzleElement; - -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCell; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableStatement; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; - -import java.util.List; -import java.util.ArrayList; - -public abstract class CaseRule_GenericStatement extends CaseRule_Generic { - - public CaseRule_GenericStatement(String ruleID, char operation, String title, - ShortTruthTableCellType[][] trueCases, - ShortTruthTableCellType[][] falseCases) { - super(ruleID, ShortTruthTableOperation.getRuleName(operation), - title + " case", - "A known " + title.toUpperCase() + " statement can have multiple forms"); - - this.operation = operation; - - this.trueCases = trueCases; - this.falseCases = falseCases; - } - - private final char operation; - - private final ShortTruthTableCellType[][] trueCases; - private final ShortTruthTableCellType[][] falseCases; - - protected static final ShortTruthTableCellType T = ShortTruthTableCellType.TRUE; - protected static final ShortTruthTableCellType F = ShortTruthTableCellType.FALSE; - protected static final ShortTruthTableCellType U = ShortTruthTableCellType.UNKNOWN; - - // Adds all elements that can be selected for this caserule - @Override - public CaseBoard getCaseBoard(Board board) { - //copy the board and add all elements that can be selected - ShortTruthTableBoard sttBoard = (ShortTruthTableBoard) board.copy(); - sttBoard.setModifiable(false); - CaseBoard caseBoard = new CaseBoard(sttBoard, this); - - //add all elements that can be selected for the case rule statement - for (PuzzleElement element : sttBoard.getPuzzleElements()) { - //get the cell object - ShortTruthTableCell cell = sttBoard.getCellFromElement(element); - //the cell must match the symbol - if (cell.getSymbol() != this.operation) continue; - //the statement must be assigned with unassigned sub-statements - if (!cell.getType().isTrueOrFalse()) continue; - if (cell.getStatementReference().getRightStatement().getCell().getType().isTrueOrFalse()) continue; - if (this.operation != ShortTruthTableOperation.NOT && - cell.getStatementReference().getRightStatement().getCell().getType().isTrueOrFalse()) { - continue; - } - //if the element has passed all the checks, it can be selected - caseBoard.addPickableElement(element); - } - return caseBoard; - } - - /** - * Gets the possible cases at a specific location based on this case rule - * - * @param board the current board state - * @param puzzleElement equivalent puzzleElement - * @return a list of elements the specified could be - */ - @SuppressWarnings("unchecked") - @Override - public ArrayList getCases(Board board, PuzzleElement puzzleElement) { - ShortTruthTableBoard sttBoard = ((ShortTruthTableBoard) board); - ShortTruthTableCell cell = sttBoard.getCellFromElement(puzzleElement); - - // If the statement is set to true, collect true cases. Otherwise, collect the false cases - if (cell.getType() == ShortTruthTableCellType.TRUE) { - return getCasesFromCell(sttBoard, puzzleElement, trueCases); - } - return getCasesFromCell(sttBoard, puzzleElement, falseCases); - } - - /** - * Collects a list of boards for each possible outcome of case-rule application - * @param board current board state - * @param puzzleElement case rule operator - * @param possibilities list of possibilities for operator state - * @return ArrayList of Boards - */ - private ArrayList getCasesFromCell(ShortTruthTableBoard board, PuzzleElement puzzleElement, ShortTruthTableCellType[][] possibilities) { - // Create branch case for each possibility - ArrayList cases = new ArrayList<>(); - for (int i = 0; i < possibilities.length; i++) { - // Create a new board to modify and get statement of selected square - ShortTruthTableBoard b = board.copy(); - ShortTruthTableCell cell = b.getCellFromElement(puzzleElement); - ShortTruthTableStatement statement = cell.getStatementReference(); - - // Modify neighboring cells of case-rule application by the provided logical cases - if (possibilities[i][0] != ShortTruthTableCellType.UNKNOWN) { - ShortTruthTableCell leftCell = statement.getLeftStatement().getCell(); - leftCell.setData(possibilities[i][0]); - b.addModifiedData(leftCell); - } - if (possibilities[i][1] != ShortTruthTableCellType.UNKNOWN) { - ShortTruthTableCell rightCell = statement.getRightStatement().getCell(); - rightCell.setData(possibilities[i][1]); - b.addModifiedData(rightCell); - } - - cases.add(b); - } - return cases; - } - - /** - * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid - * Overridden by case rules dependent on more than just the modified data - * - * @param board board state at application - * @param puzzleElement selected puzzleElement - * @return List of puzzle elements (typically cells) this application of the case rule depends upon. - * Defaults to any element modified by any case - */ - @Override - public List dependentElements(Board board, PuzzleElement puzzleElement) { - List elements = super.dependentElements(board,puzzleElement); - - elements.add(board.getPuzzleElement(puzzleElement)); - - return elements; - } -} +package edu.rpi.legup.puzzle.shorttruthtable.rules.caserule; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.CaseBoard; +import edu.rpi.legup.model.gameboard.PuzzleElement; + +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCell; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableStatement; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; + + +import java.util.ArrayList; + +public abstract class CaseRule_GenericStatement extends CaseRule_Generic { + + public CaseRule_GenericStatement(String ruleID, char operation, String title, + ShortTruthTableCellType[][] trueCases, + ShortTruthTableCellType[][] falseCases) { + super(ruleID, ShortTruthTableOperation.getRuleName(operation), + title + " case", + "A known " + title.toUpperCase() + " statement can have multiple forms"); + + this.operation = operation; + + this.trueCases = trueCases; + this.falseCases = falseCases; + } + + private final char operation; + + private final ShortTruthTableCellType[][] trueCases; + private final ShortTruthTableCellType[][] falseCases; + + protected static final ShortTruthTableCellType T = ShortTruthTableCellType.TRUE; + protected static final ShortTruthTableCellType F = ShortTruthTableCellType.FALSE; + protected static final ShortTruthTableCellType U = ShortTruthTableCellType.UNKNOWN; + + // Adds all elements that can be selected for this caserule + @Override + public CaseBoard getCaseBoard(Board board) { + //copy the board and add all elements that can be selected + ShortTruthTableBoard sttBoard = (ShortTruthTableBoard) board.copy(); + sttBoard.setModifiable(false); + CaseBoard caseBoard = new CaseBoard(sttBoard, this); + + //add all elements that can be selected for the case rule statement + for (PuzzleElement element : sttBoard.getPuzzleElements()) { + //get the cell object + ShortTruthTableCell cell = sttBoard.getCellFromElement(element); + //the cell must match the symbol + if (cell.getSymbol() != this.operation) continue; + //the statement must be assigned with unassigned sub-statements + if (!cell.getType().isTrueOrFalse()) continue; + if (cell.getStatementReference().getRightStatement().getCell().getType().isTrueOrFalse()) continue; + if (this.operation != ShortTruthTableOperation.NOT && + cell.getStatementReference().getRightStatement().getCell().getType().isTrueOrFalse()) { + continue; + } + //if the element has passed all the checks, it can be selected + caseBoard.addPickableElement(element); + } + return caseBoard; + } + + /** + * Gets the possible cases at a specific location based on this case rule + * + * @param board the current board state + * @param puzzleElement equivalent puzzleElement + * @return a list of elements the specified could be + */ + @SuppressWarnings("unchecked") + @Override + public ArrayList getCases(Board board, PuzzleElement puzzleElement) { + ShortTruthTableBoard sttBoard = ((ShortTruthTableBoard) board); + ShortTruthTableCell cell = sttBoard.getCellFromElement(puzzleElement); + + // If the statement is set to true, collect true cases. Otherwise, collect the false cases + if (cell.getType() == ShortTruthTableCellType.TRUE) { + return getCasesFromCell(sttBoard, puzzleElement, trueCases); + } + return getCasesFromCell(sttBoard, puzzleElement, falseCases); + } + + /** + * Collects a list of boards for each possible outcome of case-rule application + * @param board current board state + * @param puzzleElement case rule operator + * @param possibilities list of possibilities for operator state + * @return ArrayList of Boards + */ + private ArrayList getCasesFromCell(ShortTruthTableBoard board, PuzzleElement puzzleElement, ShortTruthTableCellType[][] possibilities) { + // Create branch case for each possibility + ArrayList cases = new ArrayList<>(); + for (int i = 0; i < possibilities.length; i++) { + // Create a new board to modify and get statement of selected square + ShortTruthTableBoard b = board.copy(); + ShortTruthTableCell cell = b.getCellFromElement(puzzleElement); + ShortTruthTableStatement statement = cell.getStatementReference(); + + // Modify neighboring cells of case-rule application by the provided logical cases + if (possibilities[i][0] != ShortTruthTableCellType.UNKNOWN) { + ShortTruthTableCell leftCell = statement.getLeftStatement().getCell(); + leftCell.setData(possibilities[i][0]); + b.addModifiedData(leftCell); + } + if (possibilities[i][1] != ShortTruthTableCellType.UNKNOWN) { + ShortTruthTableCell rightCell = statement.getRightStatement().getCell(); + rightCell.setData(possibilities[i][1]); + b.addModifiedData(rightCell); + } + + cases.add(b); + } + return cases; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java index 52e8a6400..ca6bcbe02 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java @@ -25,6 +25,9 @@ public class SkyscrapersBoard extends GridBoard { private boolean viewFlag = false; private boolean dupeFlag = false; + private SkyscrapersClue modClue = null; + //helper variable for case rule verification, tracks recently modified row/col + public SkyscrapersBoard(int size) { super(size, size); @@ -91,6 +94,14 @@ public void setViewFlag(boolean newFlag) { viewFlag = newFlag; } + public SkyscrapersClue getmodClue() { + return modClue; + } + + public void setModClue(SkyscrapersClue newClue) { + modClue = newClue; + } + @Override public SkyscrapersCell getCell(int x, int y) { return (SkyscrapersCell) super.getCell(x, y); diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClue.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClue.java index 1e7b1b45e..dc68f45c7 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClue.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClue.java @@ -47,9 +47,6 @@ public void setType(SkyscrapersType type) { } public SkyscrapersClue copy() { - SkyscrapersClue copy = new SkyscrapersClue(data, clueIndex, type); - copy.setIndex(index); - copy.setModifiable(isModifiable); - return copy; + return null; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/CellForNumberCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/CellForNumberCaseRule.java index 01527294a..683b742bf 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/CellForNumberCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/CellForNumberCaseRule.java @@ -69,6 +69,7 @@ public ArrayList getCasesFor(Board board, PuzzleElement puzzleElement, In PuzzleElement newCell = newCase.getPuzzleElement(cell); newCell.setData(number); newCase.addModifiedData(newCell); + newCase.setModClue((SkyscrapersClue) newCase.getPuzzleElement(clue)); //if flags boolean passed = true; @@ -102,7 +103,12 @@ public String checkRuleRaw(TreeTransition transition) { return "This case rule must have at least one child."; } - if (childTransitions.size() != getCasesFor(oldBoard, oldBoard.getPuzzleElement(transition.getSelection()), (Integer) childTransitions.get(0).getBoard().getModifiedData().iterator().next().getData()).size()) { + //find changed row/col + SkyscrapersClue modClue = ((SkyscrapersBoard) childTransitions.get(0).getBoard()).getmodClue(); + + //System.out.println(modClue.getType()); + //System.out.println(modClue.getClueIndex()); + if (childTransitions.size() != getCasesFor(oldBoard, modClue, (Integer) childTransitions.get(0).getBoard().getModifiedData().iterator().next().getData()).size()) { //System.out.println("Wrong number of cases."); return "Wrong number of cases."; } @@ -126,49 +132,4 @@ public String checkRuleRaw(TreeTransition transition) { public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { return checkRuleRaw(transition); } - - /** - * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid - * Overridden by case rules dependent on more than just the modified data - * - * @param board board state at application - * @param puzzleElement selected puzzleElement - * @return List of puzzle elements (typically cells) this application of the case rule depends upon. - * Defaults to any element modified by any case - */ - @Override - public List dependentElements(Board board, PuzzleElement puzzleElement) { - List elements = new ArrayList<>(); - - SkyscrapersBoard puzzleBoard = (SkyscrapersBoard) board; - SkyscrapersClue clue = (SkyscrapersClue)puzzleBoard.getPuzzleElement(puzzleElement); - - // check each point in modified row/col - List data = puzzleBoard.getRowCol(clue.getClueIndex(),SkyscrapersType.ANY,clue.getType() == SkyscrapersType.CLUE_WEST); - for (SkyscrapersCell point : data) { - List cells = new ArrayList<>(List.of(point)); - - // if dependent on row/col - if ((puzzleBoard.getDupeFlag() || puzzleBoard.getViewFlag()) && point.getType() == SkyscrapersType.UNKNOWN) { - // get perpendicular row/col intersecting this point - int index; - if (clue.getType() == SkyscrapersType.CLUE_WEST) { - index = point.getLocation().x; - } - else { - index = point.getLocation().y; - } - cells.addAll(puzzleBoard.getRowCol(index,SkyscrapersType.ANY,clue.getType() != SkyscrapersType.CLUE_WEST)); - } - - // add all to result - for (SkyscrapersCell cell : cells) { - if (!elements.contains(board.getPuzzleElement(cell))) { - elements.add(board.getPuzzleElement(cell)); - } - } - } - - return elements; - } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NumberForCellCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NumberForCellCaseRule.java index 3bf0de70a..a061c62a3 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NumberForCellCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NumberForCellCaseRule.java @@ -7,7 +7,6 @@ import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersClue; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType; import java.awt.*; @@ -135,38 +134,4 @@ public String checkRuleRaw(TreeTransition transition) { public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { return checkRuleRaw(transition); } - - /** - * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid - * Overridden by case rules dependent on more than just the modified data - * - * @param board board state at application - * @param puzzleElement selected puzzleElement - * @return List of puzzle elements (typically cells) this application of the case rule depends upon. - * Defaults to any element modified by any case - */ - @Override - public List dependentElements(Board board, PuzzleElement puzzleElement) { - List elements = new ArrayList<>(); - - SkyscrapersBoard puzzleBoard = (SkyscrapersBoard) board; - SkyscrapersCell point = (SkyscrapersCell)puzzleBoard.getPuzzleElement(puzzleElement); - - List cells = new ArrayList<>(List.of(point)); - - // if dependent on row/col - if (puzzleBoard.getDupeFlag() || puzzleBoard.getViewFlag()) { - // add all cells in row/col intersecting given point - cells.addAll(puzzleBoard.getRowCol(point.getLocation().x,SkyscrapersType.ANY,false)); - cells.addAll(puzzleBoard.getRowCol(point.getLocation().y,SkyscrapersType.ANY,true)); - } - - for (SkyscrapersCell cell : cells) { - if (!elements.contains(board.getPuzzleElement(cell))) { - elements.add(board.getPuzzleElement(cell)); - } - } - - return elements; - } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java index dc809f34d..2542ea335 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java @@ -124,11 +124,21 @@ public void notifyDeletion(PuzzleElement puzzleElement) { public List getAdjacent(TreeTentCell cell, TreeTentType type) { List adj = new ArrayList<>(); Point loc = cell.getLocation(); - for (int i = -2; i < 2; i++) { - TreeTentCell adjCell = getCell(loc.x + (i % 2), loc.y + ((i + 1) % 2)); - if (adjCell != null && adjCell.getType() == type) { - adj.add(adjCell); - } + TreeTentCell up = getCell(loc.x, loc.y - 1); + TreeTentCell right = getCell(loc.x + 1, loc.y); + TreeTentCell down = getCell(loc.x, loc.y + 1); + TreeTentCell left = getCell(loc.x - 1, loc.y); + if (up != null && up.getType() == type) { + adj.add(up); + } + if (right != null && right.getType() == type) { + adj.add(right); + } + if (down != null && down.getType() == type) { + adj.add(down); + } + if (left != null && left.getType() == type) { + adj.add(left); } return adj; } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FillinRowCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FillinRowCaseRule.java index 698b3aa5e..538772b74 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FillinRowCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FillinRowCaseRule.java @@ -160,29 +160,4 @@ public String checkRuleRaw(TreeTransition transition) { public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { return null; } - - /** - * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid - * Overridden by case rules dependent on more than just the modified data - * - * @param board board state at application - * @param puzzleElement selected puzzleElement - * @return List of puzzle elements (typically cells) this application of the case rule depends upon. - * Defaults to any element modified by any case - */ - @Override - public List dependentElements(Board board, PuzzleElement puzzleElement) { - List elements = new ArrayList<>(); - - TreeTentBoard treeTentBoard = (TreeTentBoard) board; - TreeTentClue clue = (TreeTentClue) puzzleElement; - - // add all elements of filled row - for (int i = 0; i < treeTentBoard.getWidth(); i++) { - TreeTentCell cell = treeTentBoard.getCell(i, clue.getClueIndex()-1); - elements.add(board.getPuzzleElement((cell))); - } - - return elements; - } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LinkTentCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LinkTentCaseRule.java index 39b1d0251..36f466f87 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LinkTentCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LinkTentCaseRule.java @@ -5,6 +5,7 @@ import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.rules.CaseRule; import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.treetent.TreeTent; import edu.rpi.legup.puzzle.treetent.TreeTentBoard; import edu.rpi.legup.puzzle.treetent.TreeTentType; import edu.rpi.legup.puzzle.treetent.TreeTentCell; @@ -150,18 +151,4 @@ public String checkRuleRaw(TreeTransition transition) { public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { return checkRuleRaw(transition); } - - /** - * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid - * Overridden by case rules dependent on more than just the modified data - * - * @param board board state at application - * @param puzzleElement selected puzzleElement - * @return List of puzzle elements (typically cells) this application of the case rule depends upon. - * Defaults to any element modified by any case - */ - @Override - public List dependentElements(Board board, PuzzleElement puzzleElement) { - return List.of(board.getPuzzleElement(puzzleElement)); - } } 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 72ffd62eb..249547301 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 @@ -10,7 +10,6 @@ import edu.rpi.legup.puzzle.treetent.TreeTentLine; import edu.rpi.legup.puzzle.treetent.TreeTentType; -import java.awt.Point; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -153,32 +152,4 @@ public String checkRuleRaw(TreeTransition transition) { public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { return checkRuleRaw(transition); } - - /** - * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid - * Overridden by case rules dependent on more than just the modified data - * - * @param board board state at application - * @param puzzleElement selected puzzleElement - * @return List of puzzle elements (typically cells) this application of the case rule depends upon. - * Defaults to any element modified by any case - */ - @Override - public List dependentElements(Board board, PuzzleElement puzzleElement) { - List elements = new ArrayList<>(List.of(board.getPuzzleElement(puzzleElement))); - - TreeTentBoard treeTentBoard = (TreeTentBoard) board; - TreeTentCell point = (TreeTentCell) puzzleElement; - - // get all adjacent cells - Point loc = point.getLocation(); - for (int i = -2; i < 2; i++) { - TreeTentCell cell = treeTentBoard.getCell(loc.x + (i % 2), loc.y + ((i + 1) % 2)); - if (cell != null) { - elements.add(board.getPuzzleElement(cell)); - } - } - - return elements; - } } diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeView.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeView.java index 9bfffe60a..ecf59146d 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeView.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeView.java @@ -1,886 +1,756 @@ -package edu.rpi.legup.ui.proofeditorui.treeview; - -import edu.rpi.legup.app.GameBoardFacade; -import edu.rpi.legup.controller.TreeController; -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.GridCell; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.observer.ITreeListener; -import edu.rpi.legup.model.rules.CaseRule; -import edu.rpi.legup.model.rules.Rule; -import edu.rpi.legup.model.tree.Tree; -import edu.rpi.legup.model.tree.TreeElement; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.ui.ScrollView; -import edu.rpi.legup.utility.DisjointSets; - -import javax.swing.*; -import java.awt.*; -import java.awt.image.BufferedImage; -import java.util.*; -import java.util.List; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import static edu.rpi.legup.model.tree.TreeElementType.NODE; -import static edu.rpi.legup.model.tree.TreeElementType.TRANSITION; -import static edu.rpi.legup.ui.proofeditorui.treeview.TreeNodeView.DIAMETER; -import static edu.rpi.legup.ui.proofeditorui.treeview.TreeNodeView.RADIUS; - -public class TreeView extends ScrollView implements ITreeListener { - private final static Logger LOGGER = LogManager.getLogger(TreeView.class.getName()); - - private static final int TRANS_GAP = 5; - - private static final int NODE_GAP_WIDTH = 70; - private static final int NODE_GAP_HEIGHT = 15; - - private static final int BORDER_GAP_HEIGHT = 20; - private static final int BORDER_GAP_WIDTH = 20; - - private static final int BORDER_SPACING = 100; - - private TreeNodeView nodeHover; - - private ArrayList currentStateBoxes; - private Rectangle bounds = new Rectangle(0, 0, 0, 0); - - private Tree tree; - private TreeNodeView rootNodeView; - private Map viewMap; - private Dimension dimension; - - private TreeViewSelection selection; - - public TreeView(TreeController treeController) { - super(treeController); - currentStateBoxes = new ArrayList<>(); - setSize(dimension = new Dimension(100, 200)); - setPreferredSize(new Dimension(640, 160)); - - viewMap = new HashMap<>(); - - selection = new TreeViewSelection(); - } - - public TreeViewSelection getSelection() { - return selection; - } - - /** - * Gets the tree node puzzleElement that the mouse is hovering over - * - * @return tree node puzzleElement that the mouse is hovering over - */ - public TreeNodeView getNodeHover() { - return nodeHover; - } - - /** - * Sets the tree node puzzleElement that the mouse is hovering over - * - * @param nodeHover tree node puzzleElement the mouse is hovering over - */ - public void setNodeHover(TreeNodeView nodeHover) { - this.nodeHover = nodeHover; - } - - /** - * Gets the TreeElementView by the specified point or null if no view exists at the specified point - * - * @param point location to query for a view - * @return TreeElementView at the point specified, otherwise null - */ - public TreeElementView getTreeElementView(Point point) { - return getTreeElementView(point, rootNodeView); - } - - /** - * Recursively gets the TreeElementView by the specified point or null if no view exists at the specified point or - * the view specified is null - * - * @param point location to query for a view - * @param elementView view to determine if the point is contained within it - * @return TreeElementView at the point specified, otherwise null - */ - private TreeElementView getTreeElementView(Point point, TreeElementView elementView) { - if (elementView == null) { - return null; - } - else { - if (elementView.contains(point) && elementView.isVisible()) { - if (elementView.getType() == NODE && ((TreeNodeView) elementView).isContradictoryState()) { - return null; - } - return elementView; - } - else { - if (elementView.getType() == NODE) { - TreeNodeView nodeView = (TreeNodeView) elementView; - for (TreeTransitionView transitionView : nodeView.getChildrenViews()) { - TreeElementView view = getTreeElementView(point, transitionView); - if (view != null) { - return view; - } - } - } - else { - TreeTransitionView transitionView = (TreeTransitionView) elementView; - return getTreeElementView(point, transitionView.getChildView()); - } - } - } - return null; - } - - public void updateTreeView(Tree tree) { - this.tree = tree; - if (selection.getSelectedViews().size() == 0) { - selection.newSelection(new TreeNodeView(tree.getRootNode())); - } - repaint(); - } - - /** - * Sets the tree associated with this TreeView - * - * @param tree tree - */ - public void setTree(Tree tree) { - this.tree = tree; - } - - public void updateTreeSize() { - if (GameBoardFacade.getInstance().getTree() == null) { - return; - } - setSize(bounds.getSize()); - } - - public void reset() { - if (bounds.x != 0 || bounds.y != 0) { - updateTreeSize(); - } - } - - public void zoomFit() { - double fitWidth = (viewport.getWidth() - 8.0) / (getSize().width - 200); - double fitHeight = (viewport.getHeight() - 8.0) / (getSize().height - 120); - zoomTo(Math.min(fitWidth, fitHeight)); - viewport.setViewPosition(new Point(0, viewport.getHeight() / 2)); - } - - /** - * Creates a customized viewport for the scroll pane - * - * @return viewport for the scroll pane - */ - @Override - protected JViewport createViewport() { - return new JViewport() { - @Override - protected LayoutManager createLayoutManager() { - return new ViewportLayout() { - @Override - public void layoutContainer(Container parent) { - Point point = viewport.getViewPosition(); - // determine the maximum x and y view positions - int mx = getCanvas().getWidth() - viewport.getWidth(); - int my = getCanvas().getHeight() - viewport.getHeight(); - // obey edge boundaries - if (point.x < 0) { - point.x = 0; - } - if (point.x > mx) { - point.x = mx; - } - if (point.y < 0) { - point.y = 0; - } - if (point.y > my) { - point.y = my; - } - // center margins - if (mx < 0) { - point.x = 0; - } - if (my < 0) { - point.y = my / 2; - } - viewport.setViewPosition(point); - } - }; - } - }; - } - - public void draw(Graphics2D graphics2D) { - currentStateBoxes.clear(); - Tree tree = GameBoardFacade.getInstance().getTree(); - if (tree != null) { - //setSize(bounds.getDimension()); - graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - - drawTree(graphics2D); - - dimension.width += BORDER_SPACING; - setSize(dimension); -// graphics2D.drawRect(0,0, dimension.width, dimension.height); - - if (selection.getHover() != null) { - drawMouseOver(graphics2D); - } - } - } - - public void zoomReset() { - zoomTo(1.0); - viewport.setViewPosition(new Point(0, 0)); - } - - private void redrawTree(Graphics2D graphics2D, TreeNodeView nodeView) { - if (nodeView != null) { - nodeView.draw(graphics2D); - for (TreeTransitionView transitionView : nodeView.getChildrenViews()) { - transitionView.draw(graphics2D); - redrawTree(graphics2D, transitionView.getChildView()); - } - } - } - - public void removeTreeElement(TreeElementView view) { - if (view.getType() == NODE) { - TreeNodeView nodeView = (TreeNodeView) view; - nodeView.getParentView().setChildView(null); - } - else { - TreeTransitionView transitionView = (TreeTransitionView) view; - transitionView.getParentViews().forEach((TreeNodeView n) -> n.removeChildrenView(transitionView)); - } - } - - /** - * When the edu.rpi.legup.user hovers over the transition, draws the corresponding rules image - * - * @param g the graphics to use to draw - */ - public void drawMouseOver(Graphics2D g) { - if (selection.getHover().getType() == TRANSITION && ((TreeTransitionView) selection.getHover()).getTreeElement().isJustified()) { - TreeTransition transition = (TreeTransition) selection.getHover().treeElement; - int imgWidth = 100; - int imgHeight = 100; - - BufferedImage image = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_ARGB); - image.createGraphics().drawImage(transition.getRule().getImageIcon().getImage(), 0, 0, null); - Point mousePoint = selection.getMousePoint(); - g.drawImage(image, mousePoint.x, mousePoint.y - 50, imgWidth, imgHeight, null); - } - } - - public void resetView() { - this.tree = null; - this.rootNodeView = null; - this.selection.clearSelection(); - this.selection.clearHover(); - } - - /** - * Called when a tree puzzleElement is added to the tree - * - * @param treeElement TreeElement that was added to the tree - */ - @Override - public void onTreeElementAdded(TreeElement treeElement) { - if (treeElement.getType() == NODE) { - addTreeNode((TreeNode) treeElement); - } - else { - addTreeTransition((TreeTransition) treeElement); - } - repaint(); - } - - /** - * Called when a tree puzzleElement is removed from the tree - * - * @param element TreeElement that was removed to the tree - */ - @Override - public void onTreeElementRemoved(TreeElement element) { - if (element.getType() == NODE) { - TreeNode node = (TreeNode) element; - TreeNodeView nodeView = (TreeNodeView) viewMap.get(node); - - nodeView.getParentView().setChildView(null); - removeTreeNode(node); - } - else { - TreeTransition trans = (TreeTransition) element; - TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); - - // unlock ancestor elements if case rule deleted - Rule rule = trans.getRule(); - for (TreeNode node : trans.getParents()) { - - // only if the last case of a case rule will be deleted - if (!(rule instanceof CaseRule && node.getChildren().isEmpty())) { - continue; - } - - CaseRule caseRule = (CaseRule)rule; - // set dependent elements to be modifiable by ancestors (if not dependent on others) - List ancestors = node.getAncestors(); - for (TreeNode ancestor : ancestors) { - // for all ancestors but root - if (ancestor.getParent() == null) { - continue; - } - - for (PuzzleElement pelement : caseRule.dependentElements(node.getBoard(), trans.getSelection())) { - // decrement, unlock if 0 cases depended - PuzzleElement oldElement = ancestor.getParent().getBoard().getPuzzleElement(pelement); - oldElement.setCasesDepended(oldElement.getCasesDepended() - 1); - if (oldElement.getCasesDepended() != 0) { - continue; - } - - // set modifiable if started modifiable - boolean modifiable = tree.getRootNode().getBoard().getPuzzleElement(oldElement).isModifiable(); - - // unmodifiable if already modified - TreeNode modNode = ancestor.getParent().getParents().get(0); - while (modNode.getParent()!=null) { - Board modBoard = modNode.getParent().getBoard(); - if (modBoard.getModifiedData().contains(modBoard.getPuzzleElement(oldElement))) { - modifiable = false; - break; - } - modNode = modNode.getParent().getParents().get(0); - } - oldElement.setModifiable(modifiable); - } - } - } - - transView.getParentViews().forEach(n -> n.removeChildrenView(transView)); - removeTreeTransition(trans); - } - repaint(); - } - - /** - * Called when the tree selection was changed - * - * @param selection tree selection that was changed - */ - @Override - public void onTreeSelectionChanged(TreeViewSelection selection) { - this.selection.getSelectedViews().forEach(v -> v.setSelected(false)); - selection.getSelectedViews().forEach(v -> v.setSelected(true)); - this.selection = selection; - repaint(); - } - - /** - * Called when the model has finished updating the tree. - */ - @Override - public void onUpdateTree() { - repaint(); - } - - /** - * Gets the TreeElementView by the corresponding TreeElement associated with it - * - * @param element TreeElement of the view - * @return TreeElementView of the TreeElement associated with it - */ - public TreeElementView getElementView(TreeElement element) { - return viewMap.get(element); - } - - private void removeTreeNode(TreeNode node) { - viewMap.remove(node); - List children = node.getChildren(); - - // if child is a case rule, unlock ancestor elements - if (!children.isEmpty()) { - Rule rule = children.get(0).getRule(); - if (rule instanceof CaseRule) { - CaseRule caseRule = (CaseRule)rule; - // set dependent elements to be modifiable by ancestors (if not dependent on others) - List ancestors = node.getAncestors(); - for (TreeNode ancestor : ancestors) { - // for all ancestors but root - if (ancestor.getParent() == null) { - continue; - } - for (PuzzleElement pelement : caseRule.dependentElements(node.getBoard(), children.get(0).getSelection())) { - // decrement, unlock if 0 cases depended - PuzzleElement oldElement = ancestor.getParent().getBoard().getPuzzleElement(pelement); - oldElement.setCasesDepended(oldElement.getCasesDepended() - 1); - if (oldElement.getCasesDepended() == 0) { - continue; - } - - // set modifiable if started modifiable - boolean modifiable = tree.getRootNode().getBoard().getPuzzleElement(oldElement).isModifiable(); - - // unmodifiable if already modified - TreeNode modNode = ancestor.getParent().getParents().get(0); - while (modNode.getParent() != null) { - Board modBoard = modNode.getParent().getBoard(); - if (modBoard.getModifiedData().contains(modBoard.getPuzzleElement(oldElement))) { - modifiable = false; - break; - } - modNode = modNode.getParent().getParents().get(0); - } - oldElement.setModifiable(modifiable); - } - } - } - } - node.getChildren().forEach(t -> removeTreeTransition(t)); - } - - private void removeTreeTransition(TreeTransition trans) { - viewMap.remove(trans); - if (trans.getChildNode() != null) { - removeTreeNode(trans.getChildNode()); - } - } - - private void addTreeNode(TreeNode node) { - TreeTransition parent = node.getParent(); - - TreeNodeView nodeView = new TreeNodeView(node); - TreeTransitionView parentView = (TreeTransitionView) viewMap.get(parent); - - nodeView.setParentView(parentView); - parentView.setChildView(nodeView); - - viewMap.put(node, nodeView); - - if (!node.getChildren().isEmpty()) { - - // if adding a case rule, lock dependent ancestor elements - Rule rule = node.getChildren().get(0).getRule(); - if (rule instanceof CaseRule) { - CaseRule caseRule = (CaseRule)rule; - - List ancestors = node.getAncestors(); - for (TreeNode ancestor : ancestors) { - // for all ancestors but root - if (ancestor.getParent() == null) { - continue; - } - for (PuzzleElement element : caseRule.dependentElements(node.getBoard(), node.getChildren().get(0).getSelection())) { - // increment and lock - PuzzleElement oldElement = ancestor.getParent().getBoard().getPuzzleElement(element); - oldElement.setCasesDepended(oldElement.getCasesDepended()+1); - oldElement.setModifiable(false); - } - } - } - - node.getChildren().forEach(t -> addTreeTransition(t)); - } - } - - private void addTreeTransition(TreeTransition trans) { - List parents = trans.getParents(); - - TreeTransitionView transView = new TreeTransitionView(trans); - for (TreeNode parent : parents) { - TreeNodeView parentNodeView = (TreeNodeView) viewMap.get(parent); - transView.addParentView(parentNodeView); - parentNodeView.addChildrenView(transView); - - // if transition is a new case rule, lock dependent ancestor elements - Rule rule = trans.getRule(); - if (rule instanceof CaseRule && parent.getChildren().size()==1) { - CaseRule caseRule = (CaseRule)rule; - - List ancestors = parent.getAncestors(); - for (TreeNode ancestor : ancestors) { - // for all ancestors but root - if (ancestor.getParent() == null) { - continue; - } - for (PuzzleElement element : caseRule.dependentElements(parent.getBoard(), trans.getSelection())) { - // increment and lock - PuzzleElement oldElement = ancestor.getParent().getBoard().getPuzzleElement(element); - oldElement.setCasesDepended(oldElement.getCasesDepended()+1); - oldElement.setModifiable(false); - } - } - } - } - - viewMap.put(trans, transView); - - if (trans.getChildNode() != null) { - addTreeNode(trans.getChildNode()); - } - } - - ///New Draw Methods - - public void drawTree(Graphics2D graphics2D) { - if (tree == null) { - LOGGER.error("Unable to draw tree."); - } - else { - if (rootNodeView == null) { - rootNodeView = new TreeNodeView(tree.getRootNode()); - - LOGGER.debug("Creating new views for tree view."); - createViews(rootNodeView); - - selection.newSelection(rootNodeView); - } - - dimension = new Dimension(0, 0); - calcSpan(rootNodeView); - rootNodeView.setSpan(rootNodeView.getSpan() + DIAMETER + BORDER_SPACING); - - calculateViewLocations(rootNodeView, 0); - dimension.height = (int) rootNodeView.getSpan(); - - redrawTree(graphics2D, rootNodeView); - LOGGER.debug("DrawTree: dimensions - " + dimension.width + "x" + dimension.height); - } - } - - public void createViews(TreeNodeView nodeView) { - if (nodeView != null) { - viewMap.put(nodeView.getTreeElement(), nodeView); - - TreeNode node = nodeView.getTreeElement(); - for (TreeTransition trans : node.getChildren()) { - TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); - if (transView != null) { - nodeView.addChildrenView(transView); - transView.addParentView(nodeView); - break; - } - transView = new TreeTransitionView(trans); - - viewMap.put(transView.getTreeElement(), transView); - - transView.addParentView(nodeView); - nodeView.addChildrenView(transView); - - TreeNode childNode = trans.getChildNode(); - if (childNode != null) { - TreeNodeView childNodeView = new TreeNodeView(childNode); - viewMap.put(childNodeView.getTreeElement(), childNodeView); - - childNodeView.setParentView(transView); - transView.setChildView(childNodeView); - - createViews(childNodeView); - } - } - } - } - - public void calculateViewLocations(TreeNodeView nodeView, int depth) { - nodeView.setDepth(depth); - int xLoc = (NODE_GAP_WIDTH + DIAMETER) * depth + DIAMETER; - nodeView.setX(xLoc); - dimension.width = Math.max(dimension.width, xLoc); - - TreeTransitionView parentTransView = nodeView.getParentView(); - int yLoc = parentTransView == null ? (int) nodeView.getSpan() / 2 : parentTransView.getEndY(); - nodeView.setY(yLoc); - - ArrayList children = nodeView.getChildrenViews(); - switch (children.size()) { - case 0: - break; - case 1: { - TreeTransitionView childView = children.get(0); - - List parentsViews = childView.getParentViews(); - if (parentsViews.size() == 1) { - childView.setEndY(yLoc); - - childView.setDepth(depth); - - Point lineStartPoint = childView.getLineStartPoint(0); - lineStartPoint.x = xLoc + RADIUS + TRANS_GAP / 2; - lineStartPoint.y = yLoc; - childView.setEndX((NODE_GAP_WIDTH + DIAMETER) * (depth + 1) + RADIUS - TRANS_GAP / 2); - - dimension.width = Math.max(dimension.width, childView.getEndX()); - - TreeNodeView childNodeView = childView.getChildView(); - if (childNodeView != null) { - calculateViewLocations(childNodeView, depth + 1); - } - } - else { - if (parentsViews.size() > 1 && parentsViews.get(parentsViews.size() - 1) == nodeView) { - int yAvg = 0; - for (int i = 0; i < parentsViews.size(); i++) { - TreeNodeView parentNodeView = parentsViews.get(i); - depth = Math.max(depth, parentNodeView.getDepth()); - yAvg += parentNodeView.getY(); - - Point lineStartPoint = childView.getLineStartPoint(i); - lineStartPoint.x = parentNodeView.getX() + RADIUS + TRANS_GAP / 2; - lineStartPoint.y = parentNodeView.getY(); - } - yAvg /= parentsViews.size(); - childView.setEndY(yAvg); - - childView.setDepth(depth); - - childView.setEndX((NODE_GAP_WIDTH + DIAMETER) * (depth + 1) + RADIUS - TRANS_GAP / 2); - - dimension.width = Math.max(dimension.width, childView.getEndX()); - - TreeNodeView childNodeView = childView.getChildView(); - if (childNodeView != null) { - calculateViewLocations(childNodeView, depth + 1); - } - } - } - break; - } - default: { - int span = 0; - for (TreeTransitionView childView : children) { - span += childView.getSpan(); - } - - span = (int) ((nodeView.getSpan() - span) / 2); - for (int i = 0; i < children.size(); i++) { - TreeTransitionView childView = children.get(i); - - childView.setDepth(depth); - - Point lineStartPoint = childView.getLineStartPoint(0); - lineStartPoint.x = xLoc + RADIUS + TRANS_GAP / 2; - lineStartPoint.y = yLoc; - childView.setEndX((NODE_GAP_WIDTH + DIAMETER) * (depth + 1) + RADIUS - TRANS_GAP / 2); - childView.setEndY(yLoc - (int) (nodeView.getSpan() / 2) + span + (int) (childView.getSpan() / 2)); - - span += childView.getSpan(); - TreeNodeView childNodeView = childView.getChildView(); - if (childNodeView != null) { - calculateViewLocations(childNodeView, depth + 1); - } - } - break; - } - } - } - - public void calcSpan(TreeElementView view) { - if (view.getType() == NODE) { - TreeNodeView nodeView = (TreeNodeView) view; - TreeNode node = nodeView.getTreeElement(); - if (nodeView.getChildrenViews().size() == 0) { - nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } - else { - if (nodeView.getChildrenViews().size() == 1) { - TreeTransitionView childView = nodeView.getChildrenViews().get(0); - calcSpan(childView); - if (childView.getParentViews().size() > 1) { - nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } - else { - nodeView.setSpan(childView.getSpan()); - } - } - else { - DisjointSets branches = node.findMergingBranches(); - List children = node.getChildren(); - - if (node == children.get(0).getParents().get(0)) { - reorderBranches(node, branches); - ArrayList newChildrenViews = new ArrayList<>(); - for (TreeTransition trans : node.getChildren()) { - newChildrenViews.add((TreeTransitionView) viewMap.get(trans)); - } - nodeView.setChildrenViews(newChildrenViews); - } - - List> mergingSets = branches.getAllSets(); - - double span = 0.0; - for (Set mergeSet : mergingSets) { - if (mergeSet.size() > 1) { - TreeTransition mergePoint = TreeNode.findMergingPoint(mergeSet); - TreeTransitionView mergePointView = (TreeTransitionView) viewMap.get(mergePoint); - double subSpan = 0.0; - for (TreeTransition branch : mergeSet) { - TreeTransitionView branchView = (TreeTransitionView) viewMap.get(branch); - subCalcSpan(branchView, mergePointView); - subSpan += branchView.getSpan(); - } - calcSpan(mergePointView); - span += Math.max(mergePointView.getSpan(), subSpan); - } - else { - TreeTransition trans = mergeSet.iterator().next(); - TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); - calcSpan(transView); - span += transView.getSpan(); - } - } - nodeView.setSpan(span); - } - } - } - else { - TreeTransitionView transView = (TreeTransitionView) view; - TreeNodeView nodeView = transView.getChildView(); - if (nodeView == null) { - transView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } - else { - calcSpan(nodeView); - transView.setSpan(nodeView.getSpan()); - } - } - } - - /** - * Calculates the sub span of a given sub tree rooted at the specified view and stops at the tree puzzleElement view - * specified as stop. Stop tree puzzleElement is NOT included in the span calculation - * - * @param view - * @param stop - */ - private void subCalcSpan(TreeElementView view, TreeElementView stop) { - //safe-guard for infinite loop - if (view == stop) { - return; - } - - if (view.getType() == NODE) { - TreeNodeView nodeView = (TreeNodeView) view; - TreeNode node = nodeView.getTreeElement(); - if (nodeView.getChildrenViews().size() == 0) { - nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } - else { - if (nodeView.getChildrenViews().size() == 1) { - TreeTransitionView childView = nodeView.getChildrenViews().get(0); - if (childView == stop) { - nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } - else { - subCalcSpan(childView, stop); - if (childView.getParentViews().size() > 1) { - nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } - else { - nodeView.setSpan(childView.getSpan()); - } - } - } - else { - DisjointSets branches = node.findMergingBranches(); - List children = node.getChildren(); - - if (node == children.get(0).getParents().get(0)) { - reorderBranches(node, branches); - } - - List> mergingSets = branches.getAllSets(); - - double span = 0.0; - for (Set mergeSet : mergingSets) { - if (mergeSet.size() > 1) { - TreeTransition mergePoint = TreeNode.findMergingPoint(mergeSet); - TreeTransitionView mergePointView = (TreeTransitionView) viewMap.get(mergePoint); - double subSpan = 0.0; - for (TreeTransition branch : mergeSet) { - TreeTransitionView branchView = (TreeTransitionView) viewMap.get(branch); - subCalcSpan(branchView, mergePointView); - subSpan += branchView.getSpan(); - } - subCalcSpan(mergePointView, stop); - span += Math.max(mergePointView.getSpan(), subSpan); - } - else { - TreeTransition trans = mergeSet.iterator().next(); - TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); - subCalcSpan(transView, stop); - span += transView.getSpan(); - } - } - - nodeView.setSpan(span); - } - } - } - else { - TreeTransitionView transView = (TreeTransitionView) view; - TreeNodeView nodeView = transView.getChildView(); - if (nodeView == null || nodeView == stop) { - transView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } - else { - calcSpan(nodeView); - transView.setSpan(nodeView.getSpan()); - } - } - } - - /** - * Reorders branches such that merging branches are sequentially grouped together and transitions are kept in - * relative order in the list of child transitions of the specified node - * - * @param node root node of the branches - * @param branches DisjointSets of the child branches of the specified node which determine which branches merge - */ - private void reorderBranches(TreeNode node, DisjointSets branches) { - List children = node.getChildren(); - List> mergingSets = branches.getAllSets(); - - List> newOrder = new ArrayList<>(); - for (Set set : mergingSets) { - List mergeBranch = new ArrayList<>(); - newOrder.add(mergeBranch); - children.forEach(t -> { - if (set.contains(t)) { - mergeBranch.add(t); - } - }); - mergeBranch.sort((TreeTransition t1, TreeTransition t2) -> - children.indexOf(t1) <= children.indexOf(t2) ? -1 : 1); - } - - newOrder.sort((List b1, List b2) -> { - int low1 = -1; - int low2 = -1; - for (TreeTransition t1 : b1) { - int curIndex = children.indexOf(t1); - if (low1 == -1 || curIndex < low1) { - low1 = curIndex; - } - } - for (TreeTransition t1 : b2) { - int curIndex = children.indexOf(t1); - if (low1 == -1 || curIndex < low1) { - low1 = curIndex; - } - } - return low1 < low2 ? -1 : 1; - }); - - List newChildren = new ArrayList<>(); - newOrder.forEach(l -> newChildren.addAll(l)); - node.setChildren(newChildren); - } +package edu.rpi.legup.ui.proofeditorui.treeview; + +import edu.rpi.legup.app.GameBoardFacade; +import edu.rpi.legup.controller.TreeController; +import edu.rpi.legup.model.observer.ITreeListener; +import edu.rpi.legup.model.tree.Tree; +import edu.rpi.legup.model.tree.TreeElement; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.ui.ScrollView; +import edu.rpi.legup.utility.DisjointSets; + +import javax.swing.*; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.util.*; +import java.util.List; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import static edu.rpi.legup.model.tree.TreeElementType.NODE; +import static edu.rpi.legup.model.tree.TreeElementType.TRANSITION; +import static edu.rpi.legup.ui.proofeditorui.treeview.TreeNodeView.DIAMETER; +import static edu.rpi.legup.ui.proofeditorui.treeview.TreeNodeView.RADIUS; + +public class TreeView extends ScrollView implements ITreeListener { + private final static Logger LOGGER = LogManager.getLogger(TreeView.class.getName()); + + private static final int TRANS_GAP = 5; + + private static final int NODE_GAP_WIDTH = 70; + private static final int NODE_GAP_HEIGHT = 15; + + private static final int BORDER_GAP_HEIGHT = 20; + private static final int BORDER_GAP_WIDTH = 20; + + private static final int BORDER_SPACING = 100; + + private TreeNodeView nodeHover; + + private ArrayList currentStateBoxes; + private Rectangle bounds = new Rectangle(0, 0, 0, 0); + + private Tree tree; + private TreeNodeView rootNodeView; + private Map viewMap; + private Dimension dimension; + + private TreeViewSelection selection; + + public TreeView(TreeController treeController) { + super(treeController); + currentStateBoxes = new ArrayList<>(); + setSize(dimension = new Dimension(100, 200)); + setPreferredSize(new Dimension(640, 160)); + + viewMap = new HashMap<>(); + + selection = new TreeViewSelection(); + } + + public TreeViewSelection getSelection() { + return selection; + } + + /** + * Gets the tree node puzzleElement that the mouse is hovering over + * + * @return tree node puzzleElement that the mouse is hovering over + */ + public TreeNodeView getNodeHover() { + return nodeHover; + } + + /** + * Sets the tree node puzzleElement that the mouse is hovering over + * + * @param nodeHover tree node puzzleElement the mouse is hovering over + */ + public void setNodeHover(TreeNodeView nodeHover) { + this.nodeHover = nodeHover; + } + + /** + * Gets the TreeElementView by the specified point or null if no view exists at the specified point + * + * @param point location to query for a view + * @return TreeElementView at the point specified, otherwise null + */ + public TreeElementView getTreeElementView(Point point) { + return getTreeElementView(point, rootNodeView); + } + + /** + * Recursively gets the TreeElementView by the specified point or null if no view exists at the specified point or + * the view specified is null + * + * @param point location to query for a view + * @param elementView view to determine if the point is contained within it + * @return TreeElementView at the point specified, otherwise null + */ + private TreeElementView getTreeElementView(Point point, TreeElementView elementView) { + if (elementView == null) { + return null; + } + else { + if (elementView.contains(point) && elementView.isVisible()) { + if (elementView.getType() == NODE && ((TreeNodeView) elementView).isContradictoryState()) { + return null; + } + return elementView; + } + else { + if (elementView.getType() == NODE) { + TreeNodeView nodeView = (TreeNodeView) elementView; + for (TreeTransitionView transitionView : nodeView.getChildrenViews()) { + TreeElementView view = getTreeElementView(point, transitionView); + if (view != null) { + return view; + } + } + } + else { + TreeTransitionView transitionView = (TreeTransitionView) elementView; + return getTreeElementView(point, transitionView.getChildView()); + } + } + } + return null; + } + + public void updateTreeView(Tree tree) { + this.tree = tree; + if (selection.getSelectedViews().size() == 0) { + selection.newSelection(new TreeNodeView(tree.getRootNode())); + } + repaint(); + } + + /** + * Sets the tree associated with this TreeView + * + * @param tree tree + */ + public void setTree(Tree tree) { + this.tree = tree; + } + + public void updateTreeSize() { + if (GameBoardFacade.getInstance().getTree() == null) { + return; + } + setSize(bounds.getSize()); + } + + public void reset() { + if (bounds.x != 0 || bounds.y != 0) { + updateTreeSize(); + } + } + + public void zoomFit() { + double fitWidth = (viewport.getWidth() - 8.0) / (getSize().width - 200); + double fitHeight = (viewport.getHeight() - 8.0) / (getSize().height - 120); + zoomTo(Math.min(fitWidth, fitHeight)); + viewport.setViewPosition(new Point(0, viewport.getHeight() / 2)); + } + + /** + * Creates a customized viewport for the scroll pane + * + * @return viewport for the scroll pane + */ + @Override + protected JViewport createViewport() { + return new JViewport() { + @Override + protected LayoutManager createLayoutManager() { + return new ViewportLayout() { + @Override + public void layoutContainer(Container parent) { + Point point = viewport.getViewPosition(); + // determine the maximum x and y view positions + int mx = getCanvas().getWidth() - viewport.getWidth(); + int my = getCanvas().getHeight() - viewport.getHeight(); + // obey edge boundaries + if (point.x < 0) { + point.x = 0; + } + if (point.x > mx) { + point.x = mx; + } + if (point.y < 0) { + point.y = 0; + } + if (point.y > my) { + point.y = my; + } + // center margins + if (mx < 0) { + point.x = 0; + } + if (my < 0) { + point.y = my / 2; + } + viewport.setViewPosition(point); + } + }; + } + }; + } + + public void draw(Graphics2D graphics2D) { + currentStateBoxes.clear(); + Tree tree = GameBoardFacade.getInstance().getTree(); + if (tree != null) { + //setSize(bounds.getDimension()); + graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + + drawTree(graphics2D); + + dimension.width += BORDER_SPACING; + setSize(dimension); +// graphics2D.drawRect(0,0, dimension.width, dimension.height); + + if (selection.getHover() != null) { + drawMouseOver(graphics2D); + } + } + } + + public void zoomReset() { + zoomTo(1.0); + viewport.setViewPosition(new Point(0, 0)); + } + + private void redrawTree(Graphics2D graphics2D, TreeNodeView nodeView) { + if (nodeView != null) { + nodeView.draw(graphics2D); + for (TreeTransitionView transitionView : nodeView.getChildrenViews()) { + transitionView.draw(graphics2D); + redrawTree(graphics2D, transitionView.getChildView()); + } + } + } + + public void removeTreeElement(TreeElementView view) { + if (view.getType() == NODE) { + TreeNodeView nodeView = (TreeNodeView) view; + nodeView.getParentView().setChildView(null); + } + else { + TreeTransitionView transitionView = (TreeTransitionView) view; + transitionView.getParentViews().forEach((TreeNodeView n) -> n.removeChildrenView(transitionView)); + } + } + + /** + * When the edu.rpi.legup.user hovers over the transition, draws the corresponding rules image + * + * @param g the graphics to use to draw + */ + public void drawMouseOver(Graphics2D g) { + if (selection.getHover().getType() == TRANSITION && ((TreeTransitionView) selection.getHover()).getTreeElement().isJustified()) { + TreeTransition transition = (TreeTransition) selection.getHover().treeElement; + int imgWidth = 100; + int imgHeight = 100; + + BufferedImage image = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_ARGB); + image.createGraphics().drawImage(transition.getRule().getImageIcon().getImage(), 0, 0, null); + Point mousePoint = selection.getMousePoint(); + g.drawImage(image, mousePoint.x, mousePoint.y - 50, imgWidth, imgHeight, null); + } + } + + public void resetView() { + this.tree = null; + this.rootNodeView = null; + this.selection.clearSelection(); + this.selection.clearHover(); + } + + /** + * Called when a tree puzzleElement is added to the tree + * + * @param treeElement TreeElement that was added to the tree + */ + @Override + public void onTreeElementAdded(TreeElement treeElement) { + if (treeElement.getType() == NODE) { + addTreeNode((TreeNode) treeElement); + } + else { + addTreeTransition((TreeTransition) treeElement); + } + repaint(); + } + + /** + * Called when a tree puzzleElement is removed from the tree + * + * @param element TreeElement that was removed to the tree + */ + @Override + public void onTreeElementRemoved(TreeElement element) { + if (element.getType() == NODE) { + TreeNode node = (TreeNode) element; + TreeNodeView nodeView = (TreeNodeView) viewMap.get(node); + + nodeView.getParentView().setChildView(null); + removeTreeNode(node); + } + else { + TreeTransition trans = (TreeTransition) element; + TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); + + transView.getParentViews().forEach(n -> n.removeChildrenView(transView)); + removeTreeTransition(trans); + } + repaint(); + } + + /** + * Called when the tree selection was changed + * + * @param selection tree selection that was changed + */ + @Override + public void onTreeSelectionChanged(TreeViewSelection selection) { + this.selection.getSelectedViews().forEach(v -> v.setSelected(false)); + selection.getSelectedViews().forEach(v -> v.setSelected(true)); + this.selection = selection; + repaint(); + } + + /** + * Called when the model has finished updating the tree. + */ + @Override + public void onUpdateTree() { + repaint(); + } + + /** + * Gets the TreeElementView by the corresponding TreeElement associated with it + * + * @param element TreeElement of the view + * @return TreeElementView of the TreeElement associated with it + */ + public TreeElementView getElementView(TreeElement element) { + return viewMap.get(element); + } + + private void removeTreeNode(TreeNode node) { + viewMap.remove(node); + node.getChildren().forEach(t -> removeTreeTransition(t)); + } + + private void removeTreeTransition(TreeTransition trans) { + viewMap.remove(trans); + if (trans.getChildNode() != null) { + removeTreeNode(trans.getChildNode()); + } + } + + private void addTreeNode(TreeNode node) { + TreeTransition parent = node.getParent(); + + TreeNodeView nodeView = new TreeNodeView(node); + TreeTransitionView parentView = (TreeTransitionView) viewMap.get(parent); + + nodeView.setParentView(parentView); + parentView.setChildView(nodeView); + + viewMap.put(node, nodeView); + + if (!node.getChildren().isEmpty()) { + node.getChildren().forEach(t -> addTreeTransition(t)); + } + } + + private void addTreeTransition(TreeTransition trans) { + List parents = trans.getParents(); + + TreeTransitionView transView = new TreeTransitionView(trans); + for (TreeNode parent : parents) { + TreeNodeView parentNodeView = (TreeNodeView) viewMap.get(parent); + transView.addParentView(parentNodeView); + parentNodeView.addChildrenView(transView); + } + + viewMap.put(trans, transView); + + if (trans.getChildNode() != null) { + addTreeNode(trans.getChildNode()); + } + } + + ///New Draw Methods + + public void drawTree(Graphics2D graphics2D) { + if (tree == null) { + LOGGER.error("Unable to draw tree."); + } + else { + if (rootNodeView == null) { + rootNodeView = new TreeNodeView(tree.getRootNode()); + + LOGGER.debug("Creating new views for tree view."); + createViews(rootNodeView); + + selection.newSelection(rootNodeView); + } + + dimension = new Dimension(0, 0); + calcSpan(rootNodeView); + rootNodeView.setSpan(rootNodeView.getSpan() + DIAMETER + BORDER_SPACING); + + calculateViewLocations(rootNodeView, 0); + dimension.height = (int) rootNodeView.getSpan(); + + redrawTree(graphics2D, rootNodeView); + LOGGER.debug("DrawTree: dimensions - " + dimension.width + "x" + dimension.height); + } + } + + public void createViews(TreeNodeView nodeView) { + if (nodeView != null) { + viewMap.put(nodeView.getTreeElement(), nodeView); + + TreeNode node = nodeView.getTreeElement(); + for (TreeTransition trans : node.getChildren()) { + TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); + if (transView != null) { + nodeView.addChildrenView(transView); + transView.addParentView(nodeView); + break; + } + transView = new TreeTransitionView(trans); + + viewMap.put(transView.getTreeElement(), transView); + + transView.addParentView(nodeView); + nodeView.addChildrenView(transView); + + TreeNode childNode = trans.getChildNode(); + if (childNode != null) { + TreeNodeView childNodeView = new TreeNodeView(childNode); + viewMap.put(childNodeView.getTreeElement(), childNodeView); + + childNodeView.setParentView(transView); + transView.setChildView(childNodeView); + + createViews(childNodeView); + } + } + } + } + + public void calculateViewLocations(TreeNodeView nodeView, int depth) { + nodeView.setDepth(depth); + int xLoc = (NODE_GAP_WIDTH + DIAMETER) * depth + DIAMETER; + nodeView.setX(xLoc); + dimension.width = Math.max(dimension.width, xLoc); + + TreeTransitionView parentTransView = nodeView.getParentView(); + int yLoc = parentTransView == null ? (int) nodeView.getSpan() / 2 : parentTransView.getEndY(); + nodeView.setY(yLoc); + + ArrayList children = nodeView.getChildrenViews(); + switch (children.size()) { + case 0: + break; + case 1: { + TreeTransitionView childView = children.get(0); + + List parentsViews = childView.getParentViews(); + if (parentsViews.size() == 1) { + childView.setEndY(yLoc); + + childView.setDepth(depth); + + Point lineStartPoint = childView.getLineStartPoint(0); + lineStartPoint.x = xLoc + RADIUS + TRANS_GAP / 2; + lineStartPoint.y = yLoc; + childView.setEndX((NODE_GAP_WIDTH + DIAMETER) * (depth + 1) + RADIUS - TRANS_GAP / 2); + + dimension.width = Math.max(dimension.width, childView.getEndX()); + + TreeNodeView childNodeView = childView.getChildView(); + if (childNodeView != null) { + calculateViewLocations(childNodeView, depth + 1); + } + } + else { + if (parentsViews.size() > 1 && parentsViews.get(parentsViews.size() - 1) == nodeView) { + int yAvg = 0; + for (int i = 0; i < parentsViews.size(); i++) { + TreeNodeView parentNodeView = parentsViews.get(i); + depth = Math.max(depth, parentNodeView.getDepth()); + yAvg += parentNodeView.getY(); + + Point lineStartPoint = childView.getLineStartPoint(i); + lineStartPoint.x = parentNodeView.getX() + RADIUS + TRANS_GAP / 2; + lineStartPoint.y = parentNodeView.getY(); + } + yAvg /= parentsViews.size(); + childView.setEndY(yAvg); + + childView.setDepth(depth); + + childView.setEndX((NODE_GAP_WIDTH + DIAMETER) * (depth + 1) + RADIUS - TRANS_GAP / 2); + + dimension.width = Math.max(dimension.width, childView.getEndX()); + + TreeNodeView childNodeView = childView.getChildView(); + if (childNodeView != null) { + calculateViewLocations(childNodeView, depth + 1); + } + } + } + break; + } + default: { + int span = 0; + for (TreeTransitionView childView : children) { + span += childView.getSpan(); + } + + span = (int) ((nodeView.getSpan() - span) / 2); + for (int i = 0; i < children.size(); i++) { + TreeTransitionView childView = children.get(i); + + childView.setDepth(depth); + + Point lineStartPoint = childView.getLineStartPoint(0); + lineStartPoint.x = xLoc + RADIUS + TRANS_GAP / 2; + lineStartPoint.y = yLoc; + childView.setEndX((NODE_GAP_WIDTH + DIAMETER) * (depth + 1) + RADIUS - TRANS_GAP / 2); + childView.setEndY(yLoc - (int) (nodeView.getSpan() / 2) + span + (int) (childView.getSpan() / 2)); + + span += childView.getSpan(); + TreeNodeView childNodeView = childView.getChildView(); + if (childNodeView != null) { + calculateViewLocations(childNodeView, depth + 1); + } + } + break; + } + } + } + + public void calcSpan(TreeElementView view) { + if (view.getType() == NODE) { + TreeNodeView nodeView = (TreeNodeView) view; + TreeNode node = nodeView.getTreeElement(); + if (nodeView.getChildrenViews().size() == 0) { + nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); + } + else { + if (nodeView.getChildrenViews().size() == 1) { + TreeTransitionView childView = nodeView.getChildrenViews().get(0); + calcSpan(childView); + if (childView.getParentViews().size() > 1) { + nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); + } + else { + nodeView.setSpan(childView.getSpan()); + } + } + else { + DisjointSets branches = node.findMergingBranches(); + List children = node.getChildren(); + + if (node == children.get(0).getParents().get(0)) { + reorderBranches(node, branches); + ArrayList newChildrenViews = new ArrayList<>(); + for (TreeTransition trans : node.getChildren()) { + newChildrenViews.add((TreeTransitionView) viewMap.get(trans)); + } + nodeView.setChildrenViews(newChildrenViews); + } + + List> mergingSets = branches.getAllSets(); + + double span = 0.0; + for (Set mergeSet : mergingSets) { + if (mergeSet.size() > 1) { + TreeTransition mergePoint = TreeNode.findMergingPoint(mergeSet); + TreeTransitionView mergePointView = (TreeTransitionView) viewMap.get(mergePoint); + double subSpan = 0.0; + for (TreeTransition branch : mergeSet) { + TreeTransitionView branchView = (TreeTransitionView) viewMap.get(branch); + subCalcSpan(branchView, mergePointView); + subSpan += branchView.getSpan(); + } + calcSpan(mergePointView); + span += Math.max(mergePointView.getSpan(), subSpan); + } + else { + TreeTransition trans = mergeSet.iterator().next(); + TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); + calcSpan(transView); + span += transView.getSpan(); + } + } + nodeView.setSpan(span); + } + } + } + else { + TreeTransitionView transView = (TreeTransitionView) view; + TreeNodeView nodeView = transView.getChildView(); + if (nodeView == null) { + transView.setSpan(DIAMETER + NODE_GAP_HEIGHT); + } + else { + calcSpan(nodeView); + transView.setSpan(nodeView.getSpan()); + } + } + } + + /** + * Calculates the sub span of a given sub tree rooted at the specified view and stops at the tree puzzleElement view + * specified as stop. Stop tree puzzleElement is NOT included in the span calculation + * + * @param view + * @param stop + */ + private void subCalcSpan(TreeElementView view, TreeElementView stop) { + //safe-guard for infinite loop + if (view == stop) { + return; + } + + if (view.getType() == NODE) { + TreeNodeView nodeView = (TreeNodeView) view; + TreeNode node = nodeView.getTreeElement(); + if (nodeView.getChildrenViews().size() == 0) { + nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); + } + else { + if (nodeView.getChildrenViews().size() == 1) { + TreeTransitionView childView = nodeView.getChildrenViews().get(0); + if (childView == stop) { + nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); + } + else { + subCalcSpan(childView, stop); + if (childView.getParentViews().size() > 1) { + nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); + } + else { + nodeView.setSpan(childView.getSpan()); + } + } + } + else { + DisjointSets branches = node.findMergingBranches(); + List children = node.getChildren(); + + if (node == children.get(0).getParents().get(0)) { + reorderBranches(node, branches); + } + + List> mergingSets = branches.getAllSets(); + + double span = 0.0; + for (Set mergeSet : mergingSets) { + if (mergeSet.size() > 1) { + TreeTransition mergePoint = TreeNode.findMergingPoint(mergeSet); + TreeTransitionView mergePointView = (TreeTransitionView) viewMap.get(mergePoint); + double subSpan = 0.0; + for (TreeTransition branch : mergeSet) { + TreeTransitionView branchView = (TreeTransitionView) viewMap.get(branch); + subCalcSpan(branchView, mergePointView); + subSpan += branchView.getSpan(); + } + subCalcSpan(mergePointView, stop); + span += Math.max(mergePointView.getSpan(), subSpan); + } + else { + TreeTransition trans = mergeSet.iterator().next(); + TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); + subCalcSpan(transView, stop); + span += transView.getSpan(); + } + } + + nodeView.setSpan(span); + } + } + } + else { + TreeTransitionView transView = (TreeTransitionView) view; + TreeNodeView nodeView = transView.getChildView(); + if (nodeView == null || nodeView == stop) { + transView.setSpan(DIAMETER + NODE_GAP_HEIGHT); + } + else { + calcSpan(nodeView); + transView.setSpan(nodeView.getSpan()); + } + } + } + + /** + * Reorders branches such that merging branches are sequentially grouped together and transitions are kept in + * relative order in the list of child transitions of the specified node + * + * @param node root node of the branches + * @param branches DisjointSets of the child branches of the specified node which determine which branches merge + */ + private void reorderBranches(TreeNode node, DisjointSets branches) { + List children = node.getChildren(); + List> mergingSets = branches.getAllSets(); + + List> newOrder = new ArrayList<>(); + for (Set set : mergingSets) { + List mergeBranch = new ArrayList<>(); + newOrder.add(mergeBranch); + children.forEach(t -> { + if (set.contains(t)) { + mergeBranch.add(t); + } + }); + mergeBranch.sort((TreeTransition t1, TreeTransition t2) -> + children.indexOf(t1) <= children.indexOf(t2) ? -1 : 1); + } + + newOrder.sort((List b1, List b2) -> { + int low1 = -1; + int low2 = -1; + for (TreeTransition t1 : b1) { + int curIndex = children.indexOf(t1); + if (low1 == -1 || curIndex < low1) { + low1 = curIndex; + } + } + for (TreeTransition t1 : b2) { + int curIndex = children.indexOf(t1); + if (low1 == -1 || curIndex < low1) { + low1 = curIndex; + } + } + return low1 < low2 ? -1 : 1; + }); + + List newChildren = new ArrayList<>(); + newOrder.forEach(l -> newChildren.addAll(l)); + node.setChildren(newChildren); + } } \ No newline at end of file From cfaabb43701558d59877dbd64dc319332e142ef6 Mon Sep 17 00:00:00 2001 From: Charles Tian <46334090+charlestian23@users.noreply.github.com> Date: Fri, 26 Jan 2024 10:11:05 -0500 Subject: [PATCH 02/11] Case rule test fix (#705) Co-authored-by: Chase Grajeda <76405306+Chase-Grajeda@users.noreply.github.com> --- .../java/puzzles/shorttruthtable/rules/AndCaseRuleTest.java | 4 ++-- .../java/puzzles/shorttruthtable/rules/OrCaseRuleTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/puzzles/shorttruthtable/rules/AndCaseRuleTest.java b/src/test/java/puzzles/shorttruthtable/rules/AndCaseRuleTest.java index 5f0a1243a..4d4e95762 100644 --- a/src/test/java/puzzles/shorttruthtable/rules/AndCaseRuleTest.java +++ b/src/test/java/puzzles/shorttruthtable/rules/AndCaseRuleTest.java @@ -42,7 +42,7 @@ private void falseAndTest(String fileName, ArrayList cases = RULE.getCases(board, cell); // Make sure that the rule checks out - Assert.assertNotNull(RULE.checkRule(transition)); + Assert.assertNull(RULE.checkRule(transition)); // Make sure there are two branches Assert.assertEquals(2, cases.size()); @@ -120,7 +120,7 @@ private void trueAndTest(String fileName, ArrayList cases = RULE.getCases(board, cell); // Make sure that the rule checks out - Assert.assertNotNull(RULE.checkRule(transition)); + Assert.assertNull(RULE.checkRule(transition)); // There should only be 1 branch Assert.assertEquals(1, cases.size()); diff --git a/src/test/java/puzzles/shorttruthtable/rules/OrCaseRuleTest.java b/src/test/java/puzzles/shorttruthtable/rules/OrCaseRuleTest.java index 276e822cf..0f7e93db5 100644 --- a/src/test/java/puzzles/shorttruthtable/rules/OrCaseRuleTest.java +++ b/src/test/java/puzzles/shorttruthtable/rules/OrCaseRuleTest.java @@ -43,7 +43,7 @@ private void trueOrTest(String fileName, ArrayList cases = RULE.getCases(board, cell); // Make sure that the rule checks out - Assert.assertNotNull(RULE.checkRule(transition)); + Assert.assertNull(RULE.checkRule(transition)); // Make sure there are two branches Assert.assertEquals(2, cases.size()); @@ -121,7 +121,7 @@ private void falseOrTest(String fileName, ArrayList cases = RULE.getCases(board, cell); // Make sure that the rule checks out - Assert.assertNotNull(RULE.checkRule(transition)); + Assert.assertNull(RULE.checkRule(transition)); // There should only be 1 branch Assert.assertEquals(1, cases.size()); From f20bfe1423da68c49876ecf715ca268465bba688 Mon Sep 17 00:00:00 2001 From: Chase-Grajeda Date: Fri, 26 Jan 2024 12:55:07 -0500 Subject: [PATCH 03/11] Rapid fix for STT case rules Case rules broke at some point from legacy code or merge conflict. Provided is a quick fix in CaseRule and CaseRule_Generic --- bin/main/edu/rpi/legup/log4j2.properties | 28 +++++++++---------- .../edu/rpi/legup/model/rules/CaseRule.java | 10 ------- .../rules/caserule/CaseRule_Generic.java | 22 +++++++-------- .../rules/TrueOrFalseCaseRuleTest.java | 2 +- 4 files changed, 26 insertions(+), 36 deletions(-) diff --git a/bin/main/edu/rpi/legup/log4j2.properties b/bin/main/edu/rpi/legup/log4j2.properties index 4f2556c2d..de1fa02ed 100644 --- a/bin/main/edu/rpi/legup/log4j2.properties +++ b/bin/main/edu/rpi/legup/log4j2.properties @@ -1,15 +1,15 @@ -# Logging level -# Root logger option -log4j.rootLogger=DEBUG, stdout, file -# Redirect log messages to console -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n -# Redirect log messages to a log file, support file rolling. -log4j.appender.file=org.apache.log4j.RollingFileAppender -log4j.appender.file.File=Legup.log -log4j.appender.file.MaxFileSize=5MB -log4j.appender.file.MaxBackupIndex=10 -log4j.appender.file.layout=org.apache.log4j.PatternLayout +# Logging level +# Root logger option +log4j.rootLogger=DEBUG, stdout, file +# Redirect log messages to console +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n +# Redirect log messages to a log file, support file rolling. +log4j.appender.file=org.apache.log4j.RollingFileAppender +log4j.appender.file.File=Legup.log +log4j.appender.file.MaxFileSize=5MB +log4j.appender.file.MaxBackupIndex=10 +log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n \ No newline at end of file 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 d9c7e73e5..6563f4d97 100644 --- a/src/main/java/edu/rpi/legup/model/rules/CaseRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/CaseRule.java @@ -61,20 +61,10 @@ public String checkRule(TreeTransition transition) { return "Must not have multiple parent nodes"; } - /*if (transition.getBoard().getModifiedData().size() != 0){ - return "Should not modify before case rule"; - }*/ - - for (TreeTransition childTrans : parentNodes.get(0).getChildren()) { if (childTrans.getRule() == null || !childTrans.getRule().getClass().equals(this.getClass())) { return "All children nodes must be justified with the same case rule."; } - else { - if (childTrans.getBoard().getModifiedData().isEmpty()) { - return "You must modify the board in each case node"; - } - } } String check = checkRuleRaw(transition); 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 1409f4baa..46163c2a3 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 @@ -38,20 +38,20 @@ public CaseRule_Generic(String ruleID, String ruleName, String title, String des public String checkRuleRaw(TreeTransition transition) { // Validate that two children are generated List childTransitions = transition.getParents().get(0).getChildren(); - if (childTransitions.size() >= 1) { + if (childTransitions.size() == 0) { return "ERROR: This case rule must spawn at least 1 child."; } - // Validate that the modified cells are of type UNKNOWN, TRUE, or FALSE - List cases = Arrays.asList(childTransitions.get(0), childTransitions.get(1)); - for (TreeTransition c : cases) { - ShortTruthTableCell mod1 = (ShortTruthTableCell)c.getBoard().getModifiedData().iterator().next(); - ShortTruthTableCell mod2 = (ShortTruthTableCell)c.getBoard().getModifiedData().iterator().next(); - if (!(mod1.getType() == ShortTruthTableCellType.TRUE || mod1.getType() == ShortTruthTableCellType.FALSE || mod1.getType() == ShortTruthTableCellType.UNKNOWN) && - (mod2.getType() == ShortTruthTableCellType.TRUE || mod2.getType() == ShortTruthTableCellType.FALSE || mod2.getType() == ShortTruthTableCellType.UNKNOWN)) { - return "ERROR: This case rule must be an unknown, true, or false cell."; - } - } + // // Validate that the modified cells are of type UNKNOWN, TRUE, or FALSE + // List cases = Arrays.asList(childTransitions.get(0), childTransitions.get(1)); + // for (TreeTransition c : cases) { + // ShortTruthTableCell mod1 = (ShortTruthTableCell)c.getBoard().getModifiedData().iterator().next(); + // ShortTruthTableCell mod2 = (ShortTruthTableCell)c.getBoard().getModifiedData().iterator().next(); + // if (!(mod1.getType() == ShortTruthTableCellType.TRUE || mod1.getType() == ShortTruthTableCellType.FALSE || mod1.getType() == ShortTruthTableCellType.UNKNOWN) && + // (mod2.getType() == ShortTruthTableCellType.TRUE || mod2.getType() == ShortTruthTableCellType.FALSE || mod2.getType() == ShortTruthTableCellType.UNKNOWN)) { + // return "ERROR: This case rule must be an unknown, true, or false cell."; + // } + // } return null; } diff --git a/src/test/java/puzzles/shorttruthtable/rules/TrueOrFalseCaseRuleTest.java b/src/test/java/puzzles/shorttruthtable/rules/TrueOrFalseCaseRuleTest.java index 849e9f15c..2c0b9fb15 100644 --- a/src/test/java/puzzles/shorttruthtable/rules/TrueOrFalseCaseRuleTest.java +++ b/src/test/java/puzzles/shorttruthtable/rules/TrueOrFalseCaseRuleTest.java @@ -44,7 +44,7 @@ public void TwoBranchesTest() throws InvalidFileFormatException { ArrayList cases = RULE.getCases(board, cell); // Make sure that the rule checks out - Assert.assertNotNull(RULE.checkRule(transition)); + Assert.assertNull(RULE.checkRule(transition)); // Make sure there are two branches Assert.assertEquals(2, cases.size()); From 36e1dcf5d869276f5d55a99b85e781bb79beebc3 Mon Sep 17 00:00:00 2001 From: Charles Tian <46334090+charlestian23@users.noreply.github.com> Date: Fri, 26 Jan 2024 12:57:11 -0500 Subject: [PATCH 04/11] Revert "Revert "Bugfix 549 (#682)"" (#706) This reverts commit e9fe310378721aa4b4fa358aa57ec44f21d086c1. --- puzzles files/skyscrapers/1646651 | 31 - puzzles files/skyscrapers/easy1.xml | 47 - .../legup/history/AutoCaseRuleCommand.java | 1 + .../legup/model/gameboard/PuzzleElement.java | 20 + .../edu/rpi/legup/model/rules/CaseRule.java | 29 +- .../edu/rpi/legup/model/rules/DirectRule.java | 4 + .../rpi/legup/model/tree/TreeTransition.java | 64 +- .../lightup/rules/SatisfyNumberCaseRule.java | 63 + .../caserule/CaseRule_GenericStatement.java | 256 +-- .../puzzle/skyscrapers/SkyscrapersBoard.java | 11 - .../puzzle/skyscrapers/SkyscrapersClue.java | 5 +- .../rules/CellForNumberCaseRule.java | 53 +- .../rules/NumberForCellCaseRule.java | 35 + .../legup/puzzle/treetent/TreeTentBoard.java | 20 +- .../treetent/rules/FillinRowCaseRule.java | 25 + .../treetent/rules/LinkTentCaseRule.java | 15 +- .../treetent/rules/LinkTreeCaseRule.java | 29 + .../ui/proofeditorui/treeview/TreeView.java | 1640 +++++++++-------- 18 files changed, 1354 insertions(+), 994 deletions(-) delete mode 100644 puzzles files/skyscrapers/1646651 delete mode 100644 puzzles files/skyscrapers/easy1.xml diff --git a/puzzles files/skyscrapers/1646651 b/puzzles files/skyscrapers/1646651 deleted file mode 100644 index 847d8639c..000000000 --- a/puzzles files/skyscrapers/1646651 +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/puzzles files/skyscrapers/easy1.xml b/puzzles files/skyscrapers/easy1.xml deleted file mode 100644 index 9d3135bff..000000000 --- a/puzzles files/skyscrapers/easy1.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java b/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java index 331a3dddf..a4c157c77 100644 --- a/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java +++ b/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java @@ -62,6 +62,7 @@ public void executeCommand() { board.setModifiable(false); transition.setBoard(board); transition.setRule(caseRule); + transition.setSelection(elementView.getPuzzleElement().copy()); caseTrans.add(transition); TreeNode childNode = (TreeNode) tree.addTreeElement(transition); diff --git a/src/main/java/edu/rpi/legup/model/gameboard/PuzzleElement.java b/src/main/java/edu/rpi/legup/model/gameboard/PuzzleElement.java index 97c9205cf..3d84287e3 100644 --- a/src/main/java/edu/rpi/legup/model/gameboard/PuzzleElement.java +++ b/src/main/java/edu/rpi/legup/model/gameboard/PuzzleElement.java @@ -11,6 +11,7 @@ public abstract class PuzzleElement { protected boolean isModified; protected boolean isGiven; protected boolean isValid; + protected int casesDepended; /** * PuzzleElement Constructor creates a new puzzle element. @@ -22,6 +23,7 @@ public PuzzleElement() { this.isModified = false; this.isGiven = false; this.isValid = true; + this.casesDepended = 0; } /** @@ -148,6 +150,24 @@ public void setValid(boolean isValid) { this.isValid = isValid; } + /** + * Get the number of case rules that depend upon the state of this element + * + * @return number of cases + */ + public int getCasesDepended() { + return this.casesDepended; + } + + /** + * Sets the number of case rules that depend upon the state of this element + * + * @param cases number of cases + */ + public void setCasesDepended(int cases) { + this.casesDepended = cases; + } + /** * Tests whether two puzzle elements objects have the same puzzle element * 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 6563f4d97..a01db2b6d 100644 --- a/src/main/java/edu/rpi/legup/model/rules/CaseRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/CaseRule.java @@ -7,9 +7,8 @@ import edu.rpi.legup.model.tree.TreeTransition; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; +import java.util.Set; import static edu.rpi.legup.model.rules.RuleType.CASE; @@ -69,6 +68,7 @@ public String checkRule(TreeTransition transition) { String check = checkRuleRaw(transition); + // Mark transition and new data as valid or not boolean isCorrect = (check == null); for (TreeTransition childTrans : parentNodes.get(0).getChildren()) { childTrans.setCorrect(isCorrect); @@ -115,6 +115,31 @@ public String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement */ @Override public abstract String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement); + + /** + * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid + * Overridden by case rules dependent on more than just the modified data + * + * @param board board state at application + * @param puzzleElement selected puzzleElement + * @return List of puzzle elements (typically cells) this application of the case rule depends upon. + * Defaults to any element modified by any case + */ + public List dependentElements(Board board, PuzzleElement puzzleElement) { + List elements = new ArrayList<>(); + + List cases = getCases(board,puzzleElement); + for (Board caseBoard : cases) { + Set data = caseBoard.getModifiedData(); + for (PuzzleElement element : data) { + if(!elements.contains(board.getPuzzleElement(element))){ + elements.add(board.getPuzzleElement(element)); + } + } + } + + return elements; + } } diff --git a/src/main/java/edu/rpi/legup/model/rules/DirectRule.java b/src/main/java/edu/rpi/legup/model/rules/DirectRule.java index 0465ca88c..847764b7b 100644 --- a/src/main/java/edu/rpi/legup/model/rules/DirectRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/DirectRule.java @@ -33,6 +33,10 @@ public String checkRule(TreeTransition transition) { transition.getParents().get(0).getChildren().size() != 1) { return "State must have only 1 parent and 1 child"; } + else if (finalBoard.getModifiedData().isEmpty()) { + // null transition + return null; + } else { return checkRuleRaw(transition); } diff --git a/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java b/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java index e1d042626..72572ac72 100644 --- a/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java +++ b/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java @@ -2,6 +2,7 @@ import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.CaseRule; import edu.rpi.legup.model.rules.Rule; import edu.rpi.legup.model.rules.RuleType; @@ -12,6 +13,8 @@ public class TreeTransition extends TreeElement { private ArrayList parents; private TreeNode childNode; private Rule rule; + + private PuzzleElement selection; private boolean isCorrect; private boolean isVerified; @@ -26,6 +29,7 @@ public TreeTransition(Board board) { this.childNode = null; this.board = board; this.rule = null; + this.selection = null; this.isCorrect = false; this.isVerified = false; } @@ -87,13 +91,42 @@ public void propagateChange(PuzzleElement element) { } } else { + // Overwrite previous modifications to this element + board.removeModifiedData(board.getPuzzleElement(element)); + + // apply changes to tranistion + board.notifyChange(element); + + // mark first transition as modified + if (!board.getPuzzleElement(element).equalsData(parents.get(0).getBoard().getPuzzleElement(element))) { + board.addModifiedData(element); + } + + // propagate to children if (childNode != null) { - board.notifyChange(element); - childNode.getBoard().notifyChange(element.copy()); - for (TreeTransition child : childNode.getChildren()) { - PuzzleElement copy = element.copy(); + + // find starting board + TreeNode head = childNode; + while (head.getParent() != null) { + head = head.getParent().getParents().get(0); + } + Board headBoard = head.getBoard(); + + PuzzleElement copy = element.copy(); + // Set as modifiable if reverted to starting value (and started modifiable) + if (headBoard.getPuzzleElement(element).equalsData(element)) { + copy.setModifiable(headBoard.getPuzzleElement(element).isModifiable()); + } + else{ copy.setModifiable(false); - child.propagateChange(copy); + } + + // apply changes to result node + childNode.getBoard().notifyChange(copy); + + // apply to all child transitions + for (TreeTransition child : childNode.getChildren()) { + child.propagateChange(copy.copy()); } } } @@ -327,6 +360,27 @@ public void setRule(Rule rule) { isVerified = false; } + /** + * Gets he selected element associated with this transition + * + * @return If this is a case rule, the selected element for that rule, null otherwise + */ + public PuzzleElement getSelection() { + if (this.rule instanceof CaseRule) { + return selection; + } + return null; + } + + /** + * Sets the selected element associated with this transition + * + * @param selection selected element for this transition + */ + public void setSelection(PuzzleElement selection) { + this.selection = selection; + } + /** * Gets whether this transition is correctly justified * 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 1f166685b..cf7b70ccd 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 @@ -287,4 +287,67 @@ private List getAdjacentCells(LightUpBoard board, LightUpCell cell) } return cells; } + + /** + * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid + * Overridden by case rules dependent on more than just the modified data + * + * @param board board state at application + * @param puzzleElement selected puzzleElement + * @return List of puzzle elements (typically cells) this application of the case rule depends upon. + * Defaults to any element modified by any case + */ + @Override + public List dependentElements(Board board, PuzzleElement puzzleElement) { + List elements = new ArrayList<>(); + + LightUpBoard puzzleBoard = (LightUpBoard) board; + LightUpCell point = (LightUpCell)puzzleBoard.getPuzzleElement(puzzleElement); + + List cells = getAdjacentCells(puzzleBoard,point); + + for (LightUpCell cell : cells) { + //add cells that can light adjacents from any direction + Point location = cell.getLocation(); + for (int i = location.x; i < puzzleBoard.getWidth(); i++) { + System.out.println(i); + LightUpCell c = puzzleBoard.getCell(i, location.y); + if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { + break; + } + else if (!elements.contains(board.getPuzzleElement(c))) { + elements.add(board.getPuzzleElement(c)); + } + } + for (int i = location.x; i >= 0; i--) { + LightUpCell c = puzzleBoard.getCell(i, location.y); + if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { + break; + } + else if (!elements.contains(board.getPuzzleElement(c))) { + elements.add(board.getPuzzleElement(c)); + } + } + for (int i = location.y; i < puzzleBoard.getHeight(); i++) { + LightUpCell c = puzzleBoard.getCell(location.x, i); + if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { + break; + } + else if (!elements.contains(board.getPuzzleElement(c))) { + elements.add(board.getPuzzleElement(c)); + } + } + for (int i = location.y; i >= 0; i--) { + LightUpCell c = puzzleBoard.getCell(location.x, i); + if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { + break; + } + else if (!elements.contains(board.getPuzzleElement(c))) { + elements.add(board.getPuzzleElement(c)); + } + } + } + + return elements; + } } 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 2a40bf45d..0e25586a8 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 @@ -1,119 +1,137 @@ -package edu.rpi.legup.puzzle.shorttruthtable.rules.caserule; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.CaseBoard; -import edu.rpi.legup.model.gameboard.PuzzleElement; - -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCell; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableStatement; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; - - -import java.util.ArrayList; - -public abstract class CaseRule_GenericStatement extends CaseRule_Generic { - - public CaseRule_GenericStatement(String ruleID, char operation, String title, - ShortTruthTableCellType[][] trueCases, - ShortTruthTableCellType[][] falseCases) { - super(ruleID, ShortTruthTableOperation.getRuleName(operation), - title + " case", - "A known " + title.toUpperCase() + " statement can have multiple forms"); - - this.operation = operation; - - this.trueCases = trueCases; - this.falseCases = falseCases; - } - - private final char operation; - - private final ShortTruthTableCellType[][] trueCases; - private final ShortTruthTableCellType[][] falseCases; - - protected static final ShortTruthTableCellType T = ShortTruthTableCellType.TRUE; - protected static final ShortTruthTableCellType F = ShortTruthTableCellType.FALSE; - protected static final ShortTruthTableCellType U = ShortTruthTableCellType.UNKNOWN; - - // Adds all elements that can be selected for this caserule - @Override - public CaseBoard getCaseBoard(Board board) { - //copy the board and add all elements that can be selected - ShortTruthTableBoard sttBoard = (ShortTruthTableBoard) board.copy(); - sttBoard.setModifiable(false); - CaseBoard caseBoard = new CaseBoard(sttBoard, this); - - //add all elements that can be selected for the case rule statement - for (PuzzleElement element : sttBoard.getPuzzleElements()) { - //get the cell object - ShortTruthTableCell cell = sttBoard.getCellFromElement(element); - //the cell must match the symbol - if (cell.getSymbol() != this.operation) continue; - //the statement must be assigned with unassigned sub-statements - if (!cell.getType().isTrueOrFalse()) continue; - if (cell.getStatementReference().getRightStatement().getCell().getType().isTrueOrFalse()) continue; - if (this.operation != ShortTruthTableOperation.NOT && - cell.getStatementReference().getRightStatement().getCell().getType().isTrueOrFalse()) { - continue; - } - //if the element has passed all the checks, it can be selected - caseBoard.addPickableElement(element); - } - return caseBoard; - } - - /** - * Gets the possible cases at a specific location based on this case rule - * - * @param board the current board state - * @param puzzleElement equivalent puzzleElement - * @return a list of elements the specified could be - */ - @SuppressWarnings("unchecked") - @Override - public ArrayList getCases(Board board, PuzzleElement puzzleElement) { - ShortTruthTableBoard sttBoard = ((ShortTruthTableBoard) board); - ShortTruthTableCell cell = sttBoard.getCellFromElement(puzzleElement); - - // If the statement is set to true, collect true cases. Otherwise, collect the false cases - if (cell.getType() == ShortTruthTableCellType.TRUE) { - return getCasesFromCell(sttBoard, puzzleElement, trueCases); - } - return getCasesFromCell(sttBoard, puzzleElement, falseCases); - } - - /** - * Collects a list of boards for each possible outcome of case-rule application - * @param board current board state - * @param puzzleElement case rule operator - * @param possibilities list of possibilities for operator state - * @return ArrayList of Boards - */ - private ArrayList getCasesFromCell(ShortTruthTableBoard board, PuzzleElement puzzleElement, ShortTruthTableCellType[][] possibilities) { - // Create branch case for each possibility - ArrayList cases = new ArrayList<>(); - for (int i = 0; i < possibilities.length; i++) { - // Create a new board to modify and get statement of selected square - ShortTruthTableBoard b = board.copy(); - ShortTruthTableCell cell = b.getCellFromElement(puzzleElement); - ShortTruthTableStatement statement = cell.getStatementReference(); - - // Modify neighboring cells of case-rule application by the provided logical cases - if (possibilities[i][0] != ShortTruthTableCellType.UNKNOWN) { - ShortTruthTableCell leftCell = statement.getLeftStatement().getCell(); - leftCell.setData(possibilities[i][0]); - b.addModifiedData(leftCell); - } - if (possibilities[i][1] != ShortTruthTableCellType.UNKNOWN) { - ShortTruthTableCell rightCell = statement.getRightStatement().getCell(); - rightCell.setData(possibilities[i][1]); - b.addModifiedData(rightCell); - } - - cases.add(b); - } - return cases; - } -} +package edu.rpi.legup.puzzle.shorttruthtable.rules.caserule; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.CaseBoard; +import edu.rpi.legup.model.gameboard.PuzzleElement; + +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCell; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableStatement; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; + +import java.util.List; +import java.util.ArrayList; + +public abstract class CaseRule_GenericStatement extends CaseRule_Generic { + + public CaseRule_GenericStatement(String ruleID, char operation, String title, + ShortTruthTableCellType[][] trueCases, + ShortTruthTableCellType[][] falseCases) { + super(ruleID, ShortTruthTableOperation.getRuleName(operation), + title + " case", + "A known " + title.toUpperCase() + " statement can have multiple forms"); + + this.operation = operation; + + this.trueCases = trueCases; + this.falseCases = falseCases; + } + + private final char operation; + + private final ShortTruthTableCellType[][] trueCases; + private final ShortTruthTableCellType[][] falseCases; + + protected static final ShortTruthTableCellType T = ShortTruthTableCellType.TRUE; + protected static final ShortTruthTableCellType F = ShortTruthTableCellType.FALSE; + protected static final ShortTruthTableCellType U = ShortTruthTableCellType.UNKNOWN; + + // Adds all elements that can be selected for this caserule + @Override + public CaseBoard getCaseBoard(Board board) { + //copy the board and add all elements that can be selected + ShortTruthTableBoard sttBoard = (ShortTruthTableBoard) board.copy(); + sttBoard.setModifiable(false); + CaseBoard caseBoard = new CaseBoard(sttBoard, this); + + //add all elements that can be selected for the case rule statement + for (PuzzleElement element : sttBoard.getPuzzleElements()) { + //get the cell object + ShortTruthTableCell cell = sttBoard.getCellFromElement(element); + //the cell must match the symbol + if (cell.getSymbol() != this.operation) continue; + //the statement must be assigned with unassigned sub-statements + if (!cell.getType().isTrueOrFalse()) continue; + if (cell.getStatementReference().getRightStatement().getCell().getType().isTrueOrFalse()) continue; + if (this.operation != ShortTruthTableOperation.NOT && + cell.getStatementReference().getRightStatement().getCell().getType().isTrueOrFalse()) { + continue; + } + //if the element has passed all the checks, it can be selected + caseBoard.addPickableElement(element); + } + return caseBoard; + } + + /** + * Gets the possible cases at a specific location based on this case rule + * + * @param board the current board state + * @param puzzleElement equivalent puzzleElement + * @return a list of elements the specified could be + */ + @SuppressWarnings("unchecked") + @Override + public ArrayList getCases(Board board, PuzzleElement puzzleElement) { + ShortTruthTableBoard sttBoard = ((ShortTruthTableBoard) board); + ShortTruthTableCell cell = sttBoard.getCellFromElement(puzzleElement); + + // If the statement is set to true, collect true cases. Otherwise, collect the false cases + if (cell.getType() == ShortTruthTableCellType.TRUE) { + return getCasesFromCell(sttBoard, puzzleElement, trueCases); + } + return getCasesFromCell(sttBoard, puzzleElement, falseCases); + } + + /** + * Collects a list of boards for each possible outcome of case-rule application + * @param board current board state + * @param puzzleElement case rule operator + * @param possibilities list of possibilities for operator state + * @return ArrayList of Boards + */ + private ArrayList getCasesFromCell(ShortTruthTableBoard board, PuzzleElement puzzleElement, ShortTruthTableCellType[][] possibilities) { + // Create branch case for each possibility + ArrayList cases = new ArrayList<>(); + for (int i = 0; i < possibilities.length; i++) { + // Create a new board to modify and get statement of selected square + ShortTruthTableBoard b = board.copy(); + ShortTruthTableCell cell = b.getCellFromElement(puzzleElement); + ShortTruthTableStatement statement = cell.getStatementReference(); + + // Modify neighboring cells of case-rule application by the provided logical cases + if (possibilities[i][0] != ShortTruthTableCellType.UNKNOWN) { + ShortTruthTableCell leftCell = statement.getLeftStatement().getCell(); + leftCell.setData(possibilities[i][0]); + b.addModifiedData(leftCell); + } + if (possibilities[i][1] != ShortTruthTableCellType.UNKNOWN) { + ShortTruthTableCell rightCell = statement.getRightStatement().getCell(); + rightCell.setData(possibilities[i][1]); + b.addModifiedData(rightCell); + } + + cases.add(b); + } + return cases; + } + + /** + * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid + * Overridden by case rules dependent on more than just the modified data + * + * @param board board state at application + * @param puzzleElement selected puzzleElement + * @return List of puzzle elements (typically cells) this application of the case rule depends upon. + * Defaults to any element modified by any case + */ + @Override + public List dependentElements(Board board, PuzzleElement puzzleElement) { + List elements = super.dependentElements(board,puzzleElement); + + elements.add(board.getPuzzleElement(puzzleElement)); + + return elements; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java index ca6bcbe02..52e8a6400 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java @@ -25,9 +25,6 @@ public class SkyscrapersBoard extends GridBoard { private boolean viewFlag = false; private boolean dupeFlag = false; - private SkyscrapersClue modClue = null; - //helper variable for case rule verification, tracks recently modified row/col - public SkyscrapersBoard(int size) { super(size, size); @@ -94,14 +91,6 @@ public void setViewFlag(boolean newFlag) { viewFlag = newFlag; } - public SkyscrapersClue getmodClue() { - return modClue; - } - - public void setModClue(SkyscrapersClue newClue) { - modClue = newClue; - } - @Override public SkyscrapersCell getCell(int x, int y) { return (SkyscrapersCell) super.getCell(x, y); diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClue.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClue.java index dc68f45c7..1e7b1b45e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClue.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClue.java @@ -47,6 +47,9 @@ public void setType(SkyscrapersType type) { } public SkyscrapersClue copy() { - return null; + SkyscrapersClue copy = new SkyscrapersClue(data, clueIndex, type); + copy.setIndex(index); + copy.setModifiable(isModifiable); + return copy; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/CellForNumberCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/CellForNumberCaseRule.java index 683b742bf..01527294a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/CellForNumberCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/CellForNumberCaseRule.java @@ -69,7 +69,6 @@ public ArrayList getCasesFor(Board board, PuzzleElement puzzleElement, In PuzzleElement newCell = newCase.getPuzzleElement(cell); newCell.setData(number); newCase.addModifiedData(newCell); - newCase.setModClue((SkyscrapersClue) newCase.getPuzzleElement(clue)); //if flags boolean passed = true; @@ -103,12 +102,7 @@ public String checkRuleRaw(TreeTransition transition) { return "This case rule must have at least one child."; } - //find changed row/col - SkyscrapersClue modClue = ((SkyscrapersBoard) childTransitions.get(0).getBoard()).getmodClue(); - - //System.out.println(modClue.getType()); - //System.out.println(modClue.getClueIndex()); - if (childTransitions.size() != getCasesFor(oldBoard, modClue, (Integer) childTransitions.get(0).getBoard().getModifiedData().iterator().next().getData()).size()) { + if (childTransitions.size() != getCasesFor(oldBoard, oldBoard.getPuzzleElement(transition.getSelection()), (Integer) childTransitions.get(0).getBoard().getModifiedData().iterator().next().getData()).size()) { //System.out.println("Wrong number of cases."); return "Wrong number of cases."; } @@ -132,4 +126,49 @@ public String checkRuleRaw(TreeTransition transition) { public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { return checkRuleRaw(transition); } + + /** + * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid + * Overridden by case rules dependent on more than just the modified data + * + * @param board board state at application + * @param puzzleElement selected puzzleElement + * @return List of puzzle elements (typically cells) this application of the case rule depends upon. + * Defaults to any element modified by any case + */ + @Override + public List dependentElements(Board board, PuzzleElement puzzleElement) { + List elements = new ArrayList<>(); + + SkyscrapersBoard puzzleBoard = (SkyscrapersBoard) board; + SkyscrapersClue clue = (SkyscrapersClue)puzzleBoard.getPuzzleElement(puzzleElement); + + // check each point in modified row/col + List data = puzzleBoard.getRowCol(clue.getClueIndex(),SkyscrapersType.ANY,clue.getType() == SkyscrapersType.CLUE_WEST); + for (SkyscrapersCell point : data) { + List cells = new ArrayList<>(List.of(point)); + + // if dependent on row/col + if ((puzzleBoard.getDupeFlag() || puzzleBoard.getViewFlag()) && point.getType() == SkyscrapersType.UNKNOWN) { + // get perpendicular row/col intersecting this point + int index; + if (clue.getType() == SkyscrapersType.CLUE_WEST) { + index = point.getLocation().x; + } + else { + index = point.getLocation().y; + } + cells.addAll(puzzleBoard.getRowCol(index,SkyscrapersType.ANY,clue.getType() != SkyscrapersType.CLUE_WEST)); + } + + // add all to result + for (SkyscrapersCell cell : cells) { + if (!elements.contains(board.getPuzzleElement(cell))) { + elements.add(board.getPuzzleElement(cell)); + } + } + } + + return elements; + } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NumberForCellCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NumberForCellCaseRule.java index a061c62a3..3bf0de70a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NumberForCellCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NumberForCellCaseRule.java @@ -7,6 +7,7 @@ import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersClue; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType; import java.awt.*; @@ -134,4 +135,38 @@ public String checkRuleRaw(TreeTransition transition) { public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { return checkRuleRaw(transition); } + + /** + * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid + * Overridden by case rules dependent on more than just the modified data + * + * @param board board state at application + * @param puzzleElement selected puzzleElement + * @return List of puzzle elements (typically cells) this application of the case rule depends upon. + * Defaults to any element modified by any case + */ + @Override + public List dependentElements(Board board, PuzzleElement puzzleElement) { + List elements = new ArrayList<>(); + + SkyscrapersBoard puzzleBoard = (SkyscrapersBoard) board; + SkyscrapersCell point = (SkyscrapersCell)puzzleBoard.getPuzzleElement(puzzleElement); + + List cells = new ArrayList<>(List.of(point)); + + // if dependent on row/col + if (puzzleBoard.getDupeFlag() || puzzleBoard.getViewFlag()) { + // add all cells in row/col intersecting given point + cells.addAll(puzzleBoard.getRowCol(point.getLocation().x,SkyscrapersType.ANY,false)); + cells.addAll(puzzleBoard.getRowCol(point.getLocation().y,SkyscrapersType.ANY,true)); + } + + for (SkyscrapersCell cell : cells) { + if (!elements.contains(board.getPuzzleElement(cell))) { + elements.add(board.getPuzzleElement(cell)); + } + } + + return elements; + } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java index 2542ea335..dc809f34d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java @@ -124,21 +124,11 @@ public void notifyDeletion(PuzzleElement puzzleElement) { public List getAdjacent(TreeTentCell cell, TreeTentType type) { List adj = new ArrayList<>(); Point loc = cell.getLocation(); - TreeTentCell up = getCell(loc.x, loc.y - 1); - TreeTentCell right = getCell(loc.x + 1, loc.y); - TreeTentCell down = getCell(loc.x, loc.y + 1); - TreeTentCell left = getCell(loc.x - 1, loc.y); - if (up != null && up.getType() == type) { - adj.add(up); - } - if (right != null && right.getType() == type) { - adj.add(right); - } - if (down != null && down.getType() == type) { - adj.add(down); - } - if (left != null && left.getType() == type) { - adj.add(left); + for (int i = -2; i < 2; i++) { + TreeTentCell adjCell = getCell(loc.x + (i % 2), loc.y + ((i + 1) % 2)); + if (adjCell != null && adjCell.getType() == type) { + adj.add(adjCell); + } } return adj; } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FillinRowCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FillinRowCaseRule.java index 538772b74..698b3aa5e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FillinRowCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FillinRowCaseRule.java @@ -160,4 +160,29 @@ public String checkRuleRaw(TreeTransition transition) { public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { return null; } + + /** + * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid + * Overridden by case rules dependent on more than just the modified data + * + * @param board board state at application + * @param puzzleElement selected puzzleElement + * @return List of puzzle elements (typically cells) this application of the case rule depends upon. + * Defaults to any element modified by any case + */ + @Override + public List dependentElements(Board board, PuzzleElement puzzleElement) { + List elements = new ArrayList<>(); + + TreeTentBoard treeTentBoard = (TreeTentBoard) board; + TreeTentClue clue = (TreeTentClue) puzzleElement; + + // add all elements of filled row + for (int i = 0; i < treeTentBoard.getWidth(); i++) { + TreeTentCell cell = treeTentBoard.getCell(i, clue.getClueIndex()-1); + elements.add(board.getPuzzleElement((cell))); + } + + return elements; + } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LinkTentCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LinkTentCaseRule.java index 36f466f87..39b1d0251 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LinkTentCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LinkTentCaseRule.java @@ -5,7 +5,6 @@ import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.rules.CaseRule; import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.treetent.TreeTent; import edu.rpi.legup.puzzle.treetent.TreeTentBoard; import edu.rpi.legup.puzzle.treetent.TreeTentType; import edu.rpi.legup.puzzle.treetent.TreeTentCell; @@ -151,4 +150,18 @@ public String checkRuleRaw(TreeTransition transition) { public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { return checkRuleRaw(transition); } + + /** + * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid + * Overridden by case rules dependent on more than just the modified data + * + * @param board board state at application + * @param puzzleElement selected puzzleElement + * @return List of puzzle elements (typically cells) this application of the case rule depends upon. + * Defaults to any element modified by any case + */ + @Override + public List dependentElements(Board board, PuzzleElement puzzleElement) { + return List.of(board.getPuzzleElement(puzzleElement)); + } } 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 249547301..72ffd62eb 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 @@ -10,6 +10,7 @@ import edu.rpi.legup.puzzle.treetent.TreeTentLine; import edu.rpi.legup.puzzle.treetent.TreeTentType; +import java.awt.Point; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -152,4 +153,32 @@ public String checkRuleRaw(TreeTransition transition) { public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { return checkRuleRaw(transition); } + + /** + * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid + * Overridden by case rules dependent on more than just the modified data + * + * @param board board state at application + * @param puzzleElement selected puzzleElement + * @return List of puzzle elements (typically cells) this application of the case rule depends upon. + * Defaults to any element modified by any case + */ + @Override + public List dependentElements(Board board, PuzzleElement puzzleElement) { + List elements = new ArrayList<>(List.of(board.getPuzzleElement(puzzleElement))); + + TreeTentBoard treeTentBoard = (TreeTentBoard) board; + TreeTentCell point = (TreeTentCell) puzzleElement; + + // get all adjacent cells + Point loc = point.getLocation(); + for (int i = -2; i < 2; i++) { + TreeTentCell cell = treeTentBoard.getCell(loc.x + (i % 2), loc.y + ((i + 1) % 2)); + if (cell != null) { + elements.add(board.getPuzzleElement(cell)); + } + } + + return elements; + } } diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeView.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeView.java index ecf59146d..9bfffe60a 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeView.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeView.java @@ -1,756 +1,886 @@ -package edu.rpi.legup.ui.proofeditorui.treeview; - -import edu.rpi.legup.app.GameBoardFacade; -import edu.rpi.legup.controller.TreeController; -import edu.rpi.legup.model.observer.ITreeListener; -import edu.rpi.legup.model.tree.Tree; -import edu.rpi.legup.model.tree.TreeElement; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.ui.ScrollView; -import edu.rpi.legup.utility.DisjointSets; - -import javax.swing.*; -import java.awt.*; -import java.awt.image.BufferedImage; -import java.util.*; -import java.util.List; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import static edu.rpi.legup.model.tree.TreeElementType.NODE; -import static edu.rpi.legup.model.tree.TreeElementType.TRANSITION; -import static edu.rpi.legup.ui.proofeditorui.treeview.TreeNodeView.DIAMETER; -import static edu.rpi.legup.ui.proofeditorui.treeview.TreeNodeView.RADIUS; - -public class TreeView extends ScrollView implements ITreeListener { - private final static Logger LOGGER = LogManager.getLogger(TreeView.class.getName()); - - private static final int TRANS_GAP = 5; - - private static final int NODE_GAP_WIDTH = 70; - private static final int NODE_GAP_HEIGHT = 15; - - private static final int BORDER_GAP_HEIGHT = 20; - private static final int BORDER_GAP_WIDTH = 20; - - private static final int BORDER_SPACING = 100; - - private TreeNodeView nodeHover; - - private ArrayList currentStateBoxes; - private Rectangle bounds = new Rectangle(0, 0, 0, 0); - - private Tree tree; - private TreeNodeView rootNodeView; - private Map viewMap; - private Dimension dimension; - - private TreeViewSelection selection; - - public TreeView(TreeController treeController) { - super(treeController); - currentStateBoxes = new ArrayList<>(); - setSize(dimension = new Dimension(100, 200)); - setPreferredSize(new Dimension(640, 160)); - - viewMap = new HashMap<>(); - - selection = new TreeViewSelection(); - } - - public TreeViewSelection getSelection() { - return selection; - } - - /** - * Gets the tree node puzzleElement that the mouse is hovering over - * - * @return tree node puzzleElement that the mouse is hovering over - */ - public TreeNodeView getNodeHover() { - return nodeHover; - } - - /** - * Sets the tree node puzzleElement that the mouse is hovering over - * - * @param nodeHover tree node puzzleElement the mouse is hovering over - */ - public void setNodeHover(TreeNodeView nodeHover) { - this.nodeHover = nodeHover; - } - - /** - * Gets the TreeElementView by the specified point or null if no view exists at the specified point - * - * @param point location to query for a view - * @return TreeElementView at the point specified, otherwise null - */ - public TreeElementView getTreeElementView(Point point) { - return getTreeElementView(point, rootNodeView); - } - - /** - * Recursively gets the TreeElementView by the specified point or null if no view exists at the specified point or - * the view specified is null - * - * @param point location to query for a view - * @param elementView view to determine if the point is contained within it - * @return TreeElementView at the point specified, otherwise null - */ - private TreeElementView getTreeElementView(Point point, TreeElementView elementView) { - if (elementView == null) { - return null; - } - else { - if (elementView.contains(point) && elementView.isVisible()) { - if (elementView.getType() == NODE && ((TreeNodeView) elementView).isContradictoryState()) { - return null; - } - return elementView; - } - else { - if (elementView.getType() == NODE) { - TreeNodeView nodeView = (TreeNodeView) elementView; - for (TreeTransitionView transitionView : nodeView.getChildrenViews()) { - TreeElementView view = getTreeElementView(point, transitionView); - if (view != null) { - return view; - } - } - } - else { - TreeTransitionView transitionView = (TreeTransitionView) elementView; - return getTreeElementView(point, transitionView.getChildView()); - } - } - } - return null; - } - - public void updateTreeView(Tree tree) { - this.tree = tree; - if (selection.getSelectedViews().size() == 0) { - selection.newSelection(new TreeNodeView(tree.getRootNode())); - } - repaint(); - } - - /** - * Sets the tree associated with this TreeView - * - * @param tree tree - */ - public void setTree(Tree tree) { - this.tree = tree; - } - - public void updateTreeSize() { - if (GameBoardFacade.getInstance().getTree() == null) { - return; - } - setSize(bounds.getSize()); - } - - public void reset() { - if (bounds.x != 0 || bounds.y != 0) { - updateTreeSize(); - } - } - - public void zoomFit() { - double fitWidth = (viewport.getWidth() - 8.0) / (getSize().width - 200); - double fitHeight = (viewport.getHeight() - 8.0) / (getSize().height - 120); - zoomTo(Math.min(fitWidth, fitHeight)); - viewport.setViewPosition(new Point(0, viewport.getHeight() / 2)); - } - - /** - * Creates a customized viewport for the scroll pane - * - * @return viewport for the scroll pane - */ - @Override - protected JViewport createViewport() { - return new JViewport() { - @Override - protected LayoutManager createLayoutManager() { - return new ViewportLayout() { - @Override - public void layoutContainer(Container parent) { - Point point = viewport.getViewPosition(); - // determine the maximum x and y view positions - int mx = getCanvas().getWidth() - viewport.getWidth(); - int my = getCanvas().getHeight() - viewport.getHeight(); - // obey edge boundaries - if (point.x < 0) { - point.x = 0; - } - if (point.x > mx) { - point.x = mx; - } - if (point.y < 0) { - point.y = 0; - } - if (point.y > my) { - point.y = my; - } - // center margins - if (mx < 0) { - point.x = 0; - } - if (my < 0) { - point.y = my / 2; - } - viewport.setViewPosition(point); - } - }; - } - }; - } - - public void draw(Graphics2D graphics2D) { - currentStateBoxes.clear(); - Tree tree = GameBoardFacade.getInstance().getTree(); - if (tree != null) { - //setSize(bounds.getDimension()); - graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - - drawTree(graphics2D); - - dimension.width += BORDER_SPACING; - setSize(dimension); -// graphics2D.drawRect(0,0, dimension.width, dimension.height); - - if (selection.getHover() != null) { - drawMouseOver(graphics2D); - } - } - } - - public void zoomReset() { - zoomTo(1.0); - viewport.setViewPosition(new Point(0, 0)); - } - - private void redrawTree(Graphics2D graphics2D, TreeNodeView nodeView) { - if (nodeView != null) { - nodeView.draw(graphics2D); - for (TreeTransitionView transitionView : nodeView.getChildrenViews()) { - transitionView.draw(graphics2D); - redrawTree(graphics2D, transitionView.getChildView()); - } - } - } - - public void removeTreeElement(TreeElementView view) { - if (view.getType() == NODE) { - TreeNodeView nodeView = (TreeNodeView) view; - nodeView.getParentView().setChildView(null); - } - else { - TreeTransitionView transitionView = (TreeTransitionView) view; - transitionView.getParentViews().forEach((TreeNodeView n) -> n.removeChildrenView(transitionView)); - } - } - - /** - * When the edu.rpi.legup.user hovers over the transition, draws the corresponding rules image - * - * @param g the graphics to use to draw - */ - public void drawMouseOver(Graphics2D g) { - if (selection.getHover().getType() == TRANSITION && ((TreeTransitionView) selection.getHover()).getTreeElement().isJustified()) { - TreeTransition transition = (TreeTransition) selection.getHover().treeElement; - int imgWidth = 100; - int imgHeight = 100; - - BufferedImage image = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_ARGB); - image.createGraphics().drawImage(transition.getRule().getImageIcon().getImage(), 0, 0, null); - Point mousePoint = selection.getMousePoint(); - g.drawImage(image, mousePoint.x, mousePoint.y - 50, imgWidth, imgHeight, null); - } - } - - public void resetView() { - this.tree = null; - this.rootNodeView = null; - this.selection.clearSelection(); - this.selection.clearHover(); - } - - /** - * Called when a tree puzzleElement is added to the tree - * - * @param treeElement TreeElement that was added to the tree - */ - @Override - public void onTreeElementAdded(TreeElement treeElement) { - if (treeElement.getType() == NODE) { - addTreeNode((TreeNode) treeElement); - } - else { - addTreeTransition((TreeTransition) treeElement); - } - repaint(); - } - - /** - * Called when a tree puzzleElement is removed from the tree - * - * @param element TreeElement that was removed to the tree - */ - @Override - public void onTreeElementRemoved(TreeElement element) { - if (element.getType() == NODE) { - TreeNode node = (TreeNode) element; - TreeNodeView nodeView = (TreeNodeView) viewMap.get(node); - - nodeView.getParentView().setChildView(null); - removeTreeNode(node); - } - else { - TreeTransition trans = (TreeTransition) element; - TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); - - transView.getParentViews().forEach(n -> n.removeChildrenView(transView)); - removeTreeTransition(trans); - } - repaint(); - } - - /** - * Called when the tree selection was changed - * - * @param selection tree selection that was changed - */ - @Override - public void onTreeSelectionChanged(TreeViewSelection selection) { - this.selection.getSelectedViews().forEach(v -> v.setSelected(false)); - selection.getSelectedViews().forEach(v -> v.setSelected(true)); - this.selection = selection; - repaint(); - } - - /** - * Called when the model has finished updating the tree. - */ - @Override - public void onUpdateTree() { - repaint(); - } - - /** - * Gets the TreeElementView by the corresponding TreeElement associated with it - * - * @param element TreeElement of the view - * @return TreeElementView of the TreeElement associated with it - */ - public TreeElementView getElementView(TreeElement element) { - return viewMap.get(element); - } - - private void removeTreeNode(TreeNode node) { - viewMap.remove(node); - node.getChildren().forEach(t -> removeTreeTransition(t)); - } - - private void removeTreeTransition(TreeTransition trans) { - viewMap.remove(trans); - if (trans.getChildNode() != null) { - removeTreeNode(trans.getChildNode()); - } - } - - private void addTreeNode(TreeNode node) { - TreeTransition parent = node.getParent(); - - TreeNodeView nodeView = new TreeNodeView(node); - TreeTransitionView parentView = (TreeTransitionView) viewMap.get(parent); - - nodeView.setParentView(parentView); - parentView.setChildView(nodeView); - - viewMap.put(node, nodeView); - - if (!node.getChildren().isEmpty()) { - node.getChildren().forEach(t -> addTreeTransition(t)); - } - } - - private void addTreeTransition(TreeTransition trans) { - List parents = trans.getParents(); - - TreeTransitionView transView = new TreeTransitionView(trans); - for (TreeNode parent : parents) { - TreeNodeView parentNodeView = (TreeNodeView) viewMap.get(parent); - transView.addParentView(parentNodeView); - parentNodeView.addChildrenView(transView); - } - - viewMap.put(trans, transView); - - if (trans.getChildNode() != null) { - addTreeNode(trans.getChildNode()); - } - } - - ///New Draw Methods - - public void drawTree(Graphics2D graphics2D) { - if (tree == null) { - LOGGER.error("Unable to draw tree."); - } - else { - if (rootNodeView == null) { - rootNodeView = new TreeNodeView(tree.getRootNode()); - - LOGGER.debug("Creating new views for tree view."); - createViews(rootNodeView); - - selection.newSelection(rootNodeView); - } - - dimension = new Dimension(0, 0); - calcSpan(rootNodeView); - rootNodeView.setSpan(rootNodeView.getSpan() + DIAMETER + BORDER_SPACING); - - calculateViewLocations(rootNodeView, 0); - dimension.height = (int) rootNodeView.getSpan(); - - redrawTree(graphics2D, rootNodeView); - LOGGER.debug("DrawTree: dimensions - " + dimension.width + "x" + dimension.height); - } - } - - public void createViews(TreeNodeView nodeView) { - if (nodeView != null) { - viewMap.put(nodeView.getTreeElement(), nodeView); - - TreeNode node = nodeView.getTreeElement(); - for (TreeTransition trans : node.getChildren()) { - TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); - if (transView != null) { - nodeView.addChildrenView(transView); - transView.addParentView(nodeView); - break; - } - transView = new TreeTransitionView(trans); - - viewMap.put(transView.getTreeElement(), transView); - - transView.addParentView(nodeView); - nodeView.addChildrenView(transView); - - TreeNode childNode = trans.getChildNode(); - if (childNode != null) { - TreeNodeView childNodeView = new TreeNodeView(childNode); - viewMap.put(childNodeView.getTreeElement(), childNodeView); - - childNodeView.setParentView(transView); - transView.setChildView(childNodeView); - - createViews(childNodeView); - } - } - } - } - - public void calculateViewLocations(TreeNodeView nodeView, int depth) { - nodeView.setDepth(depth); - int xLoc = (NODE_GAP_WIDTH + DIAMETER) * depth + DIAMETER; - nodeView.setX(xLoc); - dimension.width = Math.max(dimension.width, xLoc); - - TreeTransitionView parentTransView = nodeView.getParentView(); - int yLoc = parentTransView == null ? (int) nodeView.getSpan() / 2 : parentTransView.getEndY(); - nodeView.setY(yLoc); - - ArrayList children = nodeView.getChildrenViews(); - switch (children.size()) { - case 0: - break; - case 1: { - TreeTransitionView childView = children.get(0); - - List parentsViews = childView.getParentViews(); - if (parentsViews.size() == 1) { - childView.setEndY(yLoc); - - childView.setDepth(depth); - - Point lineStartPoint = childView.getLineStartPoint(0); - lineStartPoint.x = xLoc + RADIUS + TRANS_GAP / 2; - lineStartPoint.y = yLoc; - childView.setEndX((NODE_GAP_WIDTH + DIAMETER) * (depth + 1) + RADIUS - TRANS_GAP / 2); - - dimension.width = Math.max(dimension.width, childView.getEndX()); - - TreeNodeView childNodeView = childView.getChildView(); - if (childNodeView != null) { - calculateViewLocations(childNodeView, depth + 1); - } - } - else { - if (parentsViews.size() > 1 && parentsViews.get(parentsViews.size() - 1) == nodeView) { - int yAvg = 0; - for (int i = 0; i < parentsViews.size(); i++) { - TreeNodeView parentNodeView = parentsViews.get(i); - depth = Math.max(depth, parentNodeView.getDepth()); - yAvg += parentNodeView.getY(); - - Point lineStartPoint = childView.getLineStartPoint(i); - lineStartPoint.x = parentNodeView.getX() + RADIUS + TRANS_GAP / 2; - lineStartPoint.y = parentNodeView.getY(); - } - yAvg /= parentsViews.size(); - childView.setEndY(yAvg); - - childView.setDepth(depth); - - childView.setEndX((NODE_GAP_WIDTH + DIAMETER) * (depth + 1) + RADIUS - TRANS_GAP / 2); - - dimension.width = Math.max(dimension.width, childView.getEndX()); - - TreeNodeView childNodeView = childView.getChildView(); - if (childNodeView != null) { - calculateViewLocations(childNodeView, depth + 1); - } - } - } - break; - } - default: { - int span = 0; - for (TreeTransitionView childView : children) { - span += childView.getSpan(); - } - - span = (int) ((nodeView.getSpan() - span) / 2); - for (int i = 0; i < children.size(); i++) { - TreeTransitionView childView = children.get(i); - - childView.setDepth(depth); - - Point lineStartPoint = childView.getLineStartPoint(0); - lineStartPoint.x = xLoc + RADIUS + TRANS_GAP / 2; - lineStartPoint.y = yLoc; - childView.setEndX((NODE_GAP_WIDTH + DIAMETER) * (depth + 1) + RADIUS - TRANS_GAP / 2); - childView.setEndY(yLoc - (int) (nodeView.getSpan() / 2) + span + (int) (childView.getSpan() / 2)); - - span += childView.getSpan(); - TreeNodeView childNodeView = childView.getChildView(); - if (childNodeView != null) { - calculateViewLocations(childNodeView, depth + 1); - } - } - break; - } - } - } - - public void calcSpan(TreeElementView view) { - if (view.getType() == NODE) { - TreeNodeView nodeView = (TreeNodeView) view; - TreeNode node = nodeView.getTreeElement(); - if (nodeView.getChildrenViews().size() == 0) { - nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } - else { - if (nodeView.getChildrenViews().size() == 1) { - TreeTransitionView childView = nodeView.getChildrenViews().get(0); - calcSpan(childView); - if (childView.getParentViews().size() > 1) { - nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } - else { - nodeView.setSpan(childView.getSpan()); - } - } - else { - DisjointSets branches = node.findMergingBranches(); - List children = node.getChildren(); - - if (node == children.get(0).getParents().get(0)) { - reorderBranches(node, branches); - ArrayList newChildrenViews = new ArrayList<>(); - for (TreeTransition trans : node.getChildren()) { - newChildrenViews.add((TreeTransitionView) viewMap.get(trans)); - } - nodeView.setChildrenViews(newChildrenViews); - } - - List> mergingSets = branches.getAllSets(); - - double span = 0.0; - for (Set mergeSet : mergingSets) { - if (mergeSet.size() > 1) { - TreeTransition mergePoint = TreeNode.findMergingPoint(mergeSet); - TreeTransitionView mergePointView = (TreeTransitionView) viewMap.get(mergePoint); - double subSpan = 0.0; - for (TreeTransition branch : mergeSet) { - TreeTransitionView branchView = (TreeTransitionView) viewMap.get(branch); - subCalcSpan(branchView, mergePointView); - subSpan += branchView.getSpan(); - } - calcSpan(mergePointView); - span += Math.max(mergePointView.getSpan(), subSpan); - } - else { - TreeTransition trans = mergeSet.iterator().next(); - TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); - calcSpan(transView); - span += transView.getSpan(); - } - } - nodeView.setSpan(span); - } - } - } - else { - TreeTransitionView transView = (TreeTransitionView) view; - TreeNodeView nodeView = transView.getChildView(); - if (nodeView == null) { - transView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } - else { - calcSpan(nodeView); - transView.setSpan(nodeView.getSpan()); - } - } - } - - /** - * Calculates the sub span of a given sub tree rooted at the specified view and stops at the tree puzzleElement view - * specified as stop. Stop tree puzzleElement is NOT included in the span calculation - * - * @param view - * @param stop - */ - private void subCalcSpan(TreeElementView view, TreeElementView stop) { - //safe-guard for infinite loop - if (view == stop) { - return; - } - - if (view.getType() == NODE) { - TreeNodeView nodeView = (TreeNodeView) view; - TreeNode node = nodeView.getTreeElement(); - if (nodeView.getChildrenViews().size() == 0) { - nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } - else { - if (nodeView.getChildrenViews().size() == 1) { - TreeTransitionView childView = nodeView.getChildrenViews().get(0); - if (childView == stop) { - nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } - else { - subCalcSpan(childView, stop); - if (childView.getParentViews().size() > 1) { - nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } - else { - nodeView.setSpan(childView.getSpan()); - } - } - } - else { - DisjointSets branches = node.findMergingBranches(); - List children = node.getChildren(); - - if (node == children.get(0).getParents().get(0)) { - reorderBranches(node, branches); - } - - List> mergingSets = branches.getAllSets(); - - double span = 0.0; - for (Set mergeSet : mergingSets) { - if (mergeSet.size() > 1) { - TreeTransition mergePoint = TreeNode.findMergingPoint(mergeSet); - TreeTransitionView mergePointView = (TreeTransitionView) viewMap.get(mergePoint); - double subSpan = 0.0; - for (TreeTransition branch : mergeSet) { - TreeTransitionView branchView = (TreeTransitionView) viewMap.get(branch); - subCalcSpan(branchView, mergePointView); - subSpan += branchView.getSpan(); - } - subCalcSpan(mergePointView, stop); - span += Math.max(mergePointView.getSpan(), subSpan); - } - else { - TreeTransition trans = mergeSet.iterator().next(); - TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); - subCalcSpan(transView, stop); - span += transView.getSpan(); - } - } - - nodeView.setSpan(span); - } - } - } - else { - TreeTransitionView transView = (TreeTransitionView) view; - TreeNodeView nodeView = transView.getChildView(); - if (nodeView == null || nodeView == stop) { - transView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } - else { - calcSpan(nodeView); - transView.setSpan(nodeView.getSpan()); - } - } - } - - /** - * Reorders branches such that merging branches are sequentially grouped together and transitions are kept in - * relative order in the list of child transitions of the specified node - * - * @param node root node of the branches - * @param branches DisjointSets of the child branches of the specified node which determine which branches merge - */ - private void reorderBranches(TreeNode node, DisjointSets branches) { - List children = node.getChildren(); - List> mergingSets = branches.getAllSets(); - - List> newOrder = new ArrayList<>(); - for (Set set : mergingSets) { - List mergeBranch = new ArrayList<>(); - newOrder.add(mergeBranch); - children.forEach(t -> { - if (set.contains(t)) { - mergeBranch.add(t); - } - }); - mergeBranch.sort((TreeTransition t1, TreeTransition t2) -> - children.indexOf(t1) <= children.indexOf(t2) ? -1 : 1); - } - - newOrder.sort((List b1, List b2) -> { - int low1 = -1; - int low2 = -1; - for (TreeTransition t1 : b1) { - int curIndex = children.indexOf(t1); - if (low1 == -1 || curIndex < low1) { - low1 = curIndex; - } - } - for (TreeTransition t1 : b2) { - int curIndex = children.indexOf(t1); - if (low1 == -1 || curIndex < low1) { - low1 = curIndex; - } - } - return low1 < low2 ? -1 : 1; - }); - - List newChildren = new ArrayList<>(); - newOrder.forEach(l -> newChildren.addAll(l)); - node.setChildren(newChildren); - } +package edu.rpi.legup.ui.proofeditorui.treeview; + +import edu.rpi.legup.app.GameBoardFacade; +import edu.rpi.legup.controller.TreeController; +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.GridCell; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.observer.ITreeListener; +import edu.rpi.legup.model.rules.CaseRule; +import edu.rpi.legup.model.rules.Rule; +import edu.rpi.legup.model.tree.Tree; +import edu.rpi.legup.model.tree.TreeElement; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.ui.ScrollView; +import edu.rpi.legup.utility.DisjointSets; + +import javax.swing.*; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.util.*; +import java.util.List; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import static edu.rpi.legup.model.tree.TreeElementType.NODE; +import static edu.rpi.legup.model.tree.TreeElementType.TRANSITION; +import static edu.rpi.legup.ui.proofeditorui.treeview.TreeNodeView.DIAMETER; +import static edu.rpi.legup.ui.proofeditorui.treeview.TreeNodeView.RADIUS; + +public class TreeView extends ScrollView implements ITreeListener { + private final static Logger LOGGER = LogManager.getLogger(TreeView.class.getName()); + + private static final int TRANS_GAP = 5; + + private static final int NODE_GAP_WIDTH = 70; + private static final int NODE_GAP_HEIGHT = 15; + + private static final int BORDER_GAP_HEIGHT = 20; + private static final int BORDER_GAP_WIDTH = 20; + + private static final int BORDER_SPACING = 100; + + private TreeNodeView nodeHover; + + private ArrayList currentStateBoxes; + private Rectangle bounds = new Rectangle(0, 0, 0, 0); + + private Tree tree; + private TreeNodeView rootNodeView; + private Map viewMap; + private Dimension dimension; + + private TreeViewSelection selection; + + public TreeView(TreeController treeController) { + super(treeController); + currentStateBoxes = new ArrayList<>(); + setSize(dimension = new Dimension(100, 200)); + setPreferredSize(new Dimension(640, 160)); + + viewMap = new HashMap<>(); + + selection = new TreeViewSelection(); + } + + public TreeViewSelection getSelection() { + return selection; + } + + /** + * Gets the tree node puzzleElement that the mouse is hovering over + * + * @return tree node puzzleElement that the mouse is hovering over + */ + public TreeNodeView getNodeHover() { + return nodeHover; + } + + /** + * Sets the tree node puzzleElement that the mouse is hovering over + * + * @param nodeHover tree node puzzleElement the mouse is hovering over + */ + public void setNodeHover(TreeNodeView nodeHover) { + this.nodeHover = nodeHover; + } + + /** + * Gets the TreeElementView by the specified point or null if no view exists at the specified point + * + * @param point location to query for a view + * @return TreeElementView at the point specified, otherwise null + */ + public TreeElementView getTreeElementView(Point point) { + return getTreeElementView(point, rootNodeView); + } + + /** + * Recursively gets the TreeElementView by the specified point or null if no view exists at the specified point or + * the view specified is null + * + * @param point location to query for a view + * @param elementView view to determine if the point is contained within it + * @return TreeElementView at the point specified, otherwise null + */ + private TreeElementView getTreeElementView(Point point, TreeElementView elementView) { + if (elementView == null) { + return null; + } + else { + if (elementView.contains(point) && elementView.isVisible()) { + if (elementView.getType() == NODE && ((TreeNodeView) elementView).isContradictoryState()) { + return null; + } + return elementView; + } + else { + if (elementView.getType() == NODE) { + TreeNodeView nodeView = (TreeNodeView) elementView; + for (TreeTransitionView transitionView : nodeView.getChildrenViews()) { + TreeElementView view = getTreeElementView(point, transitionView); + if (view != null) { + return view; + } + } + } + else { + TreeTransitionView transitionView = (TreeTransitionView) elementView; + return getTreeElementView(point, transitionView.getChildView()); + } + } + } + return null; + } + + public void updateTreeView(Tree tree) { + this.tree = tree; + if (selection.getSelectedViews().size() == 0) { + selection.newSelection(new TreeNodeView(tree.getRootNode())); + } + repaint(); + } + + /** + * Sets the tree associated with this TreeView + * + * @param tree tree + */ + public void setTree(Tree tree) { + this.tree = tree; + } + + public void updateTreeSize() { + if (GameBoardFacade.getInstance().getTree() == null) { + return; + } + setSize(bounds.getSize()); + } + + public void reset() { + if (bounds.x != 0 || bounds.y != 0) { + updateTreeSize(); + } + } + + public void zoomFit() { + double fitWidth = (viewport.getWidth() - 8.0) / (getSize().width - 200); + double fitHeight = (viewport.getHeight() - 8.0) / (getSize().height - 120); + zoomTo(Math.min(fitWidth, fitHeight)); + viewport.setViewPosition(new Point(0, viewport.getHeight() / 2)); + } + + /** + * Creates a customized viewport for the scroll pane + * + * @return viewport for the scroll pane + */ + @Override + protected JViewport createViewport() { + return new JViewport() { + @Override + protected LayoutManager createLayoutManager() { + return new ViewportLayout() { + @Override + public void layoutContainer(Container parent) { + Point point = viewport.getViewPosition(); + // determine the maximum x and y view positions + int mx = getCanvas().getWidth() - viewport.getWidth(); + int my = getCanvas().getHeight() - viewport.getHeight(); + // obey edge boundaries + if (point.x < 0) { + point.x = 0; + } + if (point.x > mx) { + point.x = mx; + } + if (point.y < 0) { + point.y = 0; + } + if (point.y > my) { + point.y = my; + } + // center margins + if (mx < 0) { + point.x = 0; + } + if (my < 0) { + point.y = my / 2; + } + viewport.setViewPosition(point); + } + }; + } + }; + } + + public void draw(Graphics2D graphics2D) { + currentStateBoxes.clear(); + Tree tree = GameBoardFacade.getInstance().getTree(); + if (tree != null) { + //setSize(bounds.getDimension()); + graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + + drawTree(graphics2D); + + dimension.width += BORDER_SPACING; + setSize(dimension); +// graphics2D.drawRect(0,0, dimension.width, dimension.height); + + if (selection.getHover() != null) { + drawMouseOver(graphics2D); + } + } + } + + public void zoomReset() { + zoomTo(1.0); + viewport.setViewPosition(new Point(0, 0)); + } + + private void redrawTree(Graphics2D graphics2D, TreeNodeView nodeView) { + if (nodeView != null) { + nodeView.draw(graphics2D); + for (TreeTransitionView transitionView : nodeView.getChildrenViews()) { + transitionView.draw(graphics2D); + redrawTree(graphics2D, transitionView.getChildView()); + } + } + } + + public void removeTreeElement(TreeElementView view) { + if (view.getType() == NODE) { + TreeNodeView nodeView = (TreeNodeView) view; + nodeView.getParentView().setChildView(null); + } + else { + TreeTransitionView transitionView = (TreeTransitionView) view; + transitionView.getParentViews().forEach((TreeNodeView n) -> n.removeChildrenView(transitionView)); + } + } + + /** + * When the edu.rpi.legup.user hovers over the transition, draws the corresponding rules image + * + * @param g the graphics to use to draw + */ + public void drawMouseOver(Graphics2D g) { + if (selection.getHover().getType() == TRANSITION && ((TreeTransitionView) selection.getHover()).getTreeElement().isJustified()) { + TreeTransition transition = (TreeTransition) selection.getHover().treeElement; + int imgWidth = 100; + int imgHeight = 100; + + BufferedImage image = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_ARGB); + image.createGraphics().drawImage(transition.getRule().getImageIcon().getImage(), 0, 0, null); + Point mousePoint = selection.getMousePoint(); + g.drawImage(image, mousePoint.x, mousePoint.y - 50, imgWidth, imgHeight, null); + } + } + + public void resetView() { + this.tree = null; + this.rootNodeView = null; + this.selection.clearSelection(); + this.selection.clearHover(); + } + + /** + * Called when a tree puzzleElement is added to the tree + * + * @param treeElement TreeElement that was added to the tree + */ + @Override + public void onTreeElementAdded(TreeElement treeElement) { + if (treeElement.getType() == NODE) { + addTreeNode((TreeNode) treeElement); + } + else { + addTreeTransition((TreeTransition) treeElement); + } + repaint(); + } + + /** + * Called when a tree puzzleElement is removed from the tree + * + * @param element TreeElement that was removed to the tree + */ + @Override + public void onTreeElementRemoved(TreeElement element) { + if (element.getType() == NODE) { + TreeNode node = (TreeNode) element; + TreeNodeView nodeView = (TreeNodeView) viewMap.get(node); + + nodeView.getParentView().setChildView(null); + removeTreeNode(node); + } + else { + TreeTransition trans = (TreeTransition) element; + TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); + + // unlock ancestor elements if case rule deleted + Rule rule = trans.getRule(); + for (TreeNode node : trans.getParents()) { + + // only if the last case of a case rule will be deleted + if (!(rule instanceof CaseRule && node.getChildren().isEmpty())) { + continue; + } + + CaseRule caseRule = (CaseRule)rule; + // set dependent elements to be modifiable by ancestors (if not dependent on others) + List ancestors = node.getAncestors(); + for (TreeNode ancestor : ancestors) { + // for all ancestors but root + if (ancestor.getParent() == null) { + continue; + } + + for (PuzzleElement pelement : caseRule.dependentElements(node.getBoard(), trans.getSelection())) { + // decrement, unlock if 0 cases depended + PuzzleElement oldElement = ancestor.getParent().getBoard().getPuzzleElement(pelement); + oldElement.setCasesDepended(oldElement.getCasesDepended() - 1); + if (oldElement.getCasesDepended() != 0) { + continue; + } + + // set modifiable if started modifiable + boolean modifiable = tree.getRootNode().getBoard().getPuzzleElement(oldElement).isModifiable(); + + // unmodifiable if already modified + TreeNode modNode = ancestor.getParent().getParents().get(0); + while (modNode.getParent()!=null) { + Board modBoard = modNode.getParent().getBoard(); + if (modBoard.getModifiedData().contains(modBoard.getPuzzleElement(oldElement))) { + modifiable = false; + break; + } + modNode = modNode.getParent().getParents().get(0); + } + oldElement.setModifiable(modifiable); + } + } + } + + transView.getParentViews().forEach(n -> n.removeChildrenView(transView)); + removeTreeTransition(trans); + } + repaint(); + } + + /** + * Called when the tree selection was changed + * + * @param selection tree selection that was changed + */ + @Override + public void onTreeSelectionChanged(TreeViewSelection selection) { + this.selection.getSelectedViews().forEach(v -> v.setSelected(false)); + selection.getSelectedViews().forEach(v -> v.setSelected(true)); + this.selection = selection; + repaint(); + } + + /** + * Called when the model has finished updating the tree. + */ + @Override + public void onUpdateTree() { + repaint(); + } + + /** + * Gets the TreeElementView by the corresponding TreeElement associated with it + * + * @param element TreeElement of the view + * @return TreeElementView of the TreeElement associated with it + */ + public TreeElementView getElementView(TreeElement element) { + return viewMap.get(element); + } + + private void removeTreeNode(TreeNode node) { + viewMap.remove(node); + List children = node.getChildren(); + + // if child is a case rule, unlock ancestor elements + if (!children.isEmpty()) { + Rule rule = children.get(0).getRule(); + if (rule instanceof CaseRule) { + CaseRule caseRule = (CaseRule)rule; + // set dependent elements to be modifiable by ancestors (if not dependent on others) + List ancestors = node.getAncestors(); + for (TreeNode ancestor : ancestors) { + // for all ancestors but root + if (ancestor.getParent() == null) { + continue; + } + for (PuzzleElement pelement : caseRule.dependentElements(node.getBoard(), children.get(0).getSelection())) { + // decrement, unlock if 0 cases depended + PuzzleElement oldElement = ancestor.getParent().getBoard().getPuzzleElement(pelement); + oldElement.setCasesDepended(oldElement.getCasesDepended() - 1); + if (oldElement.getCasesDepended() == 0) { + continue; + } + + // set modifiable if started modifiable + boolean modifiable = tree.getRootNode().getBoard().getPuzzleElement(oldElement).isModifiable(); + + // unmodifiable if already modified + TreeNode modNode = ancestor.getParent().getParents().get(0); + while (modNode.getParent() != null) { + Board modBoard = modNode.getParent().getBoard(); + if (modBoard.getModifiedData().contains(modBoard.getPuzzleElement(oldElement))) { + modifiable = false; + break; + } + modNode = modNode.getParent().getParents().get(0); + } + oldElement.setModifiable(modifiable); + } + } + } + } + node.getChildren().forEach(t -> removeTreeTransition(t)); + } + + private void removeTreeTransition(TreeTransition trans) { + viewMap.remove(trans); + if (trans.getChildNode() != null) { + removeTreeNode(trans.getChildNode()); + } + } + + private void addTreeNode(TreeNode node) { + TreeTransition parent = node.getParent(); + + TreeNodeView nodeView = new TreeNodeView(node); + TreeTransitionView parentView = (TreeTransitionView) viewMap.get(parent); + + nodeView.setParentView(parentView); + parentView.setChildView(nodeView); + + viewMap.put(node, nodeView); + + if (!node.getChildren().isEmpty()) { + + // if adding a case rule, lock dependent ancestor elements + Rule rule = node.getChildren().get(0).getRule(); + if (rule instanceof CaseRule) { + CaseRule caseRule = (CaseRule)rule; + + List ancestors = node.getAncestors(); + for (TreeNode ancestor : ancestors) { + // for all ancestors but root + if (ancestor.getParent() == null) { + continue; + } + for (PuzzleElement element : caseRule.dependentElements(node.getBoard(), node.getChildren().get(0).getSelection())) { + // increment and lock + PuzzleElement oldElement = ancestor.getParent().getBoard().getPuzzleElement(element); + oldElement.setCasesDepended(oldElement.getCasesDepended()+1); + oldElement.setModifiable(false); + } + } + } + + node.getChildren().forEach(t -> addTreeTransition(t)); + } + } + + private void addTreeTransition(TreeTransition trans) { + List parents = trans.getParents(); + + TreeTransitionView transView = new TreeTransitionView(trans); + for (TreeNode parent : parents) { + TreeNodeView parentNodeView = (TreeNodeView) viewMap.get(parent); + transView.addParentView(parentNodeView); + parentNodeView.addChildrenView(transView); + + // if transition is a new case rule, lock dependent ancestor elements + Rule rule = trans.getRule(); + if (rule instanceof CaseRule && parent.getChildren().size()==1) { + CaseRule caseRule = (CaseRule)rule; + + List ancestors = parent.getAncestors(); + for (TreeNode ancestor : ancestors) { + // for all ancestors but root + if (ancestor.getParent() == null) { + continue; + } + for (PuzzleElement element : caseRule.dependentElements(parent.getBoard(), trans.getSelection())) { + // increment and lock + PuzzleElement oldElement = ancestor.getParent().getBoard().getPuzzleElement(element); + oldElement.setCasesDepended(oldElement.getCasesDepended()+1); + oldElement.setModifiable(false); + } + } + } + } + + viewMap.put(trans, transView); + + if (trans.getChildNode() != null) { + addTreeNode(trans.getChildNode()); + } + } + + ///New Draw Methods + + public void drawTree(Graphics2D graphics2D) { + if (tree == null) { + LOGGER.error("Unable to draw tree."); + } + else { + if (rootNodeView == null) { + rootNodeView = new TreeNodeView(tree.getRootNode()); + + LOGGER.debug("Creating new views for tree view."); + createViews(rootNodeView); + + selection.newSelection(rootNodeView); + } + + dimension = new Dimension(0, 0); + calcSpan(rootNodeView); + rootNodeView.setSpan(rootNodeView.getSpan() + DIAMETER + BORDER_SPACING); + + calculateViewLocations(rootNodeView, 0); + dimension.height = (int) rootNodeView.getSpan(); + + redrawTree(graphics2D, rootNodeView); + LOGGER.debug("DrawTree: dimensions - " + dimension.width + "x" + dimension.height); + } + } + + public void createViews(TreeNodeView nodeView) { + if (nodeView != null) { + viewMap.put(nodeView.getTreeElement(), nodeView); + + TreeNode node = nodeView.getTreeElement(); + for (TreeTransition trans : node.getChildren()) { + TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); + if (transView != null) { + nodeView.addChildrenView(transView); + transView.addParentView(nodeView); + break; + } + transView = new TreeTransitionView(trans); + + viewMap.put(transView.getTreeElement(), transView); + + transView.addParentView(nodeView); + nodeView.addChildrenView(transView); + + TreeNode childNode = trans.getChildNode(); + if (childNode != null) { + TreeNodeView childNodeView = new TreeNodeView(childNode); + viewMap.put(childNodeView.getTreeElement(), childNodeView); + + childNodeView.setParentView(transView); + transView.setChildView(childNodeView); + + createViews(childNodeView); + } + } + } + } + + public void calculateViewLocations(TreeNodeView nodeView, int depth) { + nodeView.setDepth(depth); + int xLoc = (NODE_GAP_WIDTH + DIAMETER) * depth + DIAMETER; + nodeView.setX(xLoc); + dimension.width = Math.max(dimension.width, xLoc); + + TreeTransitionView parentTransView = nodeView.getParentView(); + int yLoc = parentTransView == null ? (int) nodeView.getSpan() / 2 : parentTransView.getEndY(); + nodeView.setY(yLoc); + + ArrayList children = nodeView.getChildrenViews(); + switch (children.size()) { + case 0: + break; + case 1: { + TreeTransitionView childView = children.get(0); + + List parentsViews = childView.getParentViews(); + if (parentsViews.size() == 1) { + childView.setEndY(yLoc); + + childView.setDepth(depth); + + Point lineStartPoint = childView.getLineStartPoint(0); + lineStartPoint.x = xLoc + RADIUS + TRANS_GAP / 2; + lineStartPoint.y = yLoc; + childView.setEndX((NODE_GAP_WIDTH + DIAMETER) * (depth + 1) + RADIUS - TRANS_GAP / 2); + + dimension.width = Math.max(dimension.width, childView.getEndX()); + + TreeNodeView childNodeView = childView.getChildView(); + if (childNodeView != null) { + calculateViewLocations(childNodeView, depth + 1); + } + } + else { + if (parentsViews.size() > 1 && parentsViews.get(parentsViews.size() - 1) == nodeView) { + int yAvg = 0; + for (int i = 0; i < parentsViews.size(); i++) { + TreeNodeView parentNodeView = parentsViews.get(i); + depth = Math.max(depth, parentNodeView.getDepth()); + yAvg += parentNodeView.getY(); + + Point lineStartPoint = childView.getLineStartPoint(i); + lineStartPoint.x = parentNodeView.getX() + RADIUS + TRANS_GAP / 2; + lineStartPoint.y = parentNodeView.getY(); + } + yAvg /= parentsViews.size(); + childView.setEndY(yAvg); + + childView.setDepth(depth); + + childView.setEndX((NODE_GAP_WIDTH + DIAMETER) * (depth + 1) + RADIUS - TRANS_GAP / 2); + + dimension.width = Math.max(dimension.width, childView.getEndX()); + + TreeNodeView childNodeView = childView.getChildView(); + if (childNodeView != null) { + calculateViewLocations(childNodeView, depth + 1); + } + } + } + break; + } + default: { + int span = 0; + for (TreeTransitionView childView : children) { + span += childView.getSpan(); + } + + span = (int) ((nodeView.getSpan() - span) / 2); + for (int i = 0; i < children.size(); i++) { + TreeTransitionView childView = children.get(i); + + childView.setDepth(depth); + + Point lineStartPoint = childView.getLineStartPoint(0); + lineStartPoint.x = xLoc + RADIUS + TRANS_GAP / 2; + lineStartPoint.y = yLoc; + childView.setEndX((NODE_GAP_WIDTH + DIAMETER) * (depth + 1) + RADIUS - TRANS_GAP / 2); + childView.setEndY(yLoc - (int) (nodeView.getSpan() / 2) + span + (int) (childView.getSpan() / 2)); + + span += childView.getSpan(); + TreeNodeView childNodeView = childView.getChildView(); + if (childNodeView != null) { + calculateViewLocations(childNodeView, depth + 1); + } + } + break; + } + } + } + + public void calcSpan(TreeElementView view) { + if (view.getType() == NODE) { + TreeNodeView nodeView = (TreeNodeView) view; + TreeNode node = nodeView.getTreeElement(); + if (nodeView.getChildrenViews().size() == 0) { + nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); + } + else { + if (nodeView.getChildrenViews().size() == 1) { + TreeTransitionView childView = nodeView.getChildrenViews().get(0); + calcSpan(childView); + if (childView.getParentViews().size() > 1) { + nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); + } + else { + nodeView.setSpan(childView.getSpan()); + } + } + else { + DisjointSets branches = node.findMergingBranches(); + List children = node.getChildren(); + + if (node == children.get(0).getParents().get(0)) { + reorderBranches(node, branches); + ArrayList newChildrenViews = new ArrayList<>(); + for (TreeTransition trans : node.getChildren()) { + newChildrenViews.add((TreeTransitionView) viewMap.get(trans)); + } + nodeView.setChildrenViews(newChildrenViews); + } + + List> mergingSets = branches.getAllSets(); + + double span = 0.0; + for (Set mergeSet : mergingSets) { + if (mergeSet.size() > 1) { + TreeTransition mergePoint = TreeNode.findMergingPoint(mergeSet); + TreeTransitionView mergePointView = (TreeTransitionView) viewMap.get(mergePoint); + double subSpan = 0.0; + for (TreeTransition branch : mergeSet) { + TreeTransitionView branchView = (TreeTransitionView) viewMap.get(branch); + subCalcSpan(branchView, mergePointView); + subSpan += branchView.getSpan(); + } + calcSpan(mergePointView); + span += Math.max(mergePointView.getSpan(), subSpan); + } + else { + TreeTransition trans = mergeSet.iterator().next(); + TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); + calcSpan(transView); + span += transView.getSpan(); + } + } + nodeView.setSpan(span); + } + } + } + else { + TreeTransitionView transView = (TreeTransitionView) view; + TreeNodeView nodeView = transView.getChildView(); + if (nodeView == null) { + transView.setSpan(DIAMETER + NODE_GAP_HEIGHT); + } + else { + calcSpan(nodeView); + transView.setSpan(nodeView.getSpan()); + } + } + } + + /** + * Calculates the sub span of a given sub tree rooted at the specified view and stops at the tree puzzleElement view + * specified as stop. Stop tree puzzleElement is NOT included in the span calculation + * + * @param view + * @param stop + */ + private void subCalcSpan(TreeElementView view, TreeElementView stop) { + //safe-guard for infinite loop + if (view == stop) { + return; + } + + if (view.getType() == NODE) { + TreeNodeView nodeView = (TreeNodeView) view; + TreeNode node = nodeView.getTreeElement(); + if (nodeView.getChildrenViews().size() == 0) { + nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); + } + else { + if (nodeView.getChildrenViews().size() == 1) { + TreeTransitionView childView = nodeView.getChildrenViews().get(0); + if (childView == stop) { + nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); + } + else { + subCalcSpan(childView, stop); + if (childView.getParentViews().size() > 1) { + nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); + } + else { + nodeView.setSpan(childView.getSpan()); + } + } + } + else { + DisjointSets branches = node.findMergingBranches(); + List children = node.getChildren(); + + if (node == children.get(0).getParents().get(0)) { + reorderBranches(node, branches); + } + + List> mergingSets = branches.getAllSets(); + + double span = 0.0; + for (Set mergeSet : mergingSets) { + if (mergeSet.size() > 1) { + TreeTransition mergePoint = TreeNode.findMergingPoint(mergeSet); + TreeTransitionView mergePointView = (TreeTransitionView) viewMap.get(mergePoint); + double subSpan = 0.0; + for (TreeTransition branch : mergeSet) { + TreeTransitionView branchView = (TreeTransitionView) viewMap.get(branch); + subCalcSpan(branchView, mergePointView); + subSpan += branchView.getSpan(); + } + subCalcSpan(mergePointView, stop); + span += Math.max(mergePointView.getSpan(), subSpan); + } + else { + TreeTransition trans = mergeSet.iterator().next(); + TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); + subCalcSpan(transView, stop); + span += transView.getSpan(); + } + } + + nodeView.setSpan(span); + } + } + } + else { + TreeTransitionView transView = (TreeTransitionView) view; + TreeNodeView nodeView = transView.getChildView(); + if (nodeView == null || nodeView == stop) { + transView.setSpan(DIAMETER + NODE_GAP_HEIGHT); + } + else { + calcSpan(nodeView); + transView.setSpan(nodeView.getSpan()); + } + } + } + + /** + * Reorders branches such that merging branches are sequentially grouped together and transitions are kept in + * relative order in the list of child transitions of the specified node + * + * @param node root node of the branches + * @param branches DisjointSets of the child branches of the specified node which determine which branches merge + */ + private void reorderBranches(TreeNode node, DisjointSets branches) { + List children = node.getChildren(); + List> mergingSets = branches.getAllSets(); + + List> newOrder = new ArrayList<>(); + for (Set set : mergingSets) { + List mergeBranch = new ArrayList<>(); + newOrder.add(mergeBranch); + children.forEach(t -> { + if (set.contains(t)) { + mergeBranch.add(t); + } + }); + mergeBranch.sort((TreeTransition t1, TreeTransition t2) -> + children.indexOf(t1) <= children.indexOf(t2) ? -1 : 1); + } + + newOrder.sort((List b1, List b2) -> { + int low1 = -1; + int low2 = -1; + for (TreeTransition t1 : b1) { + int curIndex = children.indexOf(t1); + if (low1 == -1 || curIndex < low1) { + low1 = curIndex; + } + } + for (TreeTransition t1 : b2) { + int curIndex = children.indexOf(t1); + if (low1 == -1 || curIndex < low1) { + low1 = curIndex; + } + } + return low1 < low2 ? -1 : 1; + }); + + List newChildren = new ArrayList<>(); + newOrder.forEach(l -> newChildren.addAll(l)); + node.setChildren(newChildren); + } } \ No newline at end of file From 244869d9658abfa2a935cd41f8013b199a9937ad Mon Sep 17 00:00:00 2001 From: Charles Tian <46334090+charlestian23@users.noreply.github.com> Date: Tue, 30 Jan 2024 15:26:05 -0500 Subject: [PATCH 05/11] Update README.md Updating description about LEGUP web version. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f4f99d75c..f32928efb 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ LEGUP (**L**ogic **E**ngine for **G**rid-**U**sing **P**uzzles) is a better way to learn formal logic. It was created by [Dr. Bram van Heuveln](https://science.rpi.edu/itws/faculty/bram-van-heuveln), whose goal for this project is to provide a better interface for students to learn the basic principles of logical reasoning. -> Note: A web version of LEGUP ([Bram-Hub/LegupWeb](https://github.com/Bram-Hub/LegupWeb)) based on this app version of LEGUP was being developed. It is very much in the early stages of development and will not be ready for general use for quite a while. Development on this web version has halted for a while, as no one has been actively working on the project. Contributions to both versions of LEGUP are greatly appreciated. However, if you are interested in using LEGUP for educational purposes, please use this app version. +> Note: A web version of LEGUP ([Bram-Hub/LegupWeb](https://github.com/Bram-Hub/LegupWeb)) was previously under development, but it has been halted due to no one actively working on the project. Contributions to both versions of LEGUP are greatly appreciated. If you are interested in using LEGUP for educational purposes, please use this app version. ## Table of Contents - [Background](#background) From 46082224940be16500ed80b27422d553ded84587 Mon Sep 17 00:00:00 2001 From: Charles Tian <46334090+charlestian23@users.noreply.github.com> Date: Tue, 30 Jan 2024 18:31:47 -0500 Subject: [PATCH 06/11] Skyscrapers Test Suite (#708) * Simplify rule names * Contradiction Test Suite * checkstyle * Update Exporter * Revert "Update Exporter" This reverts commit bae1a1f531e407e3b9dd1d28cc79330aa181f410. * Case Rule Test Suite * Update SkyscrapersExporter.java * allow null transitions * Update TreeTransition.java * Direct Rule Test Suite * added tests pass * Update DirectRule.java Commenting out print statement --------- Co-authored-by: ThisMatt Co-authored-by: ThisMatt <98851950+ThisMatt@users.noreply.github.com> Co-authored-by: Chase Grajeda <76405306+Chase-Grajeda@users.noreply.github.com> --- .../edu/rpi/legup/model/rules/DirectRule.java | 1 + .../skyscrapers/SkyscrapersExporter.java | 5 + .../DuplicateNumberContradictionRule.java | 9 +- .../ExceedingVisibilityContradictionRule.java | 6 +- ...sufficientVisibilityContradictionRule.java | 8 +- .../rules/LastSingularCellDirectRule.java | 9 +- .../rules/LastSingularNumberDirectRule.java | 5 +- .../rules/LastVisibleCellDirectRule.java | 9 +- .../rules/LastVisibleNumberDirectRule.java | 3 +- .../skyscrapers/rules/NEdgeDirectRule.java | 3 +- .../rules/NumberForCellCaseRule.java | 4 - src/test/java/legup/TestRunner.java | 1 + .../rules/CellForNumberCaseRuleTest.java | 254 +++++++++++++++++ .../DuplicateNumberContradictionTest.java | 150 ++++++++++ .../ExceedingVisibilityContradictionTest.java | 138 ++++++++++ ...sufficientVisibilityContradictionTest.java | 138 ++++++++++ .../rules/LastSingularCellDirectTest.java | 232 ++++++++++++++++ .../rules/LastSingularNumberDirectTest.java | 145 ++++++++++ .../rules/LastVisibleCellDirectTest.java | 257 +++++++++++++++++ .../rules/LastVisibleNumberDirectTest.java | 258 ++++++++++++++++++ .../skyscrapers/rules/NEdgeDirectTest.java | 145 ++++++++++ .../rules/NumberForCellCaseRuleTest.java | 228 ++++++++++++++++ ...PreemptiveVisibilityContradictionTest.java | 155 +++++++++++ .../UnresolvedCellContradictionTest.java | 155 +++++++++++ .../UnresolvedNumberContradictionTest.java | 165 +++++++++++ .../AllContradiction | 39 +++ .../ColContradiction | 25 ++ .../RowContradiction | 25 ++ .../LastSingularCellDirectRule/0-3Opening | 26 ++ .../LastSingularCellDirectRule/1-2ColOpening | 26 ++ .../LastSingularCellDirectRule/1-2RowOpening | 26 ++ .../LastSingularCellDirectRule/2-1ColOpening | 26 ++ .../LastSingularCellDirectRule/2-1RowOpening | 26 ++ .../2-1ColOpening | 26 ++ .../2-1RowOpening | 26 ++ .../LastVisibleDirectRules/1-2ColOpening | 24 ++ .../LastVisibleDirectRules/1-2RowOpening | 24 ++ .../LastVisibleDirectRules/2-1ColOpening | 25 ++ .../LastVisibleDirectRules/2-1RowOpening | 25 ++ .../rules/NEdgeDirectRule/DownColEmpty | 26 ++ .../rules/NEdgeDirectRule/LeftRowPartial | 23 ++ .../rules/NEdgeDirectRule/UpColPartial | 25 ++ .../1-3NumberContradiction | 27 ++ .../2-2CellContradiction | 27 ++ .../2-2NumberContradiction | 28 ++ .../3-1ColContradiction | 27 ++ .../3-1RowContradiction | 27 ++ .../AllContradiction | 42 +++ .../FullColContradiction | 32 +++ .../FullRowContradiction | 32 +++ .../ImpliedAllContradiction | 31 +++ .../ImpliedColContradiction | 24 ++ .../ImpliedRowContradiction | 24 ++ .../skyscrapers/rules/common/3-0ColOpening | 26 ++ .../skyscrapers/rules/common/3-0RowOpening | 26 ++ .../puzzles/skyscrapers/rules/common/Solved | 42 +++ .../puzzles/skyscrapers/rules/common/empty | 26 ++ 57 files changed, 3334 insertions(+), 33 deletions(-) create mode 100644 src/test/java/puzzles/skyscrapers/rules/CellForNumberCaseRuleTest.java create mode 100644 src/test/java/puzzles/skyscrapers/rules/DuplicateNumberContradictionTest.java create mode 100644 src/test/java/puzzles/skyscrapers/rules/ExceedingVisibilityContradictionTest.java create mode 100644 src/test/java/puzzles/skyscrapers/rules/InsufficientVisibilityContradictionTest.java create mode 100644 src/test/java/puzzles/skyscrapers/rules/LastSingularCellDirectTest.java create mode 100644 src/test/java/puzzles/skyscrapers/rules/LastSingularNumberDirectTest.java create mode 100644 src/test/java/puzzles/skyscrapers/rules/LastVisibleCellDirectTest.java create mode 100644 src/test/java/puzzles/skyscrapers/rules/LastVisibleNumberDirectTest.java create mode 100644 src/test/java/puzzles/skyscrapers/rules/NEdgeDirectTest.java create mode 100644 src/test/java/puzzles/skyscrapers/rules/NumberForCellCaseRuleTest.java create mode 100644 src/test/java/puzzles/skyscrapers/rules/PreemptiveVisibilityContradictionTest.java create mode 100644 src/test/java/puzzles/skyscrapers/rules/UnresolvedCellContradictionTest.java create mode 100644 src/test/java/puzzles/skyscrapers/rules/UnresolvedNumberContradictionTest.java create mode 100644 src/test/resources/puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/AllContradiction create mode 100644 src/test/resources/puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/ColContradiction create mode 100644 src/test/resources/puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/RowContradiction create mode 100644 src/test/resources/puzzles/skyscrapers/rules/LastSingularCellDirectRule/0-3Opening create mode 100644 src/test/resources/puzzles/skyscrapers/rules/LastSingularCellDirectRule/1-2ColOpening create mode 100644 src/test/resources/puzzles/skyscrapers/rules/LastSingularCellDirectRule/1-2RowOpening create mode 100644 src/test/resources/puzzles/skyscrapers/rules/LastSingularCellDirectRule/2-1ColOpening create mode 100644 src/test/resources/puzzles/skyscrapers/rules/LastSingularCellDirectRule/2-1RowOpening create mode 100644 src/test/resources/puzzles/skyscrapers/rules/LastSingularNumberDirectRule/2-1ColOpening create mode 100644 src/test/resources/puzzles/skyscrapers/rules/LastSingularNumberDirectRule/2-1RowOpening create mode 100644 src/test/resources/puzzles/skyscrapers/rules/LastVisibleDirectRules/1-2ColOpening create mode 100644 src/test/resources/puzzles/skyscrapers/rules/LastVisibleDirectRules/1-2RowOpening create mode 100644 src/test/resources/puzzles/skyscrapers/rules/LastVisibleDirectRules/2-1ColOpening create mode 100644 src/test/resources/puzzles/skyscrapers/rules/LastVisibleDirectRules/2-1RowOpening create mode 100644 src/test/resources/puzzles/skyscrapers/rules/NEdgeDirectRule/DownColEmpty create mode 100644 src/test/resources/puzzles/skyscrapers/rules/NEdgeDirectRule/LeftRowPartial create mode 100644 src/test/resources/puzzles/skyscrapers/rules/NEdgeDirectRule/UpColPartial create mode 100644 src/test/resources/puzzles/skyscrapers/rules/UnresolvedContradictionRules/1-3NumberContradiction create mode 100644 src/test/resources/puzzles/skyscrapers/rules/UnresolvedContradictionRules/2-2CellContradiction create mode 100644 src/test/resources/puzzles/skyscrapers/rules/UnresolvedContradictionRules/2-2NumberContradiction create mode 100644 src/test/resources/puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1ColContradiction create mode 100644 src/test/resources/puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction create mode 100644 src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/AllContradiction create mode 100644 src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/FullColContradiction create mode 100644 src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/FullRowContradiction create mode 100644 src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedAllContradiction create mode 100644 src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedColContradiction create mode 100644 src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedRowContradiction create mode 100644 src/test/resources/puzzles/skyscrapers/rules/common/3-0ColOpening create mode 100644 src/test/resources/puzzles/skyscrapers/rules/common/3-0RowOpening create mode 100644 src/test/resources/puzzles/skyscrapers/rules/common/Solved create mode 100644 src/test/resources/puzzles/skyscrapers/rules/common/empty diff --git a/src/main/java/edu/rpi/legup/model/rules/DirectRule.java b/src/main/java/edu/rpi/legup/model/rules/DirectRule.java index 847764b7b..304a2ca90 100644 --- a/src/main/java/edu/rpi/legup/model/rules/DirectRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/DirectRule.java @@ -29,6 +29,7 @@ public DirectRule(String ruleID, String ruleName, String description, String ima */ public String checkRule(TreeTransition transition) { Board finalBoard = transition.getBoard(); + // System.out.println(finalBoard.getModifiedData().size()); if (transition.getParents().size() != 1 || transition.getParents().get(0).getChildren().size() != 1) { return "State must have only 1 parent and 1 child"; diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java index 155a1466c..765540770 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java @@ -54,6 +54,11 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { } boardElement.appendChild(axisSouth); + org.w3c.dom.Element flagsElement = newDocument.createElement("flags"); + flagsElement.setAttribute("dupe",String.valueOf(board.getDupeFlag())); + flagsElement.setAttribute("view",String.valueOf(board.getViewFlag())); + boardElement.appendChild(flagsElement); + if (!board.getLines().isEmpty()) { org.w3c.dom.Element linesElement = newDocument.createElement("lines"); for (PuzzleElement data : board.getLines()) { 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 db5357fbe..620a87f68 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 @@ -29,7 +29,6 @@ public DuplicateNumberContradictionRule() { */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { - //TODO:? Refactor to count each row/col once rather than per cell (override checkContradiction) SkyscrapersCell cell = (SkyscrapersCell) puzzleElement; SkyscrapersBoard skyscrapersboard = (SkyscrapersBoard) board; Point loc = cell.getLocation(); @@ -40,8 +39,8 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { for (int i = 0; i < skyscrapersboard.getWidth(); i++) { SkyscrapersCell c = skyscrapersboard.getCell(i, loc.y); if (i != loc.x && cell.getType() == SkyscrapersType.Number && c.getType() == SkyscrapersType.Number && c.getData() == cell.getData()) { - System.out.print(c.getData()); - System.out.println(cell.getData()); + //System.out.print(c.getData()); + //System.out.println(cell.getData()); return null; } } @@ -50,8 +49,8 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { for (int i = 0; i < skyscrapersboard.getHeight(); i++) { SkyscrapersCell c = skyscrapersboard.getCell(loc.x, i); if (i != loc.y && cell.getType() == SkyscrapersType.Number && c.getType() == SkyscrapersType.Number && c.getData() == cell.getData()) { - System.out.print(c.getData()); - System.out.println(cell.getData()); + //System.out.print(c.getData()); + //System.out.println(cell.getData()); return null; } } 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 efa905ea2..e38018745 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 @@ -65,7 +65,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { Collections.reverse(row); for (SkyscrapersCell c : row) { if (c.getData() > max) { - System.out.print(c.getData()); + //System.out.print(c.getData()); //System.out.println(cell.getData()); max = c.getData(); count++; @@ -83,7 +83,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { max = 0; count = 0; for (SkyscrapersCell c : col) { - System.out.println(c.getData()); + //System.out.println(c.getData()); if (c.getData() > max) { //System.out.println(cell.getData()); @@ -100,7 +100,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { count = 0; Collections.reverse(col); for (SkyscrapersCell c : col) { - System.out.println(c.getData()); + //System.out.println(c.getData()); if (c.getData() > max) { //System.out.println(cell.getData()); 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 afc1b1341..7d405f122 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 @@ -49,7 +49,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { //from west border for (SkyscrapersCell c : row) { if (c.getData() > max) { - System.out.print(c.getData()); + //System.out.print(c.getData()); //System.out.println(cell.getData()); max = c.getData(); count++; @@ -65,7 +65,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { Collections.reverse(row); for (SkyscrapersCell c : row) { if (c.getData() > max) { - System.out.print(c.getData()); + //System.out.print(c.getData()); //System.out.println(cell.getData()); max = c.getData(); count++; @@ -83,7 +83,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { max = 0; count = 0; for (SkyscrapersCell c : col) { - System.out.println(c.getData()); + //System.out.println(c.getData()); if (c.getData() > max) { //System.out.println(cell.getData()); @@ -100,7 +100,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { count = 0; Collections.reverse(col); for (SkyscrapersCell c : col) { - System.out.println(c.getData()); + //System.out.println(c.getData()); if (c.getData() > max) { //System.out.println(cell.getData()); diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastSingularCellDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastSingularCellDirectRule.java index 541075167..2cede4117 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastSingularCellDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastSingularCellDirectRule.java @@ -14,7 +14,7 @@ public class LastSingularCellDirectRule extends DirectRule { public LastSingularCellDirectRule() { - super("SKYS-BASC-0002", "Last Non-Duplicate Cell", + super("SKYS-BASC-0002", "Last Cell for Number", "There is only one cell on this row/col for this number that does not create a duplicate contradiction", "edu/rpi/legup/images/skyscrapers/rules/LastCell.png"); } @@ -49,8 +49,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem initialBoard.setDupeFlag(dupeTemp); initialBoard.setViewFlag(viewTemp); - System.out.println(XCandidates.size()); - System.out.println(YCandidates.size()); + //System.out.println(XCandidates.size()); + //System.out.println(YCandidates.size()); //return null if either pass, both messages otherwise String xCheck = candidateCheck(XCandidates, puzzleElement, finalCell); @@ -96,9 +96,8 @@ private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { public Board getDefaultBoard(TreeNode node) { SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); - System.out.println(lightUpBoard.getPuzzleElements().size()); + //System.out.println(lightUpBoard.getPuzzleElements().size()); for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { - System.out.println("123"); SkyscrapersCell cell = (SkyscrapersCell) element; if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) { //cell.setData(SkyscrapersType.BULB.value); diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastSingularNumberDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastSingularNumberDirectRule.java index 934496827..280325190 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastSingularNumberDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastSingularNumberDirectRule.java @@ -14,7 +14,7 @@ public class LastSingularNumberDirectRule extends DirectRule { public LastSingularNumberDirectRule() { - super("SKYS-BASC-0003", "Last Non-Duplicate Number", + super("SKYS-BASC-0003", "Last Number for Cell", "There is only one number for this cell that does not create a duplicate contradiction", "edu/rpi/legup/images/skyscrapers/rules/LastNumber.png"); } @@ -79,9 +79,8 @@ private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { public Board getDefaultBoard(TreeNode node) { SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); - System.out.println(lightUpBoard.getPuzzleElements().size()); + //System.out.println(lightUpBoard.getPuzzleElements().size()); for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { - System.out.println("123"); SkyscrapersCell cell = (SkyscrapersCell) element; if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) { //cell.setData(SkyscrapersType.BULB.value); diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastVisibleCellDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastVisibleCellDirectRule.java index 49dc33677..3aa28bab8 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastVisibleCellDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastVisibleCellDirectRule.java @@ -50,8 +50,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem initialBoard.setDupeFlag(dupeTemp); initialBoard.setViewFlag(viewTemp); - System.out.println(XCandidates.size()); - System.out.println(YCandidates.size()); + //System.out.println(XCandidates.size()); + //System.out.println(YCandidates.size()); //return null if either pass, both messages otherwise String xCheck = candidateCheck(XCandidates, puzzleElement, finalCell); @@ -97,16 +97,15 @@ private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { public Board getDefaultBoard(TreeNode node) { SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); SkyscrapersBoard modBoard = (SkyscrapersBoard) node.getBoard().copy(); - System.out.println(modBoard.getPuzzleElements().size()); + //System.out.println(modBoard.getPuzzleElements().size()); for (PuzzleElement element : modBoard.getPuzzleElements()) { - System.out.println("123"); SkyscrapersCell cell = (SkyscrapersCell) element; if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) { //cell.setData(SkyscrapersType.BULB.value); modBoard.addModifiedData(cell); } } - System.out.println(modBoard.getModifiedData().isEmpty()); + //System.out.println(modBoard.getModifiedData().isEmpty()); if (modBoard.getModifiedData().isEmpty()) { return null; } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastVisibleNumberDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastVisibleNumberDirectRule.java index d3d4ff2ab..e5524418d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastVisibleNumberDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastVisibleNumberDirectRule.java @@ -80,9 +80,8 @@ private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { public Board getDefaultBoard(TreeNode node) { SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); - System.out.println(lightUpBoard.getPuzzleElements().size()); + //System.out.println(lightUpBoard.getPuzzleElements().size()); for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { - System.out.println("123"); SkyscrapersCell cell = (SkyscrapersCell) element; if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) { //cell.setData(SkyscrapersType.BULB.value); diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NEdgeDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NEdgeDirectRule.java index 9ba726ae4..78533a819 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NEdgeDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NEdgeDirectRule.java @@ -81,9 +81,8 @@ private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { public Board getDefaultBoard(TreeNode node) { SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); - System.out.println(lightUpBoard.getPuzzleElements().size()); + //System.out.println(lightUpBoard.getPuzzleElements().size()); for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { - System.out.println("123"); SkyscrapersCell cell = (SkyscrapersCell) element; if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) { //cell.setData(SkyscrapersType.BULB.value); diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NumberForCellCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NumberForCellCaseRule.java index 3bf0de70a..02000cd6e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NumberForCellCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NumberForCellCaseRule.java @@ -88,7 +88,6 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { public String checkRuleRaw(TreeTransition transition) { List childTransitions = transition.getParents().get(0).getChildren(); if (childTransitions.size() == 0) { - //System.out.println("0"); return "This case rule must have at least one child."; } else { @@ -105,16 +104,13 @@ public String checkRuleRaw(TreeTransition transition) { for (int i = 0; i < childTransitions.size(); i++) { TreeTransition case2 = childTransitions.get(i); if (case2.getBoard().getModifiedData().size() != 1) { - //System.out.println("1"); 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 super.getInvalidUseOfRuleMessage() + ": This case rule must modify the same cell for each case."; } if (!(mod2.getType() == SkyscrapersType.Number)) { - //System.out.println("3"); return super.getInvalidUseOfRuleMessage() + ": This case rule must assign a number."; } } diff --git a/src/test/java/legup/TestRunner.java b/src/test/java/legup/TestRunner.java index 3a74c4c61..5e95a16bf 100644 --- a/src/test/java/legup/TestRunner.java +++ b/src/test/java/legup/TestRunner.java @@ -7,6 +7,7 @@ import puzzles.battleship.rules.*; import puzzles.lightup.rules.*; import puzzles.nurikabe.rules.*; +import puzzles.skyscrapers.rules.*; import puzzles.treetent.rules.*; /** diff --git a/src/test/java/puzzles/skyscrapers/rules/CellForNumberCaseRuleTest.java b/src/test/java/puzzles/skyscrapers/rules/CellForNumberCaseRuleTest.java new file mode 100644 index 000000000..eb2b692c8 --- /dev/null +++ b/src/test/java/puzzles/skyscrapers/rules/CellForNumberCaseRuleTest.java @@ -0,0 +1,254 @@ +package puzzles.skyscrapers.rules; + + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; +import edu.rpi.legup.puzzle.skyscrapers.rules.CellForNumberCaseRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.ArrayList; + +public class CellForNumberCaseRuleTest { + + private static final CellForNumberCaseRule RULE = new CellForNumberCaseRule(); + private static Skyscrapers skyscrapers; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + skyscrapers = new Skyscrapers(); + } + + //basic, max cases + @Test + public void CellForNumberCaseRule_BasicEmpty() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + + board.setDupeFlag(false); + board.setViewFlag(false); + + ArrayList cases = RULE.getCasesFor(board,board.getNorthClues().get(0), 1); + + Assert.assertEquals(board.getWidth(), cases.size()); + + for(int i=0;i cases = RULE.getCasesFor(board,board.getNorthClues().get(0), 1); + + Assert.assertEquals(board.getWidth(), cases.size()); + + for(int i=0;i cases = RULE.getCasesFor(board,board.getWestClues().get(3),1); + + Assert.assertEquals(1, cases.size()); + + SkyscrapersBoard expected = ((SkyscrapersBoard) transition.getBoard()).copy(); + PuzzleElement changedCell = expected.getCell(2,3); + changedCell.setData(1); + expected.addModifiedData(changedCell); + + Assert.assertTrue(expected.equalsBoard(cases.get(0))); + } + + //dupe, no cases + @Test + public void CellForNumberCaseRule_DupeNone() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + + board.setDupeFlag(true); + board.setViewFlag(false); + + ArrayList cases = RULE.getCasesFor(board,board.getWestClues().get(3),1); + + Assert.assertEquals(0, cases.size()); + } + + //visibility, max cases + @Test + public void CellForNumberCaseRule_ViewEmpty() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + + board.setDupeFlag(false); + board.setViewFlag(true); + + ArrayList cases = RULE.getCasesFor(board,board.getWestClues().get(1), 1); + + Assert.assertEquals(board.getWidth(), cases.size()); + + for(int i=0;i cases = RULE.getCasesFor(board,board.getWestClues().get(3),1); + + Assert.assertEquals(1, cases.size()); + + SkyscrapersBoard expected = ((SkyscrapersBoard) transition.getBoard()).copy(); + PuzzleElement changedCell = expected.getCell(2,3); + changedCell.setData(1); + expected.addModifiedData(changedCell); + + Assert.assertTrue(expected.equalsBoard(cases.get(0))); + } + + //visibility, 1 Case, implied + @Test + public void CellForNumberCaseRule_ImpliedViewSingular() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + + board.setDupeFlag(false); + board.setViewFlag(true); + + ArrayList cases = RULE.getCasesFor(board,board.getWestClues().get(0),5); + + Assert.assertEquals(1, cases.size()); + + SkyscrapersBoard expected = ((SkyscrapersBoard) transition.getBoard()).copy(); + PuzzleElement changedCell = expected.getCell(4,0); + changedCell.setData(5); + expected.addModifiedData(changedCell); + + Assert.assertTrue(expected.equalsBoard(cases.get(0))); + } + + //visibility, no cases + @Test + public void CellForNumberCaseRule_ViewNone() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + + board.setDupeFlag(false); + board.setViewFlag(true); + + ArrayList cases = RULE.getCasesFor(board,board.getWestClues().get(3),1); + + Assert.assertEquals(0, cases.size()); + } +} \ No newline at end of file diff --git a/src/test/java/puzzles/skyscrapers/rules/DuplicateNumberContradictionTest.java b/src/test/java/puzzles/skyscrapers/rules/DuplicateNumberContradictionTest.java new file mode 100644 index 000000000..00cce1b91 --- /dev/null +++ b/src/test/java/puzzles/skyscrapers/rules/DuplicateNumberContradictionTest.java @@ -0,0 +1,150 @@ +package puzzles.skyscrapers.rules; + + +import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; +import edu.rpi.legup.puzzle.skyscrapers.rules.DuplicateNumberContradictionRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class DuplicateNumberContradictionTest { + + private static final DuplicateNumberContradictionRule RULE = new DuplicateNumberContradictionRule(); + private static Skyscrapers skyscrapers; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + skyscrapers = new Skyscrapers(); + } + + //empty + @Test + public void DuplicateNumberContradictionRule_EmptyBoardTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNotNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + + //correct board, no cont + @Test + public void DuplicateNumberContradictionRule_SolvedBoardTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/Solved", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNotNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + + //invalid board, no cont + @Test + public void DuplicateNumberContradictionRule_OtherContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/FullRowContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNotNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + + //on row + @Test + public void DuplicateNumberContradictionRule_RowContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/RowContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + if((k==0 || k==1) && i==0){ + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else{ + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //on col + @Test + public void DuplicateNumberContradictionRule_ColContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/ColContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + if(k==0 && (i==0 || i==1)){ + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else{ + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //multitudes + @Test + public void DuplicateNumberContradictionRule_AllContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/AllContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } +} \ No newline at end of file diff --git a/src/test/java/puzzles/skyscrapers/rules/ExceedingVisibilityContradictionTest.java b/src/test/java/puzzles/skyscrapers/rules/ExceedingVisibilityContradictionTest.java new file mode 100644 index 000000000..c7f73c998 --- /dev/null +++ b/src/test/java/puzzles/skyscrapers/rules/ExceedingVisibilityContradictionTest.java @@ -0,0 +1,138 @@ +package puzzles.skyscrapers.rules; + + +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; +import edu.rpi.legup.puzzle.skyscrapers.rules.ExceedingVisibilityContradictionRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class ExceedingVisibilityContradictionTest { + + private static final ExceedingVisibilityContradictionRule RULE = new ExceedingVisibilityContradictionRule(); + private static Skyscrapers skyscrapers; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + skyscrapers = new Skyscrapers(); + } + + //empty + @Test + public void ExceedingVisibilityContradictionRule_EmptyBoardTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNotNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + + //correct board, no cont + @Test + public void ExceedingVisibilityContradictionRule_SolvedBoardTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/Solved", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNotNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + + //invalid board, no cont + @Test + public void ExceedingVisibilityContradictionRule_OtherContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/RowContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNotNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + + //on row + @Test + public void ExceedingVisibilityContradictionRule_RowContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/FullRowContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + if(i==1 || i==3){ + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + else{ + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + } + + //on col + @Test + public void ExceedingVisibilityContradictionRule_ColContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/FullColContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + if(i==2 || i==3){ + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + else{ + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + } + + //multitudes + @Test + public void ExceedingVisibilityContradictionRule_AllContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/AllContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } +} \ No newline at end of file diff --git a/src/test/java/puzzles/skyscrapers/rules/InsufficientVisibilityContradictionTest.java b/src/test/java/puzzles/skyscrapers/rules/InsufficientVisibilityContradictionTest.java new file mode 100644 index 000000000..4e90861fc --- /dev/null +++ b/src/test/java/puzzles/skyscrapers/rules/InsufficientVisibilityContradictionTest.java @@ -0,0 +1,138 @@ +package puzzles.skyscrapers.rules; + + +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; +import edu.rpi.legup.puzzle.skyscrapers.rules.InsufficientVisibilityContradictionRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class InsufficientVisibilityContradictionTest { + + private static final InsufficientVisibilityContradictionRule RULE = new InsufficientVisibilityContradictionRule(); + private static Skyscrapers skyscrapers; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + skyscrapers = new Skyscrapers(); + } + + //empty + @Test + public void InsufficientVisibilityContradictionRule_EmptyBoardTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNotNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + + //correct board, no cont + @Test + public void InsufficientVisibilityContradictionRule_SolvedBoardTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/Solved", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNotNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + + //invalid board, no cont + @Test + public void InsufficientVisibilityContradictionRule_OtherContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/RowContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNotNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + + //on row + @Test + public void InsufficientVisibilityContradictionRule_RowContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/FullRowContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + if(i==1 || i==3){ + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + else{ + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + } + + //on col + @Test + public void InsufficientVisibilityContradictionRule_ColContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/FullColContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + if(i==2 || i==3){ + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + else{ + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + } + + //multitudes + @Test + public void InsufficientVisibilityContradictionRule_AllContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/AllContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } +} \ No newline at end of file diff --git a/src/test/java/puzzles/skyscrapers/rules/LastSingularCellDirectTest.java b/src/test/java/puzzles/skyscrapers/rules/LastSingularCellDirectTest.java new file mode 100644 index 000000000..855c358e8 --- /dev/null +++ b/src/test/java/puzzles/skyscrapers/rules/LastSingularCellDirectTest.java @@ -0,0 +1,232 @@ +package puzzles.skyscrapers.rules; + + +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; +import edu.rpi.legup.puzzle.skyscrapers.rules.LastSingularCellDirectRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.awt.*; + +public class LastSingularCellDirectTest { + + private static final LastSingularCellDirectRule RULE = new LastSingularCellDirectRule(); + private static Skyscrapers skyscrapers; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + skyscrapers = new Skyscrapers(); + } + + //full row + @Test + public void LastSingularCellDirectRule_FullRowTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/3-0RowOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(2,3); + cell.setData(1); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //full col + @Test + public void LastSingularCellDirectRule_FullColTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/3-0ColOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(3,1); + cell.setData(1); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //empty row/col + @Test + public void LastSingularCellDirectRule_EmptyTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastSingularCellDirectRule/0-3Opening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(0,1); + cell.setData(3); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //2-1 row + @Test + public void LastSingularCellDirectRule_PartialRowTest1() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastSingularCellDirectRule/2-1RowOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(3,1); + cell.setData(1); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //2-1 col + @Test + public void LastSingularCellDirectRule_PartialColTest1() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastSingularCellDirectRule/2-1ColOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(1,2); + cell.setData(3); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //1-2 row + @Test + public void LastSingularCellDirectRule_PartialRowTest2() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastSingularCellDirectRule/1-2RowOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(1,1); + cell.setData(2); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //1-2 col + @Test + public void LastSingularCellDirectRule_PartialColTest2() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastSingularCellDirectRule/1-2ColOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(0,0); + cell.setData(4); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } +} \ No newline at end of file diff --git a/src/test/java/puzzles/skyscrapers/rules/LastSingularNumberDirectTest.java b/src/test/java/puzzles/skyscrapers/rules/LastSingularNumberDirectTest.java new file mode 100644 index 000000000..f08774a8a --- /dev/null +++ b/src/test/java/puzzles/skyscrapers/rules/LastSingularNumberDirectTest.java @@ -0,0 +1,145 @@ +package puzzles.skyscrapers.rules; + + +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; +import edu.rpi.legup.puzzle.skyscrapers.rules.LastSingularNumberDirectRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.awt.*; + +public class LastSingularNumberDirectTest { + + private static final LastSingularNumberDirectRule RULE = new LastSingularNumberDirectRule(); + private static Skyscrapers skyscrapers; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + skyscrapers = new Skyscrapers(); + } + + //full row / empty col + @Test + public void LastSingularNumberDirectRule_FullRowTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/3-0RowOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(2,3); + cell.setData(1); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //full col / empty row + @Test + public void LastSingularNumberDirectRule_FullColTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/3-0ColOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(3,1); + cell.setData(1); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //2-1 row / 1-2 col + @Test + public void LastSingularNumberDirectRule_PartialRowColTest1() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastSingularNumberDirectRule/2-1RowOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(2,1); + cell.setData(4); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //2-1 col / 1-2 row + @Test + public void LastSingularNumberDirectRule_PartialRowColTest2() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastSingularNumberDirectRule/2-1ColOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(0,2); + cell.setData(1); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } +} \ No newline at end of file diff --git a/src/test/java/puzzles/skyscrapers/rules/LastVisibleCellDirectTest.java b/src/test/java/puzzles/skyscrapers/rules/LastVisibleCellDirectTest.java new file mode 100644 index 000000000..ca50bc873 --- /dev/null +++ b/src/test/java/puzzles/skyscrapers/rules/LastVisibleCellDirectTest.java @@ -0,0 +1,257 @@ +package puzzles.skyscrapers.rules; + + +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; +import edu.rpi.legup.puzzle.skyscrapers.rules.LastVisibleCellDirectRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.awt.*; + +public class LastVisibleCellDirectTest { + + private static final LastVisibleCellDirectRule RULE = new LastVisibleCellDirectRule(); + private static Skyscrapers skyscrapers; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + skyscrapers = new Skyscrapers(); + } + + //full row + @Test + public void LastVisibleCellDirectRule_FullRowTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/3-0RowOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(2,3); + cell.setData(1); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //full col + @Test + public void LastVisibleCellDirectRule_FullColTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/3-0ColOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(3,1); + cell.setData(1); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //empty row + @Test + public void LastVisibleCellDirectRule_EmptyRowTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(0,2); + cell.setData(5); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //empty col + @Test + public void LastVisibleCellDirectRule_EmptyColTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(3,4); + cell.setData(5); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //1-2 row + public void LastVisibleCellDirectRule_PartialRowTest1() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastVisibleDirectRules/1-2RowOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(1,2); + cell.setData(3); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //1-2 col + public void LastVisibleCellDirectRule_PartialColTest1() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastVisibleDirectRules/1-2ColOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(2,2); + cell.setData(2); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //2-1 row + public void LastVisibleCellDirectRule_PartialRowTest2() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastVisibleDirectRules/2-1RowOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(1,1); + cell.setData(2); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //2-1 col + public void LastVisibleCellDirectRule_PartialColTest2() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastVisibleDirectRules/2-1ColOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(0,2); + cell.setData(1); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } +} \ No newline at end of file diff --git a/src/test/java/puzzles/skyscrapers/rules/LastVisibleNumberDirectTest.java b/src/test/java/puzzles/skyscrapers/rules/LastVisibleNumberDirectTest.java new file mode 100644 index 000000000..1816832b6 --- /dev/null +++ b/src/test/java/puzzles/skyscrapers/rules/LastVisibleNumberDirectTest.java @@ -0,0 +1,258 @@ +package puzzles.skyscrapers.rules; + + +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; +import edu.rpi.legup.puzzle.skyscrapers.rules.LastSingularCellDirectRule; +import edu.rpi.legup.puzzle.skyscrapers.rules.LastVisibleNumberDirectRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.awt.*; + +public class LastVisibleNumberDirectTest { + + private static final LastVisibleNumberDirectRule RULE = new LastVisibleNumberDirectRule(); + private static Skyscrapers skyscrapers; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + skyscrapers = new Skyscrapers(); + } + + //full row + @Test + public void LastVisibleNumberDirectRule_FullRowTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/3-0RowOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(2,3); + cell.setData(1); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //full col + @Test + public void LastVisibleNumberDirectRule_FullColTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/3-0ColOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(3,1); + cell.setData(1); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //empty row + @Test + public void LastVisibleNumberDirectRule_EmptyRowTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(0,2); + cell.setData(5); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //empty col + @Test + public void LastVisibleNumberDirectRule_EmptyColTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(3,4); + cell.setData(5); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //1-2 row + public void LastVisibleNumberDirectRule_PartialRowTest1() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastVisibleDirectRules/1-2RowOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(1,2); + cell.setData(3); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //1-2 col + public void LastVisibleNumberDirectRule_PartialColTest1() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastVisibleDirectRules/1-2ColOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(2,2); + cell.setData(2); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //2-1 row + public void LastVisibleNumberDirectRule_PartialRowTest2() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastVisibleDirectRules/2-1ColOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(1,1); + cell.setData(2); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //2-1 col + public void LastVisibleNumberDirectRule_PartialColTest2() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastVisibleDirectRules/2-1RowOpening", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(0,2); + cell.setData(1); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } +} \ No newline at end of file diff --git a/src/test/java/puzzles/skyscrapers/rules/NEdgeDirectTest.java b/src/test/java/puzzles/skyscrapers/rules/NEdgeDirectTest.java new file mode 100644 index 000000000..cc39d8183 --- /dev/null +++ b/src/test/java/puzzles/skyscrapers/rules/NEdgeDirectTest.java @@ -0,0 +1,145 @@ +package puzzles.skyscrapers.rules; + + +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; +import edu.rpi.legup.puzzle.skyscrapers.rules.NEdgeDirectRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.awt.*; + +public class NEdgeDirectTest { + + private static final NEdgeDirectRule RULE = new NEdgeDirectRule(); + private static Skyscrapers skyscrapers; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + skyscrapers = new Skyscrapers(); + } + + //-> row, empty -> full + @Test + public void NEdgeDirectRule_RightRowTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + for(int i = 0; i < 5; i++){ + SkyscrapersCell cell = board.getCell(i,0); + cell.setData(i + 1); + board.addModifiedData(cell); + } + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + if(i == 0) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //<-row, partial -> partial + @Test + public void NEdgeDirectRule_LeftRowTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/NEdgeDirectRule/LeftRowPartial", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + SkyscrapersCell cell = board.getCell(1,3); + cell.setData(2); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if(point.equals(cell.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //up col, partial -> full + @Test + public void NEdgeDirectRule_UpColTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/NEdgeDirectRule/UpColPartial", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + for(int i = 0; i < 2; i++){ + SkyscrapersCell cell = board.getCell(1,i); + cell.setData(i + 1); + board.addModifiedData(cell); + } + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + if(k == 1 && i < 2) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //down col, empty -> partial + @Test + public void NEdgeDirectRule_DownColTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/NEdgeDirectRule/DownColEmpty", skyscrapers); + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); + for(int i = 1; i < 5; i++){ + SkyscrapersCell cell = board.getCell(3,i); + cell.setData(5 - i); + board.addModifiedData(cell); + } + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++) { + for(int k = 0; k < board.getWidth(); k++) { + if(k == 3 && i > 0) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } +} \ No newline at end of file diff --git a/src/test/java/puzzles/skyscrapers/rules/NumberForCellCaseRuleTest.java b/src/test/java/puzzles/skyscrapers/rules/NumberForCellCaseRuleTest.java new file mode 100644 index 000000000..40c21e604 --- /dev/null +++ b/src/test/java/puzzles/skyscrapers/rules/NumberForCellCaseRuleTest.java @@ -0,0 +1,228 @@ +package puzzles.skyscrapers.rules; + + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; +import edu.rpi.legup.puzzle.skyscrapers.rules.NumberForCellCaseRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.ArrayList; + +public class NumberForCellCaseRuleTest { + + private static final NumberForCellCaseRule RULE = new NumberForCellCaseRule(); + private static Skyscrapers skyscrapers; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + skyscrapers = new Skyscrapers(); + } + + //basic, max cases + @Test + public void NumberForCellCaseRule_BasicEmpty() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + + board.setDupeFlag(false); + board.setViewFlag(false); + + ArrayList cases = RULE.getCases(board,board.getCell(0,0)); + + Assert.assertEquals(board.getWidth(), cases.size()); + + for(int i=0;i cases = RULE.getCases(board,board.getCell(0,0)); + + Assert.assertEquals(board.getWidth(), cases.size()); + + for(int i=0;i cases = RULE.getCases(board,board.getCell(2,3)); + + Assert.assertEquals(1, cases.size()); + + SkyscrapersBoard expected = ((SkyscrapersBoard) transition.getBoard()).copy(); + PuzzleElement changedCell = expected.getCell(2,3); + changedCell.setData(1); + expected.addModifiedData(changedCell); + + Assert.assertTrue(expected.equalsBoard(cases.get(0))); + } + + //dupe, no cases + @Test + public void NumberForCellCaseRule_DupeNone() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + + board.setDupeFlag(true); + board.setViewFlag(false); + + ArrayList cases = RULE.getCases(board,board.getCell(2,3)); + + Assert.assertEquals(0, cases.size()); + } + + //visibility, max cases + @Test + public void NumberForCellCaseRule_ViewEmpty() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + + board.setDupeFlag(false); + board.setViewFlag(true); + + ArrayList cases = RULE.getCases(board,board.getCell(1,4)); + + Assert.assertEquals(4, cases.size()); + + for(int i=0;i cases = RULE.getCases(board,board.getCell(2,3)); + + Assert.assertEquals(1, cases.size()); + + SkyscrapersBoard expected = ((SkyscrapersBoard) transition.getBoard()).copy(); + PuzzleElement changedCell = expected.getCell(2,3); + changedCell.setData(1); + expected.addModifiedData(changedCell); + + Assert.assertTrue(expected.equalsBoard(cases.get(0))); + } + + //visibility, no cases + @Test + public void NumberForCellCaseRule_ViewNone() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + + board.setDupeFlag(false); + board.setViewFlag(true); + + ArrayList cases = RULE.getCases(board,board.getCell(2,3)); + + Assert.assertEquals(0, cases.size()); + } +} \ No newline at end of file diff --git a/src/test/java/puzzles/skyscrapers/rules/PreemptiveVisibilityContradictionTest.java b/src/test/java/puzzles/skyscrapers/rules/PreemptiveVisibilityContradictionTest.java new file mode 100644 index 000000000..69f4e593a --- /dev/null +++ b/src/test/java/puzzles/skyscrapers/rules/PreemptiveVisibilityContradictionTest.java @@ -0,0 +1,155 @@ +package puzzles.skyscrapers.rules; + + +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; +import edu.rpi.legup.puzzle.skyscrapers.rules.PreemptiveVisibilityContradictionRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class PreemptiveVisibilityContradictionTest { + + private static final PreemptiveVisibilityContradictionRule RULE = new PreemptiveVisibilityContradictionRule(); + private static Skyscrapers skyscrapers; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + skyscrapers = new Skyscrapers(); + } + + //empty + @Test + public void PreemptiveVisibilityContradictionRule_EmptyBoardTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNotNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + + //correct board, no cont + @Test + public void PreemptiveVisibilityContradictionRule_SolvedBoardTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/Solved", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNotNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + + //invalid board, no cont + @Test + public void PreemptiveVisibilityContradictionRule_OtherContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/2-2CellContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNotNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + + //on row + @Test + public void PreemptiveVisibilityContradictionRule_RowContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedRowContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + if(i==1){ + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + else{ + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + } + + //on col + @Test + public void PreemptiveVisibilityContradictionRule_ColContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedColContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + if(i==2){ + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + else{ + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + } + + //multitudes + @Test + public void PreemptiveVisibilityContradictionRule_AllContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/AllContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + + //multitudes - preemptive + @Test + public void PreemptiveVisibilityContradictionRule_ImpliedAllContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedAllContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } +} \ No newline at end of file diff --git a/src/test/java/puzzles/skyscrapers/rules/UnresolvedCellContradictionTest.java b/src/test/java/puzzles/skyscrapers/rules/UnresolvedCellContradictionTest.java new file mode 100644 index 000000000..d5f21a8d7 --- /dev/null +++ b/src/test/java/puzzles/skyscrapers/rules/UnresolvedCellContradictionTest.java @@ -0,0 +1,155 @@ +package puzzles.skyscrapers.rules; + + +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; +import edu.rpi.legup.puzzle.skyscrapers.rules.UnresolvedCellContradictionRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class UnresolvedCellContradictionTest { + + private static final UnresolvedCellContradictionRule RULE = new UnresolvedCellContradictionRule(); + private static Skyscrapers skyscrapers; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + skyscrapers = new Skyscrapers(); + } + + //empty + @Test + public void UnresolvedCellContradictionRule_EmptyBoardTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNotNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + + //correct board, no cont + @Test + public void UnresolvedCellContradictionRule_SolvedBoardTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/Solved", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNotNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + + //invalid board, no cont + @Test + public void UnresolvedCellContradictionRule_OtherContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedAllContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNotNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + + //3 in a row, 1 in col creates contradiction + @Test + public void UnresolvedCellContradictionRule_RowContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + if(k==2 && i==3){ + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else{ + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //3 in a col, 1 in row creates contradiction + @Test + public void UnresolvedCellContradictionRule_ColContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1ColContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + if(k==1 && i==0){ + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else{ + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + //2 in a col, 2 in row creates cell contradiction + @Test + public void UnresolvedCellContradictionRule_MixedContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/2-2CellContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + if(k==2 && i==3){ + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else{ + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } +} \ No newline at end of file diff --git a/src/test/java/puzzles/skyscrapers/rules/UnresolvedNumberContradictionTest.java b/src/test/java/puzzles/skyscrapers/rules/UnresolvedNumberContradictionTest.java new file mode 100644 index 000000000..fe4a4865a --- /dev/null +++ b/src/test/java/puzzles/skyscrapers/rules/UnresolvedNumberContradictionTest.java @@ -0,0 +1,165 @@ +package puzzles.skyscrapers.rules; + + +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; +import edu.rpi.legup.puzzle.skyscrapers.rules.UnresolvedNumberContradictionRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class UnresolvedNumberContradictionTest { + + private static final UnresolvedNumberContradictionRule RULE = new UnresolvedNumberContradictionRule(); + private static Skyscrapers skyscrapers; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + skyscrapers = new Skyscrapers(); + } + + //empty + @Test + public void UnresolvedNumberContradictionRule_EmptyBoardTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNotNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + + //correct board, no cont + @Test + public void UnresolvedNumberContradictionRule_SolvedBoardTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/Solved", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNotNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + + //invalid board, no cont + @Test + public void UnresolvedNumberContradictionRule_OtherContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedAllContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNotNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + + //3 in a row, 1 in col creates contradiction + @Test + public void UnresolvedNumberContradictionRule_RowContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + if (i == 3) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + } + + //3 in a col, 1 in row creates contradiction + @Test + public void UnresolvedNumberContradictionRule_ColContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1ColContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + if (i == 1) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + } + + //2 in a row/col, 2 in other row/cols creates number contradiction + @Test + public void UnresolvedNumberContradictionRule_TwoContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/2-2NumberContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + if (i == 1 || i == 3) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + } + + //1 in a row/col, 3 in other row/cols creates number contradiction + @Test + public void UnresolvedNumberContradictionRule_ThreeContradictionTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/1-3NumberContradiction", skyscrapers); + + TreeNode rootNode = skyscrapers.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNull(RULE.checkContradiction((SkyscrapersBoard) transition.getBoard())); + + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < board.getHeight(); i++) { + if (i == 1 || i == 2) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/AllContradiction b/src/test/resources/puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/AllContradiction new file mode 100644 index 000000000..a1e81a86e --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/AllContradiction @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/ColContradiction b/src/test/resources/puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/ColContradiction new file mode 100644 index 000000000..2fd32645c --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/ColContradiction @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/RowContradiction b/src/test/resources/puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/RowContradiction new file mode 100644 index 000000000..29da502d9 --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/RowContradiction @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/LastSingularCellDirectRule/0-3Opening b/src/test/resources/puzzles/skyscrapers/rules/LastSingularCellDirectRule/0-3Opening new file mode 100644 index 000000000..ed281abae --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/LastSingularCellDirectRule/0-3Opening @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/LastSingularCellDirectRule/1-2ColOpening b/src/test/resources/puzzles/skyscrapers/rules/LastSingularCellDirectRule/1-2ColOpening new file mode 100644 index 000000000..193fd2cff --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/LastSingularCellDirectRule/1-2ColOpening @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/LastSingularCellDirectRule/1-2RowOpening b/src/test/resources/puzzles/skyscrapers/rules/LastSingularCellDirectRule/1-2RowOpening new file mode 100644 index 000000000..10c3d6d4e --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/LastSingularCellDirectRule/1-2RowOpening @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/LastSingularCellDirectRule/2-1ColOpening b/src/test/resources/puzzles/skyscrapers/rules/LastSingularCellDirectRule/2-1ColOpening new file mode 100644 index 000000000..f96d920f5 --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/LastSingularCellDirectRule/2-1ColOpening @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/LastSingularCellDirectRule/2-1RowOpening b/src/test/resources/puzzles/skyscrapers/rules/LastSingularCellDirectRule/2-1RowOpening new file mode 100644 index 000000000..1924e1336 --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/LastSingularCellDirectRule/2-1RowOpening @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/LastSingularNumberDirectRule/2-1ColOpening b/src/test/resources/puzzles/skyscrapers/rules/LastSingularNumberDirectRule/2-1ColOpening new file mode 100644 index 000000000..1d1f9e1ba --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/LastSingularNumberDirectRule/2-1ColOpening @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/LastSingularNumberDirectRule/2-1RowOpening b/src/test/resources/puzzles/skyscrapers/rules/LastSingularNumberDirectRule/2-1RowOpening new file mode 100644 index 000000000..a3089ea98 --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/LastSingularNumberDirectRule/2-1RowOpening @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/LastVisibleDirectRules/1-2ColOpening b/src/test/resources/puzzles/skyscrapers/rules/LastVisibleDirectRules/1-2ColOpening new file mode 100644 index 000000000..978bafec4 --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/LastVisibleDirectRules/1-2ColOpening @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/LastVisibleDirectRules/1-2RowOpening b/src/test/resources/puzzles/skyscrapers/rules/LastVisibleDirectRules/1-2RowOpening new file mode 100644 index 000000000..6b35d20f7 --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/LastVisibleDirectRules/1-2RowOpening @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/LastVisibleDirectRules/2-1ColOpening b/src/test/resources/puzzles/skyscrapers/rules/LastVisibleDirectRules/2-1ColOpening new file mode 100644 index 000000000..766bf4151 --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/LastVisibleDirectRules/2-1ColOpening @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/LastVisibleDirectRules/2-1RowOpening b/src/test/resources/puzzles/skyscrapers/rules/LastVisibleDirectRules/2-1RowOpening new file mode 100644 index 000000000..2c9892dea --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/LastVisibleDirectRules/2-1RowOpening @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/NEdgeDirectRule/DownColEmpty b/src/test/resources/puzzles/skyscrapers/rules/NEdgeDirectRule/DownColEmpty new file mode 100644 index 000000000..111d2bd87 --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/NEdgeDirectRule/DownColEmpty @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/NEdgeDirectRule/LeftRowPartial b/src/test/resources/puzzles/skyscrapers/rules/NEdgeDirectRule/LeftRowPartial new file mode 100644 index 000000000..b8ccb00e3 --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/NEdgeDirectRule/LeftRowPartial @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/NEdgeDirectRule/UpColPartial b/src/test/resources/puzzles/skyscrapers/rules/NEdgeDirectRule/UpColPartial new file mode 100644 index 000000000..5b8fd6023 --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/NEdgeDirectRule/UpColPartial @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/UnresolvedContradictionRules/1-3NumberContradiction b/src/test/resources/puzzles/skyscrapers/rules/UnresolvedContradictionRules/1-3NumberContradiction new file mode 100644 index 000000000..51aa44822 --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/UnresolvedContradictionRules/1-3NumberContradiction @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/UnresolvedContradictionRules/2-2CellContradiction b/src/test/resources/puzzles/skyscrapers/rules/UnresolvedContradictionRules/2-2CellContradiction new file mode 100644 index 000000000..2d6dd8df0 --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/UnresolvedContradictionRules/2-2CellContradiction @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/UnresolvedContradictionRules/2-2NumberContradiction b/src/test/resources/puzzles/skyscrapers/rules/UnresolvedContradictionRules/2-2NumberContradiction new file mode 100644 index 000000000..7bd380e92 --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/UnresolvedContradictionRules/2-2NumberContradiction @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1ColContradiction b/src/test/resources/puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1ColContradiction new file mode 100644 index 000000000..046d2ea8e --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1ColContradiction @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction b/src/test/resources/puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction new file mode 100644 index 000000000..3063aeea1 --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/AllContradiction b/src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/AllContradiction new file mode 100644 index 000000000..1b2a81ca8 --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/AllContradiction @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/FullColContradiction b/src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/FullColContradiction new file mode 100644 index 000000000..3c0e67993 --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/FullColContradiction @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/FullRowContradiction b/src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/FullRowContradiction new file mode 100644 index 000000000..0a731bc7d --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/FullRowContradiction @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedAllContradiction b/src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedAllContradiction new file mode 100644 index 000000000..29aa271bf --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedAllContradiction @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedColContradiction b/src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedColContradiction new file mode 100644 index 000000000..bdef438d5 --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedColContradiction @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedRowContradiction b/src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedRowContradiction new file mode 100644 index 000000000..3402712ad --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedRowContradiction @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/common/3-0ColOpening b/src/test/resources/puzzles/skyscrapers/rules/common/3-0ColOpening new file mode 100644 index 000000000..8b63a4035 --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/common/3-0ColOpening @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/common/3-0RowOpening b/src/test/resources/puzzles/skyscrapers/rules/common/3-0RowOpening new file mode 100644 index 000000000..89bf1193b --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/common/3-0RowOpening @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/common/Solved b/src/test/resources/puzzles/skyscrapers/rules/common/Solved new file mode 100644 index 000000000..5dc1210e9 --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/common/Solved @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/skyscrapers/rules/common/empty b/src/test/resources/puzzles/skyscrapers/rules/common/empty new file mode 100644 index 000000000..87f7db3d7 --- /dev/null +++ b/src/test/resources/puzzles/skyscrapers/rules/common/empty @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + From 80cb273dbaf046401ded2ea016784269329dfa79 Mon Sep 17 00:00:00 2001 From: Jaden Tian <56417002+jadeandtea@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:59:03 -0500 Subject: [PATCH 07/11] Skyscrapers puzzle editor (#720) * Fixed Short Truth Table case rule bug (#707) * Revert "Bugfix 549 (#682)" This reverts commit 5048ee69d958fdde9b1bb35854c56c9920068346. * Case rule test fix (#705) Co-authored-by: Chase Grajeda <76405306+Chase-Grajeda@users.noreply.github.com> * Rapid fix for STT case rules Case rules broke at some point from legacy code or merge conflict. Provided is a quick fix in CaseRule and CaseRule_Generic * Revert "Revert "Bugfix 549 (#682)"" (#706) This reverts commit e9fe310378721aa4b4fa358aa57ec44f21d086c1. --------- Co-authored-by: Chase-Grajeda Co-authored-by: Chase Grajeda <76405306+Chase-Grajeda@users.noreply.github.com> * Implementing Puzzle Editor Removing Extraneous TreeTent Code Allowing setting tile number * Allow for editing clues on all axies * Remove Extraneous Code Removed functionality required for TreeTent but unnecessary for Skyscrapers * Remove Extraneous Code * Clue Tile in Editor Editor now requires selecting the clue tile to edit clues Added images for the tiles * Merge branch 'dev' into skyscrapersPuzzleEditor * Checkstyle Requirement * Necessary Code * Allow for test functionality --------- Co-authored-by: Charles Tian <46334090+charlestian23@users.noreply.github.com> Co-authored-by: Chase-Grajeda Co-authored-by: Chase Grajeda <76405306+Chase-Grajeda@users.noreply.github.com> --- bin/main/edu/rpi/legup/legup/config | 2 +- .../legup/puzzle/skyscrapers/ClueCommand.java | 215 ------------------ .../legup/puzzle/skyscrapers/Skyscrapers.java | 5 +- .../puzzle/skyscrapers/SkyscrapersBoard.java | 128 +++++------ .../puzzle/skyscrapers/SkyscrapersCell.java | 31 +++ .../skyscrapers/SkyscrapersCellFactory.java | 83 +++---- .../skyscrapers/SkyscrapersClueView.java | 7 - .../skyscrapers/SkyscrapersController.java | 84 +------ .../skyscrapers/SkyscrapersExporter.java | 11 +- .../skyscrapers/SkyscrapersImporter.java | 47 ++-- .../puzzle/skyscrapers/SkyscrapersLine.java | 42 ---- .../skyscrapers/SkyscrapersLineView.java | 31 --- .../puzzle/skyscrapers/SkyscrapersType.java | 4 + .../puzzle/skyscrapers/SkyscrapersView.java | 15 -- .../puzzle/skyscrapers/elements/ClueTile.java | 10 + .../skyscrapers/elements/NumberTile.java | 9 + .../skyscrapers/elements/UnknownTile.java | 9 + .../skyscrapers_elements_reference_sheet.txt | 3 + .../images/skyscrapers/tiles/ClueTile.png | Bin 0 -> 353 bytes .../images/skyscrapers/tiles/UnknownTile.png | Bin 0 -> 9733 bytes src/main/resources/edu/rpi/legup/legup/config | 2 +- 21 files changed, 188 insertions(+), 550 deletions(-) delete mode 100644 src/main/java/edu/rpi/legup/puzzle/skyscrapers/ClueCommand.java delete mode 100644 src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersLine.java delete mode 100644 src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersLineView.java create mode 100644 src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/ClueTile.java create mode 100644 src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/NumberTile.java create mode 100644 src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/UnknownTile.java create mode 100644 src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/skyscrapers_elements_reference_sheet.txt create mode 100644 src/main/resources/edu/rpi/legup/images/skyscrapers/tiles/ClueTile.png create mode 100644 src/main/resources/edu/rpi/legup/images/skyscrapers/tiles/UnknownTile.png diff --git a/bin/main/edu/rpi/legup/legup/config b/bin/main/edu/rpi/legup/legup/config index 19e63a2a3..ccd4f5be3 100644 --- a/bin/main/edu/rpi/legup/legup/config +++ b/bin/main/edu/rpi/legup/legup/config @@ -38,6 +38,6 @@ + fileCreationDisabled="false"/> diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/ClueCommand.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/ClueCommand.java deleted file mode 100644 index e80cd3d77..000000000 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/ClueCommand.java +++ /dev/null @@ -1,215 +0,0 @@ -package edu.rpi.legup.puzzle.skyscrapers; - -import edu.rpi.legup.history.CommandError; -import edu.rpi.legup.history.PuzzleCommand; -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.tree.*; -import edu.rpi.legup.ui.proofeditorui.treeview.TreeElementView; -import edu.rpi.legup.ui.proofeditorui.treeview.TreeNodeView; -import edu.rpi.legup.ui.proofeditorui.treeview.TreeTransitionView; -import edu.rpi.legup.ui.proofeditorui.treeview.TreeViewSelection; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class ClueCommand extends PuzzleCommand { - private TreeViewSelection selection; - private SkyscrapersClueView clueView; - private Map addTran; - private List> emptyCells; - - public ClueCommand(TreeViewSelection selection, SkyscrapersClueView clueView) { - this.selection = selection; - this.clueView = clueView; - this.addTran = new HashMap<>(); - this.emptyCells = new ArrayList<>(); - } - - /** - * Executes a command - */ - @Override - public void executeCommand() { - /*Puzzle puzzle = getInstance().getPuzzleModule(); - Tree tree = puzzle.getTree(); - TreeView treeView = getInstance().getLegupUI().getTreePanel().getTreeView(); - - final TreeViewSelection newSelection = new TreeViewSelection(); - for (int i = 0; i < selection.getSelectedViews().size(); i++) { - TreeElementView selectedView = selection.getSelectedViews().get(i); - TreeElement treeElement = selectedView.getTreeElement(); - - final TreeTransition finalTran; - SkyscrapersBoard board = (SkyscrapersBoard) treeElement.getBoard(); - List tempList = emptyCells.get(i); - if (treeElement.getType() == TreeElementType.NODE) { - TreeNode treeNode = (TreeNode) treeElement; - - TreeTransition transition = addTran.get(treeNode); - if (transition == null) { - transition = tree.addNewTransition(treeNode); - addTran.put(treeNode, transition); - } else { - treeNode.addChild(transition); - } - - finalTran = transition; - puzzle.notifyTreeListeners(listener -> listener.onTreeElementAdded(finalTran)); - - newSelection.addToSelection(treeView.getElementView(finalTran)); - board = (SkyscrapersBoard) finalTran.getBoard(); - } else { - finalTran = (TreeTransition) treeElement; - newSelection.addToSelection(treeView.getElementView(treeElement)); - } - - for (SkyscrapersCell cell : tempList) { - cell = (SkyscrapersCell) board.getPuzzleElement(cell); - cell.setData(SkyscrapersType.GRASS.value); - board.addModifiedData(cell); - finalTran.propagateChange(cell); - - final SkyscrapersCell finalCell = cell; - puzzle.notifyBoardListeners(listener -> listener.onBoardDataChanged(finalCell)); - } - if (i == 0) { - puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTran)); - } - } - puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection));*/ - } - - /** - * Gets the reason why the command cannot be executed - * - * @return if command cannot be executed, returns reason for why the command cannot be executed, - * otherwise null if command can be executed - */ - @Override - public String getErrorString() { - List selectedViews = selection.getSelectedViews(); - if (selectedViews.size() != 1) { - return CommandError.ONE_SELECTED_VIEW.toString(); - } - TreeElementView selectedView = selection.getFirstSelection(); - Board board = selectedView.getTreeElement().getBoard(); - SkyscrapersClue selectedPuzzleElement = clueView.getPuzzleElement(); - if (selectedView.getType() == TreeElementType.NODE) { - - TreeNodeView nodeView = (TreeNodeView) selectedView; - if (!nodeView.getChildrenViews().isEmpty()) { - return CommandError.UNMODIFIABLE_BOARD.toString(); - } - else { - if (!board.getPuzzleElement(selectedPuzzleElement).isModifiable()) { - return CommandError.UNMODIFIABLE_DATA.toString(); - } - } - } - else { - TreeTransitionView transitionView = (TreeTransitionView) selectedView; - if (!transitionView.getTreeElement().getBoard().isModifiable()) { - return CommandError.UNMODIFIABLE_BOARD.toString(); - } - else { - if (!board.getPuzzleElement(selectedPuzzleElement).isModifiable()) { - return CommandError.UNMODIFIABLE_DATA.toString(); - } - } - } - return null; - } - /*@Override - public String getErrorString() { - if (selection.getSelectedViews().isEmpty()) { - return CommandError.NO_SELECTED_VIEWS.toString(); - } - - emptyCells.clear(); - for (TreeElementView view : selection.getSelectedViews()) { - TreeElement treeElement = view.getTreeElement(); - SkyscrapersBoard board = (SkyscrapersBoard) treeElement.getBoard(); - if (treeElement.getType() == TreeElementType.NODE) { - TreeNode node = (TreeNode) treeElement; - if (!node.getChildren().isEmpty()) { - return CommandError.UNMODIFIABLE_BOARD.toString(); - } - } else { - if (!board.isModifiable()) { - return CommandError.UNMODIFIABLE_BOARD.toString(); - } - } - - List tempList = new ArrayList<>(); - SkyscrapersClue clue = clueView.getPuzzleElement(); - if (clue.getType() == SkyscrapersType.CLUE_NORTH || clue.getType() == SkyscrapersType.CLUE_SOUTH) { - int col = clue.getType() == SkyscrapersType.CLUE_NORTH ? clue.getClueIndex() : clue.getClueIndex() - 1; - for (int i = 0; i < board.getWidth(); i++) { - SkyscrapersCell cell = board.getCell(col, i); - if (cell.getType() == SkyscrapersType.UNKNOWN && cell.isModifiable()) { - tempList.add(cell); - } - } - } else { - int row = clue.getType() == SkyscrapersType.CLUE_WEST ? clue.getClueIndex() : clue.getClueIndex() - 1; - for (int i = 0; i < board.getWidth(); i++) { - SkyscrapersCell cell = board.getCell(i, row); - if (cell.getType() == SkyscrapersType.UNKNOWN && cell.isModifiable()) { - tempList.add(cell); - } - } - } - if (tempList.isEmpty()) { - return "There are no modifiable unknown cells in every selected tree element."; - } - emptyCells.add(tempList); - } - return null; - }*/ - - /** - * Undoes an command - */ - @Override - public void undoCommand() { - /*Puzzle puzzle = getInstance().getPuzzleModule(); - Tree tree = puzzle.getTree(); - - for (int i = 0; i < selection.getSelectedViews().size(); i++) { - TreeElementView selectedView = selection.getSelectedViews().get(i); - TreeElement treeElement = selectedView.getTreeElement(); - - final TreeTransition finalTran; - SkyscrapersBoard board = (SkyscrapersBoard) treeElement.getBoard(); - List tempList = emptyCells.get(i); - if (treeElement.getType() == TreeElementType.NODE) { - TreeNode treeNode = (TreeNode) treeElement; - - finalTran = treeNode.getChildren().get(0); - tree.removeTreeElement(finalTran); - puzzle.notifyTreeListeners(listener -> listener.onTreeElementRemoved(finalTran)); - - board = (SkyscrapersBoard) finalTran.getBoard(); - } else { - finalTran = (TreeTransition) treeElement; - } - - for (SkyscrapersCell cell : tempList) { - cell = (SkyscrapersCell) board.getPuzzleElement(cell); - cell.setData(SkyscrapersType.UNKNOWN.value); - board.removeModifiedData(cell); - - final SkyscrapersCell finalCell = cell; - puzzle.notifyBoardListeners(listener -> listener.onBoardDataChanged(finalCell)); - } - - if (i == 0) { - puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTran)); - } - } - final TreeViewSelection newSelection = selection; - puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection));*/ - } -} diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/Skyscrapers.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/Skyscrapers.java index 71e8f8306..f87462978 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/Skyscrapers.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/Skyscrapers.java @@ -24,6 +24,8 @@ public Skyscrapers() { @Override public void initializeView() { boardView = new SkyscrapersView((SkyscrapersBoard) currentBoard); + boardView.setBoard(currentBoard); + addBoardListener(boardView); } /** @@ -46,8 +48,7 @@ public Board generatePuzzle(int difficulty) { * @return true if the given dimensions are valid for Skyscrapers, false otherwise */ public boolean isValidDimensions(int rows, int columns) { - // This is a placeholder, this method needs to be implemented - throw new UnsupportedOperationException(); + return rows >= 4 && rows == columns; } /** diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java index 52e8a6400..65f5eb561 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java @@ -1,17 +1,16 @@ package edu.rpi.legup.puzzle.skyscrapers; -import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.elements.Element; import edu.rpi.legup.model.gameboard.GridBoard; import edu.rpi.legup.model.gameboard.PuzzleElement; import java.awt.*; +import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; public class SkyscrapersBoard extends GridBoard { - private ArrayList lines; - private ArrayList eastClues; //EAST clues @@ -28,8 +27,6 @@ public class SkyscrapersBoard extends GridBoard { public SkyscrapersBoard(int size) { super(size, size); - this.lines = new ArrayList<>(); - this.eastClues = new ArrayList<>(); this.southClues = new ArrayList<>(); this.westClues = new ArrayList<>(); @@ -43,9 +40,6 @@ public SkyscrapersBoard(int size) { } } - public ArrayList getLines() { - return lines; - } /** * @return eastClues a list of the eastern clues ordered from loc.y = 0 to max @@ -102,52 +96,13 @@ public int getSize() { @Override public PuzzleElement getPuzzleElement(PuzzleElement element) { - switch (element.getIndex()) { - case -2: - return element; - case -1: - SkyscrapersLine line = (SkyscrapersLine) element; - SkyscrapersLine thisLine = null; - for (SkyscrapersLine l : lines) { - if (line.compare(l)) { - thisLine = l; - break; - } - } - return thisLine; - default: - return super.getPuzzleElement(element); + // If the element index is -2, it is a clue and should be returned separately + if (element.getIndex() == -2) { + return element; } + return super.getPuzzleElement(element); } - /** - * Called when a {@link PuzzleElement} has been added and passes in the equivalent puzzle element with the data. - * - * @param puzzleElement equivalent puzzle element with the data. - */ - @Override - public void notifyAddition(PuzzleElement puzzleElement) { - if (puzzleElement instanceof SkyscrapersLine) { - lines.add((SkyscrapersLine) puzzleElement); - } - } - - /** - * Called when a {@link PuzzleElement} has been deleted and passes in the equivalent puzzle element with the data. - * - * @param puzzleElement equivalent puzzle element with the data. - */ - @Override - public void notifyDeletion(PuzzleElement puzzleElement) { - if (puzzleElement instanceof SkyscrapersLine) { - for (SkyscrapersLine line : lines) { - if (line.compare((SkyscrapersLine) puzzleElement)) { - lines.remove(line); - break; - } - } - } - } /** * Gets the cells of a certain type directly adjacent to a given cell @@ -251,26 +206,66 @@ public void printBoard() { } /** - * Determines if this board contains the equivalent puzzle elements as the one specified * - * @param board board to check equivalence - * @return true if the boards are equivalent, false otherwise + * @param x position of cell + * @param y position of cell + * @param e Element to be placed (null if nothing selected) + * @param m MouseEvent + * Increases clue values if in editor mode. Currently allows for + * presetting tile values, though they will not be saved. */ @Override - public boolean equalsBoard(Board board) { - SkyscrapersBoard skyscrapersBoard = (SkyscrapersBoard) board; - for (SkyscrapersLine l1 : lines) { - boolean hasLine = false; - for (SkyscrapersLine l2 : skyscrapersBoard.lines) { - if (l1.compare(l2)) { - hasLine = true; + public void setCell(int x, int y, Element e, MouseEvent m) { + SkyscrapersClue clue = this.getClue(x, y); + if (e == null) return; + if (clue != null) { + if (!e.getElementID().equals("SKYS-UNPL-0003")) { + return; + } + + if (m.getButton() == MouseEvent.BUTTON1) { + if (clue.getData() < dimension.height) { + clue.setData(clue.getData() + 1); + } + else { + clue.setData(0); } } - if (!hasLine) { - return false; + else { + if (clue.getData() > 0) { + clue.setData(clue.getData() - 1); + } + else { + clue.setData(dimension.height); + } } } - return super.equalsBoard(skyscrapersBoard); + else { + super.setCell(x - 1, y - 1, e, m); + } + } + + /** + * + * @param x position of element on boardView + * @param y position of element on boardView + * @return The clue at the given position + */ + public SkyscrapersClue getClue(int x, int y) { + int viewIndex = getSize() + 1; + if (x == 0 && y > 0 && y < viewIndex) { + return westClues.get(y-1); + } + else if (x == viewIndex && y > 0 && y < viewIndex) { + return eastClues.get(y-1); + } + else if (y == 0 && x > 0 && x < viewIndex) { + return northClues.get(x-1); + } + else if (y == viewIndex && x > 0 && x < viewIndex) { + return southClues.get(x-1); + } + return null; } @Override @@ -281,11 +276,6 @@ public SkyscrapersBoard copy() { copy.setCell(x, y, getCell(x, y).copy()); } } - for (SkyscrapersLine line : lines) { - SkyscrapersLine lineCpy = line.copy(); - lineCpy.setModifiable(false); - copy.getLines().add(lineCpy); - } for (PuzzleElement e : modifiedData) { copy.getPuzzleElement(e).setModifiable(false); } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCell.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCell.java index f58c277d5..409555b83 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCell.java @@ -1,8 +1,10 @@ package edu.rpi.legup.puzzle.skyscrapers; +import edu.rpi.legup.model.elements.Element; import edu.rpi.legup.model.gameboard.GridCell; import java.awt.*; +import java.awt.event.MouseEvent; import static edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType.convertToSkyType; @@ -23,6 +25,35 @@ public SkyscrapersType getType() { } } + @Override + public void setType(Element e, MouseEvent m) { + switch (e.getElementID()){ + case "SKYS-UNPL-0001": + this.data = 0; + break; + case "SKYS-UNPL-0002": + switch (m.getButton()){ + case MouseEvent.BUTTON1: + if (this.data <= 0 || this.data >= this.max) { + this.data = 1; + } + else { + this.data = this.data + 1; + } + break; + case MouseEvent.BUTTON3: + if (this.data > 1) { + this.data = this.data - 1; + } + else { + this.data = this.max; + } + break; + } + break; + } + } + public int getMax() { return max; diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCellFactory.java index da6899f75..5f6de7369 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCellFactory.java @@ -22,51 +22,34 @@ public class SkyscrapersCellFactory extends ElementFactory { @Override public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormatException { try { - //SkyscrapersBoard treeTentBoard = (SkyscrapersBoard) board; + if (!node.getNodeName().equalsIgnoreCase("cell")) { + throw new InvalidFileFormatException("Skyscrapers Factory: unknown puzzleElement puzzleElement"); + } + SkyscrapersBoard skyscrapersBoard = (SkyscrapersBoard) board; - int width = skyscrapersBoard.getWidth(); - int height = skyscrapersBoard.getHeight(); + int size = skyscrapersBoard.getSize(); NamedNodeMap attributeList = node.getAttributes(); - if (node.getNodeName().equalsIgnoreCase("cell")) { - - int value = Integer.valueOf(attributeList.getNamedItem("value").getNodeValue()); - int x = Integer.valueOf(attributeList.getNamedItem("x").getNodeValue()); - int y = Integer.valueOf(attributeList.getNamedItem("y").getNodeValue()); - if (x >= width || y >= height) { - throw new InvalidFileFormatException("TreeTent Factory: cell location out of bounds"); - } - if (value < 0 || value > width) { - throw new InvalidFileFormatException("TreeTent Factory: cell unknown value"); - } - SkyscrapersCell cell = new SkyscrapersCell(value, new Point(x, y), width); - cell.setIndex(y * height + x); - return cell; + int value = Integer.valueOf(attributeList.getNamedItem("value").getNodeValue()); + int x = Integer.valueOf(attributeList.getNamedItem("x").getNodeValue()); + int y = Integer.valueOf(attributeList.getNamedItem("y").getNodeValue()); + if (x >= size || y >= size) { + throw new InvalidFileFormatException("Skyscrapers Factory: cell location out of bounds"); } - else { - if (node.getNodeName().equalsIgnoreCase("line")) { - int x1 = Integer.valueOf(attributeList.getNamedItem("x1").getNodeValue()); - int y1 = Integer.valueOf(attributeList.getNamedItem("y1").getNodeValue()); - int x2 = Integer.valueOf(attributeList.getNamedItem("x2").getNodeValue()); - int y2 = Integer.valueOf(attributeList.getNamedItem("y2").getNodeValue()); - if (x1 >= width || y1 >= height || x2 >= width || y2 >= height) { - throw new InvalidFileFormatException("TreeTent Factory: line location out of bounds"); - } - - SkyscrapersCell c1 = skyscrapersBoard.getCell(x1, y1); - SkyscrapersCell c2 = skyscrapersBoard.getCell(x2, y2); - return new SkyscrapersLine(c1, c2); - } - else { - throw new InvalidFileFormatException("TreeTent Factory: unknown puzzleElement puzzleElement"); - } + if (value < 0 || value > size) { + throw new InvalidFileFormatException("Skyscrapers Factory: cell unknown value"); } + + SkyscrapersCell cell = new SkyscrapersCell(value, new Point(x, y), size); + cell.setIndex(y * size + x); + + return cell; } catch (NumberFormatException e) { - throw new InvalidFileFormatException("TreeTent Factory: unknown value where integer expected"); + throw new InvalidFileFormatException("Skyscrapers Factory: unknown value where integer expected"); } catch (NullPointerException e) { - throw new InvalidFileFormatException("TreeTent Factory: could not find attribute(s)"); + throw new InvalidFileFormatException("Skyscrapers Factory: could not find attribute(s)"); } } @@ -78,29 +61,15 @@ public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormat * @return xml PuzzleElement */ public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleElement) { - if (puzzleElement instanceof SkyscrapersCell) { - org.w3c.dom.Element cellElement = document.createElement("cell"); + org.w3c.dom.Element cellElement = document.createElement("cell"); - SkyscrapersCell cell = (SkyscrapersCell) puzzleElement; - Point loc = cell.getLocation(); + SkyscrapersCell cell = (SkyscrapersCell) puzzleElement; + Point loc = cell.getLocation(); - cellElement.setAttribute("value", String.valueOf(cell.getData())); - cellElement.setAttribute("x", String.valueOf(loc.x)); - cellElement.setAttribute("y", String.valueOf(loc.y)); + cellElement.setAttribute("value", String.valueOf(cell.getData())); + cellElement.setAttribute("x", String.valueOf(loc.x)); + cellElement.setAttribute("y", String.valueOf(loc.y)); - return cellElement; - } - else { - org.w3c.dom.Element lineElement = document.createElement("line"); - - SkyscrapersLine line = (SkyscrapersLine) puzzleElement; - - lineElement.setAttribute("x1", String.valueOf(line.getC1().getLocation().x)); - lineElement.setAttribute("y1", String.valueOf(line.getC1().getLocation().y)); - lineElement.setAttribute("x2", String.valueOf(line.getC2().getLocation().x)); - lineElement.setAttribute("y2", String.valueOf(line.getC2().getLocation().y)); - - return lineElement; - } + return cellElement; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClueView.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClueView.java index e22e16855..649f85f4e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClueView.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClueView.java @@ -44,17 +44,10 @@ public void drawElement(Graphics2D graphics2D) { SkyscrapersClue clue = getPuzzleElement(); switch (clue.getType()) { case CLUE_NORTH: - value = String.valueOf(clue.getData()); - break; case CLUE_EAST: - value = String.valueOf(clue.getData()); - break; case CLUE_SOUTH: - value = String.valueOf(clue.getData()); - break; case CLUE_WEST: value = String.valueOf(clue.getData()); - //value = SkyscrapersClue.colNumToString(clue.getData() + 1); break; default: value = ""; diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersController.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersController.java index 58994dfe8..8e338a351 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersController.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersController.java @@ -1,96 +1,14 @@ package edu.rpi.legup.puzzle.skyscrapers; -import edu.rpi.legup.app.GameBoardFacade; import edu.rpi.legup.controller.ElementController; -import edu.rpi.legup.history.AutoCaseRuleCommand; -import edu.rpi.legup.history.EditDataCommand; -import edu.rpi.legup.history.ICommand; -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.CaseBoard; import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.ui.boardview.BoardView; -import edu.rpi.legup.ui.boardview.ElementView; -import edu.rpi.legup.ui.proofeditorui.treeview.TreePanel; -import edu.rpi.legup.ui.proofeditorui.treeview.TreeView; -import edu.rpi.legup.ui.proofeditorui.treeview.TreeViewSelection; import java.awt.event.MouseEvent; -import static edu.rpi.legup.app.GameBoardFacade.getInstance; - public class SkyscrapersController extends ElementController { - private ElementView lastCellPressed; - private ElementView dragStart; - public SkyscrapersController() { super(); - this.dragStart = null; - this.lastCellPressed = null; - } - - @Override - public void mousePressed(MouseEvent e) { - if (e.getButton() != MouseEvent.BUTTON2) { - BoardView boardView = getInstance().getLegupUI().getBoardView(); - dragStart = boardView.getElement(e.getPoint()); - lastCellPressed = boardView.getElement(e.getPoint()); - } - } - - @Override - public void mouseReleased(MouseEvent e) { - if (e.getButton() != MouseEvent.BUTTON2) { - TreePanel treePanel = GameBoardFacade.getInstance().getLegupUI().getTreePanel(); - TreeView treeView = GameBoardFacade.getInstance().getLegupUI().getTreePanel().getTreeView(); - BoardView boardView = getInstance().getLegupUI().getBoardView(); - lastCellPressed = boardView.getElement(e.getPoint()); - Board board = boardView.getBoard(); - TreeViewSelection selection = treeView.getSelection(); - - if (dragStart != null) { - if (board instanceof CaseBoard) { - CaseBoard caseBoard = (CaseBoard) board; - AutoCaseRuleCommand autoCaseRuleCommand = new AutoCaseRuleCommand(dragStart, selection, caseBoard.getCaseRule(), caseBoard, e); - if (autoCaseRuleCommand.canExecute()) { - autoCaseRuleCommand.execute(); - getInstance().getHistory().pushChange(autoCaseRuleCommand); - treePanel.updateError(""); - } - else { - treePanel.updateError(autoCaseRuleCommand.getError()); - } - } - else { - if (dragStart == lastCellPressed) { - if (dragStart.getPuzzleElement().getIndex() >= 0) { - ICommand edit = new EditDataCommand(lastCellPressed, selection, e); - if (edit.canExecute()) { - edit.execute(); - getInstance().getHistory().pushChange(edit); - treePanel.updateError(""); - } - else { - treePanel.updateError(edit.getError()); - } - } - else { - ClueCommand edit = new ClueCommand(selection, (SkyscrapersClueView) dragStart); - if (edit.canExecute()) { - edit.execute(); - getInstance().getHistory().pushChange(edit); - treePanel.updateError(""); - } - else { - treePanel.updateError(edit.getError()); - } - } - } - } - } - dragStart = null; - lastCellPressed = null; - } } @Override @@ -102,7 +20,7 @@ public void changeCell(MouseEvent e, PuzzleElement element) { cell.setData(num); } else { - cell.setData(SkyscrapersType.UNKNOWN.value); + cell.setData(SkyscrapersType.UNKNOWN.toValue()); } } else { diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java index 765540770..f784fb2d9 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java @@ -2,7 +2,6 @@ import edu.rpi.legup.model.PuzzleExporter; import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; import org.w3c.dom.Document; public class SkyscrapersExporter extends PuzzleExporter { @@ -58,15 +57,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { flagsElement.setAttribute("dupe",String.valueOf(board.getDupeFlag())); flagsElement.setAttribute("view",String.valueOf(board.getViewFlag())); boardElement.appendChild(flagsElement); - - if (!board.getLines().isEmpty()) { - org.w3c.dom.Element linesElement = newDocument.createElement("lines"); - for (PuzzleElement data : board.getLines()) { - org.w3c.dom.Element lineElement = puzzle.getFactory().exportCell(newDocument, data); - linesElement.appendChild(lineElement); - } - boardElement.appendChild(linesElement); - } + return boardElement; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersImporter.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersImporter.java index 6dded9764..2df8fe88a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersImporter.java @@ -32,7 +32,30 @@ public boolean acceptsTextInput() { */ @Override public void initializeBoard(int rows, int columns) { + //assert(rows == columns); + int size = rows; + SkyscrapersBoard skyscrapersBoard = new SkyscrapersBoard(size); + + for (int y = 0; y < size; y++) { + for (int x = 0; x < size; x++) { + SkyscrapersCell cell = new SkyscrapersCell(SkyscrapersType.UNKNOWN.toValue(), new Point(x, y), size); + cell.setIndex(y * size + x); + cell.setModifiable(true); + skyscrapersBoard.setCell(x, y, cell); + } + } + + for (int i = 0; i < size; i++) { + skyscrapersBoard.getWestClues().set(/*index - 1*/i, new SkyscrapersClue(0, i, SkyscrapersType.CLUE_WEST)); + skyscrapersBoard.getEastClues().set(/*index - 1*/i, new SkyscrapersClue(0, i, SkyscrapersType.CLUE_EAST)); + } + + for (int i = 0; i < size; i++) { + skyscrapersBoard.getNorthClues().set(/*index - 1*/i, new SkyscrapersClue(0, i, SkyscrapersType.CLUE_NORTH)); + skyscrapersBoard.getSouthClues().set(/*index - 1*/i, new SkyscrapersClue(0, i, SkyscrapersType.CLUE_SOUTH)); + } + puzzle.setCurrentBoard(skyscrapersBoard); } /** @@ -48,12 +71,6 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { throw new InvalidFileFormatException("Skyscrapers Importer: cannot find board puzzleElement"); } Element boardElement = (Element) node; - if (boardElement.getElementsByTagName("cells").getLength() == 0) { - throw new InvalidFileFormatException("Skyscrapers Importer: no puzzleElement found for board"); - } - Element dataElement = (Element) boardElement.getElementsByTagName("cells").item(0); - NodeList elementDataList = dataElement.getElementsByTagName("cell"); - SkyscrapersBoard skyscrapersBoard = null; @@ -66,8 +83,13 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { throw new InvalidFileFormatException("Skyscraper Importer: invalid board dimensions"); } - int size = skyscrapersBoard.getSize(); + if (boardElement.getElementsByTagName("cells").getLength() == 0) { + throw new InvalidFileFormatException("Skyscrapers Importer: no puzzleElement found for board"); + } + Element dataElement = (Element) boardElement.getElementsByTagName("cells").item(0); + NodeList elementDataList = dataElement.getElementsByTagName("cell"); + int size = skyscrapersBoard.getSize(); for (int i = 0; i < elementDataList.getLength(); i++) { SkyscrapersCell cell = (SkyscrapersCell) puzzle.getFactory().importCell(elementDataList.item(i), skyscrapersBoard); @@ -79,6 +101,7 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { skyscrapersBoard.setCell(loc.x, loc.y, cell); } + for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { if (skyscrapersBoard.getCell(x, y) == null) { @@ -117,7 +140,6 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { for (int i = 0; i < eastClues.getLength(); i++) { Element clue = (Element) eastClues.item(i); int value = Integer.valueOf(clue.getAttribute("value")); - //int index = SkyscrapersClue.colStringToColNum(clue.getAttribute("index")); int index = Integer.valueOf(clue.getAttribute("index")); skyscrapersBoard.getWestClues().set(/*index - 1*/i, new SkyscrapersClue(index, i, SkyscrapersType.CLUE_WEST)); @@ -134,15 +156,6 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { skyscrapersBoard.getSouthClues().set(/*index - 1*/i, new SkyscrapersClue(value, i, SkyscrapersType.CLUE_SOUTH)); } - if (boardElement.getElementsByTagName("lines").getLength() == 1) { - Element linesElement = (Element) boardElement.getElementsByTagName("lines").item(0); - NodeList linesList = linesElement.getElementsByTagName("line"); - for (int i = 0; i < linesList.getLength(); i++) { - skyscrapersBoard.getLines().add((SkyscrapersLine) puzzle.getFactory().importCell(linesList.item(i), skyscrapersBoard)); - } - } - - //Initialize present flags NodeList flagList = boardElement.getElementsByTagName("flags"); if (flagList.getLength() == 1) { Element flags = (Element) flagList.item(0); diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersLine.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersLine.java deleted file mode 100644 index 4ebae3de9..000000000 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersLine.java +++ /dev/null @@ -1,42 +0,0 @@ -package edu.rpi.legup.puzzle.skyscrapers; - -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.utility.Entry; - -public class SkyscrapersLine extends PuzzleElement> { - - public SkyscrapersLine(SkyscrapersCell c1, SkyscrapersCell c2) { - this.data = new Entry<>(c1, c2); - } - - public SkyscrapersCell getC1() { - return data.getKey(); - } - - public void setC1(SkyscrapersCell c1) { - this.data.setKey(c1); - } - - public SkyscrapersCell getC2() { - return data.getValue(); - } - - public void setC2(SkyscrapersCell c2) { - this.data.setValue(c2); - } - - public boolean compare(SkyscrapersLine line) { - return ((line.getC1().getLocation().equals(data.getKey().getLocation()) && line.getC2().getLocation().equals(data.getValue().getLocation())) || - (line.getC1().getLocation().equals(data.getValue().getLocation()) && line.getC2().getLocation().equals(data.getKey().getLocation()))); - } - - /** - * Copies this elements puzzleElement to a new PuzzleElement object - * - * @return copied PuzzleElement object - */ - @Override - public SkyscrapersLine copy() { - return new SkyscrapersLine(data.getKey().copy(), data.getValue().copy()); - } -} diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersLineView.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersLineView.java deleted file mode 100644 index 02daa7a11..000000000 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersLineView.java +++ /dev/null @@ -1,31 +0,0 @@ -package edu.rpi.legup.puzzle.skyscrapers; - -import edu.rpi.legup.ui.boardview.ElementView; - -import java.awt.*; - -public class SkyscrapersLineView extends ElementView { - private final Color LINE_COLOR = Color.GREEN; - - private final Stroke LINE_STROKE = new BasicStroke(2); - - public SkyscrapersLineView(SkyscrapersLine line) { - super(line); - } - - @Override - public void draw(Graphics2D graphics2D) { - - SkyscrapersLine line = (SkyscrapersLine) puzzleElement; - Point p1 = line.getC1().getLocation(); - Point p2 = line.getC2().getLocation(); - int x1 = (p1.x + 1) * size.width + size.width / 2; - int y1 = (p1.y + 1) * size.height + size.height / 2; - - int x2 = (p2.x + 1) * size.width + size.width / 2; - int y2 = (p2.y + 1) * size.height + size.height / 2; - graphics2D.setColor(line.isModified() ? Color.GREEN : Color.WHITE); - graphics2D.setStroke(LINE_STROKE); - graphics2D.drawLine(x1, y1, x2, y2); - } -} diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersType.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersType.java index 0b53a9472..f85d9a40e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersType.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersType.java @@ -9,6 +9,10 @@ public enum SkyscrapersType { this.value = value; } + public int toValue() { + return value; + } + public static SkyscrapersType convertToSkyType(int num) { switch (num) { case 0: diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersView.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersView.java index b12867eda..a04b32889 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersView.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersView.java @@ -9,15 +9,12 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import javax.imageio.ImageIO; import java.awt.*; -import java.io.IOException; import java.util.ArrayList; public class SkyscrapersView extends GridBoardView { private final static Logger LOGGER = LogManager.getLogger(SkyscrapersView.class.getName()); - private ArrayList lineViews; private ArrayList northClues; private ArrayList eastClues; private ArrayList southClues; @@ -26,8 +23,6 @@ public class SkyscrapersView extends GridBoardView { public SkyscrapersView(SkyscrapersBoard board) { super(new BoardController(), new SkyscrapersController(), board.getDimension()); - this.lineViews = new ArrayList<>(); - this.northClues = new ArrayList<>(); this.eastClues = new ArrayList<>(); this.southClues = new ArrayList<>(); @@ -43,12 +38,6 @@ public SkyscrapersView(SkyscrapersBoard board) { elementViews.add(elementView); } - for (SkyscrapersLine line : board.getLines()) { - SkyscrapersLineView lineView = new SkyscrapersLineView(line); - lineView.setSize(elementSize); - lineViews.add(lineView); - } - for (int i = 0; i < gridSize.height; i++) { SkyscrapersClueView row = new SkyscrapersClueView(board.getWestClues().get(i)); row.setLocation(new Point(0, (i + 1) * elementSize.height)); @@ -189,10 +178,6 @@ protected void setCasePickable() { public void drawBoard(Graphics2D graphics2D) { super.drawBoard(graphics2D); - for (SkyscrapersLineView view : lineViews) { - view.draw(graphics2D); - } - for (SkyscrapersClueView clueView : northClues) { clueView.draw(graphics2D); } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/ClueTile.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/ClueTile.java new file mode 100644 index 000000000..8505de523 --- /dev/null +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/ClueTile.java @@ -0,0 +1,10 @@ +package edu.rpi.legup.puzzle.skyscrapers.elements; + +import edu.rpi.legup.model.elements.NonPlaceableElement; + +public class ClueTile extends NonPlaceableElement { + + public ClueTile() { + super("SKYS-UNPL-0003", "Clue Tile", "Clue Updater", "edu/rpi/legup/images/skyscrapers/tiles/ClueTile.png"); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/NumberTile.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/NumberTile.java new file mode 100644 index 000000000..8f78fb1cf --- /dev/null +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/NumberTile.java @@ -0,0 +1,9 @@ +package edu.rpi.legup.puzzle.skyscrapers.elements; + +import edu.rpi.legup.model.elements.NonPlaceableElement; + +public class NumberTile extends NonPlaceableElement { + public NumberTile() { + super("SKYS-UNPL-0002", "Number Tile", "A numbered tile", "edu/rpi/legup/images/skyscrapers/tiles/ClueTile.png"); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/UnknownTile.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/UnknownTile.java new file mode 100644 index 000000000..3559dc332 --- /dev/null +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/UnknownTile.java @@ -0,0 +1,9 @@ +package edu.rpi.legup.puzzle.skyscrapers.elements; + +import edu.rpi.legup.model.elements.NonPlaceableElement; + +public class UnknownTile extends NonPlaceableElement { + public UnknownTile() { + super("SKYS-UNPL-0001", "Unknown", "A blank tile", "edu/rpi/legup/images/skyscrapers/tiles/UnknownTile.png"); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/skyscrapers_elements_reference_sheet.txt b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/skyscrapers_elements_reference_sheet.txt new file mode 100644 index 000000000..604e1824e --- /dev/null +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/skyscrapers_elements_reference_sheet.txt @@ -0,0 +1,3 @@ +SKYS-UNPL-0001: Unknown Tile +SKYS-UNPL-0002: Number Tile +SKYS-UNPL-0003: Clue "Tile" \ No newline at end of file diff --git a/src/main/resources/edu/rpi/legup/images/skyscrapers/tiles/ClueTile.png b/src/main/resources/edu/rpi/legup/images/skyscrapers/tiles/ClueTile.png new file mode 100644 index 0000000000000000000000000000000000000000..7a86827f96c840aca4175288e997c49a205ee7cd GIT binary patch literal 353 zcmV-n0iOPeP)Px$8%ab#R9HvtmOrjVKop06EWn@A7DT1eDCqQhg~~3hfW#6+6k-D^6)I}2*Z{q_ zFC%%)%gak<++44iQ_r09&6jgdMgZ`_gCP)recvBJkYyPhfE(ZjxB+SdbzLLRa}2|P z<2Yd3Hj1KvBuUiEjA;@1zK^P^Ad2EuFp46SWr<~3pePCz1QWn-6-Xk>vd}cma{z)M zVB5Cm05na*JkOs8h~pS(nj%ROgkktufN7fGI1UWMK-YCt#mV7YO*oDtT-SxJ>(@xK z1T#S2_wYOqrfH&WTbA0_9VUQvT`%Q#Uj9wY1fZ%a&hx}OzH!t5q|3=F4uSw#mNBbm zHb98~3R)}F25vw3M*C;92(%$B$j*UfgJ*;N7<4klmjq@7`jNmS4uuQ?ae8jr zQ%Yu)MZVp#9TYgf8*hX(%{CU^9J!;+j0A#MNvKa$Jt+njdWBUWjaiz zWF)szlOj%Q_{4l}jLmFyB&I)FG~53;!hrZZEkL$Czq;uQtVmlB%SPO$w|oiQdrz=U z#_+W<87!wdPFDT+xnzIQ+X`==boP_4ix-N5?teH9&*aqxo4?%C6pgASKeUZ2+3BwTuCnh&U9y{~cr{+wr+PhiQw1i)A`kRWnMuo}kS3dKUx1Pvs z+jYeNqkUclcRHmgqe-o((th%VCnur6L~?n!<74B5xFnLBFpM}O_lY?g<*0aFgQ5n$ ztU+qL8mTCpI_mp?G0+mPo@09-bSYVx>!ztVlH?tRQzH-YC71JTw$u`85t7w9`&1}$ zLV%cYr}?eqF8h<$VR6%!zwsxBTwlC4f7m!$wgpLj$gQ#E6_0HAgXsu4+5Rftm(M^` zb9ZXQ+BZvr# zz6Mt1Dw9>;B2vV(;j$@!%fGoAce8kh*a27nlBfO(Cj>orwEy|>NlRdub1;7b73%CLB?4~x%*w1=ytE@?bobt?62fI7@wAl3qRUwq+r+~OEB+7 zK4d%^xSRxTJZE|L73rd3=Qid}(~BOl>QxcBO6TqJ(oWsT`6_q4)4}%rNjvYm4~Cty z^PzV;5`5mWUb`+}S(C+A!tcbty!TbOlS8mnwl&n;Rz zdq7z5XUQN&WuCCGN|L=r(pNUDEiY05)+W$_hPBm4(o?;Zru3A{CYptndp3`2D3^)9 zQ?ZyeojIC1Dm|uR!P4UZ7MbBe4Y<~nhXEF>sTq!YZkO=*PUW(rIg_cQ%k32>V?Mf- zs4EMN?MnSP+;$>H&vnoq_O|s>t=0EU`Sigy{HS_rRia5$jy@r+Z{z2s{^Q28%$FJ_Nc zjLh?FJG(CFsMbn$P|h=$q?+MW@Gcr_xr)uGkBi z4TM;S;9-#?a?Z_INN<|bV6^PCjK8&XN+NW?8PaJXmG5u#?a;RL20WQN6cRJZy-D4y zE+3*iUAy-Uu0j&DO>J8J^vWsTjBO_tZD?a#9t6`o&V?2>wO>kq)q@!A&6uz|ZQw3h zN6dqL@hx)>a^g!&5w01?)Zb_9;#_w1NhkSkXQ%OS1KCY#yqfmiGUjNx>8&vR1(Dpj zW5vtKZb4X3oTD}MNN{oe6mK>G37T1`?na4ngVn~Jmul=6a$-i5%)n2IknqNq7VTk% zL&HGW_neinPw3f~3vu;h-&IB5W+v81<_nDulohwzzK9GCBJ(BI=WJaLj9&47=XS9c z7Li!f&*bDr`?V$c2gc+c`P}Woh0Zh?nfY$Jc?I8n@wQGE#9B^|%ew%6RxX=+uuCsA zSBy)7X>fbPavS=1u#Q-Dg}}?0`Ufk2j`o#4A`K`drZ4KYKzGEoNX(Qn2B zdF%JYh>1$<{qkJ-D$mZS>p7UKf?wq^ysn{zd&8e&y(H7ZLZW(W1uVj@6(I^Xrq_sc z^UjCYzDxFlRLHf23-?d@Nx6tBgum_={uHpNy_;J<%2Pa4Ok6Jar0jN)x{ZRk+ytJ8 zGX;jH63j2lQ}&ddJv^w42(wU}vXYhLH8RyiiKF=5^&bJ?_9 zV{7Eq16~LxL2Bq-!=-G+wwO_0mUx-O+i04h+ulCoGne|@VX|_@{Dko71|0qz+y|DI zx}18bIj|W_7D2|=dq@@WIq>^}&&No)#}*weeq1zCWZ3OL;k-@!$|>aIz=2%<-7Z{( z5^PDfG&&-^=GptaPfna&!Qia;*7}tGt)E;MxxVRyWPvT8Z`TofB+wWUAF*?eK~=yge83oQ zt!*u*nxgvNPUK+JxS?hKd8_J6^R}Ku5)n$OB{7LU#MURLpNpkwKZ`nVu6`*q`)y8T zitTx3!uu!GM4yDM=h741AX9&~CTO0gCs#vP4xcD|mvc6^$Tr8YKLKKH?FM&%J5PrW zDAkWCbtuj6bJ%w(CBuQ?CU~gbUdY<%63g`30m>mqqgVTM4Fhk@7!6UR(oU6{mzYOB zbxc+}c>DnPq+}cj38bM^Z<{%LwlP?`7}L%snXXq=ZD_*+EMtd&FuV#x6h;IZq6po`poi+xNq>;Q1~z;e2?MnoSWNQi+cUK zqltqaNu&;6l(z+P9<2fU2n)gIQY5G)FD`ctCSFUXT&IMOZ9r~8x|MR5YLxapn|tOs ztTlY^&nMDZ(jTB0=wT;02gaYG4!w7B9e5q6#p8FsdQl0_?$L^~O4@G6l)myrHfJNk zWb@+G?|M1gzn;5$h1&PZ@wMQ@{_bTmop{mXct;51T8m9f`^h}QrtwV{QJ5%klQKfa z`#q1vRkT#{Z7W}F_T1=smwD-PL~Pc+k|ubHOksXuaF=$ME_&C!JG7Cv;%v#&E@n2A1niqQ(3+E=M6~9D&J-CFO z?phdGV)NE;RdJPb%WJ%FYH;op7vMg|&F0k;Y8Q0+W0n9@)=|B$yhw?5Gz~GOt16+i zXT3(#VO>QfMf^2c6yD!>oK*ln)dsRZ*zKJx& z--(*bm~1X|Kj6PjXDB0vCn{nlq7fHW=Ne;cw%;t-?1c-OrnNvSVKb;RF6Qn}`;#I& zqB}ZKE>12zYFQ$hkzI*}=du#@Qt@Z4li(#iw7HKjk-_>Q1m&a$h*Dbvsbz~f!GOs0 z$V-l=9km?krM0C8hD}F4F}^b9nD>VE4+ah&E9bj&@=pFPH|TM~_fe;mI{_cE1ExQe zb@>!%y69Iu^r=mVkBC>>dVD7gs;bGURP(U4&tdeRd{q4GaC&;|j#G<9waydwI%r1J zA=+dgxtKb2_dxx`fR9qXQnHeQxno{e6?`dwJUwz!@bywtLDQy*nu&Ll_e)<;MiLlf zGZiz%u3Y6k>Z4NiQn%QTKUO(W939J}icIc%UVd7Aoq21x_m89cb}9$^3jJ?V-d?#) ze_i!pd1Bd+KST6($IhHwr5cmsib*4O?~QT-n&av9b?QMfJAx{gd*I zlgj1{nm$R$Qclm$zhrLGl-5tif9@zwC7`RAD}|-?SMv&!JDnKYw#mpJpFj3yfxUk* zb5yTU=haMjr|43TDz$#n>L_i=!o=pWsi)n@JGDOBx32T9RDHP>&f@K!u{30f=hGI6 z7U?WkofI~0KDgn_m~f0tLm8o5!6mMOb3^6+m6daSdFm-xO}B}FF)X{j|LNF`BlZVe z2`(S*(~ebEwqCzAsdD3D&)1tvularXF!b);Q8^b3=g1Sv=p)O8^c4D+H)SD5Urj#T z)im|ykJDS^A2e0%3e=qIZCY|%7*X)$M29$hGaa`cBIG@u)Bmvi2IGNckUNguo-!Lv zdgRrq+6GYwMxiTaRZ=2Zxl6+K;&{R6aj8T}yAN zo_mICiK`y0c3G^PO@4Hv_7>EQ-OBe&FC=lE98$P=^U-U?DcPx@K9h=zsjc5bm#yZk zrwCmt)dxgn+NGtx^KMA}{7rkCXghEQl%)V?JqJq*41rG7z!T{nBn=ML4>${gK)dxh zet3cpi3Ro`c~WRt$W(bX1WX}fA@*99FiSr}k{87^h(WRq+HXe)@*(IFA^LhkyEzyD zfJ$QF!5peDjfvr4A#1o8;C@xC2?4LEuzau(2TLokA)P@2qcl(&FsKoSas&a<69VsM z5Xl%DobgWx;0X)yVzK-%nwo4jTZ4_%pffx*;kvrInlOYW0s#dypv*uT3(tYln2M_q zKQM44CV@fmV^Qcd@G2(WgC4-bLLk66_^Q^Z*8dWORf?V=4X$K_vWb?-#)ET?>au&?NbisDLUH z@CyIUrHPrP)!!DY6nIjoerr|$*}rMBDCB?0`fYBjBWvOOIuXG9Z`|Ls|B8K08PKw{ z#Ng{jKp|q*Zs9065rIaLpl~>_6etvo4D}%CAfRXhSyu-JC+O&s z(7!;L(U>eejX+w30>CvW01gqaO(1C@&``8C$^(k>KxskoS~^Im4iT;Gfh6ea=)!b= zfjGdR09lFm{dHEWP(%QV;6c!VBVhz6jD$i#Q3RMa)B^_Kp-~93mbR9*E(s4`gCY_z z#&iZ14=g8ziuWXG`q4bs2385j?6ES#LJ%6Te;mi-oLC3cPB$mf+ysKbFOm!UQw|S9AVn*4vW&e?0vt0$|4gaBt8YOuawub>;H`|p?{7$BpUDwhz%TOP=6Tg{XaVG zrZMZC_VrHtdZ&H8)4twmU+=W9ciPuG?dzTP^-lY5opvR*bO6v!=kwTSf&;CrzOyT@ zBmxpaKT}602qe6D_2L4hWyk_TewLY~5&tm1w1f(eU_#WU)keG-ZjYTq?PM2R90U`o zHORBK8rF|IC|nzhtEmnOH7OP@Do>u?vF)j#7}y{b#Kp}c@Z;u1)ri6_TVDOep)ugE QTOg2`(SBUvUiYy70dQO53jhEB literal 0 HcmV?d00001 diff --git a/src/main/resources/edu/rpi/legup/legup/config b/src/main/resources/edu/rpi/legup/legup/config index 19e63a2a3..ccd4f5be3 100644 --- a/src/main/resources/edu/rpi/legup/legup/config +++ b/src/main/resources/edu/rpi/legup/legup/config @@ -38,6 +38,6 @@ + fileCreationDisabled="false"/> From 2190f7ea792182699139b3626db6264778111f6b Mon Sep 17 00:00:00 2001 From: Jaden Tian <56417002+jadeandtea@users.noreply.github.com> Date: Wed, 21 Feb 2024 12:39:06 -0500 Subject: [PATCH 08/11] Java Autoformatter (#728) * Create java-autoformat.yml * Setup Java * Run spotless on repository * Adding spotless dependency during build * Adding spotless dependency during build * Give permissions to run spotless * Syntax * Adding Debug Tag * Check for modified files Also removed debug tag * Automated Java code formatting changes * Test command syntax * Correctly Identify modified files * Test autoformatter * Test autoformatter * Test autoformatter * Debugging * Debugging * Change method for detecting changed files * Try building before calling spotless * Update java-autoformat.yml * Update java-autoformat.yml * Update java-autoformat.yml * Purposely bad formatting Purposely adding some bad formatting to see if the auto-formatter triggers * Update build.gradle Disabling Checkstyle in build so the auto-formatter can trigger * Update java-autoformat.yml Have auto-formatter trigger when more commits are added to a pull request * Debugging * Adding more awful formatting * Update java-autoformat.yml * Changing repo URL * Going back to checkout v1 * Trying URL change * Trying out using env * Trying this now...? * Introducing more horrible changes * Spotless formatting using google format v1.19.2 * Manual formatting fix * Automated Java code formatting changes * Different format type Trying to get it to pass checkstyle * Disable checkstyle temporarily * Automated Java code formatting changes * Default google formatting style * Automated Java code formatting changes * Comments and reordering styles * Adding extra newlines * Automated Java code formatting changes * Changing tabs from 2 to 4 spaces Supposedly the only difference that aosp makes is the 2 spaces? Hopefully it doesn't break anything else * Remove solo } requirement and reactivate checkstyle * Automated Java code formatting changes * Update checkstyle.xml Removed problematic LeftCurly and RightCurly requirements * Changing back to tabWidth * Add newline to test formatter + build * Automated Java code formatting changes * Trying some ChatGPT stuff * Getting rid of problematic experimentation --------- Co-authored-by: Bram van Heuveln Co-authored-by: Charles Tian <46334090+charlestian23@users.noreply.github.com> Co-authored-by: charlestian23 --- .github/workflows/java-autoformat.yml | 38 ++ build.gradle | 30 + config/checkstyle/checkstyle.xml | 6 - gradlew | 0 src/main/java/edu/rpi/legup/Legup.java | 2 +- src/main/java/edu/rpi/legup/ai/Solver.java | 3 +- src/main/java/edu/rpi/legup/app/Config.java | 22 +- .../edu/rpi/legup/app/GameBoardFacade.java | 179 +++--- .../edu/rpi/legup/app/LegupPreferences.java | 60 +- .../rpi/legup/app/PuzzleKeyAccelerator.java | 58 +- .../rpi/legup/controller/BoardController.java | 29 +- .../edu/rpi/legup/controller/Controller.java | 33 +- .../legup/controller/CursorController.java | 57 +- .../controller/EditorElementController.java | 21 +- .../legup/controller/ElementController.java | 110 ++-- .../rpi/legup/controller/RuleController.java | 61 +- .../legup/controller/ToolbarController.java | 12 +- .../rpi/legup/controller/TreeController.java | 53 +- .../legup/history/AddTreeElementCommand.java | 29 +- .../ApplyDefaultDirectRuleCommand.java | 257 ++++---- .../legup/history/AutoCaseRuleCommand.java | 36 +- .../edu/rpi/legup/history/CommandError.java | 1 - .../edu/rpi/legup/history/CommandState.java | 5 +- .../history/DeleteTreeElementCommand.java | 31 +- .../rpi/legup/history/EditDataCommand.java | 43 +- .../java/edu/rpi/legup/history/History.java | 35 +- .../java/edu/rpi/legup/history/ICommand.java | 17 +- .../rpi/legup/history/IHistoryListener.java | 8 +- .../InvalidCommandStateTransition.java | 11 +- .../edu/rpi/legup/history/MergeCommand.java | 24 +- .../edu/rpi/legup/history/PuzzleCommand.java | 53 +- .../history/ValidateCaseRuleCommand.java | 26 +- .../ValidateContradictionRuleCommand.java | 52 +- .../history/ValidateDirectRuleCommand.java | 294 +++++---- src/main/java/edu/rpi/legup/model/Puzzle.java | 90 ++- .../edu/rpi/legup/model/PuzzleExporter.java | 25 +- .../edu/rpi/legup/model/PuzzleImporter.java | 130 ++-- .../edu/rpi/legup/model/RegisterPuzzle.java | 4 +- .../edu/rpi/legup/model/elements/Element.java | 9 +- .../rpi/legup/model/elements/ElementType.java | 3 +- .../model/elements/NonPlaceableElement.java | 3 +- .../model/elements/PlaceableElement.java | 3 +- .../legup/model/elements/RegisterElement.java | 4 +- .../edu/rpi/legup/model/gameboard/Board.java | 24 +- .../rpi/legup/model/gameboard/CaseBoard.java | 1 - .../legup/model/gameboard/ElementFactory.java | 14 +- .../rpi/legup/model/gameboard/GridBoard.java | 73 +-- .../rpi/legup/model/gameboard/GridCell.java | 7 +- .../legup/model/gameboard/PuzzleElement.java | 13 +- .../legup/model/observer/ITreeListener.java | 4 +- .../edu/rpi/legup/model/rules/CaseRule.java | 66 +- .../legup/model/rules/ContradictionRule.java | 47 +- .../edu/rpi/legup/model/rules/DirectRule.java | 210 +++---- .../edu/rpi/legup/model/rules/MergeRule.java | 42 +- .../rpi/legup/model/rules/RegisterRule.java | 4 +- .../java/edu/rpi/legup/model/rules/Rule.java | 62 +- .../edu/rpi/legup/model/rules/RuleType.java | 5 +- .../java/edu/rpi/legup/model/tree/Tree.java | 46 +- .../edu/rpi/legup/model/tree/TreeElement.java | 11 +- .../rpi/legup/model/tree/TreeElementType.java | 3 +- .../edu/rpi/legup/model/tree/TreeNode.java | 48 +- .../rpi/legup/model/tree/TreeTransition.java | 41 +- .../rpi/legup/puzzle/PuzzleElementTypes.java | 3 +- .../legup/puzzle/battleship/Battleship.java | 174 +++--- .../puzzle/battleship/BattleshipBoard.java | 15 +- .../puzzle/battleship/BattleshipCell.java | 3 +- .../battleship/BattleshipCellController.java | 26 +- .../battleship/BattleshipCellFactory.java | 31 +- .../puzzle/battleship/BattleshipClueView.java | 2 +- .../battleship/BattleshipElementView.java | 45 +- .../puzzle/battleship/BattleshipExporter.java | 7 +- .../puzzle/battleship/BattleshipImporter.java | 125 ++-- .../puzzle/battleship/BattleshipType.java | 25 +- .../puzzle/battleship/BattleshipView.java | 6 +- .../rules/AdjacentShipsContradictionRule.java | 38 +- .../rules/ContinueShipDirectRule.java | 88 +-- .../rules/FinishWithShipsDirectRule.java | 224 ++++--- .../rules/FinishWithWaterDirectRule.java | 88 +-- .../IncompleteShipContradictionRule.java | 10 +- .../battleship/rules/SegmentTypeCaseRule.java | 27 +- .../rules/SegmentTypeDirectRule.java | 88 +-- .../rules/ShipLocationCaseRule.java | 27 +- .../battleship/rules/ShipOrWaterCaseRule.java | 27 +- .../rules/SurroundShipDirectRule.java | 88 +-- .../rules/TooFewInFleetContradictionRule.java | 10 +- .../rules/TooFewRowColContradictionRule.java | 10 +- .../TooManyInFleetContradictionRule.java | 10 +- .../rules/TooManyRowColContradiction.java | 10 +- .../rpi/legup/puzzle/fillapix/Fillapix.java | 18 +- .../legup/puzzle/fillapix/FillapixBoard.java | 3 +- .../legup/puzzle/fillapix/FillapixCell.java | 13 +- .../fillapix/FillapixCellController.java | 28 +- .../puzzle/fillapix/FillapixCellFactory.java | 22 +- .../puzzle/fillapix/FillapixCellType.java | 4 +- .../puzzle/fillapix/FillapixElementView.java | 6 +- .../puzzle/fillapix/FillapixExporter.java | 7 +- .../puzzle/fillapix/FillapixImporter.java | 34 +- .../puzzle/fillapix/FillapixUtilities.java | 133 ++-- .../legup/puzzle/fillapix/FillapixView.java | 6 +- .../puzzle/fillapix/elements/BlackTile.java | 6 +- .../puzzle/fillapix/elements/NumberTile.java | 7 +- .../puzzle/fillapix/elements/UnknownTile.java | 6 +- .../puzzle/fillapix/elements/WhiteTile.java | 6 +- .../fillapix/rules/BlackOrWhiteCaseRule.java | 22 +- .../rules/FinishWithBlackDirectRule.java | 129 ++-- .../rules/FinishWithWhiteDirectRule.java | 129 ++-- .../fillapix/rules/MirrorDirectRule.java | 210 ++++--- .../rules/NonTouchingSharedDirectRule.java | 202 +++--- .../fillapix/rules/SatisfyClueCaseRule.java | 65 +- .../TooFewBlackCellsContradictionRule.java | 11 +- .../TooManyBlackCellsContradictionRule.java | 15 +- .../rules/TouchingCornersDirectRule.java | 221 +++---- .../rules/TouchingSidesDirectRule.java | 241 +++---- .../rpi/legup/puzzle/heyawake/Heyawake.java | 12 +- .../legup/puzzle/heyawake/HeyawakeBoard.java | 1 - .../legup/puzzle/heyawake/HeyawakeCell.java | 1 - .../puzzle/heyawake/HeyawakeController.java | 3 +- .../puzzle/heyawake/HeyawakeElementView.java | 4 +- .../puzzle/heyawake/HeyawakeExporter.java | 7 +- .../puzzle/heyawake/HeyawakeFactory.java | 22 +- .../puzzle/heyawake/HeyawakeImporter.java | 32 +- .../legup/puzzle/heyawake/HeyawakeView.java | 7 +- .../AdjacentBlacksContradictionRule.java | 11 +- .../heyawake/rules/BlackOrWhiteCaseRule.java | 27 +- .../heyawake/rules/BlackPathDirectRule.java | 14 +- .../heyawake/rules/BottleNeckDirectRule.java | 14 +- .../rules/FillRoomBlackDirectRule.java | 88 +-- .../rules/FillRoomWhiteDirectRule.java | 88 +-- .../heyawake/rules/OneRowDirectRule.java | 14 +- .../rules/PreventWhiteLineDirectRule.java | 14 +- .../rules/RoomTooEmptyContradictionRule.java | 10 +- .../rules/RoomTooFullContradictionRule.java | 10 +- .../rules/ThreeByThreeDirectRule.java | 14 +- .../heyawake/rules/TwoInCornerDirectRule.java | 14 +- .../rules/WhiteAreaContradictionRule.java | 10 +- .../rules/WhiteAroundBlackDirectRule.java | 88 +-- .../heyawake/rules/WhiteEscapeDirectRule.java | 14 +- .../rules/WhiteLineContradictionRule.java | 11 +- .../heyawake/rules/ZigZagWhiteDirectRule.java | 14 +- .../edu/rpi/legup/puzzle/lightup/LightUp.java | 16 +- .../legup/puzzle/lightup/LightUpBoard.java | 16 +- .../rpi/legup/puzzle/lightup/LightUpCell.java | 9 +- .../puzzle/lightup/LightUpCellController.java | 26 +- .../puzzle/lightup/LightUpCellFactory.java | 22 +- .../legup/puzzle/lightup/LightUpCellType.java | 6 +- .../puzzle/lightup/LightUpElementView.java | 31 +- .../legup/puzzle/lightup/LightUpExporter.java | 7 +- .../legup/puzzle/lightup/LightUpImporter.java | 28 +- .../rpi/legup/puzzle/lightup/LightUpView.java | 43 +- .../puzzle/lightup/elements/BlackTile.java | 6 +- .../puzzle/lightup/elements/BulbTile.java | 6 +- .../puzzle/lightup/elements/NumberTile.java | 12 +- .../puzzle/lightup/elements/UnknownTile.java | 6 +- .../rules/BulbsInPathContradictionRule.java | 24 +- .../CannotLightACellContradictionRule.java | 26 +- .../rules/EmptyCellinLightDirectRule.java | 132 ++-- .../lightup/rules/EmptyCornersDirectRule.java | 232 +++---- .../rules/FinishWithBulbsDirectRule.java | 217 +++---- .../rules/FinishWithEmptyDirectRule.java | 240 +++---- .../lightup/rules/LightOrEmptyCaseRule.java | 35 +- .../lightup/rules/MustLightDirectRule.java | 302 ++++----- .../lightup/rules/SatisfyNumberCaseRule.java | 82 +-- .../rules/TooFewBulbsContradictionRule.java | 12 +- .../rules/TooManyBulbsContradictionRule.java | 12 +- .../legup/puzzle/masyu/EditLineCommand.java | 49 +- .../edu/rpi/legup/puzzle/masyu/Masyu.java | 13 +- .../rpi/legup/puzzle/masyu/MasyuBoard.java | 4 +- .../edu/rpi/legup/puzzle/masyu/MasyuCell.java | 1 - .../legup/puzzle/masyu/MasyuCellFactory.java | 19 +- .../legup/puzzle/masyu/MasyuController.java | 26 +- .../legup/puzzle/masyu/MasyuElementView.java | 7 +- .../rpi/legup/puzzle/masyu/MasyuExporter.java | 7 +- .../rpi/legup/puzzle/masyu/MasyuImporter.java | 31 +- .../edu/rpi/legup/puzzle/masyu/MasyuLine.java | 6 +- .../rpi/legup/puzzle/masyu/MasyuLineView.java | 1 - .../edu/rpi/legup/puzzle/masyu/MasyuType.java | 8 +- .../edu/rpi/legup/puzzle/masyu/MasyuView.java | 7 +- .../rules/BadLoopingContradictionRule.java | 11 +- .../masyu/rules/BlackContradictionRule.java | 11 +- .../masyu/rules/BlackEdgeDirectRule.java | 83 ++- .../masyu/rules/BlackSplitCaseRule.java | 28 +- .../masyu/rules/BlockedBlackDirectRule.java | 87 +-- .../masyu/rules/ConnectedCellsDirectRule.java | 87 +-- .../masyu/rules/FinishPathDirectRule.java | 87 +-- .../masyu/rules/NearWhiteDirectRule.java | 83 ++- .../rules/NoOptionsContradictionRule.java | 11 +- .../masyu/rules/NormalSplitCaseRule.java | 28 +- .../masyu/rules/OnlyOneChoiceDirectRule.java | 87 +-- .../masyu/rules/OnlyTwoContradictionRule.java | 11 +- .../masyu/rules/WhiteContradictionRule.java | 11 +- .../masyu/rules/WhiteEdgeDirectRule.java | 81 ++- .../masyu/rules/WhiteSplitCaseRule.java | 28 +- .../rpi/legup/puzzle/nurikabe/Nurikabe.java | 12 +- .../legup/puzzle/nurikabe/NurikabeBoard.java | 8 +- .../legup/puzzle/nurikabe/NurikabeCell.java | 17 +- .../puzzle/nurikabe/NurikabeCellFactory.java | 22 +- .../puzzle/nurikabe/NurikabeController.java | 26 +- .../puzzle/nurikabe/NurikabeElementView.java | 13 +- .../puzzle/nurikabe/NurikabeExporter.java | 6 +- .../puzzle/nurikabe/NurikabeImporter.java | 34 +- .../legup/puzzle/nurikabe/NurikabeType.java | 5 +- .../puzzle/nurikabe/NurikabeUtilities.java | 67 +- .../legup/puzzle/nurikabe/NurikabeView.java | 4 +- .../puzzle/nurikabe/elements/BlackTile.java | 6 +- .../puzzle/nurikabe/elements/NumberTile.java | 7 +- .../puzzle/nurikabe/elements/UnknownTile.java | 6 +- .../puzzle/nurikabe/elements/WhiteTile.java | 6 +- .../rules/BlackBetweenRegionsDirectRule.java | 234 +++---- .../rules/BlackBottleNeckDirectRule.java | 134 ++-- .../nurikabe/rules/BlackOrWhiteCaseRule.java | 38 +- .../rules/BlackSquareContradictionRule.java | 27 +- .../rules/CannotReachCellDirectRule.java | 125 ++-- .../nurikabe/rules/CornerBlackDirectRule.java | 241 +++---- .../nurikabe/rules/FillinBlackDirectRule.java | 122 ++-- .../nurikabe/rules/FillinWhiteDirectRule.java | 122 ++-- .../rules/IsolateBlackContradictionRule.java | 24 +- .../MultipleNumbersContradictionRule.java | 14 +- .../rules/NoNumberContradictionRule.java | 16 +- .../rules/PreventBlackSquareDirectRule.java | 133 ++-- .../rules/SurroundRegionDirectRule.java | 198 +++--- .../rules/TooFewSpacesContradictionRule.java | 21 +- .../rules/TooManySpacesContradictionRule.java | 14 +- ...UnreachableWhiteCellContradictionRule.java | 22 +- .../rules/WhiteBottleNeckDirectRule.java | 141 +++-- .../shorttruthtable/ShortTruthTable.java | 15 +- .../shorttruthtable/ShortTruthTableBoard.java | 41 +- .../shorttruthtable/ShortTruthTableCell.java | 53 +- .../ShortTruthTableCellFactory.java | 33 +- .../ShortTruthTableCellType.java | 14 +- .../ShortTruthTableController.java | 14 +- .../ShortTruthTableElementView.java | 25 +- .../ShortTruthTableExporter.java | 8 +- .../ShortTruthTableImporter.java | 202 +++--- .../ShortTruthTableOperation.java | 105 ++-- .../ShortTruthTableStatement.java | 163 +++-- .../shorttruthtable/ShortTruthTableView.java | 6 +- .../elements/ArgumentElement.java | 6 +- .../elements/GreenElement.java | 6 +- .../elements/LogicSymbolElement.java | 6 +- .../shorttruthtable/elements/RedElement.java | 6 +- .../elements/UnknownElement.java | 6 +- .../rules/basic/DirectRuleAtomic.java | 10 +- .../rules/basic/DirectRule_Generic.java | 45 +- .../elimination/DirectRuleAndElimination.java | 21 +- .../DirectRuleBiconditionalElimination.java | 21 +- .../DirectRuleConditionalElimination.java | 21 +- .../elimination/DirectRuleNotElimination.java | 21 +- .../elimination/DirectRuleOrElimination.java | 21 +- .../DirectRule_GenericElimination.java | 37 +- .../DirectRuleAndIntroduction.java | 21 +- .../DirectRuleBiconditionalIntroduction.java | 21 +- .../DirectRuleConditionalIntroduction.java | 21 +- .../DirectRuleNotIntroduction.java | 21 +- .../DirectRuleOrIntroduction.java | 21 +- .../DirectRule_GenericIntroduction.java | 37 +- .../rules/caserule/CaseRuleAnd.java | 40 +- .../rules/caserule/CaseRuleAtomic.java | 11 +- .../rules/caserule/CaseRuleBiconditional.java | 15 +- .../rules/caserule/CaseRuleConditional.java | 47 +- .../rules/caserule/CaseRuleOr.java | 42 +- .../rules/caserule/CaseRule_Generic.java | 134 ++-- .../caserule/CaseRule_GenericStatement.java | 69 +- .../contradiction/ContradictionRuleAnd.java | 22 +- .../ContradictionRuleAtomic.java | 32 +- .../ContradictionRuleBiconditional.java | 22 +- .../ContradictionRuleConditional.java | 20 +- .../contradiction/ContradictionRuleNot.java | 18 +- .../contradiction/ContradictionRuleOr.java | 20 +- .../ContradictionRule_GenericStatement.java | 40 +- .../legup/puzzle/skyscrapers/Skyscrapers.java | 12 +- .../puzzle/skyscrapers/SkyscrapersBoard.java | 62 +- .../puzzle/skyscrapers/SkyscrapersCell.java | 18 +- .../skyscrapers/SkyscrapersCellFactory.java | 25 +- .../puzzle/skyscrapers/SkyscrapersClue.java | 2 +- .../skyscrapers/SkyscrapersClueView.java | 1 - .../skyscrapers/SkyscrapersController.java | 10 +- .../skyscrapers/SkyscrapersElementView.java | 4 +- .../skyscrapers/SkyscrapersExporter.java | 28 +- .../skyscrapers/SkyscrapersImporter.java | 107 +++- .../puzzle/skyscrapers/SkyscrapersType.java | 10 +- .../puzzle/skyscrapers/SkyscrapersView.java | 37 +- .../puzzle/skyscrapers/elements/ClueTile.java | 6 +- .../skyscrapers/elements/NumberTile.java | 6 +- .../skyscrapers/elements/UnknownTile.java | 6 +- .../rules/CellForNumberCaseRule.java | 98 +-- .../DuplicateNumberContradictionRule.java | 32 +- .../ExceedingVisibilityContradictionRule.java | 52 +- ...sufficientVisibilityContradictionRule.java | 54 +- .../rules/LastSingularCellDirectRule.java | 243 ++++---- .../rules/LastSingularNumberDirectRule.java | 200 +++--- .../rules/LastVisibleCellDirectRule.java | 248 ++++---- .../rules/LastVisibleNumberDirectRule.java | 202 +++--- .../skyscrapers/rules/NEdgeDirectRule.java | 205 +++--- .../rules/NumberForCellCaseRule.java | 77 ++- ...PreemptiveVisibilityContradictionRule.java | 97 +-- .../UnresolvedCellContradictionRule.java | 17 +- .../UnresolvedNumberContradictionRule.java | 48 +- .../rpi/legup/puzzle/sudoku/GroupType.java | 4 +- .../sudoku/PossibleNumberCaseBoard.java | 11 +- .../edu/rpi/legup/puzzle/sudoku/Sudoku.java | 19 +- .../rpi/legup/puzzle/sudoku/SudokuBoard.java | 26 +- .../rpi/legup/puzzle/sudoku/SudokuCell.java | 7 +- .../puzzle/sudoku/SudokuCellController.java | 31 +- .../puzzle/sudoku/SudokuCellFactory.java | 19 +- .../puzzle/sudoku/SudokuElementView.java | 17 +- .../legup/puzzle/sudoku/SudokuExporter.java | 7 +- .../legup/puzzle/sudoku/SudokuImporter.java | 47 +- .../rpi/legup/puzzle/sudoku/SudokuView.java | 40 +- .../puzzle/sudoku/elements/NumberTile.java | 2 - .../rules/AdvancedDeductionDirectRule.java | 195 +++--- .../rules/LastCellForNumberDirectRule.java | 188 +++--- .../rules/LastNumberForCellDirectRule.java | 158 ++--- .../rules/NoSolutionContradictionRule.java | 12 +- .../sudoku/rules/PossibleCellCaseRule.java | 17 +- .../sudoku/rules/PossibleNumberCaseRule.java | 32 +- .../RepeatedNumberContradictionRule.java | 12 +- .../legup/puzzle/treetent/ClueCommand.java | 43 +- .../puzzle/treetent/EditLineCommand.java | 63 +- .../rpi/legup/puzzle/treetent/TreeTent.java | 16 +- .../legup/puzzle/treetent/TreeTentBoard.java | 22 +- .../legup/puzzle/treetent/TreeTentCell.java | 1 - .../puzzle/treetent/TreeTentCellFactory.java | 34 +- .../puzzle/treetent/TreeTentClueView.java | 1 - .../puzzle/treetent/TreeTentController.java | 60 +- .../puzzle/treetent/TreeTentElementView.java | 45 +- .../puzzle/treetent/TreeTentExporter.java | 6 +- .../puzzle/treetent/TreeTentImporter.java | 79 ++- .../legup/puzzle/treetent/TreeTentLine.java | 6 +- .../puzzle/treetent/TreeTentLineView.java | 3 +- .../legup/puzzle/treetent/TreeTentType.java | 14 +- .../legup/puzzle/treetent/TreeTentView.java | 58 +- .../puzzle/treetent/elements/GrassTile.java | 9 +- .../puzzle/treetent/elements/TentTile.java | 9 +- .../puzzle/treetent/elements/TreeTile.java | 8 +- .../puzzle/treetent/elements/UnknownTile.java | 8 +- .../treetent/rules/EmptyFieldDirectRule.java | 176 +++--- .../treetent/rules/FillinRowCaseRule.java | 96 +-- .../rules/FinishWithGrassDirectRule.java | 173 ++--- .../rules/FinishWithTentsDirectRule.java | 178 +++--- .../rules/LastCampingSpotDirectRule.java | 206 +++--- .../treetent/rules/LinkTentCaseRule.java | 54 +- .../treetent/rules/LinkTreeCaseRule.java | 52 +- .../rules/NoTentForTreeContradictionRule.java | 25 +- .../rules/NoTreeForTentContradictionRule.java | 23 +- .../SurroundTentWithGrassDirectRule.java | 171 ++--- .../treetent/rules/TentForTreeDirectRule.java | 249 ++++---- .../treetent/rules/TentOrGrassCaseRule.java | 34 +- .../rules/TooFewTentsContradictionRule.java | 19 +- .../rules/TooManyTentsContradictionRule.java | 19 +- .../rules/TouchingTentsContradictionRule.java | 18 +- .../treetent/rules/TreeForTentDirectRule.java | 246 ++++---- .../rpi/legup/save/ExportFileException.java | 1 - .../save/InvalidFileFormatException.java | 1 - .../java/edu/rpi/legup/save/SavableBoard.java | 7 - .../java/edu/rpi/legup/save/SavableProof.java | 4 +- .../edu/rpi/legup/ui/CreatePuzzleDialog.java | 189 +++--- .../java/edu/rpi/legup/ui/DynamicView.java | 93 +-- src/main/java/edu/rpi/legup/ui/HomePanel.java | 425 +++++++------ .../java/edu/rpi/legup/ui/LegupPanel.java | 5 +- src/main/java/edu/rpi/legup/ui/LegupUI.java | 113 ++-- .../legup/ui/ManualPuzzleCreatorDialog.java | 8 +- .../java/edu/rpi/legup/ui/PickGameDialog.java | 35 +- .../edu/rpi/legup/ui/PreferencesDialog.java | 278 +++++---- .../edu/rpi/legup/ui/ProofEditorPanel.java | 590 ++++++++++-------- .../edu/rpi/legup/ui/PuzzleEditorPanel.java | 306 ++++----- .../java/edu/rpi/legup/ui/ScrollView.java | 58 +- .../java/edu/rpi/legup/ui/ToolbarName.java | 14 +- .../java/edu/rpi/legup/ui/WrapLayout.java | 63 +- .../java/edu/rpi/legup/ui/ZoomWidget.java | 23 +- .../java/edu/rpi/legup/ui/ZoomablePane.java | 4 +- .../edu/rpi/legup/ui/boardview/BoardView.java | 26 +- .../legup/ui/boardview/DataSelectionView.java | 3 +- .../legup/ui/boardview/ElementSelection.java | 3 +- .../rpi/legup/ui/boardview/ElementView.java | 74 ++- .../rpi/legup/ui/boardview/GridBoardView.java | 21 +- .../legup/ui/boardview/SelectionItemView.java | 1 - .../ui/lookandfeel/LegupLookAndFeel.java | 114 ++-- .../animation/MaterialUIMovement.java | 5 +- .../animation/MaterialUITimer.java | 17 +- .../components/MaterialButtonUI.java | 5 +- .../MaterialCheckBoxMenuItemUI.java | 33 +- .../components/MaterialCheckBoxUI.java | 5 +- .../components/MaterialComboBoxRenderer.java | 17 +- .../components/MaterialComboBoxUI.java | 6 +- .../components/MaterialEditorPaneUI.java | 1 - .../components/MaterialFileChooserUI.java | 3 +- .../components/MaterialLabelUI.java | 3 +- .../components/MaterialMenuBarUI.java | 3 +- .../components/MaterialMenuItemUI.java | 3 +- .../components/MaterialMenuUI.java | 3 +- .../components/MaterialPanelUI.java | 3 +- .../components/MaterialPasswordFieldUI.java | 141 +++-- .../components/MaterialPopupMenuUI.java | 3 +- .../components/MaterialProgressBarUI.java | 5 +- .../MaterialRadioButtonMenuItemUI.java | 35 +- .../components/MaterialRadioButtonUI.java | 7 +- .../components/MaterialScrollBarUI.java | 5 +- .../components/MaterialSeparatorUI.java | 3 +- .../components/MaterialSliderUI.java | 51 +- .../components/MaterialSpinnerUI.java | 11 +- .../components/MaterialSplitPaneDivider.java | 26 +- .../components/MaterialSplitPaneUI.java | 18 +- .../components/MaterialTabbedPaneUI.java | 50 +- .../components/MaterialTableCellEditor.java | 10 +- .../components/MaterialTableCellRenderer.java | 10 +- .../MaterialTableHeaderCellRenderer.java | 10 +- .../components/MaterialTableHeaderUI.java | 3 +- .../components/MaterialTableUI.java | 6 +- .../components/MaterialTextFieldUI.java | 152 +++-- .../components/MaterialTextPaneUI.java | 1 - .../components/MaterialToggleButtonUI.java | 3 +- .../components/MaterialToolBarUI.java | 3 +- .../components/MaterialToolTipUI.java | 3 +- .../components/MaterialTreeCellEditor.java | 29 +- .../components/MaterialTreeCellRenderer.java | 17 +- .../components/MaterialTreeUI.java | 5 +- .../materialdesign/DropShadowBorder.java | 236 ++++--- .../materialdesign/MaterialBorders.java | 19 +- .../materialdesign/MaterialColors.java | 3 +- .../materialdesign/MaterialDrawingUtils.java | 10 +- .../materialdesign/MaterialFonts.java | 26 +- .../materialdesign/MaterialImages.java | 32 +- .../rulesview/CaseRulePanel.java | 7 +- .../rulesview/CaseRuleSelectionView.java | 3 +- .../rulesview/ContradictionRulePanel.java | 5 +- .../rulesview/DirectRulePanel.java | 46 +- .../proofeditorui/rulesview/RuleButton.java | 5 +- .../ui/proofeditorui/rulesview/RuleFrame.java | 50 +- .../ui/proofeditorui/rulesview/RulePanel.java | 154 ++--- .../rulesview/SearchBarPanel.java | 8 +- .../treeview/TreeElementView.java | 7 +- .../proofeditorui/treeview/TreeNodeView.java | 65 +- .../ui/proofeditorui/treeview/TreePanel.java | 21 +- .../treeview/TreeToolBarButton.java | 2 +- .../treeview/TreeToolBarName.java | 5 +- .../treeview/TreeToolbarPanel.java | 34 +- .../treeview/TreeTransitionView.java | 48 +- .../ui/proofeditorui/treeview/TreeView.java | 399 ++++++------ .../treeview/TreeViewSelection.java | 21 +- .../elementsview/ElementButton.java | 4 +- .../elementsview/ElementFrame.java | 40 +- .../elementsview/ElementPanel.java | 11 +- .../NonPlaceableElementPanel.java | 5 +- .../elementsview/PlaceableElementPanel.java | 5 +- .../resizeview/ResizePanel.java | 3 +- .../java/edu/rpi/legup/user/Submission.java | 8 +- .../edu/rpi/legup/user/UsageStatistics.java | 32 +- src/main/java/edu/rpi/legup/user/User.java | 4 +- .../rpi/legup/utility/ConnectedRegions.java | 23 +- .../edu/rpi/legup/utility/DisjointSets.java | 44 +- .../java/edu/rpi/legup/utility/Entry.java | 2 +- .../edu/rpi/legup/utility/LegupUtils.java | 29 +- .../java/edu/rpi/legup/utility/Logger.java | 33 +- src/test/java/legup/MockGameBoardFacade.java | 13 +- src/test/java/legup/TestRunner.java | 7 +- src/test/java/legup/TestUtilities.java | 3 +- .../AdjacentShipsContradictionRuleTest.java | 46 +- .../rules/FinishWithShipsDirectRuleTests.java | 35 +- .../BulbsInPathContradictionRuleTest.java | 45 +- ...CannotLightACellContradictionRuleTest.java | 39 +- .../rules/EmptyCellinLightDirectRuleTest.java | 70 ++- .../rules/EmptyCornersDirectRuleTest.java | 45 +- .../rules/FinishWithBulbsDirectRuleTest.java | 72 +-- .../rules/LightOrEmptyCaseRuleTest.java | 63 +- .../rules/MustLightDirectRuleTest.java | 38 +- .../rules/SatisfyNumberCaseRuleTest.java | 140 +++-- .../TooFewBulbsContradictionRuleTest.java | 30 +- .../TooManyBulbsContradictionRuleTest.java | 35 +- .../BlackBetweenRegionsDirectRuleTest.java | 394 ++++++------ .../rules/BlackBottleNeckDirectRuleTest.java | 82 ++- .../rules/BlackOrWhiteCaseRuleTest.java | 56 +- .../BlackSquareContradictionRuleTest.java | 76 +-- .../rules/CannotReachCellDirectRuleTest.java | 76 ++- .../rules/CornerBlackDirectRuleTest.java | 165 +++-- .../rules/FillinBlackDirectRuleTest.java | 87 ++- .../rules/FillinWhiteDirectRuleTest.java | 287 +++++---- .../IsolateBlackContradictionRuleTest.java | 105 ++-- .../MultipleNumbersContradictionRuleTest.java | 83 +-- .../rules/NoNumbersContradictionRuleTest.java | 38 +- .../PreventBlackSquareDirectRuleTest.java | 347 +++++----- .../rules/SurroundRegionDirectRuleTest.java | 245 ++++---- .../TooFewSpacesContradictionRuleTest.java | 67 +- .../TooManySpacesContradictionRuleTest.java | 83 +-- ...achableWhiteCellContradictionRuleTest.java | 65 +- .../rules/WhiteBottleNeckDirectRuleTest.java | 212 +++---- .../ShortTruthTableImporterTest.java | 9 +- .../ShortTruthTableStatementTest.java | 9 +- .../rules/AndCaseRuleTest.java | 71 ++- .../rules/AndEliminationDirectRuleTest.java | 67 +- .../rules/AndIntroductionDirectRuleTest.java | 16 +- .../rules/AtomicDirectRuleTest.java | 68 +- .../rules/BiconditionalEliminationTest.java | 76 ++- .../rules/BiconditionalIntroductionTest.java | 25 +- .../rules/ConditionalEliminationTest.java | 72 ++- .../rules/ConditionalIntroductionTest.java | 25 +- .../rules/NotEliminationTest.java | 102 +-- .../rules/NotIntroductionTest.java | 43 +- .../shorttruthtable/rules/OrCaseRuleTest.java | 72 ++- .../rules/OrEliminationTest.java | 42 +- .../rules/OrIntroductionTest.java | 16 +- .../rules/TrueOrFalseCaseRuleTest.java | 31 +- .../rules/CellForNumberCaseRuleTest.java | 82 +-- .../DuplicateNumberContradictionTest.java | 66 +- .../ExceedingVisibilityContradictionTest.java | 62 +- ...sufficientVisibilityContradictionTest.java | 62 +- .../rules/LastSingularCellDirectTest.java | 146 +++-- .../rules/LastSingularNumberDirectTest.java | 94 +-- .../rules/LastVisibleCellDirectTest.java | 160 +++-- .../rules/LastVisibleNumberDirectTest.java | 161 +++-- .../skyscrapers/rules/NEdgeDirectTest.java | 83 ++- .../rules/NumberForCellCaseRuleTest.java | 82 +-- ...PreemptiveVisibilityContradictionTest.java | 71 ++- .../UnresolvedCellContradictionTest.java | 64 +- .../UnresolvedNumberContradictionTest.java | 73 ++- .../rules/EmptyFieldDirectRuleTest.java | 43 +- .../rules/FinishWithGrassDirectRuleTest.java | 126 ++-- .../rules/FinishWithTentsDirectRuleTest.java | 139 ++--- .../rules/LastCampingSpotDirectRuleTest.java | 46 +- .../NoTentForTreeContradictionRuleTest.java | 48 +- .../NoTreeForTentContradictionRuleTest.java | 80 +-- .../SurroundTentWithGrassDirectRuleTest.java | 64 +- .../rules/TentForTreeDirectRuleTest.java | 19 +- .../rules/TentOrGrassCaseRuleTest.java | 26 +- .../TooFewTentsContradictionRuleTest.java | 151 +++-- .../TooManyTentsContradictionRuleTest.java | 165 +++-- .../TouchingTentsContradictionRuleTest.java | 150 ++--- .../rules/TreeForTentDirectRuleTest.java | 19 +- 527 files changed, 14439 insertions(+), 13222 deletions(-) create mode 100644 .github/workflows/java-autoformat.yml mode change 100644 => 100755 gradlew diff --git a/.github/workflows/java-autoformat.yml b/.github/workflows/java-autoformat.yml new file mode 100644 index 000000000..5afb1f7a1 --- /dev/null +++ b/.github/workflows/java-autoformat.yml @@ -0,0 +1,38 @@ +name: Java Code Auto Format +on: pull_request + +jobs: + format: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v1 + with: + ref: ${{ github.head_ref }} + + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + run: ./gradlew build -x test + + - name: Run spotless + run: ./gradlew :spotlessApply + + - name: Check for modified files + id: git-check + run: echo "modified=$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi)" >> $GITHUB_OUTPUT + + - name: Push changes + if: steps.git-check.outputs.modified == 'true' + run: | + git config --global user.name 'Bram van Heuveln' + git config --global user.email 'bram28@users.noreply.github.com' + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} + git add . + git diff --cached --exit-code || git commit -am "Automated Java code formatting changes" && git push \ No newline at end of file diff --git a/build.gradle b/build.gradle index 062a2cbff..49829e473 100644 --- a/build.gradle +++ b/build.gradle @@ -2,13 +2,43 @@ plugins { id 'java' id 'edu.sc.seis.launch4j' version '2.5.3' id 'kr.motd.sphinx' version '2.10.0' + id 'com.diffplug.spotless' version '6.25.0' } + version '2.0.0' apply plugin: 'java' apply plugin: 'application' + +spotless{ + enforceCheck false + + format 'misc', { + // define the files to apply `misc` to + target '*.gradle', '*.md', '.gitignore' + + // define the steps to apply to those files + trimTrailingWhitespace() + indentWithSpaces() // or spaces. Takes an integer argument if you don't like 4 + endWithNewline() + } + + java{ + // Use the default importOrder configuration + importOrder() + + // Cleanthat will refactor your code, but it may break your style: apply it before your formatter + cleanthat() + + googleJavaFormat('1.19.2').aosp() + + formatAnnotations() + } +} + apply plugin: 'checkstyle' + mainClassName = 'edu.rpi.legup.Legup' sourceCompatibility = 11 diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index a5dfea0af..6e17e3fc5 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -7,12 +7,6 @@ - - - - - diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/java/edu/rpi/legup/Legup.java b/src/main/java/edu/rpi/legup/Legup.java index 49887de4f..79471286b 100644 --- a/src/main/java/edu/rpi/legup/Legup.java +++ b/src/main/java/edu/rpi/legup/Legup.java @@ -15,4 +15,4 @@ public static void main(String[] args) { GameBoardFacade.getInstance(); GameBoardFacade.setupConfig(); } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/ai/Solver.java b/src/main/java/edu/rpi/legup/ai/Solver.java index 68b934bfb..5b39c2008 100644 --- a/src/main/java/edu/rpi/legup/ai/Solver.java +++ b/src/main/java/edu/rpi/legup/ai/Solver.java @@ -1,4 +1,3 @@ package edu.rpi.legup.ai; -public class Solver { -} +public class Solver {} diff --git a/src/main/java/edu/rpi/legup/app/Config.java b/src/main/java/edu/rpi/legup/app/Config.java index 1847e14e4..8a8e9665d 100644 --- a/src/main/java/edu/rpi/legup/app/Config.java +++ b/src/main/java/edu/rpi/legup/app/Config.java @@ -2,21 +2,18 @@ import java.io.*; import java.util.*; - import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; - import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; public class Config { - private final static Logger Logger = LogManager.getLogger(Config.class.getName()); + private static final Logger Logger = LogManager.getLogger(Config.class.getName()); private Map puzzles; private Map fileCreationDisabledStatuses; @@ -43,8 +40,8 @@ public List getPuzzleClassNames() { } /** - * Returns a list of the names of the puzzles which can have puzzles created and edited - * within the proof editor. + * Returns a list of the names of the puzzles which can have puzzles created and edited within + * the proof editor. * * @return the aforementioned list of Strings */ @@ -59,8 +56,8 @@ public List getFileCreationEnabledPuzzles() { } /** - * Converts the class name of the puzzles to their display names. Some examples of the conversion: - * convertClassNameToDisplayName("TreeTent") will return "Tree Tent" + * Converts the class name of the puzzles to their display names. Some examples of the + * conversion: convertClassNameToDisplayName("TreeTent") will return "Tree Tent" * convertClassNameToDisplayName("Nurikabe") will return "Nurikabe" * * @param className the name of the class @@ -140,15 +137,16 @@ private void loadConfig(InputStream stream) throws InvalidConfigException { Element puzzle = (Element) puzzleNodes.item(i); String name = puzzle.getAttribute("name"); String className = puzzle.getAttribute("qualifiedClassName"); - boolean status = Boolean.parseBoolean(puzzle.getAttribute("fileCreationDisabled").toLowerCase()); + boolean status = + Boolean.parseBoolean( + puzzle.getAttribute("fileCreationDisabled").toLowerCase()); Logger.debug("Class Name: " + className); this.puzzles.put(name, className); this.fileCreationDisabledStatuses.put(name, Boolean.valueOf(status)); } - } - catch (ParserConfigurationException | SAXException | IOException e) { + } catch (ParserConfigurationException | SAXException | IOException e) { throw new InvalidConfigException(e.getMessage()); } } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/app/GameBoardFacade.java b/src/main/java/edu/rpi/legup/app/GameBoardFacade.java index 55273ab4f..c928c1209 100644 --- a/src/main/java/edu/rpi/legup/app/GameBoardFacade.java +++ b/src/main/java/edu/rpi/legup/app/GameBoardFacade.java @@ -11,16 +11,6 @@ import edu.rpi.legup.ui.LegupUI; import edu.rpi.legup.ui.ProofEditorPanel; import edu.rpi.legup.ui.PuzzleEditorPanel; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.xml.sax.SAXException; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; import java.awt.*; import java.io.File; import java.io.FileInputStream; @@ -31,11 +21,20 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.xml.sax.SAXException; public class GameBoardFacade implements IHistorySubject { - private final static Logger LOGGER = LogManager.getLogger(GameBoardFacade.class.getName()); + private static final Logger LOGGER = LogManager.getLogger(GameBoardFacade.class.getName()); - protected volatile static GameBoardFacade instance; + protected static volatile GameBoardFacade instance; private Config config; @@ -52,9 +51,7 @@ public class GameBoardFacade implements IHistorySubject { private History history; private List historyListeners; - /** - * Private GameBoardFacade Constructor creates a game board facade - */ + /** Private GameBoardFacade Constructor creates a game board facade */ protected GameBoardFacade() { history = new History(); historyListeners = new ArrayList<>(); @@ -68,7 +65,7 @@ protected GameBoardFacade() { * * @return single instance of GameBoardFacade */ - public synchronized static GameBoardFacade getInstance() { + public static synchronized GameBoardFacade getInstance() { if (instance == null) { instance = new GameBoardFacade(); } @@ -76,13 +73,14 @@ public synchronized static GameBoardFacade getInstance() { } public void initializeUI() { - EventQueue.invokeLater(() -> { - legupUI = new LegupUI(); - puzzleSolver = legupUI.getProofEditor(); - puzzleEditor = legupUI.getPuzzleEditor(); - addHistoryListener(legupUI.getProofEditor()); - addHistoryListener(legupUI.getPuzzleEditor()); - }); + EventQueue.invokeLater( + () -> { + legupUI = new LegupUI(); + puzzleSolver = legupUI.getProofEditor(); + puzzleEditor = legupUI.getPuzzleEditor(); + addHistoryListener(legupUI.getProofEditor()); + addHistoryListener(legupUI.getPuzzleEditor()); + }); } public void setPuzzle(Puzzle puzzle) { @@ -101,14 +99,12 @@ public static void setupConfig() { Config config = null; try { config = new Config(); - } - catch (InvalidConfigException e) { + } catch (InvalidConfigException e) { System.exit(1); } GameBoardFacade.getInstance().setConfig(config); } - public void setPuzzleEditor(Puzzle puzzle) { this.puzzle = puzzle; this.puzzleEditor.setPuzzleView(puzzle); @@ -121,11 +117,11 @@ public void setConfig(Config config) { /** * Validates the given dimensions for the given puzzle * - * @param game name of the puzzle - * @param rows the number of rows on the board + * @param game name of the puzzle + * @param rows the number of rows on the board * @param columns the number of columns on the board * @return true if it is possible to create a board for the given game with the given number of - * rows and columns, false otherwise + * rows and columns, false otherwise * @throws RuntimeException if any of the given input is invalid */ public boolean validateDimensions(String game, int rows, int columns) throws RuntimeException { @@ -135,9 +131,11 @@ public boolean validateDimensions(String game, int rows, int columns) throws Run Constructor constructor = c.getConstructor(); Puzzle puzzle = (Puzzle) constructor.newInstance(); return puzzle.isValidDimensions(rows, columns); - } - catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | - InstantiationException e) { + } catch (ClassNotFoundException + | NoSuchMethodException + | InvocationTargetException + | IllegalAccessException + | InstantiationException e) { LOGGER.error(e); throw new RuntimeException("Error validating puzzle dimensions"); } @@ -146,10 +144,10 @@ public boolean validateDimensions(String game, int rows, int columns) throws Run /** * Validates the given text input for the given puzzle * - * @param game the name of the puzzle - * @param statements an array of statements - * @return true if it is possible to create a board for the given game with the given statements, - * false otherwise + * @param game the name of the puzzle + * @param statements an array of statements + * @return true if it is possible to create a board for the given game with the given + * statements, false otherwise * @throws RuntimeException if any of the input is invalid */ public boolean validateTextInput(String game, String[] statements) throws RuntimeException { @@ -159,9 +157,11 @@ public boolean validateTextInput(String game, String[] statements) throws Runtim Constructor constructor = c.getConstructor(); Puzzle puzzle = (Puzzle) constructor.newInstance(); return puzzle.isValidTextInput(statements); - } - catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | - InstantiationException e) { + } catch (ClassNotFoundException + | NoSuchMethodException + | InvocationTargetException + | IllegalAccessException + | InstantiationException e) { LOGGER.error(e); throw new RuntimeException("Error validating puzzle text input"); } @@ -170,8 +170,8 @@ public boolean validateTextInput(String game, String[] statements) throws Runtim /** * Loads an empty puzzle * - * @param game name of the puzzle - * @param rows the number of rows on the board + * @param game name of the puzzle + * @param rows the number of rows on the board * @param columns the number of columns on the board */ public void loadPuzzle(String game, int rows, int columns) throws RuntimeException { @@ -192,21 +192,24 @@ public void loadPuzzle(String game, int rows, int columns) throws RuntimeExcepti // Theoretically, this exception should never be thrown, since LEGUP should not be // allowing the user to give row/column input for a puzzle that doesn't support it if (!importer.acceptsRowsAndColumnsInput()) { - throw new IllegalArgumentException(puzzle.getName() + " does not accept rows and columns input"); + throw new IllegalArgumentException( + puzzle.getName() + " does not accept rows and columns input"); } setWindowTitle(puzzle.getName(), "New " + puzzle.getName() + " Puzzle"); importer.initializePuzzle(rows, columns); puzzle.initializeView(); -// puzzle.getBoardView().onTreeElementChanged(puzzle.getTree().getRootNode()); + // + // puzzle.getBoardView().onTreeElementChanged(puzzle.getTree().getRootNode()); setPuzzleEditor(puzzle); - } - catch (IllegalArgumentException exception) { + } catch (IllegalArgumentException exception) { throw new IllegalArgumentException(exception.getMessage()); - } - catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | - IllegalAccessException | InstantiationException e) { + } catch (ClassNotFoundException + | NoSuchMethodException + | InvocationTargetException + | IllegalAccessException + | InstantiationException e) { LOGGER.error(e); throw new RuntimeException("Puzzle creation error"); } @@ -230,25 +233,27 @@ public void loadPuzzle(String game, String[] statements) { // Theoretically, this exception should never be thrown, since LEGUP should not be // allowing the user to give text input for a puzzle that doesn't support it if (!importer.acceptsTextInput()) { - throw new IllegalArgumentException(puzzle.getName() + " does not accept text input"); + throw new IllegalArgumentException( + puzzle.getName() + " does not accept text input"); } setWindowTitle(puzzle.getName(), "New " + puzzle.getName() + " Puzzle"); importer.initializePuzzle(statements); puzzle.initializeView(); -// puzzle.getBoardView().onTreeElementChanged(puzzle.getTree().getRootNode()); + // + // puzzle.getBoardView().onTreeElementChanged(puzzle.getTree().getRootNode()); setPuzzleEditor(puzzle); - } - catch (IllegalArgumentException exception) { + } catch (IllegalArgumentException exception) { throw new IllegalArgumentException(exception.getMessage()); - } - catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | - IllegalAccessException | InstantiationException e) { + } catch (ClassNotFoundException + | NoSuchMethodException + | InvocationTargetException + | IllegalAccessException + | InstantiationException e) { LOGGER.error(e); throw new RuntimeException("Puzzle creation error"); } - } /** @@ -262,8 +267,7 @@ public void loadPuzzle(String fileName) throws InvalidFileFormatException { loadPuzzle(new FileInputStream(fileName)); curFileName = fileName; setWindowTitle(puzzle.getName(), fileName); - } - catch (IOException e) { + } catch (IOException e) { LOGGER.error("Invalid file " + fileName, e); throw new InvalidFileFormatException("Could not find file"); } @@ -274,8 +278,7 @@ public void loadPuzzleEditor(String fileName) throws InvalidFileFormatException loadPuzzleEditor(new FileInputStream(fileName)); curFileName = fileName; setWindowTitle(puzzle.getName(), fileName); - } - catch (IOException e) { + } catch (IOException e) { LOGGER.error("Invalid file " + fileName, e); throw new InvalidFileFormatException("Could not find file"); } @@ -287,8 +290,7 @@ public void loadPuzzleEditor(InputStream inputStream) throws InvalidFileFormatEx DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.parse(inputStream); - } - catch (IOException | SAXException | ParserConfigurationException e) { + } catch (IOException | SAXException | ParserConfigurationException e) { LOGGER.error("Invalid file", e); throw new InvalidFileFormatException("Could not find file"); } @@ -297,12 +299,16 @@ public void loadPuzzleEditor(InputStream inputStream) throws InvalidFileFormatEx if (rootNode.getTagName().equals("Legup")) { try { Node node = rootNode.getElementsByTagName("puzzle").item(0); - String qualifiedClassName = config.getPuzzleClassForName(node.getAttributes().getNamedItem("name").getNodeValue()); + String qualifiedClassName = + config.getPuzzleClassForName( + node.getAttributes().getNamedItem("name").getNodeValue()); if (qualifiedClassName == null) { - throw new InvalidFileFormatException("Puzzle creation error: cannot find puzzle with that name"); + throw new InvalidFileFormatException( + "Puzzle creation error: cannot find puzzle with that name"); } - //Check if puzzle is a "FileCreationEnabled" puzzle (meaning it is editable). - String[] editablePuzzles = config.getFileCreationEnabledPuzzles().toArray(new String[0]); + // Check if puzzle is a "FileCreationEnabled" puzzle (meaning it is editable). + String[] editablePuzzles = + config.getFileCreationEnabledPuzzles().toArray(new String[0]); boolean isEditablePuzzle = false; for (int i = 0; i < editablePuzzles.length; i++) { if (qualifiedClassName.contains(editablePuzzles[i])) { @@ -314,7 +320,7 @@ public void loadPuzzleEditor(InputStream inputStream) throws InvalidFileFormatEx LOGGER.error("Puzzle is not editable"); throw new InvalidFileFormatException("Puzzle is not editable"); } - //If it is editable, start loading it + // If it is editable, start loading it LOGGER.debug("Loading " + qualifiedClassName); Class c = Class.forName(qualifiedClassName); @@ -330,14 +336,15 @@ public void loadPuzzleEditor(InputStream inputStream) throws InvalidFileFormatEx puzzle.initializeView(); puzzle.getBoardView().onTreeElementChanged(puzzle.getTree().getRootNode()); setPuzzleEditor(puzzle); - } - catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | - IllegalAccessException | InstantiationException e) { + } catch (ClassNotFoundException + | NoSuchMethodException + | InvocationTargetException + | IllegalAccessException + | InstantiationException e) { LOGGER.error(e); throw new InvalidFileFormatException("Puzzle creation error"); } - } - else { + } else { LOGGER.error("Invalid file"); throw new InvalidFileFormatException("Invalid file: must be a Legup file"); } @@ -345,6 +352,7 @@ public void loadPuzzleEditor(InputStream inputStream) throws InvalidFileFormatEx /** * Loads a puzzle file from the input stream + * * @throws InvalidFileFormatException if input is invalid * @param inputStream input stream for the puzzle file */ @@ -354,8 +362,7 @@ public void loadPuzzle(InputStream inputStream) throws InvalidFileFormatExceptio DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.parse(inputStream); - } - catch (IOException | SAXException | ParserConfigurationException e) { + } catch (IOException | SAXException | ParserConfigurationException e) { LOGGER.error("Invalid file", e); throw new InvalidFileFormatException("Could not find file"); } @@ -364,9 +371,12 @@ public void loadPuzzle(InputStream inputStream) throws InvalidFileFormatExceptio if (rootNode.getTagName().equals("Legup")) { try { Node node = rootNode.getElementsByTagName("puzzle").item(0); - String qualifiedClassName = config.getPuzzleClassForName(node.getAttributes().getNamedItem("name").getNodeValue()); + String qualifiedClassName = + config.getPuzzleClassForName( + node.getAttributes().getNamedItem("name").getNodeValue()); if (qualifiedClassName == null) { - throw new InvalidFileFormatException("Puzzle creation error: cannot find puzzle with that name"); + throw new InvalidFileFormatException( + "Puzzle creation error: cannot find puzzle with that name"); } LOGGER.debug("Loading " + qualifiedClassName); @@ -383,25 +393,25 @@ public void loadPuzzle(InputStream inputStream) throws InvalidFileFormatExceptio puzzle.initializeView(); puzzle.getBoardView().onTreeElementChanged(puzzle.getTree().getRootNode()); setPuzzle(puzzle); - } - catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | - IllegalAccessException | InstantiationException e) { + } catch (ClassNotFoundException + | NoSuchMethodException + | InvocationTargetException + | IllegalAccessException + | InstantiationException e) { LOGGER.error(e); throw new InvalidFileFormatException("Puzzle creation error"); } - } - else { + } else { LOGGER.error("Invalid file"); throw new InvalidFileFormatException("Invalid file: must be a Legup file"); } } /** - * Sets the window title to 'PuzzleName - FileName' - * Removes the extension + * Sets the window title to 'PuzzleName - FileName' Removes the extension * * @param puzzleName puzzle name for the file - * @param fileName file name of the edu.rpi.legup.puzzle + * @param fileName file name of the edu.rpi.legup.puzzle */ public void setWindowTitle(String puzzleName, String fileName) { File file = new File(fileName); @@ -514,4 +524,3 @@ public History getHistory() { return history; } } - diff --git a/src/main/java/edu/rpi/legup/app/LegupPreferences.java b/src/main/java/edu/rpi/legup/app/LegupPreferences.java index 578cefc5b..12433d7e4 100644 --- a/src/main/java/edu/rpi/legup/app/LegupPreferences.java +++ b/src/main/java/edu/rpi/legup/app/LegupPreferences.java @@ -10,7 +10,8 @@ public class LegupPreferences { private static String SAVED_PATH = ""; - private static final Preferences preferences = Preferences.userNodeForPackage(LegupPreferences.class); + private static final Preferences preferences = + Preferences.userNodeForPackage(LegupPreferences.class); private static final Map preferencesMap = new HashMap<>(); private static final Map defaultPreferencesMap = new HashMap<>(); @@ -26,7 +27,6 @@ public class LegupPreferences { public static final String IMMEDIATE_FEEDBACK = "immediate-feedback"; public static final String COLOR_BLIND = "color-blind"; - static { defaultPreferencesMap.put(WORK_DIRECTORY, System.getProperty("user.home")); defaultPreferencesMap.put(START_FULL_SCREEN, Boolean.toString(false)); @@ -41,16 +41,35 @@ public class LegupPreferences { } static { - preferencesMap.put(WORK_DIRECTORY, preferences.get(WORK_DIRECTORY, defaultPreferencesMap.get(WORK_DIRECTORY))); - preferencesMap.put(START_FULL_SCREEN, preferences.get(START_FULL_SCREEN, defaultPreferencesMap.get(START_FULL_SCREEN))); - preferencesMap.put(AUTO_UPDATE, preferences.get(AUTO_UPDATE, defaultPreferencesMap.get(AUTO_UPDATE))); - preferencesMap.put(DARK_MODE, preferences.get(DARK_MODE, defaultPreferencesMap.get(DARK_MODE))); - preferencesMap.put(SHOW_MISTAKES, preferences.get(SHOW_MISTAKES, defaultPreferencesMap.get(SHOW_MISTAKES))); - preferencesMap.put(SHOW_ANNOTATIONS, preferences.get(SHOW_ANNOTATIONS, defaultPreferencesMap.get(SHOW_ANNOTATIONS))); - preferencesMap.put(ALLOW_DEFAULT_RULES, preferences.get(ALLOW_DEFAULT_RULES, defaultPreferencesMap.get(ALLOW_DEFAULT_RULES))); - preferencesMap.put(AUTO_GENERATE_CASES, preferences.get(AUTO_GENERATE_CASES, defaultPreferencesMap.get(AUTO_GENERATE_CASES))); - preferencesMap.put(IMMEDIATE_FEEDBACK, preferences.get(IMMEDIATE_FEEDBACK, defaultPreferencesMap.get(IMMEDIATE_FEEDBACK))); - preferencesMap.put(COLOR_BLIND, preferences.get(COLOR_BLIND, defaultPreferencesMap.get(COLOR_BLIND))); + preferencesMap.put( + WORK_DIRECTORY, + preferences.get(WORK_DIRECTORY, defaultPreferencesMap.get(WORK_DIRECTORY))); + preferencesMap.put( + START_FULL_SCREEN, + preferences.get(START_FULL_SCREEN, defaultPreferencesMap.get(START_FULL_SCREEN))); + preferencesMap.put( + AUTO_UPDATE, preferences.get(AUTO_UPDATE, defaultPreferencesMap.get(AUTO_UPDATE))); + preferencesMap.put( + DARK_MODE, preferences.get(DARK_MODE, defaultPreferencesMap.get(DARK_MODE))); + preferencesMap.put( + SHOW_MISTAKES, + preferences.get(SHOW_MISTAKES, defaultPreferencesMap.get(SHOW_MISTAKES))); + preferencesMap.put( + SHOW_ANNOTATIONS, + preferences.get(SHOW_ANNOTATIONS, defaultPreferencesMap.get(SHOW_ANNOTATIONS))); + preferencesMap.put( + ALLOW_DEFAULT_RULES, + preferences.get( + ALLOW_DEFAULT_RULES, defaultPreferencesMap.get(ALLOW_DEFAULT_RULES))); + preferencesMap.put( + AUTO_GENERATE_CASES, + preferences.get( + AUTO_GENERATE_CASES, defaultPreferencesMap.get(AUTO_GENERATE_CASES))); + preferencesMap.put( + IMMEDIATE_FEEDBACK, + preferences.get(IMMEDIATE_FEEDBACK, defaultPreferencesMap.get(IMMEDIATE_FEEDBACK))); + preferencesMap.put( + COLOR_BLIND, preferences.get(COLOR_BLIND, defaultPreferencesMap.get(COLOR_BLIND))); } /** @@ -65,12 +84,8 @@ public static LegupPreferences getInstance() { return instance; } - /** - * Private LegupPreferences Singleton Constructor - */ - private LegupPreferences() { - - } + /** Private LegupPreferences Singleton Constructor */ + private LegupPreferences() {} /** * Gets the user preference by the string key @@ -85,7 +100,7 @@ public String getUserPref(String key) { /** * Gets the user preference by the string key, value pair * - * @param key key name of the preference + * @param key key name of the preference * @param value value of the preference */ public void setUserPref(String key, String value) { @@ -96,18 +111,15 @@ public void setUserPref(String key, String value) { public boolean getUserPrefAsBool(String key) { if (preferencesMap.get(key).equalsIgnoreCase(Boolean.toString(true))) { return true; - } - else { + } else { if (preferencesMap.get(key).equalsIgnoreCase(Boolean.toString(false))) { return false; - } - else { + } else { throw new RuntimeException("Cannot get user preference - " + key); } } } - public String getSavedPath() { return SAVED_PATH; } diff --git a/src/main/java/edu/rpi/legup/app/PuzzleKeyAccelerator.java b/src/main/java/edu/rpi/legup/app/PuzzleKeyAccelerator.java index 36ffb08aa..f3945be22 100644 --- a/src/main/java/edu/rpi/legup/app/PuzzleKeyAccelerator.java +++ b/src/main/java/edu/rpi/legup/app/PuzzleKeyAccelerator.java @@ -1,22 +1,21 @@ package edu.rpi.legup.app; +import static edu.rpi.legup.app.GameBoardFacade.getInstance; + import edu.rpi.legup.history.ICommand; -import edu.rpi.legup.history.ValidateDirectRuleCommand; import edu.rpi.legup.history.ValidateContradictionRuleCommand; -import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.history.ValidateDirectRuleCommand; import edu.rpi.legup.model.rules.ContradictionRule; +import edu.rpi.legup.model.rules.DirectRule; import edu.rpi.legup.model.rules.Rule; import edu.rpi.legup.model.rules.RuleType; import edu.rpi.legup.ui.proofeditorui.treeview.TreeView; import edu.rpi.legup.ui.proofeditorui.treeview.TreeViewSelection; - -import javax.swing.*; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.util.HashMap; import java.util.Map; - -import static edu.rpi.legup.app.GameBoardFacade.getInstance; +import javax.swing.*; public class PuzzleKeyAccelerator implements KeyListener { @@ -39,21 +38,17 @@ public void clearKeyMap() { } /** - * Invoked when a key has been typed. - * See the class description for {@link KeyEvent} for a definition of - * a key typed event. + * Invoked when a key has been typed. See the class description for {@link KeyEvent} for a + * definition of a key typed event. * * @param e the event to be processed */ @Override - public void keyTyped(KeyEvent e) { - - } + public void keyTyped(KeyEvent e) {} /** - * Invoked when a key has been pressed. - * See the class description for {@link KeyEvent} for a definition of - * a key pressed event. + * Invoked when a key has been pressed. See the class description for {@link KeyEvent} for a + * definition of a key pressed event. * * @param e the event to be processed */ @@ -62,35 +57,35 @@ public void keyPressed(KeyEvent e) { KeyStroke keyStroke = KeyStroke.getKeyStrokeForEvent(e); Rule rule = keyStrokeMap.get(keyStroke); if (rule != null) { - TreeView treeView = GameBoardFacade.getInstance().getLegupUI().getTreePanel().getTreeView(); + TreeView treeView = + GameBoardFacade.getInstance().getLegupUI().getTreePanel().getTreeView(); String update = ""; if (rule.getRuleType() == RuleType.CASE) { - // TODO: review this line of code and figure out what it's supposed to do (remove if necessary) -// handleCaseRule((CaseRule)rule); - } - else { + // TODO: review this line of code and figure out what it's supposed to do (remove if + // necessary) + // handleCaseRule((CaseRule)rule); + } else { if (rule.getRuleType() == RuleType.CONTRADICTION) { TreeViewSelection selection = treeView.getSelection(); - ICommand validate = new ValidateContradictionRuleCommand(selection, (ContradictionRule) rule); + ICommand validate = + new ValidateContradictionRuleCommand( + selection, (ContradictionRule) rule); if (validate.canExecute()) { getInstance().getHistory().pushChange(validate); validate.execute(); - } - else { + } else { update = validate.getError(); } - } - else { + } else { TreeViewSelection selection = treeView.getSelection(); ICommand validate = new ValidateDirectRuleCommand(selection, (DirectRule) rule); if (validate.canExecute()) { getInstance().getHistory().pushChange(validate); validate.execute(); - } - else { + } else { update = validate.getError(); } } @@ -100,14 +95,11 @@ public void keyPressed(KeyEvent e) { } /** - * Invoked when a key has been released. - * See the class description for {@link KeyEvent} for a definition of - * a key released event. + * Invoked when a key has been released. See the class description for {@link KeyEvent} for a + * definition of a key released event. * * @param e the event to be processed */ @Override - public void keyReleased(KeyEvent e) { - - } + public void keyReleased(KeyEvent e) {} } diff --git a/src/main/java/edu/rpi/legup/controller/BoardController.java b/src/main/java/edu/rpi/legup/controller/BoardController.java index f9c328a99..eaae3851d 100644 --- a/src/main/java/edu/rpi/legup/controller/BoardController.java +++ b/src/main/java/edu/rpi/legup/controller/BoardController.java @@ -3,16 +3,13 @@ import java.awt.*; import java.awt.event.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - public class BoardController extends Controller { protected Point lastLeftMousePoint; protected Point lastRightMousePoint; /** - * BoardController Constructor creates a controller object to listen - * to ui events from a ScrollView + * BoardController Constructor creates a controller object to listen to ui events from a + * ScrollView */ public BoardController() { super(); @@ -26,13 +23,10 @@ public BoardController() { * @param e MouseEvent object */ @Override - public void mouseClicked(MouseEvent e) { - - } + public void mouseClicked(MouseEvent e) {} /** - * Mouse Pressed event - sets the cursor to the move cursor and stores - * info for possible panning + * Mouse Pressed event - sets the cursor to the move cursor and stores info for possible panning * * @param e MouseEvent object */ @@ -42,8 +36,7 @@ public void mousePressed(MouseEvent e) { } /** - * Mouse Released event - sets the cursor back to the default cursor and reset - * info for panning + * Mouse Released event - sets the cursor back to the default cursor and reset info for panning * * @param e MouseEvent object */ @@ -58,9 +51,7 @@ public void mouseReleased(MouseEvent e) { * @param e MouseEvent object */ @Override - public void mouseEntered(MouseEvent e) { - - } + public void mouseEntered(MouseEvent e) {} /** * Mouse Exited event - no default action @@ -68,9 +59,7 @@ public void mouseEntered(MouseEvent e) { * @param e MouseEvent object */ @Override - public void mouseExited(MouseEvent e) { - - } + public void mouseExited(MouseEvent e) {} /** * Mouse Dragged event - adjusts the viewport @@ -88,9 +77,7 @@ public void mouseDragged(MouseEvent e) { * @param e MouseEvent object */ @Override - public void mouseMoved(MouseEvent e) { - - } + public void mouseMoved(MouseEvent e) {} /** * Mouse Wheel Moved event - zooms in on the viewport diff --git a/src/main/java/edu/rpi/legup/controller/Controller.java b/src/main/java/edu/rpi/legup/controller/Controller.java index 5eef8cc17..57ce107ac 100644 --- a/src/main/java/edu/rpi/legup/controller/Controller.java +++ b/src/main/java/edu/rpi/legup/controller/Controller.java @@ -1,10 +1,9 @@ package edu.rpi.legup.controller; import edu.rpi.legup.ui.ScrollView; - -import javax.swing.*; import java.awt.*; import java.awt.event.*; +import javax.swing.*; public abstract class Controller implements MouseMotionListener, MouseListener, MouseWheelListener { protected ScrollView viewer; @@ -12,7 +11,8 @@ public abstract class Controller implements MouseMotionListener, MouseListener, private boolean pan; /** - * Controller Constructor creates a controller object to listen to ui events from a {@link ScrollView} + * Controller Constructor creates a controller object to listen to ui events from a {@link + * ScrollView} */ public Controller() { x = y = -1; @@ -29,13 +29,10 @@ public void setViewer(ScrollView viewer) { * @param e MouseEvent object */ @Override - public void mouseClicked(MouseEvent e) { - - } + public void mouseClicked(MouseEvent e) {} /** - * Mouse Pressed event sets the cursor to the move cursor and stores - * info for possible panning + * Mouse Pressed event sets the cursor to the move cursor and stores info for possible panning * * @param e MouseEvent object */ @@ -50,8 +47,7 @@ public void mousePressed(MouseEvent e) { } /** - * Mouse Released event sets the cursor back to the default cursor and reset - * info for panning + * Mouse Released event sets the cursor back to the default cursor and reset info for panning * * @param e MouseEvent object */ @@ -69,9 +65,7 @@ public void mouseReleased(MouseEvent e) { * @param e MouseEvent object */ @Override - public void mouseEntered(MouseEvent e) { - - } + public void mouseEntered(MouseEvent e) {} /** * Mouse Exited event no default action @@ -79,9 +73,7 @@ public void mouseEntered(MouseEvent e) { * @param e MouseEvent object */ @Override - public void mouseExited(MouseEvent e) { - - } + public void mouseExited(MouseEvent e) {} /** * Mouse Dragged event adjusts the viewport @@ -106,9 +98,7 @@ public void mouseDragged(MouseEvent e) { * @param e MouseEvent object */ @Override - public void mouseMoved(MouseEvent e) { - - } + public void mouseMoved(MouseEvent e) {} /** * Mouse Wheel Moved event zooms in on the viewport @@ -122,11 +112,10 @@ public void mouseWheelMoved(MouseWheelEvent e) { if (e.getWheelRotation() != 0) { viewer.zoom(e.getWheelRotation() * 2, e.getPoint()); } - } - else { + } else { if (e.getWheelRotation() != 0) { viewer.zoom(e.getWheelRotation(), e.getPoint()); } } } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/controller/CursorController.java b/src/main/java/edu/rpi/legup/controller/CursorController.java index 0c9a644ed..2706bd522 100644 --- a/src/main/java/edu/rpi/legup/controller/CursorController.java +++ b/src/main/java/edu/rpi/legup/controller/CursorController.java @@ -2,7 +2,6 @@ import java.awt.Component; import java.awt.Cursor; -import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Timer; import java.util.TimerTask; @@ -10,7 +9,7 @@ public class CursorController { public static final Cursor BUSY_CURSOR = new Cursor(Cursor.WAIT_CURSOR); public static final Cursor DEFAULT_CURSOR = new Cursor(Cursor.DEFAULT_CURSOR); - public static final int DELAY = 200; // in milliseconds + public static final int DELAY = 200; // in milliseconds private CursorController() { // Intentionally left empty @@ -18,36 +17,38 @@ private CursorController() { /** * Creates an ActionListener that will still do the same action processing as the given - * ActionListener while also displaying a loading cursor if the time it takes to execute - * the given process exceeds the time (in milliseconds) specified in this.DELAY - *

- * Sources consulted: http://www.catalysoft.com/articles/busycursor.html + * ActionListener while also displaying a loading cursor if the time it takes to execute the + * given process exceeds the time (in milliseconds) specified in this.DELAY * - * @param component The component you want to set the cursor for + *

Sources consulted: http://www.catalysoft.com/articles/busycursor.html + * + * @param component The component you want to set the cursor for * @param mainActionListener The ActionListener that does the intended action processing - * @return An ActionListener object that does the same action processing - * as mainActionListener while also modifying the cursor if needed + * @return An ActionListener object that does the same action processing as mainActionListener + * while also modifying the cursor if needed */ - public static ActionListener createListener(final Component component, final ActionListener mainActionListener) { - ActionListener actionListener = e -> { - TimerTask timerTask = new TimerTask() { - @Override - public void run() { - component.setCursor(BUSY_CURSOR); - } - }; + public static ActionListener createListener( + final Component component, final ActionListener mainActionListener) { + ActionListener actionListener = + e -> { + TimerTask timerTask = + new TimerTask() { + @Override + public void run() { + component.setCursor(BUSY_CURSOR); + } + }; - Timer timer = new Timer(); - try { - timer.schedule(timerTask, DELAY); - mainActionListener.actionPerformed(e); - } - finally { - timer.cancel(); - component.setCursor(DEFAULT_CURSOR); - } - }; + Timer timer = new Timer(); + try { + timer.schedule(timerTask, DELAY); + mainActionListener.actionPerformed(e); + } finally { + timer.cancel(); + component.setCursor(DEFAULT_CURSOR); + } + }; return actionListener; } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/controller/EditorElementController.java b/src/main/java/edu/rpi/legup/controller/EditorElementController.java index 80e7dd35a..5a23885af 100644 --- a/src/main/java/edu/rpi/legup/controller/EditorElementController.java +++ b/src/main/java/edu/rpi/legup/controller/EditorElementController.java @@ -1,31 +1,13 @@ package edu.rpi.legup.controller; -import edu.rpi.legup.app.GameBoardFacade; -import edu.rpi.legup.app.LegupPreferences; import edu.rpi.legup.history.*; -import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.elements.Element; -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.CaseBoard; -import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.rules.*; -import edu.rpi.legup.model.tree.TreeElement; -import edu.rpi.legup.model.tree.TreeElementType; -import edu.rpi.legup.ui.proofeditorui.rulesview.RuleButton; -import edu.rpi.legup.ui.proofeditorui.treeview.TreeElementView; -import edu.rpi.legup.ui.proofeditorui.treeview.TreePanel; -import edu.rpi.legup.ui.proofeditorui.treeview.TreeView; -import edu.rpi.legup.ui.proofeditorui.treeview.TreeViewSelection; import edu.rpi.legup.ui.puzzleeditorui.elementsview.ElementButton; - -import javax.swing.*; -import javax.swing.border.Border; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.List; - -import static edu.rpi.legup.app.GameBoardFacade.getInstance; +import javax.swing.*; public class EditorElementController implements ActionListener { protected Object lastSource; @@ -66,6 +48,5 @@ public void actionPerformed(ActionEvent e) { button.setBorderToSelected(); this.prevButton = button; - } } diff --git a/src/main/java/edu/rpi/legup/controller/ElementController.java b/src/main/java/edu/rpi/legup/controller/ElementController.java index 50fa7d1b9..5840650e1 100644 --- a/src/main/java/edu/rpi/legup/controller/ElementController.java +++ b/src/main/java/edu/rpi/legup/controller/ElementController.java @@ -1,10 +1,12 @@ package edu.rpi.legup.controller; -import edu.rpi.legup.puzzle.treetent.TreeTentBoard; -import edu.rpi.legup.ui.ScrollView; +import static edu.rpi.legup.app.GameBoardFacade.*; + import edu.rpi.legup.app.GameBoardFacade; import edu.rpi.legup.app.LegupPreferences; import edu.rpi.legup.history.AutoCaseRuleCommand; +import edu.rpi.legup.history.EditDataCommand; +import edu.rpi.legup.history.ICommand; import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.elements.Element; import edu.rpi.legup.model.gameboard.Board; @@ -14,26 +16,24 @@ import edu.rpi.legup.model.tree.TreeElement; import edu.rpi.legup.model.tree.TreeElementType; import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.treetent.TreeTentBoard; import edu.rpi.legup.ui.DynamicView; import edu.rpi.legup.ui.boardview.BoardView; import edu.rpi.legup.ui.boardview.ElementSelection; import edu.rpi.legup.ui.boardview.ElementView; import edu.rpi.legup.ui.boardview.SelectionItemView; import edu.rpi.legup.ui.proofeditorui.treeview.*; -import edu.rpi.legup.history.ICommand; -import edu.rpi.legup.history.EditDataCommand; - import java.awt.*; import java.awt.event.*; -import static edu.rpi.legup.app.GameBoardFacade.*; - -public class ElementController implements MouseListener, MouseMotionListener, ActionListener, KeyListener { +public class ElementController + implements MouseListener, MouseMotionListener, ActionListener, KeyListener { protected BoardView boardView; private Element selectedElement; /** - * ElementController Constructor controller to handles ui events associated interacting with a {@link BoardView} + * ElementController Constructor controller to handles ui events associated interacting with a + * {@link BoardView} */ public ElementController() { this.boardView = null; @@ -59,9 +59,7 @@ public void setBoardView(BoardView boardView) { * @param e the event to be processed */ @Override - public void mouseClicked(MouseEvent e) { - - } + public void mouseClicked(MouseEvent e) {} /** * Invoked when a mouse button has been pressed on a component. @@ -69,9 +67,7 @@ public void mouseClicked(MouseEvent e) { * @param e the event to be processed */ @Override - public void mousePressed(MouseEvent e) { - - } + public void mousePressed(MouseEvent e) {} /** * Invoked when a mouse button has been released on a component. @@ -100,21 +96,21 @@ public void mouseReleased(MouseEvent e) { if (elementView != null) { if (board instanceof CaseBoard) { CaseBoard caseBoard = (CaseBoard) board; - AutoCaseRuleCommand autoCaseRuleCommand = new AutoCaseRuleCommand(elementView, selection, caseBoard.getCaseRule(), caseBoard, e); + AutoCaseRuleCommand autoCaseRuleCommand = + new AutoCaseRuleCommand( + elementView, selection, caseBoard.getCaseRule(), caseBoard, e); if (autoCaseRuleCommand.canExecute()) { autoCaseRuleCommand.execute(); getInstance().getHistory().pushChange(autoCaseRuleCommand); if (treePanel != null) { treePanel.updateError(""); } - } - else { + } else { if (treePanel != null) { treePanel.updateError(autoCaseRuleCommand.getError()); } } - } - else { + } else { if (selection != null) { ICommand edit = new EditDataCommand(elementView, selection, e); if (edit.canExecute()) { @@ -123,8 +119,7 @@ public void mouseReleased(MouseEvent e) { if (treePanel != null) { treePanel.updateError(""); } - } - else { + } else { if (treePanel != null) { treePanel.updateError(edit.getError()); } @@ -132,20 +127,27 @@ public void mouseReleased(MouseEvent e) { } } } -// if (selectedElement != null) { + // if (selectedElement != null) { GridBoard b = (GridBoard) this.boardView.getBoard(); Point point = e.getPoint(); - Point scaledPoint = new Point((int) Math.floor(point.x / (30 * this.boardView.getScale())), (int) Math.floor(point.y / (30 * this.boardView.getScale()))); + Point scaledPoint = + new Point( + (int) Math.floor(point.x / (30 * this.boardView.getScale())), + (int) Math.floor(point.y / (30 * this.boardView.getScale()))); if (this.boardView.getBoard() instanceof TreeTentBoard) { scaledPoint.setLocation(scaledPoint.getX() - 1, scaledPoint.getY() - 1); } - System.out.printf("selected Element is NOT null, attempting to change board at (%d, %d)\n", scaledPoint.x, scaledPoint.y); -// System.out.println("Before: " + b.getCell(scaledPoint.x, scaledPoint.y).getData()); + System.out.printf( + "selected Element is NOT null, attempting to change board at (%d, %d)\n", + scaledPoint.x, scaledPoint.y); + // System.out.println("Before: " + b.getCell(scaledPoint.x, + // scaledPoint.y).getData()); b.setCell(scaledPoint.x, scaledPoint.y, this.selectedElement, e); -// System.out.println("After: " + b.getCell(scaledPoint.x, scaledPoint.y).getData()); -// } else { -// System.out.println("selected Element is null!"); -// } + // System.out.println("After: " + b.getCell(scaledPoint.x, + // scaledPoint.y).getData()); + // } else { + // System.out.println("selected Element is null!"); + // } boardView.repaint(); } @@ -175,7 +177,9 @@ public void mouseEntered(MouseEvent e) { selection.newHover(elementView); if (LegupPreferences.getInstance().getUserPrefAsBool(LegupPreferences.SHOW_MISTAKES)) { PuzzleElement element = elementView.getPuzzleElement(); - if (treeElement != null && treeElement.getType() == TreeElementType.TRANSITION && board.getModifiedData().contains(element)) { + if (treeElement != null + && treeElement.getType() == TreeElementType.TRANSITION + && board.getModifiedData().contains(element)) { TreeTransition transition = (TreeTransition) treeElement; if (transition.isJustified() && !transition.isCorrect()) { error = transition.getRule().checkRuleAt(transition, element); @@ -183,8 +187,7 @@ public void mouseEntered(MouseEvent e) { } if (error != null) { dynamicView.updateError(error); - } - else { + } else { dynamicView.resetStatus(); } } @@ -222,9 +225,7 @@ public void mouseExited(MouseEvent e) { * @param e the event to be processed */ @Override - public void mouseDragged(MouseEvent e) { - - } + public void mouseDragged(MouseEvent e) {} /** * Invoked when the mouse moved @@ -250,7 +251,9 @@ public void mouseMoved(MouseEvent e) { selection.newHover(elementView); if (LegupPreferences.getInstance().getUserPrefAsBool(LegupPreferences.SHOW_MISTAKES)) { PuzzleElement element = elementView.getPuzzleElement(); - if (treeElement != null && treeElement.getType() == TreeElementType.TRANSITION && board.getModifiedData().contains(element)) { + if (treeElement != null + && treeElement.getType() == TreeElementType.TRANSITION + && board.getModifiedData().contains(element)) { TreeTransition transition = (TreeTransition) treeElement; if (transition.isJustified() && !transition.isCorrect()) { error = transition.getRule().checkRuleAt(transition, element); @@ -258,8 +261,7 @@ public void mouseMoved(MouseEvent e) { } if (error != null) { dynamicView.updateError(error); - } - else { + } else { dynamicView.resetStatus(); } } @@ -267,9 +269,7 @@ public void mouseMoved(MouseEvent e) { } } - public void changeCell(MouseEvent e, PuzzleElement data) { - - } + public void changeCell(MouseEvent e, PuzzleElement data) {} /** * Invoked when an action occurs. @@ -299,8 +299,7 @@ public void actionPerformed(ActionEvent e) { if (puzzleElement.equalsData(prevBord.getPuzzleElement(puzzleElement))) { puzzleElement.setModified(false); - } - else { + } else { puzzleElement.setModified(true); } @@ -311,33 +310,26 @@ public void actionPerformed(ActionEvent e) { } /** - * Invoked when a key has been typed. - * See the class description for {@link KeyEvent} for a definition of - * a key typed event. + * Invoked when a key has been typed. See the class description for {@link KeyEvent} for a + * definition of a key typed event. * * @param e the event to be processed */ @Override - public void keyTyped(KeyEvent e) { - - } + public void keyTyped(KeyEvent e) {} /** - * Invoked when a key has been pressed. - * See the class description for {@link KeyEvent} for a definition of - * a key pressed event. + * Invoked when a key has been pressed. See the class description for {@link KeyEvent} for a + * definition of a key pressed event. * * @param e the event to be processed */ @Override - public void keyPressed(KeyEvent e) { - - } + public void keyPressed(KeyEvent e) {} /** - * Invoked when a key has been released. - * See the class description for {@link KeyEvent} for a definition of - * a key released event. + * Invoked when a key has been released. See the class description for {@link KeyEvent} for a + * definition of a key released event. * * @param e the event to be processed */ diff --git a/src/main/java/edu/rpi/legup/controller/RuleController.java b/src/main/java/edu/rpi/legup/controller/RuleController.java index fef6fca45..6e88dc4be 100644 --- a/src/main/java/edu/rpi/legup/controller/RuleController.java +++ b/src/main/java/edu/rpi/legup/controller/RuleController.java @@ -1,5 +1,7 @@ package edu.rpi.legup.controller; +import static edu.rpi.legup.app.GameBoardFacade.getInstance; + import edu.rpi.legup.app.GameBoardFacade; import edu.rpi.legup.app.LegupPreferences; import edu.rpi.legup.history.*; @@ -10,19 +12,16 @@ import edu.rpi.legup.ui.proofeditorui.rulesview.RuleButton; import edu.rpi.legup.ui.proofeditorui.rulesview.RulePanel; import edu.rpi.legup.ui.proofeditorui.treeview.*; - import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.List; -import static edu.rpi.legup.app.GameBoardFacade.getInstance; - public class RuleController implements ActionListener { protected Object lastSource; /** - * RuleController Constructor creates a controller object to listen - * to ui events from a {@link RulePanel} + * RuleController Constructor creates a controller object to listen to ui events from a {@link + * RulePanel} */ public RuleController() { super(); @@ -51,56 +50,56 @@ public void buttonPressed(Rule rule) { if (caseRuleCommand.canExecute()) { caseRuleCommand.execute(); getInstance().getHistory().pushChange(caseRuleCommand); - } - else { + } else { updateErrorString = caseRuleCommand.getError(); } - } - else { - if (LegupPreferences.getInstance().getUserPref(LegupPreferences.AUTO_GENERATE_CASES).equalsIgnoreCase(Boolean.toString(true))) { + } else { + if (LegupPreferences.getInstance() + .getUserPref(LegupPreferences.AUTO_GENERATE_CASES) + .equalsIgnoreCase(Boolean.toString(true))) { CaseBoard caseBoard = caseRule.getCaseBoard(element.getBoard()); if (caseBoard != null && caseBoard.getCount() > 0) { - puzzle.notifyBoardListeners(listener -> listener.onCaseBoardAdded(caseBoard)); - } - else { + puzzle.notifyBoardListeners( + listener -> listener.onCaseBoardAdded(caseBoard)); + } else { updateErrorString = "This board cannot be applied with this case rule."; } - } - else { - updateErrorString = "Auto generated case rules are turned off in preferences."; + } else { + updateErrorString = + "Auto generated case rules are turned off in preferences."; } } - } - else { + } else { ICommand caseRuleCommand = new ValidateCaseRuleCommand(selection, caseRule); if (caseRuleCommand.canExecute()) { caseRuleCommand.execute(); getInstance().getHistory().pushChange(caseRuleCommand); - } - else { + } else { updateErrorString = caseRuleCommand.getError(); } } - } - else { + } else { if (rule.getRuleType() == RuleType.CONTRADICTION) { - ICommand validate = new ValidateContradictionRuleCommand(selection, (ContradictionRule) rule); + ICommand validate = + new ValidateContradictionRuleCommand(selection, (ContradictionRule) rule); if (validate.canExecute()) { getInstance().getHistory().pushChange(validate); validate.execute(); - } - else { + } else { updateErrorString = validate.getError(); } - } - else { - boolean def = LegupPreferences.getInstance().getUserPrefAsBool(LegupPreferences.ALLOW_DEFAULT_RULES); - ICommand validate = def ? new ApplyDefaultDirectRuleCommand(selection, (DirectRule) rule) : new ValidateDirectRuleCommand(selection, (DirectRule) rule); + } else { + boolean def = + LegupPreferences.getInstance() + .getUserPrefAsBool(LegupPreferences.ALLOW_DEFAULT_RULES); + ICommand validate = + def + ? new ApplyDefaultDirectRuleCommand(selection, (DirectRule) rule) + : new ValidateDirectRuleCommand(selection, (DirectRule) rule); if (validate.canExecute()) { getInstance().getHistory().pushChange(validate); validate.execute(); - } - else { + } else { updateErrorString = validate.getError(); } } diff --git a/src/main/java/edu/rpi/legup/controller/ToolbarController.java b/src/main/java/edu/rpi/legup/controller/ToolbarController.java index 2ee4ee25e..6cbb5ee60 100644 --- a/src/main/java/edu/rpi/legup/controller/ToolbarController.java +++ b/src/main/java/edu/rpi/legup/controller/ToolbarController.java @@ -1,19 +1,15 @@ package edu.rpi.legup.controller; import edu.rpi.legup.ui.LegupUI; - import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - public class ToolbarController implements ActionListener { private LegupUI legupUI; /** - * ToolbarController Constructor - creates a new {@link ToolbarController} to listen - * for button pressed from the tool mBar + * ToolbarController Constructor - creates a new {@link ToolbarController} to listen for button + * pressed from the tool mBar * * @param legupUI legupUI */ @@ -27,7 +23,5 @@ public ToolbarController(LegupUI legupUI) { * @param e action event */ @Override - public void actionPerformed(ActionEvent e) { - - } + public void actionPerformed(ActionEvent e) {} } diff --git a/src/main/java/edu/rpi/legup/controller/TreeController.java b/src/main/java/edu/rpi/legup/controller/TreeController.java index 6eae4ac3b..80fdee1af 100644 --- a/src/main/java/edu/rpi/legup/controller/TreeController.java +++ b/src/main/java/edu/rpi/legup/controller/TreeController.java @@ -1,25 +1,22 @@ package edu.rpi.legup.controller; +import static edu.rpi.legup.app.GameBoardFacade.getInstance; + import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.tree.Tree; -import edu.rpi.legup.model.tree.TreeElementType; import edu.rpi.legup.ui.boardview.BoardView; import edu.rpi.legup.ui.proofeditorui.treeview.*; - -import javax.swing.*; import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; - -import static edu.rpi.legup.app.GameBoardFacade.getInstance; +import javax.swing.*; public class TreeController extends Controller { /** - * TreeController Constructor creates a controller object to listen to ui events from a {@link TreePanel} + * TreeController Constructor creates a controller object to listen to ui events from a {@link + * TreePanel} */ - public TreeController() { - - } + public TreeController() {} /** * Mouse Clicked event no default action @@ -27,9 +24,7 @@ public TreeController() { * @param e MouseEvent object */ @Override - public void mouseClicked(MouseEvent e) { - - } + public void mouseClicked(MouseEvent e) {} /** * Mouse Pressed event sets the cursor to the move cursor and stores info for possible panning @@ -44,6 +39,7 @@ public void mousePressed(MouseEvent e) { /** * Mouse Released event sets the cursor back to the default cursor and reset info for panning * Set board modifiability + * * @param e MouseEvent object */ @Override @@ -58,19 +54,19 @@ public void mouseReleased(MouseEvent e) { if (treeElementView != null) { if (e.isShiftDown()) { selection.addToSelection(treeElementView); - } - else { + } else { if (e.isControlDown()) { - if (!(selection.getSelectedViews().size() == 1 && treeElementView == selection.getFirstSelection())) { + if (!(selection.getSelectedViews().size() == 1 + && treeElementView == selection.getFirstSelection())) { selection.toggleSelection(treeElementView); } - } - else { + } else { selection.newSelection(treeElementView); } } puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection)); - puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(treeElementView.getTreeElement())); + puzzle.notifyBoardListeners( + listener -> listener.onTreeElementChanged(treeElementView.getTreeElement())); } } @@ -88,7 +84,8 @@ public void mouseEntered(MouseEvent e) { TreeElementView treeElementView = treeView.getTreeElementView(point); Puzzle puzzle = getInstance().getPuzzleModule(); if (treeElementView != null) { - puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(treeElementView.getTreeElement())); + puzzle.notifyBoardListeners( + listener -> listener.onTreeElementChanged(treeElementView.getTreeElement())); } } @@ -108,7 +105,8 @@ public void mouseExited(MouseEvent e) { selection.setMousePoint(null); if (elementView != null) { TreeElementView selectedView = selection.getFirstSelection(); - puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(selectedView.getTreeElement())); + puzzle.notifyBoardListeners( + listener -> listener.onTreeElementChanged(selectedView.getTreeElement())); } } @@ -137,15 +135,20 @@ public void mouseMoved(MouseEvent e) { TreeViewSelection selection = treeView.getSelection(); selection.setMousePoint(treeView.getActualPoint(e.getPoint())); if (treeElementView != null && treeElementView != selection.getHover()) { - puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(treeElementView.getTreeElement())); + puzzle.notifyBoardListeners( + listener -> + listener.onTreeElementChanged(treeElementView.getTreeElement())); selection.newHover(treeElementView); puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection)); - } - else { + } else { if (treeElementView == null && selection.getHover() != null) { - puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(selection.getFirstSelection().getTreeElement())); + puzzle.notifyBoardListeners( + listener -> + listener.onTreeElementChanged( + selection.getFirstSelection().getTreeElement())); selection.clearHover(); - puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection)); + puzzle.notifyTreeListeners( + listener -> listener.onTreeSelectionChanged(selection)); } } } diff --git a/src/main/java/edu/rpi/legup/history/AddTreeElementCommand.java b/src/main/java/edu/rpi/legup/history/AddTreeElementCommand.java index 0aa6f416d..12b39cd85 100644 --- a/src/main/java/edu/rpi/legup/history/AddTreeElementCommand.java +++ b/src/main/java/edu/rpi/legup/history/AddTreeElementCommand.java @@ -6,7 +6,6 @@ import edu.rpi.legup.ui.proofeditorui.treeview.TreeElementView; import edu.rpi.legup.ui.proofeditorui.treeview.TreeView; import edu.rpi.legup.ui.proofeditorui.treeview.TreeViewSelection; - import java.util.HashMap; import java.util.List; import java.util.Map; @@ -18,7 +17,8 @@ public class AddTreeElementCommand extends PuzzleCommand { private Map addChild; /** - * AddTreeElementCommand Constructor creates a command for adding a tree element to the proof tree + * AddTreeElementCommand Constructor creates a command for adding a tree element to the proof + * tree * * @param selection selection of tree elements views */ @@ -27,9 +27,7 @@ public AddTreeElementCommand(TreeViewSelection selection) { this.addChild = new HashMap<>(); } - /** - * Executes an command - */ + /** Executes an command */ @Override public void executeCommand() { Tree tree = GameBoardFacade.getInstance().getTree(); @@ -43,12 +41,11 @@ public void executeCommand() { TreeElement child = addChild.get(treeElement); if (child == null) { child = tree.addTreeElement(treeElement); - } - else { + } else { + if (treeElement.getType() == TreeElementType.NODE) { child = tree.addTreeElement((TreeNode) treeElement, (TreeTransition) child); - } - else { + } else { child = tree.addTreeElement((TreeTransition) treeElement, (TreeNode) child); } } @@ -69,15 +66,14 @@ public void executeCommand() { * Gets the reason why the command cannot be executed * * @return if command cannot be executed, returns reason for why the command cannot be executed, - * otherwise null if command can be executed + * otherwise null if command can be executed */ @Override public String getErrorString() { List selectedViews = selection.getSelectedViews(); if (selectedViews.isEmpty()) { return CommandError.NO_SELECTED_VIEWS.toString(); - } - else { + } else { for (TreeElementView view : selectedViews) { TreeElement element = view.getTreeElement(); if (element.getType() == TreeElementType.TRANSITION) { @@ -85,8 +81,7 @@ public String getErrorString() { if (transition.getChildNode() != null) { return CommandError.ADD_WITH_CHILD.toString(); } - } - else { + } else { TreeNode node = (TreeNode) element; if (!node.getChildren().isEmpty()) { TreeTransition transition = node.getChildren().get(0); @@ -100,9 +95,7 @@ public String getErrorString() { return null; } - /** - * Undoes an command - */ + /** Undoes an command */ @Override public void undoCommand() { Tree tree = GameBoardFacade.getInstance().getTree(); @@ -119,4 +112,4 @@ public void undoCommand() { } puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection)); } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/history/ApplyDefaultDirectRuleCommand.java b/src/main/java/edu/rpi/legup/history/ApplyDefaultDirectRuleCommand.java index bc4c89741..02dffae44 100644 --- a/src/main/java/edu/rpi/legup/history/ApplyDefaultDirectRuleCommand.java +++ b/src/main/java/edu/rpi/legup/history/ApplyDefaultDirectRuleCommand.java @@ -1,128 +1,129 @@ -package edu.rpi.legup.history; - -import edu.rpi.legup.app.GameBoardFacade; -import edu.rpi.legup.model.Puzzle; -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.*; -import edu.rpi.legup.ui.proofeditorui.treeview.*; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class ApplyDefaultDirectRuleCommand extends PuzzleCommand { - - private TreeViewSelection selection; - private DirectRule rule; - private Map addMap; - - /** - * ApplyDefaultDirectRuleCommand Constructor creates a command for applying the default of a basic rule - * - * @param selection selection of tree element views - * @param rule basic rule for the command - */ - public ApplyDefaultDirectRuleCommand(TreeViewSelection selection, DirectRule rule) { - this.selection = selection.copy(); - this.rule = rule; - this.addMap = new HashMap<>(); - } - - /** - * Gets the reason why the command cannot be executed - * - * @return if command cannot be executed, returns reason for why the command cannot be executed, - * otherwise null if command can be executed - */ - @Override - public String getErrorString() { - List selectedViews = selection.getSelectedViews(); - if (selectedViews.isEmpty()) { - return CommandError.DEFAULT_APPLICATION + " - " + CommandError.NO_SELECTED_VIEWS.toString(); - } - else { - for (TreeElementView view : selectedViews) { - TreeElement element = view.getTreeElement(); - if (element.getType() == TreeElementType.NODE) { - TreeNode node = (TreeNode) element; - if (!node.getChildren().isEmpty()) { - return CommandError.DEFAULT_APPLICATION + " - " + CommandError.NO_CHILDREN.toString(); - } - else { - if (rule.getDefaultBoard(node) == null) { - return CommandError.DEFAULT_APPLICATION + " - " + "This selection contains a tree element that this rule cannot be applied to."; - } - } - } - else { - return CommandError.DEFAULT_APPLICATION + " - " + CommandError.SELECTION_CONTAINS_TRANSITION.toString(); - } - } - } - return null; - } - - /** - * Executes an command - */ - @Override - public void executeCommand() { - Tree tree = GameBoardFacade.getInstance().getTree(); - TreeView treeView = GameBoardFacade.getInstance().getLegupUI().getTreePanel().getTreeView(); - Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); - final TreeViewSelection newSelection = new TreeViewSelection(); - - for (TreeElementView selectedView : selection.getSelectedViews()) { - TreeNodeView nodeView = (TreeNodeView) selectedView; - TreeNode node = nodeView.getTreeElement(); - TreeTransition transition = addMap.get(node); - TreeNode childNode; - if (transition == null) { - transition = (TreeTransition) tree.addTreeElement(node); - childNode = (TreeNode) tree.addTreeElement(transition); - addMap.put(node, transition); - } - else { - tree.addTreeElement(node, transition); - childNode = transition.getChildNode(); - } - - transition.setRule(rule); - Board defaultBoard = rule.getDefaultBoard(node); - transition.setBoard(defaultBoard); - Board copyBoard = defaultBoard.copy(); - copyBoard.setModifiable(false); - childNode.setBoard(copyBoard); - - final TreeTransition finalTran = transition; - puzzle.notifyTreeListeners(listener -> listener.onTreeElementAdded(finalTran)); - - newSelection.addToSelection(treeView.getElementView(childNode)); - } - - final TreeElement finalTreeElement = newSelection.getFirstSelection().getTreeElement(); - puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement)); - puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection)); - } - - /** - * Undoes an command - */ - @Override - public void undoCommand() { - Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); - - for (TreeElementView selectedView : selection.getSelectedViews()) { - TreeNodeView nodeView = (TreeNodeView) selectedView; - TreeNode node = nodeView.getTreeElement(); - final TreeTransition transition = addMap.get(node); - - puzzle.notifyTreeListeners(listener -> listener.onTreeElementRemoved(transition)); - } - - final TreeElement finalTreeElement = selection.getFirstSelection().getTreeElement(); - puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement)); - puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection)); - } -} +package edu.rpi.legup.history; + +import edu.rpi.legup.app.GameBoardFacade; +import edu.rpi.legup.model.Puzzle; +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.*; +import edu.rpi.legup.ui.proofeditorui.treeview.*; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ApplyDefaultDirectRuleCommand extends PuzzleCommand { + + private TreeViewSelection selection; + private DirectRule rule; + private Map addMap; + + /** + * ApplyDefaultDirectRuleCommand Constructor creates a command for applying the default of a + * basic rule + * + * @param selection selection of tree element views + * @param rule basic rule for the command + */ + public ApplyDefaultDirectRuleCommand(TreeViewSelection selection, DirectRule rule) { + this.selection = selection.copy(); + this.rule = rule; + this.addMap = new HashMap<>(); + } + + /** + * Gets the reason why the command cannot be executed + * + * @return if command cannot be executed, returns reason for why the command cannot be executed, + * otherwise null if command can be executed + */ + @Override + public String getErrorString() { + List selectedViews = selection.getSelectedViews(); + if (selectedViews.isEmpty()) { + return CommandError.DEFAULT_APPLICATION + + " - " + + CommandError.NO_SELECTED_VIEWS.toString(); + } else { + for (TreeElementView view : selectedViews) { + TreeElement element = view.getTreeElement(); + if (element.getType() == TreeElementType.NODE) { + TreeNode node = (TreeNode) element; + if (!node.getChildren().isEmpty()) { + + return CommandError.DEFAULT_APPLICATION + + " - " + + CommandError.NO_CHILDREN.toString(); + } else { + if (rule.getDefaultBoard(node) == null) { + return CommandError.DEFAULT_APPLICATION + + " - This selection contains a tree element that this rule" + + " cannot be applied to."; + } + } + } else { + return CommandError.DEFAULT_APPLICATION + + " - " + + CommandError.SELECTION_CONTAINS_TRANSITION.toString(); + } + } + } + return null; + } + + /** Executes an command */ + @Override + public void executeCommand() { + Tree tree = GameBoardFacade.getInstance().getTree(); + TreeView treeView = GameBoardFacade.getInstance().getLegupUI().getTreePanel().getTreeView(); + Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); + final TreeViewSelection newSelection = new TreeViewSelection(); + + for (TreeElementView selectedView : selection.getSelectedViews()) { + TreeNodeView nodeView = (TreeNodeView) selectedView; + TreeNode node = nodeView.getTreeElement(); + TreeTransition transition = addMap.get(node); + TreeNode childNode; + if (transition == null) { + transition = (TreeTransition) tree.addTreeElement(node); + childNode = (TreeNode) tree.addTreeElement(transition); + addMap.put(node, transition); + } else { + tree.addTreeElement(node, transition); + childNode = transition.getChildNode(); + } + + transition.setRule(rule); + Board defaultBoard = rule.getDefaultBoard(node); + transition.setBoard(defaultBoard); + Board copyBoard = defaultBoard.copy(); + copyBoard.setModifiable(false); + childNode.setBoard(copyBoard); + + final TreeTransition finalTran = transition; + puzzle.notifyTreeListeners(listener -> listener.onTreeElementAdded(finalTran)); + + newSelection.addToSelection(treeView.getElementView(childNode)); + } + + final TreeElement finalTreeElement = newSelection.getFirstSelection().getTreeElement(); + puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement)); + puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection)); + } + + /** Undoes an command */ + @Override + public void undoCommand() { + Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); + + for (TreeElementView selectedView : selection.getSelectedViews()) { + TreeNodeView nodeView = (TreeNodeView) selectedView; + TreeNode node = nodeView.getTreeElement(); + final TreeTransition transition = addMap.get(node); + + puzzle.notifyTreeListeners(listener -> listener.onTreeElementRemoved(transition)); + } + + final TreeElement finalTreeElement = selection.getFirstSelection().getTreeElement(); + puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement)); + puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection)); + } +} diff --git a/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java b/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java index a4c157c77..54e33756a 100644 --- a/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java +++ b/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java @@ -1,5 +1,7 @@ package edu.rpi.legup.history; +import static edu.rpi.legup.app.GameBoardFacade.getInstance; + import edu.rpi.legup.app.GameBoardFacade; import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.gameboard.Board; @@ -8,12 +10,9 @@ import edu.rpi.legup.model.tree.*; import edu.rpi.legup.ui.boardview.ElementView; import edu.rpi.legup.ui.proofeditorui.treeview.*; - import java.awt.event.MouseEvent; import java.util.*; -import static edu.rpi.legup.app.GameBoardFacade.getInstance; - public class AutoCaseRuleCommand extends PuzzleCommand { private ElementView elementView; @@ -30,12 +29,17 @@ public class AutoCaseRuleCommand extends PuzzleCommand { * AutoCaseRuleCommand Constructor creates a command for validating a case rule * * @param elementView currently selected puzzle puzzleElement view that is being edited - * @param selection currently selected tree puzzleElement views that is being edited + * @param selection currently selected tree puzzleElement views that is being edited * @param caseRule currently selected caseRule puzzleElement view that is being edited * @param caseBoard currently selected caseBoard puzzleElement view that is being edited * @param mouseEvent currently selected mouseEvent puzzleElement view that is being edited */ - public AutoCaseRuleCommand(ElementView elementView, TreeViewSelection selection, CaseRule caseRule, CaseBoard caseBoard, MouseEvent mouseEvent) { + public AutoCaseRuleCommand( + ElementView elementView, + TreeViewSelection selection, + CaseRule caseRule, + CaseBoard caseBoard, + MouseEvent mouseEvent) { this.elementView = elementView; this.selection = selection.copy(); this.caseRule = caseRule; @@ -44,9 +48,7 @@ public AutoCaseRuleCommand(ElementView elementView, TreeViewSelection selection, this.caseTrans = new ArrayList<>(); } - /** - * Executes an command - */ + /** Executes an command */ @Override public void executeCommand() { Tree tree = getInstance().getTree(); @@ -56,7 +58,8 @@ public void executeCommand() { TreeNode node = (TreeNode) selection.getFirstSelection().getTreeElement(); if (caseTrans.isEmpty()) { - List cases = caseRule.getCases(caseBoard.getBaseBoard(), elementView.getPuzzleElement()); + List cases = + caseRule.getCases(caseBoard.getBaseBoard(), elementView.getPuzzleElement()); for (Board board : cases) { final TreeTransition transition = (TreeTransition) tree.addTreeElement(node); board.setModifiable(false); @@ -70,8 +73,7 @@ public void executeCommand() { puzzle.notifyTreeListeners(listener -> listener.onTreeElementAdded(transition)); newSelection.addToSelection(treeView.getElementView(childNode)); } - } - else { + } else { for (final TreeTransition transition : caseTrans) { tree.addTreeElement(node, transition); TreeNode childNode = transition.getChildNode(); @@ -89,7 +91,7 @@ public void executeCommand() { * Gets the reason why the command cannot be executed * * @return if command cannot be executed, returns reason for why the command cannot be executed, - * otherwise null if command can be executed + * otherwise null if command can be executed */ @Override public String getErrorString() { @@ -111,20 +113,20 @@ public String getErrorString() { return "The selected data element is not pickable with this case rule."; } - if (caseRule.getCases(caseBoard.getBaseBoard(), elementView.getPuzzleElement()).size() == 0) { + if (caseRule.getCases(caseBoard.getBaseBoard(), elementView.getPuzzleElement()).size() + == 0) { return "The selection must produce at least one case"; } - if (caseRule.getCases(caseBoard.getBaseBoard(), elementView.getPuzzleElement()).size() > MAX_CASES) { + if (caseRule.getCases(caseBoard.getBaseBoard(), elementView.getPuzzleElement()).size() + > MAX_CASES) { return "The selection can produce a max of " + MAX_CASES + " cases"; } return null; } - /** - * Undoes an command - */ + /** Undoes an command */ @Override public void undoCommand() { Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); diff --git a/src/main/java/edu/rpi/legup/history/CommandError.java b/src/main/java/edu/rpi/legup/history/CommandError.java index 90c9db526..35b7bb15b 100644 --- a/src/main/java/edu/rpi/legup/history/CommandError.java +++ b/src/main/java/edu/rpi/legup/history/CommandError.java @@ -1,7 +1,6 @@ package edu.rpi.legup.history; public enum CommandError { - NO_SELECTED_VIEWS("The selection does not have any tree elements."), ONE_SELECTED_VIEW("The selection must have exactly one tree element."), UNMODIFIABLE_BOARD("The selection contains a board which is not modifiable."), diff --git a/src/main/java/edu/rpi/legup/history/CommandState.java b/src/main/java/edu/rpi/legup/history/CommandState.java index b7c2ff938..f47c0405d 100644 --- a/src/main/java/edu/rpi/legup/history/CommandState.java +++ b/src/main/java/edu/rpi/legup/history/CommandState.java @@ -1,7 +1,10 @@ package edu.rpi.legup.history; public enum CommandState { - CREATED("Created"), EXECUTED("Executed"), UNDOED("Undoed"), REDOED("Redoed"); + CREATED("Created"), + EXECUTED("Executed"), + UNDOED("Undoed"), + REDOED("Redoed"); private String value; diff --git a/src/main/java/edu/rpi/legup/history/DeleteTreeElementCommand.java b/src/main/java/edu/rpi/legup/history/DeleteTreeElementCommand.java index 80cad9b24..0469685c1 100644 --- a/src/main/java/edu/rpi/legup/history/DeleteTreeElementCommand.java +++ b/src/main/java/edu/rpi/legup/history/DeleteTreeElementCommand.java @@ -5,14 +5,14 @@ import edu.rpi.legup.model.observer.ITreeListener; import edu.rpi.legup.model.tree.*; import edu.rpi.legup.ui.proofeditorui.treeview.*; - import java.util.List; public class DeleteTreeElementCommand extends PuzzleCommand { private TreeViewSelection selection; /** - * DeleteTreeElementCommand Constructor creates a PuzzleCommand for deleting a tree puzzleElement + * DeleteTreeElementCommand Constructor creates a PuzzleCommand for deleting a tree + * puzzleElement * * @param selection the currently selected tree elements before the command is executed */ @@ -20,9 +20,7 @@ public DeleteTreeElementCommand(TreeViewSelection selection) { this.selection = selection.copy(); } - /** - * Executes an command - */ + /** Executes an command */ @Override public void executeCommand() { Tree tree = GameBoardFacade.getInstance().getTree(); @@ -35,8 +33,7 @@ public void executeCommand() { if (firstSelectedView.getType() == TreeElementType.NODE) { TreeNodeView nodeView = (TreeNodeView) firstSelectedView; newSelectedView = nodeView.getParentView(); - } - else { + } else { TreeTransitionView transitionView = (TreeTransitionView) firstSelectedView; newSelectedView = transitionView.getParentViews().get(0); } @@ -48,15 +45,17 @@ public void executeCommand() { } final TreeViewSelection newSelection = new TreeViewSelection(newSelectedView); - puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(newSelectedView.getTreeElement())); - puzzle.notifyTreeListeners((ITreeListener listener) -> listener.onTreeSelectionChanged(newSelection)); + puzzle.notifyBoardListeners( + listener -> listener.onTreeElementChanged(newSelectedView.getTreeElement())); + puzzle.notifyTreeListeners( + (ITreeListener listener) -> listener.onTreeSelectionChanged(newSelection)); } /** * Gets the reason why the command cannot be executed * * @return if command cannot be executed, returns reason for why the command cannot be executed, - * otherwise null if command can be executed + * otherwise null if command can be executed */ @Override public String getErrorString() { @@ -74,9 +73,7 @@ public String getErrorString() { return null; } - /** - * Undoes an command - */ + /** Undoes an command */ @Override public void undoCommand() { Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); @@ -89,8 +86,7 @@ public void undoCommand() { node.getParent().setChildNode(node); puzzle.notifyTreeListeners(listener -> listener.onTreeElementAdded(node)); - } - else { + } else { TreeTransition transition = (TreeTransition) element; transition.getParents().forEach(node -> node.addChild(transition)); transition.getParents().get(0).getChildren().forEach(TreeTransition::reverify); @@ -99,7 +95,10 @@ public void undoCommand() { } } - puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(selection.getFirstSelection().getTreeElement())); + puzzle.notifyBoardListeners( + listener -> + listener.onTreeElementChanged( + selection.getFirstSelection().getTreeElement())); puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection)); } } diff --git a/src/main/java/edu/rpi/legup/history/EditDataCommand.java b/src/main/java/edu/rpi/legup/history/EditDataCommand.java index 328cc050d..d65f03d66 100644 --- a/src/main/java/edu/rpi/legup/history/EditDataCommand.java +++ b/src/main/java/edu/rpi/legup/history/EditDataCommand.java @@ -1,5 +1,7 @@ package edu.rpi.legup.history; +import static edu.rpi.legup.app.GameBoardFacade.getInstance; + import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.PuzzleElement; @@ -8,12 +10,9 @@ import edu.rpi.legup.ui.boardview.BoardView; import edu.rpi.legup.ui.boardview.ElementView; import edu.rpi.legup.ui.proofeditorui.treeview.*; - import java.awt.event.MouseEvent; import java.util.List; -import static edu.rpi.legup.app.GameBoardFacade.getInstance; - public class EditDataCommand extends PuzzleCommand { private TreeTransition transition; private PuzzleElement savePuzzleElement; @@ -27,8 +26,8 @@ public class EditDataCommand extends PuzzleCommand { * EditDataCommand Constructor create a puzzle command for editing a board * * @param elementView currently selected puzzle puzzleElement view that is being edited - * @param selection currently selected tree puzzleElement views that is being edited - * @param event mouse event + * @param selection currently selected tree puzzleElement views that is being edited + * @param event mouse event */ public EditDataCommand(ElementView elementView, TreeViewSelection selection, MouseEvent event) { this.elementView = elementView; @@ -39,9 +38,7 @@ public EditDataCommand(ElementView elementView, TreeViewSelection selection, Mou this.transition = null; } - /** - * Executes a command - */ + /** Executes a command */ @SuppressWarnings("unchecked") @Override public void executeCommand() { @@ -69,8 +66,7 @@ public void executeCommand() { puzzleElement = board.getPuzzleElement(selectedPuzzleElement); savePuzzleElement = puzzleElement.copy(); - } - else { + } else { transition = (TreeTransition) treeElement; puzzleElement = board.getPuzzleElement(selectedPuzzleElement); savePuzzleElement = puzzleElement.copy(); @@ -82,8 +78,7 @@ public void executeCommand() { if (prevBoard.getPuzzleElement(selectedPuzzleElement).equalsData(puzzleElement)) { board.removeModifiedData(puzzleElement); - } - else { + } else { board.addModifiedData(puzzleElement); } transition.propagateChange(puzzleElement); @@ -92,7 +87,8 @@ public void executeCommand() { puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement)); puzzle.notifyBoardListeners(listener -> listener.onBoardDataChanged(puzzleElement)); - final TreeViewSelection newSelection = new TreeViewSelection(treeView.getElementView(transition)); + final TreeViewSelection newSelection = + new TreeViewSelection(treeView.getElementView(transition)); puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection)); } @@ -100,7 +96,7 @@ public void executeCommand() { * Gets the reason why the command cannot be executed * * @return if command cannot be executed, returns reason for why the command cannot be executed, - * otherwise null if command can be executed + * otherwise null if command can be executed */ @Override public String getErrorString() { @@ -116,19 +112,16 @@ public String getErrorString() { TreeNodeView nodeView = (TreeNodeView) selectedView; if (!nodeView.getChildrenViews().isEmpty()) { return CommandError.UNMODIFIABLE_BOARD.toString(); - } - else { + } else { if (!board.getPuzzleElement(selectedPuzzleElement).isModifiable()) { return CommandError.UNMODIFIABLE_DATA.toString(); } } - } - else { + } else { TreeTransitionView transitionView = (TreeTransitionView) selectedView; if (!transitionView.getTreeElement().getBoard().isModifiable()) { return CommandError.UNMODIFIABLE_BOARD.toString(); - } - else { + } else { if (!board.getPuzzleElement(selectedPuzzleElement).isModifiable()) { return CommandError.UNMODIFIABLE_DATA.toString(); } @@ -137,9 +130,7 @@ public String getErrorString() { return null; } - /** - * Undoes an command - */ + /** Undoes an command */ @SuppressWarnings("unchecked") @Override public void undoCommand() { @@ -152,7 +143,8 @@ public void undoCommand() { if (selectedView.getType() == TreeElementType.NODE) { tree.removeTreeElement(transition); - puzzle.notifyTreeListeners((ITreeListener listener) -> listener.onTreeElementRemoved(transition)); + puzzle.notifyTreeListeners( + (ITreeListener listener) -> listener.onTreeElementRemoved(transition)); } Board prevBoard = transition.getParents().get(0).getBoard(); @@ -162,8 +154,7 @@ public void undoCommand() { if (prevBoard.getPuzzleElement(selectedPuzzleElement).equalsData(puzzleElement)) { board.removeModifiedData(puzzleElement); - } - else { + } else { board.addModifiedData(puzzleElement); } transition.propagateChange(puzzleElement); diff --git a/src/main/java/edu/rpi/legup/history/History.java b/src/main/java/edu/rpi/legup/history/History.java index 77e3fae94..371284f8c 100644 --- a/src/main/java/edu/rpi/legup/history/History.java +++ b/src/main/java/edu/rpi/legup/history/History.java @@ -1,10 +1,8 @@ package edu.rpi.legup.history; import edu.rpi.legup.app.GameBoardFacade; - import java.util.ArrayList; import java.util.List; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -16,10 +14,9 @@ public class History { private int curIndex; /** - * History Constructor this holds information about changes to the board - * and Tree structure for undoing and redoing operations. Though history is - * an List, it is implemented like a stack. The curIndex points to the - * top of the stack (where the last change was made). + * History Constructor this holds information about changes to the board and Tree structure for + * undoing and redoing operations. Though history is an List, it is implemented like a stack. + * The curIndex points to the top of the stack (where the last change was made). */ public History() { history = new ArrayList<>(); @@ -27,9 +24,9 @@ public History() { } /** - * Pushes a change to the history list and increments the current index. - * If the current index does not point to the top of the stack, then at least - * 1 undo operation was called and that information will be lost by the next change + * Pushes a change to the history list and increments the current index. If the current index + * does not point to the top of the stack, then at least 1 undo operation was called and that + * information will be lost by the next change * * @param command command to be pushed onto the stack */ @@ -47,37 +44,35 @@ public void pushChange(ICommand command) { } } - /** - * Undoes an action - */ + /** Undoes an action */ public void undo() { synchronized (lock) { if (curIndex > -1) { ICommand command = history.get(curIndex--); command.undo(); LOGGER.info("Undoed " + command.getClass().getSimpleName()); - GameBoardFacade.getInstance().notifyHistoryListeners(l -> l.onUndo(curIndex < 0, curIndex == history.size() - 1)); + GameBoardFacade.getInstance() + .notifyHistoryListeners( + l -> l.onUndo(curIndex < 0, curIndex == history.size() - 1)); } } } - /** - * Redoes an action - */ + /** Redoes an action */ public void redo() { synchronized (lock) { if (curIndex < history.size() - 1) { ICommand command = history.get(++curIndex); command.redo(); LOGGER.info("Redoed " + command.getClass().getSimpleName()); - GameBoardFacade.getInstance().notifyHistoryListeners(l -> l.onRedo(curIndex < 0, curIndex == history.size() - 1)); + GameBoardFacade.getInstance() + .notifyHistoryListeners( + l -> l.onRedo(curIndex < 0, curIndex == history.size() - 1)); } } } - /** - * Clears all actions from the history stack - */ + /** Clears all actions from the history stack */ public void clear() { history.clear(); curIndex = -1; diff --git a/src/main/java/edu/rpi/legup/history/ICommand.java b/src/main/java/edu/rpi/legup/history/ICommand.java index bc82c4df5..913d9daaf 100644 --- a/src/main/java/edu/rpi/legup/history/ICommand.java +++ b/src/main/java/edu/rpi/legup/history/ICommand.java @@ -1,13 +1,12 @@ package edu.rpi.legup.history; public interface ICommand { - /** - * Executes a command - */ + /** Executes a command */ void execute(); /** * Determines whether this command can be executed + * * @return true if can execute, false otherwise */ boolean canExecute(); @@ -16,17 +15,13 @@ public interface ICommand { * Gets the reason why the command cannot be executed * * @return if command cannot be executed, returns reason for why the command cannot be executed, - * otherwise null if command can be executed + * otherwise null if command can be executed */ String getError(); - /** - * Undoes a command - */ + /** Undoes a command */ void undo(); - /** - * Redoes a command - */ + /** Redoes a command */ void redo(); -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/history/IHistoryListener.java b/src/main/java/edu/rpi/legup/history/IHistoryListener.java index 5201a09c5..f464941d6 100644 --- a/src/main/java/edu/rpi/legup/history/IHistoryListener.java +++ b/src/main/java/edu/rpi/legup/history/IHistoryListener.java @@ -12,7 +12,7 @@ public interface IHistoryListener { * Called when an action is undone * * @param isBottom true if there are no more actions to undo, false otherwise - * @param isTop true if there are no more changes to redo, false otherwise + * @param isTop true if there are no more changes to redo, false otherwise */ void onUndo(boolean isBottom, boolean isTop); @@ -20,12 +20,10 @@ public interface IHistoryListener { * Called when an action is redone * * @param isBottom true if there are no more actions to undo, false otherwise - * @param isTop true if there are no more changes to redo, false otherwise + * @param isTop true if there are no more changes to redo, false otherwise */ void onRedo(boolean isBottom, boolean isTop); - /** - * Called when the edu.rpi.legup.history is cleared - */ + /** Called when the edu.rpi.legup.history is cleared */ void onClearHistory(); } diff --git a/src/main/java/edu/rpi/legup/history/InvalidCommandStateTransition.java b/src/main/java/edu/rpi/legup/history/InvalidCommandStateTransition.java index 7e79814a6..71d072328 100644 --- a/src/main/java/edu/rpi/legup/history/InvalidCommandStateTransition.java +++ b/src/main/java/edu/rpi/legup/history/InvalidCommandStateTransition.java @@ -2,7 +2,14 @@ public class InvalidCommandStateTransition extends RuntimeException { - public InvalidCommandStateTransition(PuzzleCommand puzzleCommand, CommandState from, CommandState to) { - super("PuzzleCommand - " + puzzleCommand.getClass().getSimpleName() + " - Attempted invalid command state transition from " + from + " to " + to); + public InvalidCommandStateTransition( + PuzzleCommand puzzleCommand, CommandState from, CommandState to) { + super( + "PuzzleCommand - " + + puzzleCommand.getClass().getSimpleName() + + " - Attempted invalid command state transition from " + + from + + " to " + + to); } } diff --git a/src/main/java/edu/rpi/legup/history/MergeCommand.java b/src/main/java/edu/rpi/legup/history/MergeCommand.java index 2091ecf0a..f234a0884 100644 --- a/src/main/java/edu/rpi/legup/history/MergeCommand.java +++ b/src/main/java/edu/rpi/legup/history/MergeCommand.java @@ -6,7 +6,6 @@ import edu.rpi.legup.model.rules.MergeRule; import edu.rpi.legup.model.tree.*; import edu.rpi.legup.ui.proofeditorui.treeview.*; - import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -25,9 +24,7 @@ public MergeCommand(TreeViewSelection selection) { this.transition = null; } - /** - * Executes an command - */ + /** Executes an command */ @Override public void executeCommand() { List selectedViews = selection.getSelectedViews(); @@ -55,8 +52,7 @@ public void executeCommand() { transition.setRule(new MergeRule()); transition.setChildNode(mergedNode); mergedNode.setParent(transition); - } - else { + } else { mergedNode = transition.getChildNode(); } @@ -75,15 +71,14 @@ public void executeCommand() { puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection)); } - /** - * Undoes an command - */ + /** Undoes an command */ @Override public void undoCommand() { Tree tree = GameBoardFacade.getInstance().getTree(); Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); - TreeTransition transition = ((TreeNode) selection.getFirstSelection().getTreeElement()).getChildren().get(0); + TreeTransition transition = + ((TreeNode) selection.getFirstSelection().getTreeElement()).getChildren().get(0); tree.removeTreeElement(transition); puzzle.notifyTreeListeners(listener -> listener.onTreeElementRemoved(transition)); @@ -94,7 +89,7 @@ public void undoCommand() { * Gets the reason why the command cannot be executed * * @return if command cannot be executed, returns reason for why the command cannot be executed, - * otherwise null if command can be executed + * otherwise null if command can be executed */ @Override public String getErrorString() { @@ -112,8 +107,7 @@ public String getErrorString() { return CommandError.NO_CHILDREN.toString(); } nodeList.add(nodeView.getTreeElement()); - } - else { + } else { return CommandError.SELECTION_CONTAINS_TRANSITION.toString(); } } @@ -130,12 +124,12 @@ public String getErrorString() { } Set leafNodes = tree.getLeafTreeElements(lca); if (leafNodes.size() != mergingNodes.size()) { -// return "Unable to merge tree elements."; + // return "Unable to merge tree elements."; } for (TreeNode node : mergingNodes) { if (!leafNodes.contains(node)) { -// return "Unable to merge tree elements."; + // return "Unable to merge tree elements."; } } diff --git a/src/main/java/edu/rpi/legup/history/PuzzleCommand.java b/src/main/java/edu/rpi/legup/history/PuzzleCommand.java index 0c96b16f5..3768e3cbd 100644 --- a/src/main/java/edu/rpi/legup/history/PuzzleCommand.java +++ b/src/main/java/edu/rpi/legup/history/PuzzleCommand.java @@ -1,25 +1,18 @@ package edu.rpi.legup.history; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - public abstract class PuzzleCommand implements ICommand { private CommandState state; private boolean isCached; private String cachedError; - /** - * Puzzle Command Constructor for creating an undoable and redoable change to the model. - */ + /** Puzzle Command Constructor for creating an undoable and redoable change to the model. */ protected PuzzleCommand() { this.state = CommandState.CREATED; this.isCached = false; this.cachedError = null; } - /** - * Executes an command - */ + /** Executes an command */ @Override public final void execute() { if (canExecute()) { @@ -28,9 +21,7 @@ public final void execute() { } } - /** - * Determines whether this command can be executed - */ + /** Determines whether this command can be executed */ @Override public final boolean canExecute() { cachedError = getError(); @@ -42,14 +33,13 @@ public final boolean canExecute() { * Gets the reason why the command cannot be executed * * @return if command cannot be executed, returns reason for why the command cannot be executed, - * otherwise null if command can be executed + * otherwise null if command can be executed */ @Override public final String getError() { if (isCached) { return cachedError; - } - else { + } else { return getErrorString(); } } @@ -58,57 +48,44 @@ public final String getError() { * Gets the reason why the command cannot be executed * * @return if command cannot be executed, returns reason for why the command cannot be executed, - * otherwise null if command can be executed + * otherwise null if command can be executed */ public abstract String getErrorString(); - /** - * Executes an command - */ + /** Executes an command */ public abstract void executeCommand(); - /** - * Undoes an command - */ + /** Undoes an command */ public abstract void undoCommand(); - /** - * Redoes an command - */ + /** Redoes an command */ public void redoCommand() { if (state == CommandState.UNDOED) { executeCommand(); state = CommandState.REDOED; - } - else { + } else { throw new InvalidCommandStateTransition(this, state, CommandState.REDOED); } } - /** - * Undoes an command - */ + /** Undoes an command */ @Override public final void undo() { if (state == CommandState.EXECUTED || state == CommandState.REDOED) { undoCommand(); state = CommandState.UNDOED; - } - else { + } else { throw new InvalidCommandStateTransition(this, state, CommandState.UNDOED); } } - /** - * Redoes an command - */ + /** Redoes an command */ public final void redo() { if (state == CommandState.UNDOED) { redoCommand(); state = CommandState.REDOED; - } - else { + } else { throw new InvalidCommandStateTransition(this, state, CommandState.REDOED); } } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/history/ValidateCaseRuleCommand.java b/src/main/java/edu/rpi/legup/history/ValidateCaseRuleCommand.java index 398f17478..7737ecfd3 100644 --- a/src/main/java/edu/rpi/legup/history/ValidateCaseRuleCommand.java +++ b/src/main/java/edu/rpi/legup/history/ValidateCaseRuleCommand.java @@ -1,18 +1,17 @@ package edu.rpi.legup.history; +import static edu.rpi.legup.app.GameBoardFacade.getInstance; + import edu.rpi.legup.app.GameBoardFacade; import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.rules.CaseRule; import edu.rpi.legup.model.rules.Rule; import edu.rpi.legup.model.tree.*; import edu.rpi.legup.ui.proofeditorui.treeview.*; - import java.util.HashMap; import java.util.List; import java.util.Map; -import static edu.rpi.legup.app.GameBoardFacade.getInstance; - public class ValidateCaseRuleCommand extends PuzzleCommand { private TreeViewSelection selection; @@ -34,9 +33,7 @@ public ValidateCaseRuleCommand(TreeViewSelection selection, CaseRule caseRule) { this.addNode = new HashMap<>(); } - /** - * Executes an command - */ + /** Executes an command */ @Override public void executeCommand() { Tree tree = getInstance().getTree(); @@ -58,8 +55,7 @@ public void executeCommand() { if (childNode == null) { childNode = (TreeNode) tree.addTreeElement(transition); addNode.put(transition, childNode); - } - else { + } else { childNode = (TreeNode) tree.addTreeElement(transition, childNode); } @@ -75,8 +71,7 @@ public void executeCommand() { if (firstSelectedView.getType() == TreeElementType.NODE) { TreeNodeView nodeView = (TreeNodeView) firstSelectedView; finalTreeElement = nodeView.getChildrenViews().get(0).getTreeElement(); - } - else { + } else { TreeTransitionView transitionView = (TreeTransitionView) firstSelectedView; finalTreeElement = transitionView.getChildView().getTreeElement(); } @@ -88,7 +83,7 @@ public void executeCommand() { * Gets the reason why the command cannot be executed * * @return if command cannot be executed, returns reason for why the command cannot be executed, - * otherwise null if command can be executed + * otherwise null if command can be executed */ @Override public String getErrorString() { @@ -100,8 +95,7 @@ public String getErrorString() { for (TreeElementView view : selectedViews) { if (view.getType() == TreeElementType.NODE) { return CommandError.SELECTION_CONTAINS_NODE.toString(); - } - else { + } else { TreeTransitionView transView = (TreeTransitionView) view; if (transView.getParentViews().size() > 1) { return CommandError.CONTAINS_MERGE.toString(); @@ -111,9 +105,7 @@ public String getErrorString() { return null; } - /** - * Undoes an command - */ + /** Undoes an command */ @Override public void undoCommand() { Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); @@ -136,4 +128,4 @@ public void undoCommand() { puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement)); puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection)); } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java b/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java index 23f8dce21..8737b4008 100644 --- a/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java +++ b/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java @@ -5,7 +5,6 @@ import edu.rpi.legup.model.rules.ContradictionRule; import edu.rpi.legup.model.tree.*; import edu.rpi.legup.ui.proofeditorui.treeview.*; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -19,10 +18,11 @@ public class ValidateContradictionRuleCommand extends PuzzleCommand { private Map addTran; /** - * ValidateContradictionRuleCommand Constructor creates a puzzle command for verifying a contradiction rule + * ValidateContradictionRuleCommand Constructor creates a puzzle command for verifying a + * contradiction rule * * @param selection currently selected tree puzzleElement views - * @param rule contradiction rule to be set to all the tree elements + * @param rule contradiction rule to be set to all the tree elements */ public ValidateContradictionRuleCommand(TreeViewSelection selection, ContradictionRule rule) { this.selection = selection.copy(); @@ -31,9 +31,7 @@ public ValidateContradictionRuleCommand(TreeViewSelection selection, Contradicti this.addTran = new HashMap<>(); } - /** - * Executes a command - */ + /** Executes a command */ @Override public void executeCommand() { Tree tree = GameBoardFacade.getInstance().getTree(); @@ -48,8 +46,7 @@ public void executeCommand() { if (treeElement.getType() == TreeElementType.TRANSITION) { TreeTransition transition = (TreeTransition) treeElement; treeNode = transition.getParents().get(0); - } - else { + } else { treeNode = (TreeNode) treeElement; } @@ -58,7 +55,11 @@ public void executeCommand() { saveElements.put(treeNode, save); } - treeNode.getChildren().forEach(n -> puzzle.notifyTreeListeners(listener -> listener.onTreeElementRemoved(n))); + treeNode.getChildren() + .forEach( + n -> + puzzle.notifyTreeListeners( + listener -> listener.onTreeElementRemoved(n))); treeNode.getChildren().clear(); @@ -68,8 +69,7 @@ public void executeCommand() { transition.setRule(newRule); transition.getBoard().setModifiable(false); tree.addTreeElement(transition); - } - else { + } else { transition.getBoard().setModifiable(false); tree.addTreeElement(treeNode, transition); } @@ -85,19 +85,18 @@ public void executeCommand() { if (firstSelectedView.getType() == TreeElementType.NODE) { TreeNodeView nodeView = (TreeNodeView) firstSelectedView; finalTreeElement = nodeView.getChildrenViews().get(0).getTreeElement(); - } - else { + } else { TreeTransitionView transitionView = (TreeTransitionView) firstSelectedView; if (transitionView.getChildView() != null) { finalTreeElement = transitionView.getChildView().getTreeElement(); - } - else { + } else { finalTreeElement = null; } } if (finalTreeElement != null) { - puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement)); + puzzle.notifyBoardListeners( + listener -> listener.onTreeElementChanged(finalTreeElement)); } puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection)); } @@ -106,7 +105,7 @@ public void executeCommand() { * Gets the reason why the command cannot be executed * * @return if command cannot be executed, returns reason for why the command cannot be executed, - * otherwise null if command can be executed + * otherwise null if command can be executed */ @Override public String getErrorString() { @@ -126,9 +125,7 @@ public String getErrorString() { return null; } - /** - * Undoes a command - */ + /** Undoes a command */ @Override public void undoCommand() { Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); @@ -140,18 +137,25 @@ public void undoCommand() { if (element.getType() == TreeElementType.TRANSITION) { TreeTransition transition = (TreeTransition) element; node = transition.getParents().get(0); - } - else { + } else { node = (TreeNode) element; } - node.getChildren().forEach(n -> puzzle.notifyTreeListeners(listener -> listener.onTreeElementRemoved(n))); + node.getChildren() + .forEach( + n -> + puzzle.notifyTreeListeners( + listener -> listener.onTreeElementRemoved(n))); node.getChildren().clear(); ArrayList save = saveElements.get(node); if (save != null) { node.getChildren().addAll(save); - node.getChildren().forEach(n -> puzzle.notifyTreeListeners(listener -> listener.onTreeElementAdded(n))); + node.getChildren() + .forEach( + n -> + puzzle.notifyTreeListeners( + listener -> listener.onTreeElementAdded(n))); } } diff --git a/src/main/java/edu/rpi/legup/history/ValidateDirectRuleCommand.java b/src/main/java/edu/rpi/legup/history/ValidateDirectRuleCommand.java index 61babe883..d9c063464 100644 --- a/src/main/java/edu/rpi/legup/history/ValidateDirectRuleCommand.java +++ b/src/main/java/edu/rpi/legup/history/ValidateDirectRuleCommand.java @@ -1,152 +1,142 @@ -package edu.rpi.legup.history; - -import edu.rpi.legup.app.GameBoardFacade; -import edu.rpi.legup.model.Puzzle; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.rules.Rule; -import edu.rpi.legup.model.tree.*; -import edu.rpi.legup.ui.proofeditorui.treeview.*; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class ValidateDirectRuleCommand extends PuzzleCommand { - private TreeViewSelection selection; - - private Map oldRules; - private Map addNode; - private DirectRule newRule; - - /** - * ValidateDesireRuleCommand Constructor creates a command for verifying a basic rule - * - * @param selection selection of tree elements - * @param rule basic rule - */ - public ValidateDirectRuleCommand(TreeViewSelection selection, DirectRule rule) { - this.selection = selection.copy(); - this.newRule = rule; - this.oldRules = new HashMap<>(); - this.addNode = new HashMap<>(); - } - - /** - * Executes an command - */ - @Override - public void executeCommand() { - Tree tree = GameBoardFacade.getInstance().getTree(); - TreeView treeView = GameBoardFacade.getInstance().getLegupUI().getTreePanel().getTreeView(); - Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); - final TreeViewSelection newSelection = new TreeViewSelection(); - - List selectedViews = selection.getSelectedViews(); - for (TreeElementView selectedView : selectedViews) { - TreeElement element = selectedView.getTreeElement(); - TreeTransitionView transitionView; - if (element.getType() == TreeElementType.NODE) { - TreeNodeView nodeView = (TreeNodeView) selectedView; - transitionView = nodeView.getChildrenViews().get(0); - } - else { - transitionView = (TreeTransitionView) selectedView; - } - TreeTransition transition = transitionView.getTreeElement(); - - oldRules.put(transition, transition.getRule()); - transition.setRule(newRule); - - TreeNode childNode = transition.getChildNode(); - if (childNode == null) { - childNode = addNode.get(transition); - if (childNode == null) { - childNode = (TreeNode) tree.addTreeElement(transition); - addNode.put(transition, childNode); - } - else { - tree.addTreeElement(transition, childNode); - } - - final TreeNode finalNode = childNode; - puzzle.notifyTreeListeners(listener -> listener.onTreeElementAdded(finalNode)); - } - newSelection.addToSelection(treeView.getElementView(childNode)); - } - TreeElementView firstSelectedView = selection.getFirstSelection(); - final TreeElement finalTreeElement; - if (firstSelectedView.getType() == TreeElementType.NODE) { - TreeNodeView nodeView = (TreeNodeView) firstSelectedView; - finalTreeElement = nodeView.getChildrenViews().get(0).getTreeElement(); - } - else { - TreeTransitionView transitionView = (TreeTransitionView) firstSelectedView; - finalTreeElement = transitionView.getChildView().getTreeElement(); - } - puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement)); - puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection)); - } - - /** - * Gets the reason why the command cannot be executed - * - * @return if command cannot be executed, returns reason for why the command cannot be executed, - * otherwise null if command can be executed - */ - @Override - public String getErrorString() { - List selectedViews = selection.getSelectedViews(); - if (selectedViews.isEmpty()) { - return CommandError.NO_SELECTED_VIEWS.toString(); - } - - for (TreeElementView view : selectedViews) { - if (view.getType() == TreeElementType.NODE) { - TreeNodeView nodeView = (TreeNodeView) view; - if (nodeView.getChildrenViews().size() != 1) { - return CommandError.ONE_CHILD.toString(); - } - } - else { - TreeTransitionView transView = (TreeTransitionView) view; - if (transView.getParentViews().size() > 1) { - return CommandError.CONTAINS_MERGE.toString(); - } - } - } - return null; - } - - /** - * Undoes an command - */ - @Override - public void undoCommand() { - Tree tree = GameBoardFacade.getInstance().getTree(); - Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); - - for (TreeElementView selectedView : selection.getSelectedViews()) { - TreeElement element = selectedView.getTreeElement(); - TreeTransitionView transitionView; - if (element.getType() == TreeElementType.NODE) { - TreeNodeView nodeView = (TreeNodeView) selectedView; - transitionView = nodeView.getChildrenViews().get(0); - } - else { - transitionView = (TreeTransitionView) selectedView; - } - TreeTransition transition = transitionView.getTreeElement(); - transition.setRule(oldRules.get(transition)); - - if (addNode.get(transition) != null) { - final TreeNode childNode = transition.getChildNode(); - tree.removeTreeElement(childNode); - puzzle.notifyTreeListeners(listener -> listener.onTreeElementRemoved(childNode)); - } - } - - final TreeElement finalTreeElement = selection.getFirstSelection().getTreeElement(); - puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement)); - puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection)); - } -} +package edu.rpi.legup.history; + +import edu.rpi.legup.app.GameBoardFacade; +import edu.rpi.legup.model.Puzzle; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.rules.Rule; +import edu.rpi.legup.model.tree.*; +import edu.rpi.legup.ui.proofeditorui.treeview.*; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ValidateDirectRuleCommand extends PuzzleCommand { + private TreeViewSelection selection; + + private Map oldRules; + private Map addNode; + private DirectRule newRule; + + /** + * ValidateDesireRuleCommand Constructor creates a command for verifying a basic rule + * + * @param selection selection of tree elements + * @param rule basic rule + */ + public ValidateDirectRuleCommand(TreeViewSelection selection, DirectRule rule) { + this.selection = selection.copy(); + this.newRule = rule; + this.oldRules = new HashMap<>(); + this.addNode = new HashMap<>(); + } + + /** Executes an command */ + @Override + public void executeCommand() { + Tree tree = GameBoardFacade.getInstance().getTree(); + TreeView treeView = GameBoardFacade.getInstance().getLegupUI().getTreePanel().getTreeView(); + Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); + final TreeViewSelection newSelection = new TreeViewSelection(); + + List selectedViews = selection.getSelectedViews(); + for (TreeElementView selectedView : selectedViews) { + TreeElement element = selectedView.getTreeElement(); + TreeTransitionView transitionView; + if (element.getType() == TreeElementType.NODE) { + TreeNodeView nodeView = (TreeNodeView) selectedView; + transitionView = nodeView.getChildrenViews().get(0); + } else { + transitionView = (TreeTransitionView) selectedView; + } + TreeTransition transition = transitionView.getTreeElement(); + + oldRules.put(transition, transition.getRule()); + transition.setRule(newRule); + + TreeNode childNode = transition.getChildNode(); + if (childNode == null) { + childNode = addNode.get(transition); + if (childNode == null) { + childNode = (TreeNode) tree.addTreeElement(transition); + addNode.put(transition, childNode); + } else { + tree.addTreeElement(transition, childNode); + } + + final TreeNode finalNode = childNode; + puzzle.notifyTreeListeners(listener -> listener.onTreeElementAdded(finalNode)); + } + newSelection.addToSelection(treeView.getElementView(childNode)); + } + TreeElementView firstSelectedView = selection.getFirstSelection(); + final TreeElement finalTreeElement; + if (firstSelectedView.getType() == TreeElementType.NODE) { + TreeNodeView nodeView = (TreeNodeView) firstSelectedView; + finalTreeElement = nodeView.getChildrenViews().get(0).getTreeElement(); + } else { + TreeTransitionView transitionView = (TreeTransitionView) firstSelectedView; + finalTreeElement = transitionView.getChildView().getTreeElement(); + } + puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement)); + puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection)); + } + + /** + * Gets the reason why the command cannot be executed + * + * @return if command cannot be executed, returns reason for why the command cannot be executed, + * otherwise null if command can be executed + */ + @Override + public String getErrorString() { + List selectedViews = selection.getSelectedViews(); + if (selectedViews.isEmpty()) { + return CommandError.NO_SELECTED_VIEWS.toString(); + } + + for (TreeElementView view : selectedViews) { + if (view.getType() == TreeElementType.NODE) { + TreeNodeView nodeView = (TreeNodeView) view; + if (nodeView.getChildrenViews().size() != 1) { + return CommandError.ONE_CHILD.toString(); + } + } else { + TreeTransitionView transView = (TreeTransitionView) view; + if (transView.getParentViews().size() > 1) { + return CommandError.CONTAINS_MERGE.toString(); + } + } + } + return null; + } + + /** Undoes an command */ + @Override + public void undoCommand() { + Tree tree = GameBoardFacade.getInstance().getTree(); + Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); + + for (TreeElementView selectedView : selection.getSelectedViews()) { + TreeElement element = selectedView.getTreeElement(); + TreeTransitionView transitionView; + if (element.getType() == TreeElementType.NODE) { + TreeNodeView nodeView = (TreeNodeView) selectedView; + transitionView = nodeView.getChildrenViews().get(0); + } else { + transitionView = (TreeTransitionView) selectedView; + } + TreeTransition transition = transitionView.getTreeElement(); + transition.setRule(oldRules.get(transition)); + + if (addNode.get(transition) != null) { + final TreeNode childNode = transition.getChildNode(); + tree.removeTreeElement(childNode); + puzzle.notifyTreeListeners(listener -> listener.onTreeElementRemoved(childNode)); + } + } + + final TreeElement finalTreeElement = selection.getFirstSelection().getTreeElement(); + puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement)); + puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(selection)); + } +} diff --git a/src/main/java/edu/rpi/legup/model/Puzzle.java b/src/main/java/edu/rpi/legup/model/Puzzle.java index 18614131b..7971c95af 100644 --- a/src/main/java/edu/rpi/legup/model/Puzzle.java +++ b/src/main/java/edu/rpi/legup/model/Puzzle.java @@ -1,6 +1,7 @@ package edu.rpi.legup.model; import edu.rpi.legup.model.elements.*; +import edu.rpi.legup.model.elements.Element; import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.ElementFactory; import edu.rpi.legup.model.observer.IBoardListener; @@ -12,32 +13,27 @@ import edu.rpi.legup.model.tree.TreeElement; import edu.rpi.legup.model.tree.TreeElementType; import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.puzzle.nurikabe.NurikabeType; -import edu.rpi.legup.ui.puzzleeditorui.elementsview.NonPlaceableElementPanel; -import edu.rpi.legup.utility.LegupUtils; -import org.w3c.dom.Document; -import edu.rpi.legup.model.elements.Element; -import org.w3c.dom.Node; import edu.rpi.legup.save.InvalidFileFormatException; import edu.rpi.legup.ui.boardview.BoardView; -import org.xml.sax.SAXException; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; +import edu.rpi.legup.utility.LegupUtils; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.lang.annotation.Annotation; import java.lang.reflect.Constructor; -import java.lang.reflect.Modifier; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; - +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.xml.sax.SAXException; public abstract class Puzzle implements IBoardSubject, ITreeSubject { private static final Logger LOGGER = LogManager.getLogger(Puzzle.class.getName()); @@ -59,9 +55,7 @@ public abstract class Puzzle implements IBoardSubject, ITreeSubject { protected List placeableElements; protected List nonPlaceableElements; - /** - * Puzzle Constructor - creates a new Puzzle - */ + /** Puzzle Constructor - creates a new Puzzle */ public Puzzle() { this.boardListeners = new ArrayList<>(); this.treeListeners = new ArrayList<>(); @@ -87,7 +81,7 @@ private void registerPuzzleElements() { System.out.println("possible element: " + c.getName()); - //check that the element is not abstract + // check that the element is not abstract if (Modifier.isAbstract(c.getModifiers())) continue; for (Annotation a : c.getAnnotations()) { @@ -107,8 +101,7 @@ private void registerPuzzleElements() { default: break; } - } - catch (InvocationTargetException e) { + } catch (InvocationTargetException e) { System.out.println(" Failed "); e.getTargetException().printStackTrace(); } @@ -116,12 +109,14 @@ private void registerPuzzleElements() { } } -// } catch (IOException | ClassNotFoundException | NoSuchMethodException | -// InstantiationException | IllegalAccessException | InvocationTargetException e) { -// LOGGER.error("Unable to find rules for " + this.getClass().getSimpleName(), e); -// } - } - catch (Exception e) { + // } catch (IOException | ClassNotFoundException | NoSuchMethodException | + // InstantiationException | IllegalAccessException | + // InvocationTargetException + // e) { + // LOGGER.error("Unable to find rules for " + + // this.getClass().getSimpleName(), e); + // } + } catch (Exception e) { LOGGER.error("Unable to find elements for " + this.getClass().getSimpleName(), e); } } @@ -136,7 +131,7 @@ private void registerRules() { System.out.println("possible rule: " + c.getName()); - //check that the rule is not abstract + // check that the rule is not abstract if (Modifier.isAbstract(c.getModifiers())) continue; for (Annotation a : c.getAnnotations()) { @@ -161,8 +156,7 @@ private void registerRules() { default: break; } - } - catch (InvocationTargetException e) { + } catch (InvocationTargetException e) { System.out.println(" Failed "); e.getTargetException().printStackTrace(); } @@ -170,19 +164,19 @@ private void registerRules() { } } -// } catch (IOException | ClassNotFoundException | NoSuchMethodException | -// InstantiationException | IllegalAccessException | InvocationTargetException e) { -// LOGGER.error("Unable to find rules for " + this.getClass().getSimpleName(), e); -// } - } - catch (Exception e) { + // } catch (IOException | ClassNotFoundException | NoSuchMethodException | + // InstantiationException | IllegalAccessException | + // InvocationTargetException + // e) { + // LOGGER.error("Unable to find rules for " + + // this.getClass().getSimpleName(), e); + // } + } catch (Exception e) { LOGGER.error("Unable to find rules for " + this.getClass().getSimpleName(), e); } } - /** - * Initializes the view. Called by the invoker of the class - */ + /** Initializes the view. Called by the invoker of the class */ public abstract void initializeView(); /** @@ -196,7 +190,7 @@ private void registerRules() { /** * Checks if the given height and width are valid board dimensions for the given puzzle * - * @param rows the number of rows on the board + * @param rows the number of rows on the board * @param columns the number of columns on the board * @return true if the given dimensions are valid for the given puzzle, false otherwise */ @@ -230,13 +224,13 @@ public boolean isPuzzleComplete() { if (leaf.getType() == TreeElementType.NODE) { TreeNode node = (TreeNode) leaf; if (!node.isRoot()) { - isComplete &= node.getParent().isContradictoryBranch() || isBoardComplete(node.getBoard()); - } - else { + isComplete &= + node.getParent().isContradictoryBranch() + || isBoardComplete(node.getBoard()); + } else { isComplete &= isBoardComplete(node.getBoard()); } - } - else { + } else { isComplete = false; } } @@ -268,8 +262,7 @@ public boolean isPuzzleComplete() { public void importPuzzle(String fileName) throws InvalidFileFormatException { try { importPuzzle(new FileInputStream(fileName)); - } - catch (IOException e) { + } catch (IOException e) { LOGGER.error("Importing puzzle error", e); throw new InvalidFileFormatException("Could not find file"); } @@ -287,8 +280,7 @@ public void importPuzzle(InputStream inputStream) throws InvalidFileFormatExcept DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.parse(inputStream); - } - catch (IOException | SAXException | ParserConfigurationException e) { + } catch (IOException | SAXException | ParserConfigurationException e) { LOGGER.error("Importing puzzle error", e); throw new InvalidFileFormatException("Could not find file"); } @@ -300,8 +292,7 @@ public void importPuzzle(InputStream inputStream) throws InvalidFileFormatExcept throw new InvalidFileFormatException("Puzzle importer null"); } importer.initializePuzzle(node); - } - else { + } else { LOGGER.error("Invalid file"); throw new InvalidFileFormatException("Invalid file: must be a Legup file"); } @@ -351,7 +342,6 @@ public List getNonPlaceableElements() { return nonPlaceableElements; } - /** * Sets the list of direct rules * diff --git a/src/main/java/edu/rpi/legup/model/PuzzleExporter.java b/src/main/java/edu/rpi/legup/model/PuzzleExporter.java index 613d2ed1c..a052a736a 100644 --- a/src/main/java/edu/rpi/legup/model/PuzzleExporter.java +++ b/src/main/java/edu/rpi/legup/model/PuzzleExporter.java @@ -3,23 +3,21 @@ import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; -import org.w3c.dom.Document; import edu.rpi.legup.save.ExportFileException; - +import java.io.File; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.*; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.*; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; -import java.io.File; -import java.util.*; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.time.ZoneId; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.w3c.dom.Document; import org.w3c.dom.Element; public abstract class PuzzleExporter { @@ -60,7 +58,8 @@ public void exportPuzzle(String fileName) throws ExportFileException { legupElement.appendChild(puzzleElement); puzzleElement.appendChild(createBoardElement(newDocument)); - if (puzzle.getTree() != null && !puzzle.getTree().getRootNode().getChildren().isEmpty()) { + if (puzzle.getTree() != null + && !puzzle.getTree().getRootNode().getChildren().isEmpty()) { puzzleElement.appendChild(createProofElement(newDocument)); } @@ -84,13 +83,11 @@ public void exportPuzzle(String fileName) throws ExportFileException { StreamResult result = new StreamResult(new File(fileName)); transformer.transform(source, result); - } - catch (ParserConfigurationException | TransformerException e) { + } catch (ParserConfigurationException | TransformerException e) { throw new ExportFileException("Puzzle Exporter: parser configuration exception"); - } - catch (Exception e) { + } catch (Exception e) { throw e; - //throw new ExportFileException(e.getMessage()); + // throw new ExportFileException(e.getMessage()); } } diff --git a/src/main/java/edu/rpi/legup/model/PuzzleImporter.java b/src/main/java/edu/rpi/legup/model/PuzzleImporter.java index 327a92773..0cc163200 100644 --- a/src/main/java/edu/rpi/legup/model/PuzzleImporter.java +++ b/src/main/java/edu/rpi/legup/model/PuzzleImporter.java @@ -6,14 +6,13 @@ import edu.rpi.legup.model.rules.Rule; import edu.rpi.legup.model.tree.*; import edu.rpi.legup.save.InvalidFileFormatException; +import java.util.*; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import java.util.*; - public abstract class PuzzleImporter { private static final Logger LOGGER = LogManager.getLogger(PuzzleImporter.class.getName()); @@ -35,20 +34,20 @@ public PuzzleImporter(Puzzle puzzle) { /** * Initializes an empty puzzle * - * @param rows number of rows on the puzzle + * @param rows number of rows on the puzzle * @param columns number of columns on the puzzle * @throws RuntimeException if puzzle can not be made */ public void initializePuzzle(int rows, int columns) throws RuntimeException { if (this.puzzle.isValidDimensions(rows, columns)) { initializeBoard(rows, columns); - } - else { + } else { throw new IllegalArgumentException("Invalid dimensions provided"); } } - public void initializePuzzle(String[] statements) throws InputMismatchException, IllegalArgumentException { + public void initializePuzzle(String[] statements) + throws InputMismatchException, IllegalArgumentException { // Note: Error checking for the statements will be left up to the puzzles that support // text input. For example, some puzzles may be okay with "blank" statements (Strings with // length = 0) while others may not. @@ -72,46 +71,49 @@ public void initializePuzzle(Node node) throws InvalidFileFormatException { Node n = childNodes.item(i); if (n.getNodeName().equalsIgnoreCase("board")) { if (initBoard) { - throw new InvalidFileFormatException("Puzzle creation error: duplicate board puzzleElement found"); + throw new InvalidFileFormatException( + "Puzzle creation error: duplicate board puzzleElement found"); } initializeBoard(n); initBoard = true; - } - else { + } else { if (n.getNodeName().equalsIgnoreCase("proof")) { if (initProof) { - throw new InvalidFileFormatException("Puzzle creation error: duplicate proof puzzleElement found"); + throw new InvalidFileFormatException( + "Puzzle creation error: duplicate proof puzzleElement found"); } if (!initBoard) { - throw new InvalidFileFormatException("Puzzle creation error: could not find board puzzleElement"); + throw new InvalidFileFormatException( + "Puzzle creation error: could not find board puzzleElement"); } initializeProof(n); initProof = true; - } - else { + } else { if (!n.getNodeName().equalsIgnoreCase("#text")) { - throw new InvalidFileFormatException("Puzzle creation error: unknown node found in file"); + throw new InvalidFileFormatException( + "Puzzle creation error: unknown node found in file"); } } } } if (!initBoard) { - throw new InvalidFileFormatException("Puzzle creation error: could not find board puzzleElement"); + throw new InvalidFileFormatException( + "Puzzle creation error: could not find board puzzleElement"); } if (!initProof) { createDefaultTree(); } - } - else { - throw new InvalidFileFormatException("Invalid file format; does not contain \"puzzle\" node"); + } else { + throw new InvalidFileFormatException( + "Invalid file format; does not contain \"puzzle\" node"); } } /** * Creates the board for building * - * @param rows number of rows on the puzzle + * @param rows number of rows on the puzzle * @param columns number of columns on the puzzle * @throws RuntimeException if board can not be created */ @@ -125,7 +127,8 @@ public void initializePuzzle(Node node) throws InvalidFileFormatException { */ public abstract void initializeBoard(Node node) throws InvalidFileFormatException; - public abstract void initializeBoard(String[] statements) throws UnsupportedOperationException, IllegalArgumentException; + public abstract void initializeBoard(String[] statements) + throws UnsupportedOperationException, IllegalArgumentException; /** * Creates the proof for building @@ -143,21 +146,22 @@ public void initializeProof(Node node) throws InvalidFileFormatException { Node n = treeList.item(i); if (n.getNodeName().equalsIgnoreCase("tree")) { if (initTree) { - throw new InvalidFileFormatException("Proof Tree construction error: duplicate tree puzzleElement"); + throw new InvalidFileFormatException( + "Proof Tree construction error: duplicate tree puzzleElement"); } createTree(n); initTree = true; - } - else { - throw new InvalidFileFormatException("Proof Tree construction error: unknown puzzleElement found"); + } else { + throw new InvalidFileFormatException( + "Proof Tree construction error: unknown puzzleElement found"); } } if (!initTree) { createDefaultTree(); } - } - else { - throw new InvalidFileFormatException("Invalid file format; does not contain \"proof\" node"); + } else { + throw new InvalidFileFormatException( + "Invalid file format; does not contain \"proof\" node"); } } @@ -171,7 +175,8 @@ protected void setCells(Node node) throws InvalidFileFormatException { NodeList dataList = ((org.w3c.dom.Element) node).getElementsByTagName("cell"); Board board = puzzle.getCurrentBoard(); for (int i = 0; i < dataList.getLength(); i++) { - PuzzleElement data = puzzle.getFactory().importCell(dataList.item(i), puzzle.getCurrentBoard()); + PuzzleElement data = + puzzle.getFactory().importCell(dataList.item(i), puzzle.getCurrentBoard()); board.setPuzzleElement(data.getIndex(), data); } } @@ -199,15 +204,18 @@ protected void createTree(Node node) throws InvalidFileFormatException { String nodeId = treeNodeElement.getAttribute("id"); String isRoot = treeNodeElement.getAttribute("root"); if (nodeId.isEmpty()) { - throw new InvalidFileFormatException("Proof Tree construction error: cannot find node ID"); + throw new InvalidFileFormatException( + "Proof Tree construction error: cannot find node ID"); } if (treeNodes.containsKey(nodeId)) { - throw new InvalidFileFormatException("Proof Tree construction error: duplicate tree node ID found"); + throw new InvalidFileFormatException( + "Proof Tree construction error: duplicate tree node ID found"); } TreeNode treeNode = new TreeNode(puzzle.getCurrentBoard().copy()); if (isRoot.equalsIgnoreCase("true")) { if (tree.getRootNode() != null) { - throw new InvalidFileFormatException("Proof Tree construction error: multiple root nodes declared"); + throw new InvalidFileFormatException( + "Proof Tree construction error: multiple root nodes declared"); } treeNode.setRoot(true); tree.setRootNode(treeNode); @@ -215,7 +223,6 @@ protected void createTree(Node node) throws InvalidFileFormatException { treeNodes.put(nodeId, treeNode); } - for (int i = 0; i < nodeList.getLength(); i++) { org.w3c.dom.Element treeNodeElement = (org.w3c.dom.Element) nodeList.item(i); String nodeId = treeNodeElement.getAttribute("id"); @@ -231,11 +238,10 @@ protected void createTree(Node node) throws InvalidFileFormatException { transition.addParent(treeNode); treeNode.addChild(transition); continue; + } else { + throw new InvalidFileFormatException( + "Proof Tree construction error: duplicate transition ID found"); } - else { - throw new InvalidFileFormatException("Proof Tree construction error: duplicate transition ID found"); - } - } String childId = trans.getAttribute("child"); @@ -250,7 +256,8 @@ protected void createTree(Node node) throws InvalidFileFormatException { if (!ruleName.isEmpty()) { rule = puzzle.getRuleByID(ruleId); if (rule == null) { - throw new InvalidFileFormatException("Proof Tree construction error: could not find rule by ID"); + throw new InvalidFileFormatException( + "Proof Tree construction error: could not find rule by ID"); } transition.setRule(rule); } @@ -266,14 +273,16 @@ protected void createTree(Node node) throws InvalidFileFormatException { } } - //validateTreeStructure(treeNodes, treeTransitions); + // validateTreeStructure(treeNodes, treeTransitions); System.err.println("Tree Size: " + treeTransitions.size()); for (Map.Entry entry : nodeChanges.entrySet()) { makeTransitionChanges(entry.getKey(), entry.getValue()); } } - protected void validateTreeStructure(HashMap nodes, HashMap transitions) throws InvalidFileFormatException { + protected void validateTreeStructure( + HashMap nodes, HashMap transitions) + throws InvalidFileFormatException { Tree tree = puzzle.getTree(); if (tree == null) { @@ -300,25 +309,27 @@ protected void validateTreeStructure(HashMap nodes, HashMap nodes, HashMap mergingNodes = transition.getParents(); List mergingBoards = new ArrayList<>(); @@ -349,7 +363,8 @@ protected void makeTransitionChanges(TreeTransition transition, Node transElemen TreeNode lca = Tree.getLowestCommonAncestor(mergingNodes); if (lca == null) { - throw new InvalidFileFormatException("Proof Tree construction error: unable to find merge node"); + throw new InvalidFileFormatException( + "Proof Tree construction error: unable to find merge node"); } Board lcaBoard = lca.getBoard(); @@ -360,8 +375,7 @@ protected void makeTransitionChanges(TreeTransition transition, Node transElemen if (childNode != null) { childNode.setBoard(mergedBoard.copy()); } - } - else { + } else { NodeList cellList = transElement.getChildNodes(); for (int i = 0; i < cellList.getLength(); i++) { Node node = cellList.item(i); @@ -372,10 +386,10 @@ protected void makeTransitionChanges(TreeTransition transition, Node transElemen board.setPuzzleElement(cell.getIndex(), cell); board.addModifiedData(cell); transition.propagateChange(cell); - } - else { + } else { if (!node.getNodeName().equalsIgnoreCase("#text")) { - throw new InvalidFileFormatException("Proof Tree construction error: unknown node in transition"); + throw new InvalidFileFormatException( + "Proof Tree construction error: unknown node in transition"); } } } diff --git a/src/main/java/edu/rpi/legup/model/RegisterPuzzle.java b/src/main/java/edu/rpi/legup/model/RegisterPuzzle.java index 32f01edbc..c4c1ed273 100644 --- a/src/main/java/edu/rpi/legup/model/RegisterPuzzle.java +++ b/src/main/java/edu/rpi/legup/model/RegisterPuzzle.java @@ -7,6 +7,4 @@ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) -public @interface RegisterPuzzle { - -} +public @interface RegisterPuzzle {} diff --git a/src/main/java/edu/rpi/legup/model/elements/Element.java b/src/main/java/edu/rpi/legup/model/elements/Element.java index 7ab502c63..8b75d075d 100644 --- a/src/main/java/edu/rpi/legup/model/elements/Element.java +++ b/src/main/java/edu/rpi/legup/model/elements/Element.java @@ -1,10 +1,8 @@ package edu.rpi.legup.model.elements; -import edu.rpi.legup.model.rules.RuleType; - -import javax.swing.*; import java.awt.*; import java.awt.image.BufferedImage; +import javax.swing.*; @RegisterElement public abstract class Element { @@ -31,10 +29,11 @@ public Element(String elementID, String elementName, String description, String private void loadImage() { if (imageName != null) { this.image = new ImageIcon(ClassLoader.getSystemClassLoader().getResource(imageName)); - //Resize images to be 100px wide + // Resize images to be 100px wide Image image = this.image.getImage(); if (this.image.getIconWidth() < 120) return; - int height = (int) (100 * ((double) this.image.getIconHeight() / this.image.getIconWidth())); + int height = + (int) (100 * ((double) this.image.getIconHeight() / this.image.getIconWidth())); if (height == 0) { System.out.println("height is 0 error"); System.out.println("height: " + this.image.getIconHeight()); diff --git a/src/main/java/edu/rpi/legup/model/elements/ElementType.java b/src/main/java/edu/rpi/legup/model/elements/ElementType.java index ea47ca0eb..dff4fe04f 100644 --- a/src/main/java/edu/rpi/legup/model/elements/ElementType.java +++ b/src/main/java/edu/rpi/legup/model/elements/ElementType.java @@ -1,5 +1,6 @@ package edu.rpi.legup.model.elements; public enum ElementType { - PLACEABLE, NONPLACEABLE + PLACEABLE, + NONPLACEABLE } diff --git a/src/main/java/edu/rpi/legup/model/elements/NonPlaceableElement.java b/src/main/java/edu/rpi/legup/model/elements/NonPlaceableElement.java index 87859991f..4ab0ab509 100644 --- a/src/main/java/edu/rpi/legup/model/elements/NonPlaceableElement.java +++ b/src/main/java/edu/rpi/legup/model/elements/NonPlaceableElement.java @@ -1,7 +1,8 @@ package edu.rpi.legup.model.elements; public abstract class NonPlaceableElement extends Element { - public NonPlaceableElement(String elementID, String elementName, String description, String imageName) { + public NonPlaceableElement( + String elementID, String elementName, String description, String imageName) { super(elementID, elementName, description, imageName); this.elementType = ElementType.NONPLACEABLE; } diff --git a/src/main/java/edu/rpi/legup/model/elements/PlaceableElement.java b/src/main/java/edu/rpi/legup/model/elements/PlaceableElement.java index 2d018ddbb..133658700 100644 --- a/src/main/java/edu/rpi/legup/model/elements/PlaceableElement.java +++ b/src/main/java/edu/rpi/legup/model/elements/PlaceableElement.java @@ -1,7 +1,8 @@ package edu.rpi.legup.model.elements; public abstract class PlaceableElement extends Element { - public PlaceableElement(String elementID, String elementName, String description, String imageName) { + public PlaceableElement( + String elementID, String elementName, String description, String imageName) { super(elementID, elementName, description, imageName); this.elementType = ElementType.PLACEABLE; } diff --git a/src/main/java/edu/rpi/legup/model/elements/RegisterElement.java b/src/main/java/edu/rpi/legup/model/elements/RegisterElement.java index bda3f3070..368ecc8d1 100644 --- a/src/main/java/edu/rpi/legup/model/elements/RegisterElement.java +++ b/src/main/java/edu/rpi/legup/model/elements/RegisterElement.java @@ -6,6 +6,4 @@ @Inherited @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) -public @interface RegisterElement { - -} +public @interface RegisterElement {} diff --git a/src/main/java/edu/rpi/legup/model/gameboard/Board.java b/src/main/java/edu/rpi/legup/model/gameboard/Board.java index 4bf2ff548..d8bdf5199 100644 --- a/src/main/java/edu/rpi/legup/model/gameboard/Board.java +++ b/src/main/java/edu/rpi/legup/model/gameboard/Board.java @@ -11,9 +11,7 @@ public abstract class Board { protected Set modifiedData; protected boolean isModifiable; - /** - * Board Constructor creates an empty board. - */ + /** Board Constructor creates an empty board. */ public Board() { this.puzzleElements = new ArrayList<>(); this.modifiedData = new HashSet<>(); @@ -46,7 +44,7 @@ public PuzzleElement getPuzzleElement(PuzzleElement puzzleElement) { /** * Sets a specific {@link PuzzleElement} on the board. * - * @param index index of the puzzleElement + * @param index index of the puzzleElement * @param puzzleElement new puzzleElement at the index */ public void setPuzzleElement(int index, PuzzleElement puzzleElement) { @@ -139,8 +137,8 @@ public void removeModifiedData(PuzzleElement data) { } /** - * Called when a {@link PuzzleElement} data on this has changed and passes in the equivalent puzzle element with - * the new data. + * Called when a {@link PuzzleElement} data on this has changed and passes in the equivalent + * puzzle element with the new data. * * @param puzzleElement equivalent puzzle element with the new data. */ @@ -150,22 +148,20 @@ public void notifyChange(PuzzleElement puzzleElement) { } /** - * Called when a {@link PuzzleElement} has been added and passes in the equivalent puzzle element with the data. + * Called when a {@link PuzzleElement} has been added and passes in the equivalent puzzle + * element with the data. * * @param puzzleElement equivalent puzzle element with the data. */ - public void notifyAddition(PuzzleElement puzzleElement) { - - } + public void notifyAddition(PuzzleElement puzzleElement) {} /** - * Called when a {@link PuzzleElement} has been deleted and passes in the equivalent puzzle element with the data. + * Called when a {@link PuzzleElement} has been deleted and passes in the equivalent puzzle + * element with the data. * * @param puzzleElement equivalent puzzle element with the data. */ - public void notifyDeletion(PuzzleElement puzzleElement) { - - } + public void notifyDeletion(PuzzleElement puzzleElement) {} @SuppressWarnings("unchecked") public Board mergedBoard(Board lca, List boards) { diff --git a/src/main/java/edu/rpi/legup/model/gameboard/CaseBoard.java b/src/main/java/edu/rpi/legup/model/gameboard/CaseBoard.java index 799825025..fa3625a43 100644 --- a/src/main/java/edu/rpi/legup/model/gameboard/CaseBoard.java +++ b/src/main/java/edu/rpi/legup/model/gameboard/CaseBoard.java @@ -1,7 +1,6 @@ package edu.rpi.legup.model.gameboard; import edu.rpi.legup.model.rules.CaseRule; - import java.awt.event.MouseEvent; import java.util.HashSet; import java.util.Set; diff --git a/src/main/java/edu/rpi/legup/model/gameboard/ElementFactory.java b/src/main/java/edu/rpi/legup/model/gameboard/ElementFactory.java index 99e9bf65a..bfc785bdd 100644 --- a/src/main/java/edu/rpi/legup/model/gameboard/ElementFactory.java +++ b/src/main/java/edu/rpi/legup/model/gameboard/ElementFactory.java @@ -1,28 +1,30 @@ package edu.rpi.legup.model.gameboard; +import edu.rpi.legup.save.InvalidFileFormatException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; -import edu.rpi.legup.save.InvalidFileFormatException; public abstract class ElementFactory { /** * Creates a {@link PuzzleElement} based on the xml document Node and adds it to the board. * - * @param node node that represents the puzzleElement + * @param node node that represents the puzzleElement * @param board board to add the newly created cell * @return newly created cell from the xml document Node - * @throws InvalidFileFormatException thrown if the xml node is invalid for the specific puzzle element + * @throws InvalidFileFormatException thrown if the xml node is invalid for the specific puzzle + * element */ - public abstract PuzzleElement importCell(Node node, Board board) throws InvalidFileFormatException; + public abstract PuzzleElement importCell(Node node, Board board) + throws InvalidFileFormatException; /** * Creates a xml document {@link PuzzleElement} from a cell for exporting. * - * @param document xml document + * @param document xml document * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ public abstract Element exportCell(Document document, PuzzleElement puzzleElement); -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/model/gameboard/GridBoard.java b/src/main/java/edu/rpi/legup/model/gameboard/GridBoard.java index d31e8185a..9593690ce 100644 --- a/src/main/java/edu/rpi/legup/model/gameboard/GridBoard.java +++ b/src/main/java/edu/rpi/legup/model/gameboard/GridBoard.java @@ -1,10 +1,8 @@ package edu.rpi.legup.model.gameboard; import edu.rpi.legup.model.elements.Element; -import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; import edu.rpi.legup.puzzle.treetent.TreeTentBoard; import edu.rpi.legup.puzzle.treetent.TreeTentClue; - import java.awt.*; import java.awt.event.MouseEvent; @@ -15,7 +13,7 @@ public class GridBoard extends Board { /** * GridBoard Constructor creates a board for grid using puzzles from a width and height. * - * @param width width of the board + * @param width width of the board * @param height height of the board */ public GridBoard(int width, int height) { @@ -43,83 +41,88 @@ public GridBoard(int size) { * @return grid cell at location (x, y) */ public GridCell getCell(int x, int y) { - if (y * dimension.width + x >= puzzleElements.size() || x >= dimension.width || - y >= dimension.height || x < 0 || y < 0) { - System.err.printf("not in bounds, bounds are %dx%d\n", dimension.width, dimension.height); + if (y * dimension.width + x >= puzzleElements.size() + || x >= dimension.width + || y >= dimension.height + || x < 0 + || y < 0) { + System.err.printf( + "not in bounds, bounds are %dx%d\n", dimension.width, dimension.height); return null; } return (GridCell) puzzleElements.get(y * dimension.width + x); } /** - * Sets the {@link GridCell} at the location (x,y). This method does not set the cell if the location specified is - * out of bounds. + * Sets the {@link GridCell} at the location (x,y). This method does not set the cell if the + * location specified is out of bounds. * - * @param x x location of the cell - * @param y y location of the cell + * @param x x location of the cell + * @param y y location of the cell * @param cell grid cell to set at location (x,y) */ public void setCell(int x, int y, GridCell cell) { - if (y * dimension.width + x >= puzzleElements.size() || x >= dimension.width || - y >= dimension.height || x < 0 || y < 0) { + if (y * dimension.width + x >= puzzleElements.size() + || x >= dimension.width + || y >= dimension.height + || x < 0 + || y < 0) { return; } puzzleElements.set(y * dimension.width + x, cell); } public void setCell(int x, int y, Element e, MouseEvent m) { - if (this instanceof TreeTentBoard && ((y == dimension.height && 0 <= x && x < dimension.width) || (x == dimension.width && 0 <= y && y < dimension.height))) { + if (this instanceof TreeTentBoard + && ((y == dimension.height && 0 <= x && x < dimension.width) + || (x == dimension.width && 0 <= y && y < dimension.height))) { TreeTentBoard treeTentBoard = ((TreeTentBoard) this); TreeTentClue clue = treeTentBoard.getClue(x, y); if (y == dimension.height) { if (m.getButton() == MouseEvent.BUTTON1) { if (clue.getData() < dimension.height) { clue.setData(clue.getData() + 1); - } - else { + } else { clue.setData(0); } - } - else { + } else { if (clue.getData() > 0) { clue.setData(clue.getData() - 1); - } - else { + } else { clue.setData(dimension.height); } } - } - else { //x == dimension.width + } else { // x == dimension.width if (m.getButton() == MouseEvent.BUTTON1) { if (clue.getData() < dimension.width) { clue.setData(clue.getData() + 1); - } - else { + } else { clue.setData(0); } - } - else { + } else { if (clue.getData() > 0) { clue.setData(clue.getData() - 1); - } - else { + } else { clue.setData(dimension.width); } } } - } - else { - if (e != null && y * dimension.width + x >= puzzleElements.size() || x >= dimension.width || - y >= dimension.height || x < 0 || y < 0) { + } else { + if (e != null && y * dimension.width + x >= puzzleElements.size() + || x >= dimension.width + || y >= dimension.height + || x < 0 + || y < 0) { return; - } - else { + } else { if (e != null) { puzzleElements.get(y * dimension.width + x).setType(e, m); } } } -// puzzleElements.set(y * dimension.width + x, puzzleElements.get(y * dimension.width + x)); + // puzzleElements.set(y * dimension.width + x, puzzleElements.get(y * dimension.width + // + + // x)); } /** @@ -163,4 +166,4 @@ public GridBoard copy() { } return newGridBoard; } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/model/gameboard/GridCell.java b/src/main/java/edu/rpi/legup/model/gameboard/GridCell.java index 8209c0b6f..a33c3ec80 100644 --- a/src/main/java/edu/rpi/legup/model/gameboard/GridCell.java +++ b/src/main/java/edu/rpi/legup/model/gameboard/GridCell.java @@ -8,7 +8,7 @@ public class GridCell extends PuzzleElement { /** * GridCell Constructor creates a grid cell at the specified location given as a {@link Point} * - * @param value data value that represents the grid cell + * @param value data value that represents the grid cell * @param location location on the board */ public GridCell(T value, Point location) { @@ -20,8 +20,8 @@ public GridCell(T value, Point location) { * GridCell Constructor creates a grid cell at the specified location given as x,y pair * * @param value data value that represents the grid cell - * @param x x location - * @param y y location + * @param x x location + * @param y y location */ public GridCell(T value, int x, int y) { this(value, new Point(x, y)); @@ -59,4 +59,3 @@ public GridCell copy() { return copy; } } - diff --git a/src/main/java/edu/rpi/legup/model/gameboard/PuzzleElement.java b/src/main/java/edu/rpi/legup/model/gameboard/PuzzleElement.java index 3d84287e3..4ce030a04 100644 --- a/src/main/java/edu/rpi/legup/model/gameboard/PuzzleElement.java +++ b/src/main/java/edu/rpi/legup/model/gameboard/PuzzleElement.java @@ -1,7 +1,6 @@ package edu.rpi.legup.model.gameboard; import edu.rpi.legup.model.elements.Element; - import java.awt.event.MouseEvent; public abstract class PuzzleElement { @@ -13,9 +12,7 @@ public abstract class PuzzleElement { protected boolean isValid; protected int casesDepended; - /** - * PuzzleElement Constructor creates a new puzzle element. - */ + /** PuzzleElement Constructor creates a new puzzle element. */ public PuzzleElement() { this.index = -1; this.data = null; @@ -131,8 +128,8 @@ public void setGiven(boolean given) { } /** - * Get whether this puzzle element data is a valid change according to the rule applied to the transition that - * this puzzle element is contained in. + * Get whether this puzzle element data is a valid change according to the rule applied to the + * transition that this puzzle element is contained in. * * @return true if the puzzle element logically follows from the rule, otherwise false. */ @@ -141,8 +138,8 @@ public boolean isValid() { } /** - * Sets whether this puzzle element data is a valid change according to the rule applied to the transition that - * this puzzle element is contained in. + * Sets whether this puzzle element data is a valid change according to the rule applied to the + * transition that this puzzle element is contained in. * * @param isValid true if the puzzle element logically follows from the rule, otherwise false. */ diff --git a/src/main/java/edu/rpi/legup/model/observer/ITreeListener.java b/src/main/java/edu/rpi/legup/model/observer/ITreeListener.java index d8fa24166..d5e7fdb2d 100644 --- a/src/main/java/edu/rpi/legup/model/observer/ITreeListener.java +++ b/src/main/java/edu/rpi/legup/model/observer/ITreeListener.java @@ -25,8 +25,6 @@ public interface ITreeListener { */ void onTreeSelectionChanged(TreeViewSelection selection); - /** - * Called when the model has finished updating the tree. - */ + /** Called when the model has finished updating the tree. */ void onUpdateTree(); } 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 a01db2b6d..e87896fcc 100644 --- a/src/main/java/edu/rpi/legup/model/rules/CaseRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/CaseRule.java @@ -1,17 +1,16 @@ package edu.rpi.legup.model.rules; +import static edu.rpi.legup.model.rules.RuleType.CASE; + import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.CaseBoard; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; - import java.util.ArrayList; import java.util.List; import java.util.Set; -import static edu.rpi.legup.model.rules.RuleType.CASE; - public abstract class CaseRule extends Rule { private final String INVALID_USE_MESSAGE; @@ -19,10 +18,10 @@ public abstract class CaseRule extends Rule { /** * CaseRule Constructor creates a new case rule. * - * @param ruleID ID of the rule - * @param ruleName name of the rule + * @param ruleID ID of the rule + * @param ruleName name of the rule * @param description description of the rule - * @param imageName file name of the image + * @param imageName file name of the image */ public CaseRule(String ruleID, String ruleName, String description, String imageName) { super(ruleID, ruleName, description, imageName); @@ -31,7 +30,8 @@ public CaseRule(String ruleID, String ruleName, String description, String image } /** - * Gets the case board that indicates where this case rule can be applied on the given {@link Board}. + * Gets the case board that indicates where this case rule can be applied on the given {@link + * Board}. * * @param board board to find locations where this case rule can be applied * @return a case board @@ -39,16 +39,18 @@ public CaseRule(String ruleID, String ruleName, String description, String image public abstract CaseBoard getCaseBoard(Board board); /** - * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on this case rule. + * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on + * this case rule. * - * @param board the current board state + * @param board the current board state * @param puzzleElement equivalent puzzleElement * @return a list of elements the specified could be */ public abstract List getCases(Board board, PuzzleElement puzzleElement); /** - * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. + * Checks whether the {@link TreeTransition} logically follows from the parent node using this + * rule. * * @param transition transition to check * @return null if the child node logically follow from the parent node, otherwise error message @@ -61,7 +63,8 @@ public String checkRule(TreeTransition transition) { } for (TreeTransition childTrans : parentNodes.get(0).getChildren()) { - if (childTrans.getRule() == null || !childTrans.getRule().getClass().equals(this.getClass())) { + if (childTrans.getRule() == null + || !childTrans.getRule().getClass().equals(this.getClass())) { return "All children nodes must be justified with the same case rule."; } } @@ -81,8 +84,8 @@ public String checkRule(TreeTransition transition) { } /** - * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. This method is - * the one that should overridden in child classes. + * Checks whether the {@link TreeTransition} logically follows from the parent node using this + * rule. This method is the one that should overridden in child classes. * * @param transition transition to check * @return null if the child node logically follow from the parent node, otherwise error message @@ -91,13 +94,13 @@ public String checkRule(TreeTransition transition) { public abstract String checkRuleRaw(TreeTransition transition); /** - * Checks whether the child node logically follows from the parent node at the specific puzzleElement index using - * this rule. + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule. * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement) { @@ -105,34 +108,35 @@ public String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement } /** - * Checks whether the child node logically follows from the parent node at the specific puzzleElement index using - * this rule. This method is the one that should overridden in child classes. + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule. This method is the one that should overridden in child + * classes. * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public abstract String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement); /** - * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid - * Overridden by case rules dependent on more than just the modified data + * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be + * valid Overridden by case rules dependent on more than just the modified data * - * @param board board state at application + * @param board board state at application * @param puzzleElement selected puzzleElement - * @return List of puzzle elements (typically cells) this application of the case rule depends upon. - * Defaults to any element modified by any case + * @return List of puzzle elements (typically cells) this application of the case rule depends + * upon. Defaults to any element modified by any case */ public List dependentElements(Board board, PuzzleElement puzzleElement) { List elements = new ArrayList<>(); - List cases = getCases(board,puzzleElement); + List cases = getCases(board, puzzleElement); for (Board caseBoard : cases) { Set data = caseBoard.getModifiedData(); for (PuzzleElement element : data) { - if(!elements.contains(board.getPuzzleElement(element))){ + if (!elements.contains(board.getPuzzleElement(element))) { elements.add(board.getPuzzleElement(element)); } } @@ -141,5 +145,3 @@ public List dependentElements(Board board, PuzzleElement puzzleEl return elements; } } - - 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 0d3a79a98..b38a95fd2 100644 --- a/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/ContradictionRule.java @@ -1,22 +1,23 @@ package edu.rpi.legup.model.rules; +import static edu.rpi.legup.model.rules.RuleType.CONTRADICTION; + import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.tree.TreeTransition; -import static edu.rpi.legup.model.rules.RuleType.CONTRADICTION; - public abstract class ContradictionRule extends Rule { - private final String NO_CONTRADICTION_MESSAGE = "No instance of the contradiction " + this.ruleName + " here"; + private final String NO_CONTRADICTION_MESSAGE = + "No instance of the contradiction " + this.ruleName + " here"; /** * ContradictionRule Constructor creates a new contradiction rule * - * @param ruleID ID of the rule - * @param ruleName name of the rule + * @param ruleID ID of the rule + * @param ruleName name of the rule * @param description description of the rule - * @param imageName file name of the image + * @param imageName file name of the image */ public ContradictionRule(String ruleID, String ruleName, String description, String imageName) { super(ruleID, ruleName, description, imageName); @@ -35,13 +36,13 @@ public String checkRule(TreeTransition transition) { } /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement) { @@ -49,8 +50,8 @@ public String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement } /** - * Checks whether the transition logically follows from the parent node using this rule. - * This method is the one that should overridden in child classes + * Checks whether the transition logically follows from the parent node using this rule. This + * method is the one that should overridden in child classes * * @param transition transition to check * @return null if the child node logically follow from the parent node, otherwise error message @@ -61,14 +62,14 @@ public String checkRuleRaw(TreeTransition transition) { } /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * This method is the one that should overridden in child classes + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule This method is the one that should overridden in child + * classes * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { @@ -96,13 +97,13 @@ public String getNoContradictionMessage() { } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ public abstract String checkContradictionAt(Board board, PuzzleElement puzzleElement); - } diff --git a/src/main/java/edu/rpi/legup/model/rules/DirectRule.java b/src/main/java/edu/rpi/legup/model/rules/DirectRule.java index 304a2ca90..d550bc02c 100644 --- a/src/main/java/edu/rpi/legup/model/rules/DirectRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/DirectRule.java @@ -1,106 +1,104 @@ -package edu.rpi.legup.model.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; - -import static edu.rpi.legup.model.rules.RuleType.BASIC; - -public abstract class DirectRule extends Rule { - /** - * DirectRule Constructor creates a new basic rule. - * - * @param ruleID ID of the rule - * @param ruleName name of the rule - * @param description description of the rule - * @param imageName file name of the image - */ - public DirectRule(String ruleID, String ruleName, String description, String imageName) { - super(ruleID, ruleName, description, imageName); - this.ruleType = BASIC; - } - - /** - * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. - * - * @param transition transition to check - * @return null if the child node logically follow from the parent node, otherwise error message - */ - public String checkRule(TreeTransition transition) { - Board finalBoard = transition.getBoard(); - // System.out.println(finalBoard.getModifiedData().size()); - if (transition.getParents().size() != 1 || - transition.getParents().get(0).getChildren().size() != 1) { - return "State must have only 1 parent and 1 child"; - } - else if (finalBoard.getModifiedData().isEmpty()) { - // null transition - return null; - } - else { - return checkRuleRaw(transition); - } - } - - /** - * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. This method is - * the one that should overridden in child classes. - * - * @param transition transition to check - * @return null if the child node logically follow from the parent node, otherwise error message - */ - public String checkRuleRaw(TreeTransition transition) { - Board finalBoard = transition.getBoard(); - String checkStr = null; - - // Go directly to specific direct rule's judgement if no cell's are edited - if (finalBoard.getModifiedData().size() == 0) { - checkStr = checkRuleRawAt(transition, null); - } - for (PuzzleElement puzzleElement : finalBoard.getModifiedData()) { - String tempStr = checkRuleAt(transition, puzzleElement); - if (tempStr != null) { - checkStr = tempStr; - } - } - return checkStr; - } - - /** - * Checks whether the child node logically follows from the parent node at the specific {@link PuzzleElement} using - * this rule. - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - public String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement) { - Board finalBoard = transition.getBoard(); - puzzleElement = finalBoard.getPuzzleElement(puzzleElement); - String checkStr; - if (!puzzleElement.isModified()) { - checkStr = "PuzzleElement must be modified"; - } - else { - if (transition.getParents().size() != 1 || - transition.getParents().get(0).getChildren().size() != 1) { - checkStr = "State must have only 1 parent and 1 child"; - } - else { - checkStr = checkRuleRawAt(transition, puzzleElement); - } - } - puzzleElement.setValid(checkStr == null); - return checkStr; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - public abstract Board getDefaultBoard(TreeNode node); -} +package edu.rpi.legup.model.rules; + +import static edu.rpi.legup.model.rules.RuleType.BASIC; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; + +public abstract class DirectRule extends Rule { + /** + * DirectRule Constructor creates a new basic rule. + * + * @param ruleID ID of the rule + * @param ruleName name of the rule + * @param description description of the rule + * @param imageName file name of the image + */ + public DirectRule(String ruleID, String ruleName, String description, String imageName) { + super(ruleID, ruleName, description, imageName); + this.ruleType = BASIC; + } + + /** + * Checks whether the {@link TreeTransition} logically follows from the parent node using this + * rule. + * + * @param transition transition to check + * @return null if the child node logically follow from the parent node, otherwise error message + */ + public String checkRule(TreeTransition transition) { + Board finalBoard = transition.getBoard(); + // System.out.println(finalBoard.getModifiedData().size()); + if (transition.getParents().size() != 1 + || transition.getParents().get(0).getChildren().size() != 1) { + return "State must have only 1 parent and 1 child"; + } else if (finalBoard.getModifiedData().isEmpty()) { + // null transition + return null; + } else { + return checkRuleRaw(transition); + } + } + + /** + * Checks whether the {@link TreeTransition} logically follows from the parent node using this + * rule. This method is the one that should overridden in child classes. + * + * @param transition transition to check + * @return null if the child node logically follow from the parent node, otherwise error message + */ + public String checkRuleRaw(TreeTransition transition) { + Board finalBoard = transition.getBoard(); + String checkStr = null; + + // Go directly to specific direct rule's judgement if no cell's are edited + if (finalBoard.getModifiedData().size() == 0) { + checkStr = checkRuleRawAt(transition, null); + } + for (PuzzleElement puzzleElement : finalBoard.getModifiedData()) { + String tempStr = checkRuleAt(transition, puzzleElement); + if (tempStr != null) { + checkStr = tempStr; + } + } + return checkStr; + } + + /** + * Checks whether the child node logically follows from the parent node at the specific {@link + * PuzzleElement} using this rule. + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + public String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement) { + Board finalBoard = transition.getBoard(); + puzzleElement = finalBoard.getPuzzleElement(puzzleElement); + String checkStr; + if (!puzzleElement.isModified()) { + checkStr = "PuzzleElement must be modified"; + } else { + if (transition.getParents().size() != 1 + || transition.getParents().get(0).getChildren().size() != 1) { + checkStr = "State must have only 1 parent and 1 child"; + } else { + checkStr = checkRuleRawAt(transition, puzzleElement); + } + } + puzzleElement.setValid(checkStr == null); + return checkStr; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + public abstract Board getDefaultBoard(TreeNode node); +} diff --git a/src/main/java/edu/rpi/legup/model/rules/MergeRule.java b/src/main/java/edu/rpi/legup/model/rules/MergeRule.java index 9ae18648e..f7badcd8b 100644 --- a/src/main/java/edu/rpi/legup/model/rules/MergeRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/MergeRule.java @@ -1,33 +1,29 @@ package edu.rpi.legup.model.rules; +import static edu.rpi.legup.model.rules.RuleType.MERGE; + import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.tree.Tree; import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; - import java.util.ArrayList; import java.util.List; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import static edu.rpi.legup.model.rules.RuleType.MERGE; - public class MergeRule extends Rule { - /** - * MergeRule Constructor merges to board states together - */ + /** MergeRule Constructor merges to board states together */ public MergeRule() { - super("MERGE", "Merge Rule", + super( + "MERGE", + "Merge Rule", "Merge any number of nodes into one", "edu/rpi/legup/images/Legup/MergeRule.png"); this.ruleType = MERGE; } /** - * Checks whether the transition logically follows from the parent node using this rule. - * This method is the one that should overridden in child classes + * Checks whether the transition logically follows from the parent node using this rule. This + * method is the one that should overridden in child classes * * @param transition transition to check * @return null if the child node logically follow from the parent node, otherwise error message @@ -61,14 +57,14 @@ public String checkRuleRaw(TreeTransition transition) { } /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * This method is the one that should overridden in child classes + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule This method is the one that should overridden in child + * classes * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { @@ -87,13 +83,13 @@ public String checkRule(TreeTransition transition) { } /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/model/rules/RegisterRule.java b/src/main/java/edu/rpi/legup/model/rules/RegisterRule.java index 40def6edd..c1fe0b88c 100644 --- a/src/main/java/edu/rpi/legup/model/rules/RegisterRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/RegisterRule.java @@ -5,6 +5,4 @@ @Inherited @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) -public @interface RegisterRule { - -} +public @interface RegisterRule {} 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 50f2cf962..f70bb2889 100644 --- a/src/main/java/edu/rpi/legup/model/rules/Rule.java +++ b/src/main/java/edu/rpi/legup/model/rules/Rule.java @@ -1,17 +1,12 @@ package edu.rpi.legup.model.rules; +import edu.rpi.legup.app.LegupPreferences; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.tree.TreeTransition; - -import edu.rpi.legup.app.LegupPreferences; - -import javax.swing.ImageIcon; -import java.awt.image.BufferedImage; -import java.awt.Image; import java.awt.Graphics2D; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.awt.Image; +import java.awt.image.BufferedImage; +import javax.swing.ImageIcon; @RegisterRule public abstract class Rule { @@ -27,10 +22,10 @@ public abstract class Rule { /** * Rule Constructor creates a new rule * - * @param ruleID ID of the rule - * @param ruleName name of the rule + * @param ruleID ID of the rule + * @param ruleName name of the rule * @param description description of the rule - * @param imageName file name of the image + * @param imageName file name of the image */ public Rule(String ruleID, String ruleName, String description, String imageName) { this.ruleID = ruleID; @@ -50,8 +45,8 @@ public Rule(String ruleID, String ruleName, String description, String imageName public abstract String checkRule(TreeTransition transition); /** - * Checks whether the transition logically follows from the parent node using this rule. - * This method is the one that should overridden in child classes + * Checks whether the transition logically follows from the parent node using this rule. This + * method is the one that should overridden in child classes * * @param transition transition to check * @return null if the child node logically follow from the parent node, otherwise error message @@ -59,43 +54,44 @@ public Rule(String ruleID, String ruleName, String description, String imageName protected abstract String checkRuleRaw(TreeTransition transition); /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ public abstract String checkRuleAt(TreeTransition transition, PuzzleElement puzzleElement); /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * This method is the one that should overridden in child classes + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule This method is the one that should overridden in child + * classes * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ - protected abstract String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement); + protected abstract String checkRuleRawAt( + TreeTransition transition, PuzzleElement puzzleElement); - /** - * Loads the image file - */ + /** Loads the image file */ public void loadImage() { if (imageName != null) { String name = imageName; LegupPreferences prefs = LegupPreferences.getInstance(); - if (name.contains("shorttruthtable") && prefs.getUserPref(LegupPreferences.COLOR_BLIND).equals("true")) { + if (name.contains("shorttruthtable") + && prefs.getUserPref(LegupPreferences.COLOR_BLIND).equals("true")) { name = name.replace("ruleimages", "ruleimages_cb"); } this.image = new ImageIcon(ClassLoader.getSystemClassLoader().getResource(name)); - //Resize images to be 100px wide + // Resize images to be 100px wide Image image = this.image.getImage(); if (this.image.getIconWidth() < 120) return; - int height = (int) (100 * ((double) this.image.getIconHeight() / this.image.getIconWidth())); + int height = + (int) (100 * ((double) this.image.getIconHeight() / this.image.getIconWidth())); if (height == 0) { System.out.println("height is 0 error"); System.out.println("height: " + this.image.getIconHeight()); @@ -166,4 +162,4 @@ public RuleType getRuleType() { public String getInvalidUseOfRuleMessage() { return this.INVALID_USE_MESSAGE; } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/model/rules/RuleType.java b/src/main/java/edu/rpi/legup/model/rules/RuleType.java index b7ce315cf..06aa1844b 100644 --- a/src/main/java/edu/rpi/legup/model/rules/RuleType.java +++ b/src/main/java/edu/rpi/legup/model/rules/RuleType.java @@ -1,5 +1,8 @@ package edu.rpi.legup.model.rules; public enum RuleType { - BASIC, CASE, CONTRADICTION, MERGE + BASIC, + CASE, + CONTRADICTION, + MERGE } diff --git a/src/main/java/edu/rpi/legup/model/tree/Tree.java b/src/main/java/edu/rpi/legup/model/tree/Tree.java index 79c0bcece..a0746db87 100644 --- a/src/main/java/edu/rpi/legup/model/tree/Tree.java +++ b/src/main/java/edu/rpi/legup/model/tree/Tree.java @@ -1,7 +1,6 @@ package edu.rpi.legup.model.tree; import edu.rpi.legup.model.gameboard.Board; - import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -20,9 +19,7 @@ public Tree(Board initBoard) { this.rootNode.setRoot(true); } - /** - * Tree Constructor creates the tree structure with null root node - */ + /** Tree Constructor creates the tree structure with null root node */ public Tree() { this.rootNode = null; } @@ -44,9 +41,9 @@ public TreeNode addNode(TreeTransition transition) { public TreeElement addTreeElement(TreeElement element) { if (element.getType() == TreeElementType.NODE) { TreeNode treeNode = (TreeNode) element; - return addTreeElement(treeNode, new TreeTransition(treeNode, treeNode.getBoard().copy())); - } - else { + return addTreeElement( + treeNode, new TreeTransition(treeNode, treeNode.getBoard().copy())); + } else { TreeTransition transition = (TreeTransition) element; Board copyBoard = transition.board.copy(); copyBoard.setModifiable(false); @@ -70,8 +67,7 @@ public void removeTreeElement(TreeElement element) { if (element.getType() == TreeElementType.NODE) { TreeNode node = (TreeNode) element; node.getParent().setChildNode(null); - } - else { + } else { TreeTransition transition = (TreeTransition) element; transition.getParents().forEach(n -> n.removeChild(transition)); transition.getParents().get(0).getChildren().forEach(TreeTransition::reverify); @@ -79,8 +75,8 @@ public void removeTreeElement(TreeElement element) { } /** - * Determines if the tree is valid by checking whether this tree puzzleElement and - * all descendants of this tree puzzleElement is justified and justified correctly + * Determines if the tree is valid by checking whether this tree puzzleElement and all + * descendants of this tree puzzleElement is justified and justified correctly * * @return true if tree is valid, false otherwise */ @@ -114,7 +110,7 @@ public Set getLeafTreeElements(TreeNode node) { /** * Recursively gets a Set of TreeNodes that are leaf nodes * - * @param leafs Set of TreeNodes that are leaf nodes + * @param leafs Set of TreeNodes that are leaf nodes * @param element current TreeNode being evaluated */ private void getLeafTreeElements(Set leafs, TreeElement element) { @@ -123,41 +119,37 @@ private void getLeafTreeElements(Set leafs, TreeElement element) { List childTrans = node.getChildren(); if (childTrans.isEmpty()) { leafs.add(node); - } - else { + } else { childTrans.forEach(t -> getLeafTreeElements(leafs, t)); } - } - else { + } else { TreeTransition transition = (TreeTransition) element; TreeNode childNode = transition.getChildNode(); if (childNode == null) { leafs.add(transition); - } - else { + } else { getLeafTreeElements(leafs, childNode); } } } /** - * Gets the lowest common ancestor (LCA) among the list of {@link TreeNode} passed into - * the function. This lowest common ancestor is the most immediate ancestor - * node such that the list of tree nodes specified are descendants of the node. - * This will return null if no such ancestor exists + * Gets the lowest common ancestor (LCA) among the list of {@link TreeNode} passed into the + * function. This lowest common ancestor is the most immediate ancestor node such that the list + * of tree nodes specified are descendants of the node. This will return null if no such + * ancestor exists * * @param nodes list of tree nodes to find the LCA - * @return the first ancestor node that all tree nodes have in common, otherwise null if none exists + * @return the first ancestor node that all tree nodes have in common, otherwise null if none + * exists */ public static TreeNode getLowestCommonAncestor(List nodes) { if (nodes.isEmpty()) { return null; - } - else { + } else { if (nodes.size() == 1) { return nodes.get(0); - } - else { + } else { List> ancestors = new ArrayList<>(); for (TreeNode node : nodes) { ancestors.add(node.getAncestors()); diff --git a/src/main/java/edu/rpi/legup/model/tree/TreeElement.java b/src/main/java/edu/rpi/legup/model/tree/TreeElement.java index 17168ac98..59f75acf3 100644 --- a/src/main/java/edu/rpi/legup/model/tree/TreeElement.java +++ b/src/main/java/edu/rpi/legup/model/tree/TreeElement.java @@ -16,8 +16,8 @@ public TreeElement(TreeElementType type) { } /** - * Determines if this tree node leads to a contradiction. Every path from this tree node - * must lead to a contradiction including all of its children + * Determines if this tree node leads to a contradiction. Every path from this tree node must + * lead to a contradiction including all of its children * * @return true if this tree node leads to a contradiction, false otherwise */ @@ -28,15 +28,16 @@ public TreeElement(TreeElementType type) { * whether this tree puzzleElement and all descendants of this tree puzzleElement is justified * and justified correctly * - * @return true if this tree puzzleElement and all descendants of this tree puzzleElement is valid, - * false otherwise + * @return true if this tree puzzleElement and all descendants of this tree puzzleElement is + * valid, false otherwise */ public abstract boolean isValidBranch(); /** * Gets the type of tree puzzleElement * - * @return NODE if this tree puzzleElement is a tree node, TRANSITION, if this tree puzzleElement is a transition + * @return NODE if this tree puzzleElement is a tree node, TRANSITION, if this tree + * puzzleElement is a transition */ public TreeElementType getType() { return type; diff --git a/src/main/java/edu/rpi/legup/model/tree/TreeElementType.java b/src/main/java/edu/rpi/legup/model/tree/TreeElementType.java index ad93f16b6..67437a535 100644 --- a/src/main/java/edu/rpi/legup/model/tree/TreeElementType.java +++ b/src/main/java/edu/rpi/legup/model/tree/TreeElementType.java @@ -1,5 +1,6 @@ package edu.rpi.legup.model.tree; public enum TreeElementType { - NODE, TRANSITION + NODE, + TRANSITION } diff --git a/src/main/java/edu/rpi/legup/model/tree/TreeNode.java b/src/main/java/edu/rpi/legup/model/tree/TreeNode.java index 59f6e736e..a2ac7cb21 100644 --- a/src/main/java/edu/rpi/legup/model/tree/TreeNode.java +++ b/src/main/java/edu/rpi/legup/model/tree/TreeNode.java @@ -2,7 +2,6 @@ import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.utility.DisjointSets; - import java.util.*; public class TreeNode extends TreeElement { @@ -24,8 +23,8 @@ public TreeNode(Board board) { } /** - * Determines if this tree node leads to a contradiction. Every path from this tree node - * must lead to a contradiction including all of its children + * Determines if this tree node leads to a contradiction. Every path from this tree node must + * lead to a contradiction including all of its children * * @return true if this tree node leads to a contradiction, false otherwise */ @@ -43,8 +42,8 @@ public boolean isContradictoryBranch() { * whether this tree puzzleElement and all descendants of this tree puzzleElement is justified * and justified correctly * - * @return true if this tree puzzleElement and all descendants of this tree puzzleElement is valid, - * false otherwise + * @return true if this tree puzzleElement and all descendants of this tree puzzleElement is + * valid, false otherwise */ @Override public boolean isValidBranch() { @@ -104,8 +103,7 @@ public List getDescendants() { it.add(transition); } } - } - else { + } else { TreeTransition trans = (TreeTransition) next; TreeNode childNode = trans.getChildNode(); if (childNode != null && !descendants.contains(childNode)) { @@ -118,9 +116,9 @@ public List getDescendants() { } /** - * Gets a DisjointSets containing the children of this node such that the sets contained within the DisjointSets - * are such that elements in the same set are branches of this tree node that will eventually merge. This could - * mean that multiple merges take place before this happens. + * Gets a DisjointSets containing the children of this node such that the sets contained within + * the DisjointSets are such that elements in the same set are branches of this tree node that + * will eventually merge. This could mean that multiple merges take place before this happens. * * @return DisjointSets of tree transitions containing unique non-merging branches */ @@ -143,8 +141,7 @@ public DisjointSets findMergingBranches() { if (element.getType() == TreeElementType.NODE) { TreeNode node = (TreeNode) element; nodes.addAll(node.getChildren()); - } - else { + } else { TreeTransition childTran = (TreeTransition) element; if (childTran.getChildNode() != null) { nodes.add(childTran.getChildNode()); @@ -169,8 +166,8 @@ public DisjointSets findMergingBranches() { } /** - * Finds the point at which the set of tree elements passed in will merge. This must be a set gotten from - * findMergingBranches method DisjointSets + * Finds the point at which the set of tree elements passed in will merge. This must be a set + * gotten from findMergingBranches method DisjointSets * * @param branches tree elements to find the merging point * @return tree transition of the merging point or null if no such point exists @@ -186,14 +183,15 @@ public static TreeTransition findMergingPoint(Set branche mergeSet.createSet(element); if (element.getType() == TreeElementType.NODE) { TreeNode node = (TreeNode) element; - node.getDescendants().forEach((TreeElement e) -> { - if (!mergeSet.contains(e)) { - mergeSet.createSet(e); - } - mergeSet.union(element, e); - }); - } - else { + node.getDescendants() + .forEach( + (TreeElement e) -> { + if (!mergeSet.contains(e)) { + mergeSet.createSet(e); + } + mergeSet.union(element, e); + }); + } else { TreeTransition transition = (TreeTransition) element; TreeNode childNode = transition.getChildNode(); if (childNode != null) { @@ -228,8 +226,7 @@ public static TreeTransition findMergingPoint(Set branche if (element.getType() == TreeElementType.NODE) { TreeNode node = (TreeNode) element; next.addAll(node.getChildren()); - } - else { + } else { TreeTransition tran = (TreeTransition) element; next.add(tran.getChildNode()); } @@ -332,5 +329,4 @@ public void setRoot(boolean isRoot) { public void clearChildren() { this.children.clear(); } - -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java b/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java index 72572ac72..e79cd4b96 100644 --- a/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java +++ b/src/main/java/edu/rpi/legup/model/tree/TreeTransition.java @@ -5,7 +5,6 @@ import edu.rpi.legup.model.rules.CaseRule; import edu.rpi.legup.model.rules.Rule; import edu.rpi.legup.model.rules.RuleType; - import java.util.ArrayList; import java.util.List; @@ -38,7 +37,7 @@ public TreeTransition(Board board) { * TreeTransition Constructor - create a transition from one node to another * * @param parent parent tree node associated with the transition - * @param board board state of the transition + * @param board board state of the transition */ public TreeTransition(TreeNode parent, Board board) { this(board); @@ -71,8 +70,7 @@ public void propagateChange(PuzzleElement element) { board.removeModifiedData(element); board.notifyChange(element); changed = true; - } - else { + } else { if (!lcaElement.equalsData(element)) { mergedData.setData(element.getData()); board.addModifiedData(mergedData); @@ -89,8 +87,7 @@ public void propagateChange(PuzzleElement element) { } } } - } - else { + } else { // Overwrite previous modifications to this element board.removeModifiedData(board.getPuzzleElement(element)); @@ -98,7 +95,8 @@ public void propagateChange(PuzzleElement element) { board.notifyChange(element); // mark first transition as modified - if (!board.getPuzzleElement(element).equalsData(parents.get(0).getBoard().getPuzzleElement(element))) { + if (!board.getPuzzleElement(element) + .equalsData(parents.get(0).getBoard().getPuzzleElement(element))) { board.addModifiedData(element); } @@ -116,8 +114,7 @@ public void propagateChange(PuzzleElement element) { // Set as modifiable if reverted to starting value (and started modifiable) if (headBoard.getPuzzleElement(element).equalsData(element)) { copy.setModifiable(headBoard.getPuzzleElement(element).isModifiable()); - } - else{ + } else { copy.setModifiable(false); } @@ -159,8 +156,7 @@ public void propagateAddition(PuzzleElement element) { board.removeModifiedData(element); board.notifyDeletion(element); changed = true; - } - else { + } else { if (!lcaElement.equalsData(element)) { mergedData.setData(element.getData()); board.addModifiedData(mergedData); @@ -175,8 +171,7 @@ public void propagateAddition(PuzzleElement element) { } } } - } - else { + } else { if (childNode != null) { board.notifyAddition(element); childNode.getBoard().notifyAddition(element.copy()); @@ -214,8 +209,7 @@ public void propagateDeletion(PuzzleElement element) { board.removeModifiedData(element); board.notifyDeletion(element); changed = true; - } - else { + } else { if (!lcaElement.equalsData(element)) { mergedData.setData(element.getData()); board.addModifiedData(mergedData); @@ -230,8 +224,7 @@ public void propagateDeletion(PuzzleElement element) { } } } - } - else { + } else { if (childNode != null) { board.notifyDeletion(element); childNode.getBoard().notifyDeletion(element.copy()); @@ -244,8 +237,8 @@ public void propagateDeletion(PuzzleElement element) { } /** - * Determines if this tree node leads to a contradiction. Every path from this tree node - * must lead to a contradiction including all of its children + * Determines if this tree node leads to a contradiction. Every path from this tree node must + * lead to a contradiction including all of its children * * @return true if this tree node leads to a contradiction, false otherwise */ @@ -253,12 +246,10 @@ public void propagateDeletion(PuzzleElement element) { public boolean isContradictoryBranch() { if (isJustified() && isCorrect() && rule.getRuleType() == RuleType.CONTRADICTION) { return true; - } - else { + } else { if (childNode == null) { return false; - } - else { + } else { return childNode.isContradictoryBranch() && isJustified() && isCorrect(); } } @@ -269,8 +260,8 @@ public boolean isContradictoryBranch() { * whether this tree puzzleElement and all descendants of this tree puzzleElement is justified * and justified correctly * - * @return true if this tree puzzleElement and all descendants of this tree puzzleElement is valid, - * false otherwise + * @return true if this tree puzzleElement and all descendants of this tree puzzleElement is + * valid, false otherwise */ @Override public boolean isValidBranch() { diff --git a/src/main/java/edu/rpi/legup/puzzle/PuzzleElementTypes.java b/src/main/java/edu/rpi/legup/puzzle/PuzzleElementTypes.java index f2ddb056c..f0dd5a6e9 100644 --- a/src/main/java/edu/rpi/legup/puzzle/PuzzleElementTypes.java +++ b/src/main/java/edu/rpi/legup/puzzle/PuzzleElementTypes.java @@ -1,4 +1,3 @@ package edu.rpi.legup.puzzle; -public enum PuzzleElementTypes { -} +public enum PuzzleElementTypes {} diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/Battleship.java b/src/main/java/edu/rpi/legup/puzzle/battleship/Battleship.java index 22a980251..41af3f626 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/Battleship.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/Battleship.java @@ -17,9 +17,7 @@ public Battleship() { this.factory = new BattleshipCellFactory(); } - /** - * Initializes the game board. Called by the invoker of the class - */ + /** Initializes the game board. Called by the invoker of the class */ @Override public void initializeView() { boardView = new BattleshipView((BattleshipBoard) currentBoard); @@ -35,8 +33,8 @@ public Board generatePuzzle(int difficulty) { /** * Determines if the given dimensions are valid for Battleship * - * @param rows the number of rows - * @param columns the number of columns + * @param rows the number of rows + * @param columns the number of columns * @return true if the given dimensions are valid for Battleship, false otherwise */ public boolean isValidDimensions(int rows, int columns) { @@ -74,84 +72,98 @@ public boolean isBoardComplete(Board board) { * @param board the board that has changed */ @Override - public void onBoardChange(Board board) { + public void onBoardChange(Board board) {} - } -// -// @Override -// public void onTreeSelectionChange(ArrayList newSelection) -// { -// -// } + // + // @Override + // public void onTreeSelectionChange(ArrayList newSelection) + // { + // + // } @Override public void importPuzzle(String fileName) { -// if(fileName != null) -// { -// InputStream inputStream = new FileInputStream(fileName); -// DocumentBuilder builder = null;//factory.newDocumentBuilder(); -// Document document = builder.parse(inputStream); -// -// BattleShipBoard battleShipBoard; -// -// PuzzleElement rootNode = document.getDocumentElement(); -// PuzzleElement puzzleElement = (PuzzleElement) rootNode.getElementsByTagName("edu.rpi.legup.puzzle").item(0); -// PuzzleElement boardElement = (PuzzleElement) puzzleElement.getElementsByTagName("board").item(0); -// PuzzleElement axesElement = (PuzzleElement) boardElement.getElementsByTagName("axes").item(0); -// PuzzleElement shipElement = (PuzzleElement) boardElement.getElementsByTagName("ships").item(0); -// PuzzleElement cellElement = (PuzzleElement) boardElement.getElementsByTagName("cells").item(0); -// PuzzleElement rightElement = (PuzzleElement) axesElement.getElementsByTagName("right").item(0); -// PuzzleElement bottomElement = (PuzzleElement) axesElement.getElementsByTagName("bottom").item(0); -// NodeList rightClueList = rightElement.getElementsByTagName("clue"); -// NodeList bottomClueList = bottomElement.getElementsByTagName("clue"); -// NodeList shipList = shipElement.getElementsByTagName("ship"); -// NodeList cells = cellElement.getElementsByTagName("cell"); -// -// int size = Integer.valueOf(boardElement.getAttribute("size")); -// battleShipBoard = new BattleShipBoard(size); -// -// ArrayList battleShipData = new ArrayList<>(); -// for(int i = 0; i < size * size; i++) -// { -// battleShipData.add(null); -// } -// -// for (int i = 0; i < rightClueList.getLength(); i++) { -// battleShipBoard.getRight()[i] = Integer.valueOf(rightClueList.item(i).getAttributes().getNamedItem("value").getNodeValue()); -// } -// -// for (int i = 0; i < bottomClueList.getLength(); i++) { -// battleShipBoard.getBottom()[i] = Integer.valueOf(bottomClueList.item(i).getAttributes().getNamedItem("value").getNodeValue()); -// } -// -// for (int i = 0; i < shipList.getLength(); i++) { -// int length = Integer.valueOf(shipList.item(i).getAttributes().getNamedItem("length").getNodeValue()); -// int count = Integer.valueOf(shipList.item(i).getAttributes().getNamedItem("count").getNodeValue()); -// battleShipBoard.getShips().add(new Ship(length, count)); -// } -// -// for (int i = 0; i < cells.getLength(); i++) { -// int x = Integer.valueOf(cells.item(i).getAttributes().getNamedItem("x").getNodeValue()); -// int y = Integer.valueOf(cells.item(i).getAttributes().getNamedItem("y").getNodeValue()); -// String value = cells.item(i).getAttributes().getNamedItem("value").getNodeValue().toUpperCase(); -// -// BattleShipCell cell = new BattleShipCell(BattleShipType.valueOf(value).ordinal(), new Point(x, y)); -// battleShipBoard.setCell(x, y, cell); -// cell.setModifiable(false); -// cell.setGiven(true); -// } -// -// for (int x = 0; x < size; x++) { -// for (int y = 0; y < size; y++) { -// if (battleShipBoard.getCell(x, y) == null) { -// BattleShipCell cell = new BattleShipCell(9, new Point(x, y)); -// cell.setModifiable(true); -// battleShipBoard.setCell(x, y, cell); -// } -// } -// } -// this.currentBoard = battleShipBoard; -// this.tree = new Tree(currentBoard); -// } + // if(fileName != null) + // { + // InputStream inputStream = new FileInputStream(fileName); + // DocumentBuilder builder = null;//factory.newDocumentBuilder(); + // Document document = builder.parse(inputStream); + // + // BattleShipBoard battleShipBoard; + // + // PuzzleElement rootNode = document.getDocumentElement(); + // PuzzleElement puzzleElement = (PuzzleElement) + // rootNode.getElementsByTagName("edu.rpi.legup.puzzle").item(0); + // PuzzleElement boardElement = (PuzzleElement) + // puzzleElement.getElementsByTagName("board").item(0); + // PuzzleElement axesElement = (PuzzleElement) + // boardElement.getElementsByTagName("axes").item(0); + // PuzzleElement shipElement = (PuzzleElement) + // boardElement.getElementsByTagName("ships").item(0); + // PuzzleElement cellElement = (PuzzleElement) + // boardElement.getElementsByTagName("cells").item(0); + // PuzzleElement rightElement = (PuzzleElement) + // axesElement.getElementsByTagName("right").item(0); + // PuzzleElement bottomElement = (PuzzleElement) + // axesElement.getElementsByTagName("bottom").item(0); + // NodeList rightClueList = rightElement.getElementsByTagName("clue"); + // NodeList bottomClueList = bottomElement.getElementsByTagName("clue"); + // NodeList shipList = shipElement.getElementsByTagName("ship"); + // NodeList cells = cellElement.getElementsByTagName("cell"); + // + // int size = Integer.valueOf(boardElement.getAttribute("size")); + // battleShipBoard = new BattleShipBoard(size); + // + // ArrayList battleShipData = new ArrayList<>(); + // for(int i = 0; i < size * size; i++) + // { + // battleShipData.add(null); + // } + // + // for (int i = 0; i < rightClueList.getLength(); i++) { + // battleShipBoard.getRight()[i] = + // Integer.valueOf(rightClueList.item(i).getAttributes().getNamedItem("value").getNodeValue()); + // } + // + // for (int i = 0; i < bottomClueList.getLength(); i++) { + // battleShipBoard.getBottom()[i] = + // Integer.valueOf(bottomClueList.item(i).getAttributes().getNamedItem("value").getNodeValue()); + // } + // + // for (int i = 0; i < shipList.getLength(); i++) { + // int length = + // Integer.valueOf(shipList.item(i).getAttributes().getNamedItem("length").getNodeValue()); + // int count = + // Integer.valueOf(shipList.item(i).getAttributes().getNamedItem("count").getNodeValue()); + // battleShipBoard.getShips().add(new Ship(length, count)); + // } + // + // for (int i = 0; i < cells.getLength(); i++) { + // int x = + // Integer.valueOf(cells.item(i).getAttributes().getNamedItem("x").getNodeValue()); + // int y = + // Integer.valueOf(cells.item(i).getAttributes().getNamedItem("y").getNodeValue()); + // String value = + // cells.item(i).getAttributes().getNamedItem("value").getNodeValue().toUpperCase(); + // + // BattleShipCell cell = new + // BattleShipCell(BattleShipType.valueOf(value).ordinal(), new Point(x, y)); + // battleShipBoard.setCell(x, y, cell); + // cell.setModifiable(false); + // cell.setGiven(true); + // } + // + // for (int x = 0; x < size; x++) { + // for (int y = 0; y < size; y++) { + // if (battleShipBoard.getCell(x, y) == null) { + // BattleShipCell cell = new BattleShipCell(9, new Point(x, y)); + // cell.setModifiable(true); + // battleShipBoard.setCell(x, y, cell); + // } + // } + // } + // this.currentBoard = battleShipBoard; + // this.tree = new Tree(currentBoard); + // } } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipBoard.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipBoard.java index 5965f7055..555c8471f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipBoard.java @@ -2,7 +2,6 @@ import edu.rpi.legup.model.gameboard.GridBoard; import edu.rpi.legup.model.gameboard.PuzzleElement; - import java.awt.*; import java.util.ArrayList; import java.util.List; @@ -15,7 +14,7 @@ public class BattleshipBoard extends GridBoard { /** * Constructor for creating a rectangular battleship board. * - * @param width width of the board + * @param width width of the board * @param height height of the board */ public BattleshipBoard(int width, int height) { @@ -44,8 +43,7 @@ public BattleshipBoard(int size) { /** * Gets the east {@link BattleshipClue} * - * @return List of BattleShipClue objects on the east - * side of the board + * @return List of BattleShipClue objects on the east side of the board */ public List getEast() { return east; @@ -90,8 +88,7 @@ public BattleshipBoard copy() { * Get a list of all orthogonally adjacent cells. * * @param cell The cell to get adjacent cells from. - * @return List of adjacent cells in clockwise order: - * { up, right, down, left } + * @return List of adjacent cells in clockwise order: { up, right, down, left } */ public List getAdjOrthogonals(BattleshipCell cell) { List adj = new ArrayList<>(); @@ -111,8 +108,8 @@ public List getAdjOrthogonals(BattleshipCell cell) { * Get a list of all diagonally adjacent cells. * * @param cell The cell to get diagonally adjacent cells from. - * @return List of diagonally adjacent cells in clockwise order: - * { upRight, downRight, downLeft, upLeft } + * @return List of diagonally adjacent cells in clockwise order: + * { upRight, downRight, downLeft, upLeft } */ public List getAdjDiagonals(BattleshipCell cell) { List dia = new ArrayList<>(); @@ -155,4 +152,4 @@ public List getColumn(int x) { } return column; } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCell.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCell.java index 5f2c5b975..5a5b86094 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCell.java @@ -1,7 +1,6 @@ package edu.rpi.legup.puzzle.battleship; import edu.rpi.legup.model.gameboard.GridCell; - import java.awt.*; public class BattleshipCell extends GridCell { @@ -9,7 +8,7 @@ public class BattleshipCell extends GridCell { /** * BattleShipCell Constructor - creates a BattleShipCell from the specified value and location * - * @param value value of the BattleShipCell + * @param value value of the BattleShipCell * @param location position of the BattleShipCell */ public BattleshipCell(BattleshipType value, Point location) { diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellController.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellController.java index 89b5fa19a..9db0cca84 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellController.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellController.java @@ -2,39 +2,39 @@ import edu.rpi.legup.controller.ElementController; import edu.rpi.legup.model.gameboard.PuzzleElement; - import java.awt.event.MouseEvent; public class BattleshipCellController extends ElementController { /** - * Controller class for the Battleship puzzle - - * receives user mouse input and changes what's shown on the GUI + * Controller class for the Battleship puzzle - receives user mouse input and changes what's + * shown on the GUI * * @param data the PuzzleElement to be changed - * @param e the user mouse input + * @param e the user mouse input */ @Override public void changeCell(MouseEvent e, PuzzleElement data) { BattleshipCell cell = (BattleshipCell) data; if (e.getButton() == MouseEvent.BUTTON1) { if (e.isControlDown()) { - this.boardView.getSelectionPopupMenu().show(boardView, this.boardView.getCanvas().getX() + e.getX(), this.boardView.getCanvas().getY() + e.getY()); - } - else { + this.boardView + .getSelectionPopupMenu() + .show( + boardView, + this.boardView.getCanvas().getX() + e.getX(), + this.boardView.getCanvas().getY() + e.getY()); + } else { if (cell.getData() == BattleshipType.SHIP_MIDDLE) { cell.setData(BattleshipType.UNKNOWN); - } - else { + } else { cell.setData(BattleshipType.getType(cell.getData().value + 1)); } } - } - else { + } else { if (e.getButton() == MouseEvent.BUTTON3) { if (cell.getData() == BattleshipType.UNKNOWN) { cell.setData(BattleshipType.SHIP_MIDDLE); - } - else { + } else { cell.setData(BattleshipType.getType(cell.getData().value - 1)); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellFactory.java index 81629c360..1b3b6c427 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellFactory.java @@ -4,23 +4,23 @@ import edu.rpi.legup.model.gameboard.ElementFactory; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; -import java.awt.*; - public class BattleshipCellFactory extends ElementFactory { /** * Creates a puzzleElement based on the xml document Node and adds it to the board * - * @param node node that represents the puzzleElement + * @param node node that represents the puzzleElement * @param board board to add the newly created cell * @return newly created cell from the xml document Node * @throws InvalidFileFormatException if file is invalid */ @Override - public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormatException { + public PuzzleElement importCell(Node node, Board board) + throws InvalidFileFormatException { try { BattleshipBoard battleShipBoard = (BattleshipBoard) board; int width = battleShipBoard.getWidth(); @@ -32,24 +32,25 @@ public PuzzleElement importCell(Node node, Board board) throws I int x = Integer.parseInt(attributeList.getNamedItem("x").getNodeValue()); int y = Integer.parseInt(attributeList.getNamedItem("y").getNodeValue()); if (x >= width || y >= height) { - throw new InvalidFileFormatException("BattleShip Factory: cell location out of bounds"); + throw new InvalidFileFormatException( + "BattleShip Factory: cell location out of bounds"); } if (value < 0 || value > 3) { throw new InvalidFileFormatException("BattleShip Factory: cell unknown value"); } - BattleshipCell cell = new BattleshipCell(BattleshipType.getType(value), new Point(x, y)); + BattleshipCell cell = + new BattleshipCell(BattleshipType.getType(value), new Point(x, y)); cell.setIndex(y * height + x); return cell; + } else { + throw new InvalidFileFormatException( + "BattleShip Factory: unknown puzzleElement puzzleElement"); } - else { - throw new InvalidFileFormatException("BattleShip Factory: unknown puzzleElement puzzleElement"); - } - } - catch (NumberFormatException e) { - throw new InvalidFileFormatException("BattleShip Factory: unknown value where integer expected"); - } - catch (NullPointerException e) { + } catch (NumberFormatException e) { + throw new InvalidFileFormatException( + "BattleShip Factory: unknown value where integer expected"); + } catch (NullPointerException e) { throw new InvalidFileFormatException("BattleShip Factory: could not find attribute(s)"); } } @@ -57,7 +58,7 @@ public PuzzleElement importCell(Node node, Board board) throws I /** * Creates a xml document puzzleElement from a cell for exporting * - * @param document xml document + * @param document xml document * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipClueView.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipClueView.java index 6a29eb7a3..788c860f3 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipClueView.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipClueView.java @@ -1,7 +1,6 @@ package edu.rpi.legup.puzzle.battleship; import edu.rpi.legup.ui.boardview.ElementView; - import java.awt.*; public class BattleshipClueView extends ElementView { @@ -26,6 +25,7 @@ public BattleshipClue getPuzzleElement() { @Override /** * Draws the clue from the PuzzleElement associated with this view on the given frame + * * @param graphics2D the frame the clue is to be drawn on */ public void draw(Graphics2D graphics2D) { diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipElementView.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipElementView.java index d66f159d7..1898468ce 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipElementView.java @@ -1,7 +1,6 @@ package edu.rpi.legup.puzzle.battleship; import edu.rpi.legup.ui.boardview.GridElementView; - import java.awt.*; public class BattleshipElementView extends GridElementView { @@ -22,6 +21,7 @@ public BattleshipElementView(BattleshipCell cell) { @Override /** * Draws on the given frame based on the type of the cell of the current puzzleElement + * * @param graphics2D the frame to be drawn on */ public void drawElement(Graphics2D graphics2D) { @@ -39,37 +39,60 @@ public void drawElement(Graphics2D graphics2D) { break; case SHIP_UNKNOWN: graphics2D.setColor(SHIP_COLOR); - graphics2D.fillRect(location.x + 3 * size.width / 8, location.y + 3 * size.height / 8, - size.width / 4, size.height / 4); + graphics2D.fillRect( + location.x + 3 * size.width / 8, + location.y + 3 * size.height / 8, + size.width / 4, + size.height / 4); graphics2D.setColor(FONT_COLOR); graphics2D.setFont(FONT); FontMetrics metrics = graphics2D.getFontMetrics(FONT); String value = "?"; int xText = location.x + (size.width - metrics.stringWidth(value)) / 2; - int yText = location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent(); + int yText = + location.y + + ((size.height - metrics.getHeight()) / 2) + + metrics.getAscent(); graphics2D.drawString(value, xText, yText); break; case SUBMARINE: graphics2D.setColor(SHIP_COLOR); - graphics2D.fillOval(location.x + size.width / 4, location.y + size.width / 4, - size.width / 2, size.height / 2); + graphics2D.fillOval( + location.x + size.width / 4, + location.y + size.width / 4, + size.width / 2, + size.height / 2); break; case SHIP_TOP: graphics2D.setColor(SHIP_COLOR); - graphics2D.fillArc(location.x, location.y - size.height / 2, size.width, size.height, 180, 180); + graphics2D.fillArc( + location.x, + location.y - size.height / 2, + size.width, + size.height, + 180, + 180); break; case SHIP_RIGHT: graphics2D.setColor(SHIP_COLOR); - graphics2D.fillArc(location.x + size.height / 2, location.y, size.width, size.height, 90, 180); + graphics2D.fillArc( + location.x + size.height / 2, location.y, size.width, size.height, 90, 180); break; case SHIP_BOTTOM: graphics2D.setColor(SHIP_COLOR); - graphics2D.fillArc(location.x, location.y + size.height / 2, size.width, size.height, 0, 180); + graphics2D.fillArc( + location.x, location.y + size.height / 2, size.width, size.height, 0, 180); break; case SHIP_LEFT: graphics2D.setColor(SHIP_COLOR); - graphics2D.fillArc(location.x - size.height / 2, location.y, size.width, size.height, 270, 180); + graphics2D.fillArc( + location.x - size.height / 2, + location.y, + size.width, + size.height, + 270, + 180); break; case SHIP_MIDDLE: graphics2D.setColor(SHIP_COLOR); @@ -84,4 +107,4 @@ public void drawElement(Graphics2D graphics2D) { graphics2D.setStroke(OUTLINE_STROKE); graphics2D.drawRect(location.x, location.y, size.width, size.height); } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipExporter.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipExporter.java index 4205d0125..cbc364842 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipExporter.java @@ -2,7 +2,6 @@ import edu.rpi.legup.model.PuzzleExporter; import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; import org.w3c.dom.Document; public class BattleshipExporter extends PuzzleExporter { @@ -22,8 +21,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { BattleshipBoard board; if (puzzle.getTree() != null) { board = (BattleshipBoard) puzzle.getTree().getRootNode().getBoard(); - } - else { + } else { board = (BattleshipBoard) puzzle.getBoardView().getBoard(); } @@ -35,7 +33,8 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { for (PuzzleElement puzzleElement : board.getPuzzleElements()) { BattleshipCell cell = (BattleshipCell) puzzleElement; if (cell.getData() != BattleshipType.getType(0)) { - org.w3c.dom.Element cellElement = puzzle.getFactory().exportCell(newDocument, puzzleElement); + org.w3c.dom.Element cellElement = + puzzle.getFactory().exportCell(newDocument, puzzleElement); cellsElement.appendChild(cellElement); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipImporter.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipImporter.java index 749ceaaa9..cbc1dd02b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipImporter.java @@ -2,12 +2,11 @@ import edu.rpi.legup.model.PuzzleImporter; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import java.awt.*; - public class BattleshipImporter extends PuzzleImporter { public BattleshipImporter(Battleship battleShip) { super(battleShip); @@ -26,14 +25,12 @@ public boolean acceptsTextInput() { /** * Creates an empty board for building * - * @param rows the number of rows on the board + * @param rows the number of rows on the board * @param columns the number of columns on the board * @throws RuntimeException if board can not be created */ @Override - public void initializeBoard(int rows, int columns) { - - } + public void initializeBoard(int rows, int columns) {} /** * Creates the board for building @@ -45,46 +42,43 @@ public void initializeBoard(int rows, int columns) { public void initializeBoard(Node node) throws InvalidFileFormatException { try { if (!node.getNodeName().equalsIgnoreCase("board")) { - throw new InvalidFileFormatException("BattleShip Importer: " + - "cannot find board puzzleElement"); + throw new InvalidFileFormatException( + "BattleShip Importer: " + "cannot find board puzzleElement"); } Element boardElement = (Element) node; if (boardElement.getElementsByTagName("cells").getLength() == 0) { - throw new InvalidFileFormatException("BattleShip Importer: " + - "no puzzleElement found for board"); + throw new InvalidFileFormatException( + "BattleShip Importer: " + "no puzzleElement found for board"); } - Element dataElement = (Element) boardElement.getElementsByTagName( - "cells").item(0); + Element dataElement = (Element) boardElement.getElementsByTagName("cells").item(0); NodeList elementDataList = dataElement.getElementsByTagName("cell"); BattleshipBoard battleShipBoard = null; if (!boardElement.getAttribute("size").isEmpty()) { - int size = Integer.valueOf(boardElement.getAttribute( - "size")); + int size = Integer.valueOf(boardElement.getAttribute("size")); battleShipBoard = new BattleshipBoard(size); - } - else { + } else { if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { - int width = Integer.valueOf(boardElement.getAttribute( - "width")); - int height = Integer.valueOf(boardElement.getAttribute( - "height")); + int width = Integer.valueOf(boardElement.getAttribute("width")); + int height = Integer.valueOf(boardElement.getAttribute("height")); battleShipBoard = new BattleshipBoard(width, height); } } if (battleShipBoard == null) { - throw new InvalidFileFormatException("BattleShip Importer: " + - "invalid board dimensions"); + throw new InvalidFileFormatException( + "BattleShip Importer: " + "invalid board dimensions"); } int width = battleShipBoard.getWidth(); int height = battleShipBoard.getHeight(); for (int i = 0; i < elementDataList.getLength(); i++) { - BattleshipCell cell = (BattleshipCell) puzzle.getFactory() - .importCell(elementDataList.item(i), battleShipBoard); + BattleshipCell cell = + (BattleshipCell) + puzzle.getFactory() + .importCell(elementDataList.item(i), battleShipBoard); Point loc = cell.getLocation(); if (cell.getData() != BattleshipType.getType(0)) { cell.setModifiable(false); @@ -96,8 +90,8 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (battleShipBoard.getCell(x, y) == null) { - BattleshipCell cell = new BattleshipCell( - BattleshipType.UNKNOWN, new Point(x, y)); + BattleshipCell cell = + new BattleshipCell(BattleshipType.UNKNOWN, new Point(x, y)); cell.setIndex(y * height + x); cell.setModifiable(true); battleShipBoard.setCell(x, y, cell); @@ -107,59 +101,58 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { NodeList axes = boardElement.getElementsByTagName("axis"); if (axes.getLength() != 2) { - throw new InvalidFileFormatException("BattleShip Importer: " + - "cannot find axes"); + throw new InvalidFileFormatException("BattleShip Importer: " + "cannot find axes"); } Element axis1 = (Element) axes.item(0); Element axis2 = (Element) axes.item(1); - if (!axis1.hasAttribute("side") || !axis2.hasAttribute( - "side")) { - throw new InvalidFileFormatException("BattleShip Importer: " + - "side attribute of axis not specified"); + if (!axis1.hasAttribute("side") || !axis2.hasAttribute("side")) { + throw new InvalidFileFormatException( + "BattleShip Importer: " + "side attribute of axis not specified"); } String side1 = axis1.getAttribute("side"); String side2 = axis2.getAttribute("side"); if (side1.equalsIgnoreCase(side2) - || !(side1.equalsIgnoreCase("east") - || side1.equalsIgnoreCase("south")) - || !(side2.equalsIgnoreCase("east") - || side2.equalsIgnoreCase("south"))) { - throw new InvalidFileFormatException("BattleShip Importer: " + - "axes must be different and be {east | south}"); + || !(side1.equalsIgnoreCase("east") || side1.equalsIgnoreCase("south")) + || !(side2.equalsIgnoreCase("east") || side2.equalsIgnoreCase("south"))) { + throw new InvalidFileFormatException( + "BattleShip Importer: " + "axes must be different and be {east | south}"); } - NodeList eastClues = side1.equalsIgnoreCase("east") - ? axis1.getElementsByTagName("clue") : - axis2.getElementsByTagName("clue"); - NodeList southClues = side1.equalsIgnoreCase("south") - ? axis1.getElementsByTagName("clue") : - axis2.getElementsByTagName("clue"); + NodeList eastClues = + side1.equalsIgnoreCase("east") + ? axis1.getElementsByTagName("clue") + : axis2.getElementsByTagName("clue"); + NodeList southClues = + side1.equalsIgnoreCase("south") + ? axis1.getElementsByTagName("clue") + : axis2.getElementsByTagName("clue"); if (eastClues.getLength() != battleShipBoard.getHeight() || southClues.getLength() != battleShipBoard.getWidth()) { - throw new InvalidFileFormatException("BattleShip Importer: " + - "there must be same number of clues as the dimension " + - "of the board"); + throw new InvalidFileFormatException( + "BattleShip Importer: " + + "there must be same number of clues as the dimension " + + "of the board"); } for (int i = 0; i < eastClues.getLength(); i++) { Element clue = (Element) eastClues.item(i); int value = Integer.valueOf(clue.getAttribute("value")); - int index = BattleshipClue.colStringToColNum( - clue.getAttribute("index")); + int index = BattleshipClue.colStringToColNum(clue.getAttribute("index")); if (index - 1 < 0 || index - 1 > battleShipBoard.getHeight()) { - throw new InvalidFileFormatException("BattleShip Importer: " + - "clue index out of bounds"); + throw new InvalidFileFormatException( + "BattleShip Importer: " + "clue index out of bounds"); } if (battleShipBoard.getEast().get(index - 1) != null) { - throw new InvalidFileFormatException("BattleShip Importer: " + - "duplicate clue index"); + throw new InvalidFileFormatException( + "BattleShip Importer: " + "duplicate clue index"); } - battleShipBoard.getEast().set(index - 1, new BattleshipClue( - value, index, BattleshipType.CLUE_EAST)); + battleShipBoard + .getEast() + .set(index - 1, new BattleshipClue(value, index, BattleshipType.CLUE_EAST)); } for (int i = 0; i < southClues.getLength(); i++) { @@ -168,23 +161,25 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { int index = Integer.valueOf(clue.getAttribute("index")); if (index - 1 < 0 || index - 1 > battleShipBoard.getWidth()) { - throw new InvalidFileFormatException("BattleShip Importer: " + - "clue index out of bounds"); + throw new InvalidFileFormatException( + "BattleShip Importer: " + "clue index out of bounds"); } if (battleShipBoard.getSouth().get(index - 1) != null) { - throw new InvalidFileFormatException("BattleShip Importer: " + - "duplicate clue index"); + throw new InvalidFileFormatException( + "BattleShip Importer: " + "duplicate clue index"); } - battleShipBoard.getSouth().set(index - 1, new BattleshipClue( - value, index, BattleshipType.CLUE_SOUTH)); + battleShipBoard + .getSouth() + .set( + index - 1, + new BattleshipClue(value, index, BattleshipType.CLUE_SOUTH)); } puzzle.setCurrentBoard(battleShipBoard); - } - catch (NumberFormatException e) { - throw new InvalidFileFormatException("BattleShip Importer: " + - "unknown value where integer expected"); + } catch (NumberFormatException e) { + throw new InvalidFileFormatException( + "BattleShip Importer: " + "unknown value where integer expected"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipType.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipType.java index 6994222e3..0d505f43c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipType.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipType.java @@ -1,9 +1,19 @@ package edu.rpi.legup.puzzle.battleship; public enum BattleshipType { - UNKNOWN, WATER, SUBMARINE, SHIP_UNKNOWN, - SHIP_TOP, SHIP_RIGHT, SHIP_BOTTOM, SHIP_LEFT, SHIP_MIDDLE, - CLUE_NORTH, CLUE_EAST, CLUE_SOUTH, CLUE_WEST; + UNKNOWN, + WATER, + SUBMARINE, + SHIP_UNKNOWN, + SHIP_TOP, + SHIP_RIGHT, + SHIP_BOTTOM, + SHIP_LEFT, + SHIP_MIDDLE, + CLUE_NORTH, + CLUE_EAST, + CLUE_SOUTH, + CLUE_WEST; public int value; @@ -13,6 +23,7 @@ public enum BattleshipType { /** * Gets the enum of this BattleShipType + * * @param value the integer value input * @return enum equivalent BattleShipType of integer value */ @@ -31,7 +42,11 @@ public static BattleshipType getType(int value) { * @return true if the type is a ship, false otherwise */ public static boolean isShip(BattleshipType type) { - return type == SHIP_UNKNOWN || type == SHIP_TOP || type == SHIP_RIGHT - || type == SHIP_BOTTOM || type == SHIP_LEFT || type == SHIP_MIDDLE; + return type == SHIP_UNKNOWN + || type == SHIP_TOP + || type == SHIP_RIGHT + || type == SHIP_BOTTOM + || type == SHIP_LEFT + || type == SHIP_MIDDLE; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipView.java b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipView.java index fbae2fa99..4095db54a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipView.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipView.java @@ -3,7 +3,6 @@ import edu.rpi.legup.controller.BoardController; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.ui.boardview.GridBoardView; - import java.awt.*; public class BattleshipView extends GridBoardView { @@ -17,7 +16,8 @@ public BattleshipView(BattleshipBoard board) { BattleshipElementView elementView = new BattleshipElementView(cell); elementView.setIndex(cell.getIndex()); elementView.setSize(elementSize); - elementView.setLocation(new Point(loc.x * elementSize.width, loc.y * elementSize.height)); + elementView.setLocation( + new Point(loc.x * elementSize.width, loc.y * elementSize.height)); elementViews.add(elementView); } } @@ -26,4 +26,4 @@ public BattleshipView(BattleshipBoard board) { public void drawBoard(Graphics2D graphics2D) { super.drawBoard(graphics2D); } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/AdjacentShipsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/AdjacentShipsContradictionRule.java index 49bee101a..f1ecd6685 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/AdjacentShipsContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/AdjacentShipsContradictionRule.java @@ -6,31 +6,29 @@ import edu.rpi.legup.puzzle.battleship.BattleshipBoard; import edu.rpi.legup.puzzle.battleship.BattleshipCell; import edu.rpi.legup.puzzle.battleship.BattleshipType; - import java.util.List; public class AdjacentShipsContradictionRule extends ContradictionRule { - private final String NO_CONTRADICTION_MESSAGE - = "No instance of the contradiction " + this.ruleName + " here"; + private final String NO_CONTRADICTION_MESSAGE = + "No instance of the contradiction " + this.ruleName + " here"; public AdjacentShipsContradictionRule() { - super("BTSP-CONT-0001", + super( + "BTSP-CONT-0001", "Adjacent Ships", "Cells next to the battleship must be water.", - "edu/rpi/legup/images/battleship/contradictions" + - "/AdjacentShips.png"); + "edu/rpi/legup/images/battleship/contradictions" + "/AdjacentShips.png"); } /** - * Checks whether the transition has a contradiction at the specific - * {@link PuzzleElement} index using this rule. + * Checks whether the transition has a contradiction at the specific {@link PuzzleElement} index + * using this rule. * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent {@link PuzzleElement} - * @return null if the transition contains a - * contradiction at the specified {@link PuzzleElement}, - * otherwise return a no contradiction message. + * @return null if the transition contains a contradiction at the specified {@link + * PuzzleElement}, otherwise return a no contradiction message. */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { @@ -43,19 +41,20 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { } // check orthogonally adjacent cells - List orthoAdjCells - = bsBoard.getAdjOrthogonals(cell); + List orthoAdjCells = bsBoard.getAdjOrthogonals(cell); BattleshipCell up = orthoAdjCells.get(0); BattleshipCell right = orthoAdjCells.get(1); BattleshipCell down = orthoAdjCells.get(2); BattleshipCell left = orthoAdjCells.get(3); - boolean isVertical = (up != null && BattleshipType.isShip(up.getData())) - || (down != null && BattleshipType.isShip(down.getData())); + boolean isVertical = + (up != null && BattleshipType.isShip(up.getData())) + || (down != null && BattleshipType.isShip(down.getData())); - boolean isHorizontal = (left != null && BattleshipType.isShip(left.getData())) - || (right != null && BattleshipType.isShip(right.getData())); + boolean isHorizontal = + (left != null && BattleshipType.isShip(left.getData())) + || (right != null && BattleshipType.isShip(right.getData())); // ships cannot be both vertical and horizontal if (isVertical && isHorizontal) { @@ -63,8 +62,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { } // check diagonally adjacent cells - List diagAdjCells - = bsBoard.getAdjDiagonals(cell); + List diagAdjCells = bsBoard.getAdjDiagonals(cell); BattleshipCell upRight = diagAdjCells.get(0); BattleshipCell downRight = diagAdjCells.get(1); diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ContinueShipDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ContinueShipDirectRule.java index 18c55d635..670a136a4 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ContinueShipDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ContinueShipDirectRule.java @@ -1,43 +1,45 @@ -package edu.rpi.legup.puzzle.battleship.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; - -public class ContinueShipDirectRule extends DirectRule { - - public ContinueShipDirectRule() { - super("BTSP-BASC-0001", - "Continue Ship", - "", - "edu/rpi/legup/images/battleship/rules/ContinueShip.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * This method is the one that should be overridden in child classes - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - return null; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.battleship.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; + +public class ContinueShipDirectRule extends DirectRule { + + public ContinueShipDirectRule() { + super( + "BTSP-BASC-0001", + "Continue Ship", + "", + "edu/rpi/legup/images/battleship/rules/ContinueShip.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule This method is the one that should be overridden in child + * classes + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + return null; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/FinishWithShipsDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/FinishWithShipsDirectRule.java index 3374d1806..9bc4065aa 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/FinishWithShipsDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/FinishWithShipsDirectRule.java @@ -1,116 +1,108 @@ -package edu.rpi.legup.puzzle.battleship.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.battleship.BattleshipBoard; -import edu.rpi.legup.puzzle.battleship.BattleshipCell; -import edu.rpi.legup.puzzle.battleship.BattleshipClue; -import edu.rpi.legup.puzzle.battleship.BattleshipType; - -import java.awt.*; -import java.util.List; - -public class FinishWithShipsDirectRule extends DirectRule { - - public FinishWithShipsDirectRule() { - super("BTSP-BASC-0002", - "Finish with Ships", - "The number of undetermined squares is equal to the number " + - "of segments remaining for each clue.", - "edu/rpi/legup/images/battleship/rules/finishShip.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * This method is the one that should be overridden in child classes - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node - * at the specified puzzleElement, otherwise error message. - */ - @Override - protected String checkRuleRawAt(TreeTransition transition, - PuzzleElement puzzleElement) { - BattleshipBoard initBoard = (BattleshipBoard) transition.getParents() - .get(0).getBoard(); - BattleshipCell initCell = (BattleshipCell) initBoard - .getPuzzleElement(puzzleElement); - BattleshipBoard finalBoard = (BattleshipBoard) transition.getBoard(); - BattleshipCell finalCell = (BattleshipCell) finalBoard - .getPuzzleElement(puzzleElement); - if (!(initCell.getType() == BattleshipType.UNKNOWN - && BattleshipType.isShip(finalCell.getType()))) { - return super.getInvalidUseOfRuleMessage() + ": This cell must be a ship."; - } - - if (isForced(initBoard, initCell)) { - return null; - } - else { - return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to" + - "be a ship segment."; - } - } - - private boolean isForced(BattleshipBoard board, BattleshipCell cell) { - Point loc = cell.getLocation(); - - // count the number of ship segments and unknowns in the row - List row = board.getRow(loc.y); - int rowCount = 0; - for (BattleshipCell c : row) { - if (c.getType() == BattleshipType.SHIP_UNKNOWN - || BattleshipType.isShip(c.getType())) { - rowCount++; - } - } - - // count the number of ship segments and unknowns in the column - List col = board.getColumn(loc.x); - int colCount = 0; - for (BattleshipCell c : col) { - if (c.getType() == BattleshipType.SHIP_UNKNOWN - || BattleshipType.isShip(c.getType())) { - colCount++; - } - } - - // compare the counts with the clues - BattleshipClue east = board.getEast().get(loc.y); - BattleshipClue south = board.getSouth().get(loc.x); - - return rowCount <= east.getData() && colCount <= south.getData(); - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the - * {@link TreeNode}. - * - * @param node tree node used to create default transition board. - * @return default board or null if this rule cannot be applied to this tree - * node. - */ - @Override - public Board getDefaultBoard(TreeNode node) { - BattleshipBoard board = (BattleshipBoard) node.getBoard().copy(); - for (PuzzleElement element : board.getPuzzleElements()) { - BattleshipCell cell = (BattleshipCell) element; - if (cell.getType() == BattleshipType.UNKNOWN && isForced(board, cell)) { - cell.setData(BattleshipType.SHIP_UNKNOWN); - board.addModifiedData(cell); - } - } - - if (board.getModifiedData().isEmpty()) { - return null; - } - else { - return board; - } - } -} +package edu.rpi.legup.puzzle.battleship.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.battleship.BattleshipBoard; +import edu.rpi.legup.puzzle.battleship.BattleshipCell; +import edu.rpi.legup.puzzle.battleship.BattleshipClue; +import edu.rpi.legup.puzzle.battleship.BattleshipType; +import java.awt.*; +import java.util.List; + +public class FinishWithShipsDirectRule extends DirectRule { + + public FinishWithShipsDirectRule() { + super( + "BTSP-BASC-0002", + "Finish with Ships", + "The number of undetermined squares is equal to the number " + + "of segments remaining for each clue.", + "edu/rpi/legup/images/battleship/rules/finishShip.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule This method is the one that should be overridden in child + * classes + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message. + */ + @Override + protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + BattleshipBoard initBoard = (BattleshipBoard) transition.getParents().get(0).getBoard(); + BattleshipCell initCell = (BattleshipCell) initBoard.getPuzzleElement(puzzleElement); + BattleshipBoard finalBoard = (BattleshipBoard) transition.getBoard(); + BattleshipCell finalCell = (BattleshipCell) finalBoard.getPuzzleElement(puzzleElement); + if (!(initCell.getType() == BattleshipType.UNKNOWN + && BattleshipType.isShip(finalCell.getType()))) { + return super.getInvalidUseOfRuleMessage() + ": This cell must be a ship."; + } + + if (isForced(initBoard, initCell)) { + return null; + } else { + return super.getInvalidUseOfRuleMessage() + + ": This cell is not forced to" + + "be a ship segment."; + } + } + + private boolean isForced(BattleshipBoard board, BattleshipCell cell) { + Point loc = cell.getLocation(); + + // count the number of ship segments and unknowns in the row + List row = board.getRow(loc.y); + int rowCount = 0; + for (BattleshipCell c : row) { + if (c.getType() == BattleshipType.SHIP_UNKNOWN || BattleshipType.isShip(c.getType())) { + rowCount++; + } + } + + // count the number of ship segments and unknowns in the column + List col = board.getColumn(loc.x); + int colCount = 0; + for (BattleshipCell c : col) { + if (c.getType() == BattleshipType.SHIP_UNKNOWN || BattleshipType.isShip(c.getType())) { + colCount++; + } + } + + // compare the counts with the clues + BattleshipClue east = board.getEast().get(loc.y); + BattleshipClue south = board.getSouth().get(loc.x); + + return rowCount <= east.getData() && colCount <= south.getData(); + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board. + * @return default board or null if this rule cannot be applied to this tree node. + */ + @Override + public Board getDefaultBoard(TreeNode node) { + BattleshipBoard board = (BattleshipBoard) node.getBoard().copy(); + for (PuzzleElement element : board.getPuzzleElements()) { + BattleshipCell cell = (BattleshipCell) element; + if (cell.getType() == BattleshipType.UNKNOWN && isForced(board, cell)) { + cell.setData(BattleshipType.SHIP_UNKNOWN); + board.addModifiedData(cell); + } + } + + if (board.getModifiedData().isEmpty()) { + return null; + } else { + return board; + } + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/FinishWithWaterDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/FinishWithWaterDirectRule.java index 157b13d01..99e5925e0 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/FinishWithWaterDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/FinishWithWaterDirectRule.java @@ -1,43 +1,45 @@ -package edu.rpi.legup.puzzle.battleship.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; - -public class FinishWithWaterDirectRule extends DirectRule { - - public FinishWithWaterDirectRule() { - super("BTSP-BASC-0003", - "Finish with Water", - "", - "edu/rpi/legup/images/battleship/rules/finishWater.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * This method is the one that should overridden in child classes - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - return null; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.battleship.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; + +public class FinishWithWaterDirectRule extends DirectRule { + + public FinishWithWaterDirectRule() { + super( + "BTSP-BASC-0003", + "Finish with Water", + "", + "edu/rpi/legup/images/battleship/rules/finishWater.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule This method is the one that should overridden in child + * classes + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + return null; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/IncompleteShipContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/IncompleteShipContradictionRule.java index 4a6cb3d15..e8cfebb90 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/IncompleteShipContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/IncompleteShipContradictionRule.java @@ -7,19 +7,21 @@ public class IncompleteShipContradictionRule extends ContradictionRule { public IncompleteShipContradictionRule() { - super("BTSP-CONT-0002", + super( + "BTSP-CONT-0002", "Incomplete Ship", "", "edu/rpi/legup/images/battleship/contradictions/IncompleteShip.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SegmentTypeCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SegmentTypeCaseRule.java index 3850ee39f..93079fb71 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SegmentTypeCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SegmentTypeCaseRule.java @@ -5,20 +5,20 @@ import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.rules.CaseRule; import edu.rpi.legup.model.tree.TreeTransition; - import java.util.List; public class SegmentTypeCaseRule extends CaseRule { public SegmentTypeCaseRule() { - super("BTSP-CASE-0001", + super( + "BTSP-CASE-0001", "Segment Type", "", "edu/rpi/legup/images/battleship/cases/SegmentType.png"); } /** - * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. This method is - * the one that should overridden in child classes. + * Checks whether the {@link TreeTransition} logically follows from the parent node using this + * rule. This method is the one that should overridden in child classes. * * @param transition transition to check * @return null if the child node logically follow from the parent node, otherwise error message @@ -29,13 +29,14 @@ public String checkRuleRaw(TreeTransition transition) { } /** - * Checks whether the child node logically follows from the parent node at the specific puzzleElement index using - * this rule. This method is the one that should overridden in child classes. + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule. This method is the one that should overridden in child + * classes. * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { @@ -43,7 +44,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem } /** - * Gets the case board that indicates where this case rule can be applied on the given {@link Board}. + * Gets the case board that indicates where this case rule can be applied on the given {@link + * Board}. * * @param board board to find locations where this case rule can be applied * @return a case board @@ -54,9 +56,10 @@ public CaseBoard getCaseBoard(Board board) { } /** - * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on this case rule. + * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on + * this case rule. * - * @param board the current board state + * @param board the current board state * @param puzzleElement equivalent puzzleElement * @return a list of elements the specified could be */ diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SegmentTypeDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SegmentTypeDirectRule.java index f90dea1bd..8576ef722 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SegmentTypeDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SegmentTypeDirectRule.java @@ -1,43 +1,45 @@ -package edu.rpi.legup.puzzle.battleship.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; - -public class SegmentTypeDirectRule extends DirectRule { - - public SegmentTypeDirectRule() { - super("BTSP-BASC-0004", - "Segment Type", - "", - "edu/rpi/legup/images/battleship/rules/SegmentChoice.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * This method is the one that should overridden in child classes - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - return null; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.battleship.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; + +public class SegmentTypeDirectRule extends DirectRule { + + public SegmentTypeDirectRule() { + super( + "BTSP-BASC-0004", + "Segment Type", + "", + "edu/rpi/legup/images/battleship/rules/SegmentChoice.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule This method is the one that should overridden in child + * classes + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + return null; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ShipLocationCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ShipLocationCaseRule.java index f21488cca..da8f33cc2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ShipLocationCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ShipLocationCaseRule.java @@ -5,21 +5,21 @@ import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.rules.CaseRule; import edu.rpi.legup.model.tree.TreeTransition; - import java.util.List; public class ShipLocationCaseRule extends CaseRule { public ShipLocationCaseRule() { - super("BTSP-CASE-0002", + super( + "BTSP-CASE-0002", "Ship Location", "", "edu/rpi/legup/images/battleship/cases/ShipLocations.png"); } /** - * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. This method is - * the one that should overridden in child classes. + * Checks whether the {@link TreeTransition} logically follows from the parent node using this + * rule. This method is the one that should overridden in child classes. * * @param transition transition to check * @return null if the child node logically follow from the parent node, otherwise error message @@ -30,13 +30,14 @@ public String checkRuleRaw(TreeTransition transition) { } /** - * Checks whether the child node logically follows from the parent node at the specific puzzleElement index using - * this rule. This method is the one that should overridden in child classes. + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule. This method is the one that should overridden in child + * classes. * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { @@ -44,7 +45,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem } /** - * Gets the case board that indicates where this case rule can be applied on the given {@link Board}. + * Gets the case board that indicates where this case rule can be applied on the given {@link + * Board}. * * @param board board to find locations where this case rule can be applied * @return a case board @@ -55,9 +57,10 @@ public CaseBoard getCaseBoard(Board board) { } /** - * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on this case rule. + * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on + * this case rule. * - * @param board the current board state + * @param board the current board state * @param puzzleElement equivalent puzzleElement * @return a list of elements the specified could be */ diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ShipOrWaterCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ShipOrWaterCaseRule.java index a419b831f..3c123d7c1 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ShipOrWaterCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/ShipOrWaterCaseRule.java @@ -5,21 +5,21 @@ import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.rules.CaseRule; import edu.rpi.legup.model.tree.TreeTransition; - import java.util.List; public class ShipOrWaterCaseRule extends CaseRule { public ShipOrWaterCaseRule() { - super("BTSP-CASE-0003", + super( + "BTSP-CASE-0003", "Ship or Water", "", "edu/rpi/legup/images/battleship/cases/ShipOrWater.png"); } /** - * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. This method is - * the one that should overridden in child classes. + * Checks whether the {@link TreeTransition} logically follows from the parent node using this + * rule. This method is the one that should overridden in child classes. * * @param transition transition to check * @return null if the child node logically follow from the parent node, otherwise error message @@ -30,13 +30,14 @@ public String checkRuleRaw(TreeTransition transition) { } /** - * Checks whether the child node logically follows from the parent node at the specific puzzleElement index using - * this rule. This method is the one that should overridden in child classes. + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule. This method is the one that should overridden in child + * classes. * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { @@ -44,7 +45,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem } /** - * Gets the case board that indicates where this case rule can be applied on the given {@link Board}. + * Gets the case board that indicates where this case rule can be applied on the given {@link + * Board}. * * @param board board to find locations where this case rule can be applied * @return a case board @@ -55,9 +57,10 @@ public CaseBoard getCaseBoard(Board board) { } /** - * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on this case rule. + * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on + * this case rule. * - * @param board the current board state + * @param board the current board state * @param puzzleElement equivalent puzzleElement * @return a list of elements the specified could be */ diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SurroundShipDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SurroundShipDirectRule.java index 57ad42121..d26c3ed29 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SurroundShipDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/SurroundShipDirectRule.java @@ -1,43 +1,45 @@ -package edu.rpi.legup.puzzle.battleship.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; - -public class SurroundShipDirectRule extends DirectRule { - - public SurroundShipDirectRule() { - super("BTSP-BASC-0005", - "Surround Ship", - "", - "edu/rpi/legup/images/battleship/rules/SurroundShip.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * This method is the one that should overridden in child classes - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - return null; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.battleship.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; + +public class SurroundShipDirectRule extends DirectRule { + + public SurroundShipDirectRule() { + super( + "BTSP-BASC-0005", + "Surround Ship", + "", + "edu/rpi/legup/images/battleship/rules/SurroundShip.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule This method is the one that should overridden in child + * classes + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + return null; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooFewInFleetContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooFewInFleetContradictionRule.java index 5a4eb187e..d10e086d2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooFewInFleetContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooFewInFleetContradictionRule.java @@ -7,19 +7,21 @@ public class TooFewInFleetContradictionRule extends ContradictionRule { public TooFewInFleetContradictionRule() { - super("BTSP-CONT-0003", + super( + "BTSP-CONT-0003", "Too Few in Fleet", "", "edu/rpi/legup/images/battleship/contradictions/too_few_in_fleet.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooFewRowColContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooFewRowColContradictionRule.java index 7c2fa7819..382ba6e39 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooFewRowColContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooFewRowColContradictionRule.java @@ -7,19 +7,21 @@ public class TooFewRowColContradictionRule extends ContradictionRule { public TooFewRowColContradictionRule() { - super("BTSP-CONT-0004", + super( + "BTSP-CONT-0004", "Too few in row/col", "", "edu/rpi/legup/images/battleship/contradictions/too_few_segments.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooManyInFleetContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooManyInFleetContradictionRule.java index 3aad88613..d58701c0b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooManyInFleetContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooManyInFleetContradictionRule.java @@ -7,19 +7,21 @@ public class TooManyInFleetContradictionRule extends ContradictionRule { public TooManyInFleetContradictionRule() { - super("BTSP-CONT-0005", + super( + "BTSP-CONT-0005", "Too Many in Fleet", "", "edu/rpi/legup/images/battleship/contradictions/too_many_in_fleet.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooManyRowColContradiction.java b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooManyRowColContradiction.java index 0970c9c69..27caa0524 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooManyRowColContradiction.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/rules/TooManyRowColContradiction.java @@ -7,19 +7,21 @@ public class TooManyRowColContradiction extends ContradictionRule { public TooManyRowColContradiction() { - super("BTSP-CONT-0006", + super( + "BTSP-CONT-0006", "Too Many row/col", "", "edu/rpi/legup/images/battleship/contradictions/too_many_segments.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/Fillapix.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/Fillapix.java index ef78f66aa..79574caa6 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/Fillapix.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/Fillapix.java @@ -6,9 +6,7 @@ import edu.rpi.legup.model.rules.ContradictionRule; public class Fillapix extends Puzzle { - /** - * Fillapix Constructor - */ + /** Fillapix Constructor */ public Fillapix() { super(); @@ -20,9 +18,7 @@ public Fillapix() { this.factory = new FillapixCellFactory(); } - /** - * Initializes the game board - */ + /** Initializes the game board */ @Override public void initializeView() { boardView = new FillapixView((FillapixBoard) currentBoard); @@ -39,8 +35,8 @@ public Board generatePuzzle(int difficulty) { /** * Determines if the given dimensions are valid for Fillapix * - * @param rows the number of rows - * @param columns the number of columns + * @param rows the number of rows + * @param columns the number of columns * @return true if the given dimensions are valid for Fillapix, false otherwise */ public boolean isValidDimensions(int rows, int columns) { @@ -65,7 +61,5 @@ public boolean isBoardComplete(Board board) { } @Override - public void onBoardChange(Board board) { - - } -} \ No newline at end of file + public void onBoardChange(Board board) {} +} diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixBoard.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixBoard.java index 67987a6fd..a6672bd4f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixBoard.java @@ -2,12 +2,11 @@ import edu.rpi.legup.model.gameboard.GridBoard; import edu.rpi.legup.model.gameboard.PuzzleElement; - import java.awt.*; import java.util.logging.Logger; public class FillapixBoard extends GridBoard { - private final static Logger LOGGER = Logger.getLogger(FillapixBoard.class.getName()); + private static final Logger LOGGER = Logger.getLogger(FillapixBoard.class.getName()); public FillapixBoard(int width, int height) { super(width, height); diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCell.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCell.java index 5e6d4b9ed..a9e5aa2df 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCell.java @@ -2,7 +2,6 @@ import edu.rpi.legup.model.elements.Element; import edu.rpi.legup.model.gameboard.GridCell; - import java.awt.*; import java.awt.event.MouseEvent; import java.util.Objects; @@ -42,7 +41,7 @@ public void setCellType(FillapixCellType type) { @Override public void setType(Element e, MouseEvent m) { - switch(e.getElementID()) { + switch (e.getElementID()) { case "FPIX-PLAC-0001": this.setCellType(FillapixCellType.BLACK); break; @@ -88,9 +87,11 @@ public FillapixCell copy() { } public boolean equals(FillapixCell otherCell) { -// return this.location.equals(otherCell.location) && this.index == otherCell.index && this.data == otherCell.data; - //return this.index == otherCell.index && this.data == otherCell.data; - //return this.index == otherCell.index; + // return this.location.equals(otherCell.location) && this.index == otherCell.index + // && + // this.data == otherCell.data; + // return this.index == otherCell.index && this.data == otherCell.data; + // return this.index == otherCell.index; return this.location.x == otherCell.location.x && this.location.y == otherCell.location.y; } @@ -101,4 +102,4 @@ public int compareTo(FillapixCell otherCell) { public int hashCode() { return Objects.hash(this.index); } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellController.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellController.java index df3bba403..f59c0df47 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellController.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellController.java @@ -2,7 +2,6 @@ import edu.rpi.legup.controller.ElementController; import edu.rpi.legup.model.gameboard.PuzzleElement; - import java.awt.event.MouseEvent; public class FillapixCellController extends ElementController { @@ -11,34 +10,33 @@ public void changeCell(MouseEvent e, PuzzleElement puzzleElement) { FillapixCell cell = (FillapixCell) puzzleElement; if (e.getButton() == MouseEvent.BUTTON1) { if (e.isControlDown()) { - this.boardView.getSelectionPopupMenu().show(boardView, this.boardView.getCanvas().getX() + e.getX(), this.boardView.getCanvas().getY() + e.getY()); - } - else { + this.boardView + .getSelectionPopupMenu() + .show( + boardView, + this.boardView.getCanvas().getX() + e.getX(), + this.boardView.getCanvas().getY() + e.getY()); + } else { if (cell.getType() == FillapixCellType.UNKNOWN) { cell.setCellType(FillapixCellType.BLACK); - } - else { + } else { if (cell.getType() == FillapixCellType.BLACK) { cell.setCellType(FillapixCellType.WHITE); - } - else { + } else { if (cell.getType() == FillapixCellType.WHITE) { cell.setCellType(FillapixCellType.UNKNOWN); } } } } - } - else { + } else { if (e.getButton() == MouseEvent.BUTTON3) { if (cell.getType() == FillapixCellType.UNKNOWN) { cell.setCellType(FillapixCellType.WHITE); - } - else { + } else { if (cell.getType() == FillapixCellType.BLACK) { cell.setCellType(FillapixCellType.UNKNOWN); - } - else { + } else { if (cell.getType() == FillapixCellType.WHITE) { cell.setCellType(FillapixCellType.BLACK); } @@ -47,4 +45,4 @@ public void changeCell(MouseEvent e, PuzzleElement puzzleElement) { } } } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellFactory.java index fcc48bccd..9f689bc96 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellFactory.java @@ -4,17 +4,16 @@ import edu.rpi.legup.model.gameboard.ElementFactory; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; -import java.awt.*; - public class FillapixCellFactory extends ElementFactory { /** * Creates a puzzleElement based on the xml document Node and adds it to the board * - * @param node node that represents the puzzleElement + * @param node node that represents the puzzleElement * @param board board to add the newly created cell * @return newly created cell from the xml document Node * @throws InvalidFileFormatException if file is invalid @@ -23,7 +22,8 @@ public class FillapixCellFactory extends ElementFactory { public FillapixCell importCell(Node node, Board board) throws InvalidFileFormatException { try { if (!node.getNodeName().equalsIgnoreCase("cell")) { - throw new InvalidFileFormatException("Fillapix Factory: unknown puzzleElement puzzleElement"); + throw new InvalidFileFormatException( + "Fillapix Factory: unknown puzzleElement puzzleElement"); } FillapixBoard fillapixBoard = (FillapixBoard) board; @@ -35,7 +35,8 @@ public FillapixCell importCell(Node node, Board board) throws InvalidFileFormatE int x = Integer.valueOf(attributeList.getNamedItem("x").getNodeValue()); int y = Integer.valueOf(attributeList.getNamedItem("y").getNodeValue()); if (x >= width || y >= height) { - throw new InvalidFileFormatException("Fillapix Factory: cell location out of bounds"); + throw new InvalidFileFormatException( + "Fillapix Factory: cell location out of bounds"); } if (value / 100 > 2 || value % 100 > 10) { throw new InvalidFileFormatException("Fillapix Factory: cell unknown value"); @@ -44,11 +45,10 @@ public FillapixCell importCell(Node node, Board board) throws InvalidFileFormatE FillapixCell cell = new FillapixCell(value, new Point(x, y)); cell.setIndex(y * height + x); return cell; - } - catch (NumberFormatException e) { - throw new InvalidFileFormatException("Fillapix Factory: unknown value where integer expected"); - } - catch (NullPointerException e) { + } catch (NumberFormatException e) { + throw new InvalidFileFormatException( + "Fillapix Factory: unknown value where integer expected"); + } catch (NullPointerException e) { throw new InvalidFileFormatException("Fillapix Factory: could not find attribute(s)"); } } @@ -56,7 +56,7 @@ public FillapixCell importCell(Node node, Board board) throws InvalidFileFormatE /** * Creates a xml document puzzleElement from a cell for exporting * - * @param document xml document + * @param document xml document * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellType.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellType.java index 3789fe339..28a263467 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellType.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellType.java @@ -1,7 +1,9 @@ package edu.rpi.legup.puzzle.fillapix; public enum FillapixCellType { - UNKNOWN(0), BLACK(1), WHITE(2); + UNKNOWN(0), + BLACK(1), + WHITE(2); public int value; diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixElementView.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixElementView.java index 93fa0d451..47465a522 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixElementView.java @@ -1,7 +1,6 @@ package edu.rpi.legup.puzzle.fillapix; import edu.rpi.legup.ui.boardview.GridElementView; - import java.awt.*; public class FillapixElementView extends GridElementView { @@ -53,10 +52,11 @@ public void drawElement(Graphics2D graphics2D) { FontMetrics metrics = graphics2D.getFontMetrics(FONT); String value = String.valueOf(cell.getNumber()); int xText = location.x + (size.width - metrics.stringWidth(value)) / 2; - int yText = location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent(); + int yText = + location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent(); graphics2D.drawString(value, xText, yText); } graphics2D.setColor(BLACK_COLOR); graphics2D.drawRect(location.x, location.y, size.width, size.height); } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixExporter.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixExporter.java index 757d14cd8..ffabd8762 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixExporter.java @@ -2,7 +2,6 @@ import edu.rpi.legup.model.PuzzleExporter; import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; import org.w3c.dom.Document; public class FillapixExporter extends PuzzleExporter { @@ -16,8 +15,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { FillapixBoard board; if (puzzle.getTree() != null) { board = (FillapixBoard) puzzle.getTree().getRootNode().getBoard(); - } - else { + } else { board = (FillapixBoard) puzzle.getBoardView().getBoard(); } @@ -29,7 +27,8 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { for (PuzzleElement puzzleElement : board.getPuzzleElements()) { FillapixCell cell = (FillapixCell) puzzleElement; if (cell.getNumber() != -1 || cell.getType() != FillapixCellType.UNKNOWN) { - org.w3c.dom.Element cellElement = puzzle.getFactory().exportCell(newDocument, puzzleElement); + org.w3c.dom.Element cellElement = + puzzle.getFactory().exportCell(newDocument, puzzleElement); cellsElement.appendChild(cellElement); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixImporter.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixImporter.java index 5213e7139..d16bc8219 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixImporter.java @@ -2,12 +2,11 @@ import edu.rpi.legup.model.PuzzleImporter; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import java.awt.*; - public class FillapixImporter extends PuzzleImporter { public FillapixImporter(Fillapix fillapix) { super(fillapix); @@ -26,7 +25,7 @@ public boolean acceptsTextInput() { /** * Creates an empty board for building * - * @param rows the number of rows on the board + * @param rows the number of rows on the board * @param columns the number of columns on the board * @throws RuntimeException if board can not be made */ @@ -36,7 +35,8 @@ public void initializeBoard(int rows, int columns) { for (int y = 0; y < rows; y++) { for (int x = 0; x < columns; x++) { - FillapixCell cell = new FillapixCell(FillapixCellType.UNKNOWN.value, new Point(x, y)); + FillapixCell cell = + new FillapixCell(FillapixCellType.UNKNOWN.value, new Point(x, y)); cell.setIndex(y * columns + x); cell.setNumber(FillapixCell.DEFAULT_VALUE); cell.setModifiable(true); @@ -56,11 +56,13 @@ public void initializeBoard(int rows, int columns) { public void initializeBoard(Node node) throws InvalidFileFormatException { try { if (!node.getNodeName().equalsIgnoreCase("board")) { - throw new InvalidFileFormatException("Fillapix Importer: cannot find board puzzleElement"); + throw new InvalidFileFormatException( + "Fillapix Importer: cannot find board puzzleElement"); } Element boardElement = (Element) node; if (boardElement.getElementsByTagName("cells").getLength() == 0) { - throw new InvalidFileFormatException("Fillapix Importer: no puzzleElement found for board"); + throw new InvalidFileFormatException( + "Fillapix Importer: no puzzleElement found for board"); } Element dataElement = (Element) boardElement.getElementsByTagName("cells").item(0); NodeList elementDataList = dataElement.getElementsByTagName("cell"); @@ -69,9 +71,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { if (!boardElement.getAttribute("size").isEmpty()) { int size = Integer.valueOf(boardElement.getAttribute("size")); fillapixBoard = new FillapixBoard(size); - } - else { - if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { + } else { + if (!boardElement.getAttribute("width").isEmpty() + && !boardElement.getAttribute("height").isEmpty()) { int width = Integer.valueOf(boardElement.getAttribute("width")); int height = Integer.valueOf(boardElement.getAttribute("height")); fillapixBoard = new FillapixBoard(width, height); @@ -86,7 +88,10 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { int height = fillapixBoard.getHeight(); for (int i = 0; i < elementDataList.getLength(); i++) { - FillapixCell cell = (FillapixCell) puzzle.getFactory().importCell(elementDataList.item(i), fillapixBoard); + FillapixCell cell = + (FillapixCell) + puzzle.getFactory() + .importCell(elementDataList.item(i), fillapixBoard); Point loc = cell.getLocation(); cell.setModifiable(true); cell.setGiven(true); @@ -96,7 +101,8 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (fillapixBoard.getCell(x, y) == null) { - FillapixCell cell = new FillapixCell(FillapixCell.DEFAULT_VALUE, new Point(x, y)); + FillapixCell cell = + new FillapixCell(FillapixCell.DEFAULT_VALUE, new Point(x, y)); cell.setIndex(y * height + x); cell.setModifiable(true); fillapixBoard.setCell(x, y, cell); @@ -104,9 +110,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { } } puzzle.setCurrentBoard(fillapixBoard); - } - catch (NumberFormatException e) { - throw new InvalidFileFormatException("Fillapix Importer: unknown value where integer expected"); + } catch (NumberFormatException e) { + throw new InvalidFileFormatException( + "Fillapix Importer: unknown value where integer expected"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixUtilities.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixUtilities.java index a7feac91d..571a0c7f7 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixUtilities.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixUtilities.java @@ -3,14 +3,14 @@ import edu.rpi.legup.model.rules.ContradictionRule; import edu.rpi.legup.puzzle.fillapix.rules.TooFewBlackCellsContradictionRule; import edu.rpi.legup.puzzle.fillapix.rules.TooManyBlackCellsContradictionRule; - import java.awt.*; import java.util.ArrayList; public class FillapixUtilities { public static boolean isForcedBlack(FillapixBoard board, FillapixCell cell) { - TooFewBlackCellsContradictionRule tooManyBlackCells = new TooFewBlackCellsContradictionRule(); + TooFewBlackCellsContradictionRule tooManyBlackCells = + new TooFewBlackCellsContradictionRule(); FillapixBoard whiteCaseBoard = board.copy(); FillapixCell whiteCell = (FillapixCell) whiteCaseBoard.getPuzzleElement(cell); whiteCell.setCellType(FillapixCellType.WHITE); @@ -24,7 +24,8 @@ public static boolean isForcedBlack(FillapixBoard board, FillapixCell cell) { } public static boolean isForcedWhite(FillapixBoard board, FillapixCell cell) { - TooManyBlackCellsContradictionRule tooManyBlackCells = new TooManyBlackCellsContradictionRule(); + TooManyBlackCellsContradictionRule tooManyBlackCells = + new TooManyBlackCellsContradictionRule(); FillapixBoard blackCaseBoard = board.copy(); FillapixCell blackCell = (FillapixCell) blackCaseBoard.getPuzzleElement(cell); blackCell.setCellType(FillapixCellType.BLACK); @@ -59,15 +60,16 @@ public static boolean hasEmptyAdjacent(FillapixBoard board, FillapixCell cell) { return false; } - /** - * Gets all cells adjacent to a specific cell. The cell itself will be included. - */ + /** Gets all cells adjacent to a specific cell. The cell itself will be included. */ public static ArrayList getAdjacentCells(FillapixBoard board, FillapixCell cell) { ArrayList adjCells = new ArrayList(); Point cellLoc = cell.getLocation(); - for (int i=-1; i <= 1; i++) { - for (int j=-1; j <= 1; j++) { - if (cellLoc.getX() + i < 0 || cellLoc.y + j < 0 || cellLoc.x + i >= board.getWidth() || cellLoc.y + j >= board.getHeight()) { + for (int i = -1; i <= 1; i++) { + for (int j = -1; j <= 1; j++) { + if (cellLoc.getX() + i < 0 + || cellLoc.y + j < 0 + || cellLoc.x + i >= board.getWidth() + || cellLoc.y + j >= board.getHeight()) { continue; } FillapixCell adjCell = board.getCell(cellLoc.x + i, cellLoc.y + j); @@ -81,22 +83,34 @@ public static ArrayList getAdjacentCells(FillapixBoard board, Fill } /** - * Gets all cells that are contained in the square defined as having 'distance' - * cells between the center and the outer wall. For example, distance = 1:

- * |X|X|X|X|X|

- * |X| | | |X|

- * |X| |O| |X|

- * |X| | | |X|

- * |X|X|X|X|X|

- * O is 'cell', and all 'X' will be returned in the ArrayList + * Gets all cells that are contained in the square defined as having 'distance' cells between + * the center and the outer wall. For example, distance = 1: + * + *

|X|X|X|X|X| + * + *

|X| | | |X| + * + *

|X| |O| |X| + * + *

|X| | | |X| + * + *

|X|X|X|X|X| + * + *

O is 'cell', and all 'X' will be returned in the ArrayList */ - public static ArrayList getCellsAtDistance(FillapixBoard board, FillapixCell cell, int distance) { + public static ArrayList getCellsAtDistance( + FillapixBoard board, FillapixCell cell, int distance) { ArrayList adjCells = new ArrayList(); Point cellLoc = cell.getLocation(); int i = 0, j = 0; // top line - for (i = cellLoc.x - (distance), j = cellLoc.y - (distance+1); i <= cellLoc.x + (distance+1); i++) { - if (cellLoc.getX() + i < 0 || cellLoc.y + j < 0 || cellLoc.x + i >= board.getWidth() || cellLoc.y + j >= board.getHeight()) { + for (i = cellLoc.x - (distance), j = cellLoc.y - (distance + 1); + i <= cellLoc.x + (distance + 1); + i++) { + if (cellLoc.getX() + i < 0 + || cellLoc.y + j < 0 + || cellLoc.x + i >= board.getWidth() + || cellLoc.y + j >= board.getHeight()) { continue; } FillapixCell adjCell = board.getCell(cellLoc.x + i, cellLoc.y + j); @@ -106,8 +120,13 @@ public static ArrayList getCellsAtDistance(FillapixBoard board, Fi adjCells.add(adjCell); } // right line - for (i = cellLoc.x + (distance+1), j = cellLoc.y - (distance); j <= cellLoc.y + (distance+1); j++) { - if (cellLoc.getX() + i < 0 || cellLoc.y + j < 0 || cellLoc.x + i >= board.getWidth() || cellLoc.y + j >= board.getHeight()) { + for (i = cellLoc.x + (distance + 1), j = cellLoc.y - (distance); + j <= cellLoc.y + (distance + 1); + j++) { + if (cellLoc.getX() + i < 0 + || cellLoc.y + j < 0 + || cellLoc.x + i >= board.getWidth() + || cellLoc.y + j >= board.getHeight()) { continue; } FillapixCell adjCell = board.getCell(cellLoc.x + i, cellLoc.y + j); @@ -115,10 +134,15 @@ public static ArrayList getCellsAtDistance(FillapixBoard board, Fi continue; } adjCells.add(adjCell); - } + } // bottom line - for (i = cellLoc.x + (distance), j = cellLoc.y + (distance+1); i <= cellLoc.x - (distance+1); i--) { - if (cellLoc.getX() + i < 0 || cellLoc.y + j < 0 || cellLoc.x + i >= board.getWidth() || cellLoc.y + j >= board.getHeight()) { + for (i = cellLoc.x + (distance), j = cellLoc.y + (distance + 1); + i <= cellLoc.x - (distance + 1); + i--) { + if (cellLoc.getX() + i < 0 + || cellLoc.y + j < 0 + || cellLoc.x + i >= board.getWidth() + || cellLoc.y + j >= board.getHeight()) { continue; } FillapixCell adjCell = board.getCell(cellLoc.x + i, cellLoc.y + j); @@ -126,10 +150,15 @@ public static ArrayList getCellsAtDistance(FillapixBoard board, Fi continue; } adjCells.add(adjCell); - } + } // left line - for (i = cellLoc.x - (distance+1), j = cellLoc.y + (distance); j <= cellLoc.y - (distance+1); j--) { - if (cellLoc.getX() + i < 0 || cellLoc.y + j < 0 || cellLoc.x + i >= board.getWidth() || cellLoc.y + j >= board.getHeight()) { + for (i = cellLoc.x - (distance + 1), j = cellLoc.y + (distance); + j <= cellLoc.y - (distance + 1); + j--) { + if (cellLoc.getX() + i < 0 + || cellLoc.y + j < 0 + || cellLoc.x + i >= board.getWidth() + || cellLoc.y + j >= board.getHeight()) { continue; } FillapixCell adjCell = board.getCell(cellLoc.x + i, cellLoc.y + j); @@ -137,25 +166,25 @@ public static ArrayList getCellsAtDistance(FillapixBoard board, Fi continue; } adjCells.add(adjCell); - } + } return adjCells; - } + } /** - * Finds all possible combinations of chosenNumObj items can be - * chosen from totalNumObj total items. - * For example, if 1 item is chosen from 2 possible items, the combinations - * are: + * Finds all possible combinations of chosenNumObj items can be chosen from + * totalNumObj total items. For example, if 1 item is chosen from 2 possible items, the + * combinations are: + * *

[ [true,false], [false,true] ]
- * + * * @param totalNumItems the total number of items that can possibly be chosen * @param chosenNumItems the number of items to be chosen - * - * @return an ArrayList of Boolean arrays. Each index in the ArrayList represents - * a distinct combination. Each Boolean array will be totalNumItems - * long and each index will be true if the corresponding item is - * included in that combination, and false otherwise. + * @return an ArrayList of Boolean arrays. Each index in the ArrayList represents a distinct + * combination. Each Boolean array will be totalNumItems long and each index + * will be true if the corresponding item is included in that combination, and + * + * false otherwise. */ public static ArrayList getCombinations(int chosenNumItems, int totalNumItems) { ArrayList combinations = new ArrayList(); @@ -165,9 +194,15 @@ public static ArrayList getCombinations(int chosenNumItems, int total recurseCombinations(combinations, 0, chosenNumItems, 0, totalNumItems, array); return combinations; - } + } - private static void recurseCombinations(ArrayList result, int curIndex, int maxBlack, int numBlack, int len, boolean[] workingArray) { + private static void recurseCombinations( + ArrayList result, + int curIndex, + int maxBlack, + int numBlack, + int len, + boolean[] workingArray) { if (curIndex == len) { // complete, but not valid solution if (numBlack != maxBlack) { @@ -184,19 +219,19 @@ private static void recurseCombinations(ArrayList result, int curInde if (numBlack < maxBlack) { workingArray[curIndex] = true; - recurseCombinations(result, curIndex+1, maxBlack, numBlack+1, len, workingArray); + recurseCombinations(result, curIndex + 1, maxBlack, numBlack + 1, len, workingArray); } workingArray[curIndex] = false; - recurseCombinations(result, curIndex+1, maxBlack, numBlack, len, workingArray); + recurseCombinations(result, curIndex + 1, maxBlack, numBlack, len, workingArray); } - + public static boolean checkBoardForContradiction(FillapixBoard board) { ContradictionRule tooManyBlack = new TooManyBlackCellsContradictionRule(); ContradictionRule tooManyWhite = new TooFewBlackCellsContradictionRule(); - for (int i= 0; i < board.getWidth(); i++) { - for (int j=0; j < board.getHeight(); j++) { - if (tooManyBlack.checkContradictionAt(board, board.getCell(i, j)) == null || - tooManyWhite.checkContradictionAt(board, board.getCell(i, j)) == null) { + for (int i = 0; i < board.getWidth(); i++) { + for (int j = 0; j < board.getHeight(); j++) { + if (tooManyBlack.checkContradictionAt(board, board.getCell(i, j)) == null + || tooManyWhite.checkContradictionAt(board, board.getCell(i, j)) == null) { return true; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixView.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixView.java index 7e6453f58..55332e47d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixView.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixView.java @@ -3,7 +3,6 @@ import edu.rpi.legup.controller.BoardController; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.ui.boardview.GridBoardView; - import java.awt.*; public class FillapixView extends GridBoardView { @@ -16,8 +15,9 @@ public FillapixView(FillapixBoard board) { FillapixElementView elementView = new FillapixElementView(cell); elementView.setIndex(cell.getIndex()); elementView.setSize(elementSize); - elementView.setLocation(new Point(loc.x * elementSize.width, loc.y * elementSize.height)); + elementView.setLocation( + new Point(loc.x * elementSize.width, loc.y * elementSize.height)); elementViews.add(elementView); } } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/BlackTile.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/BlackTile.java index 7e43fc6b4..1d7c038a3 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/BlackTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/BlackTile.java @@ -4,6 +4,10 @@ public class BlackTile extends PlaceableElement { public BlackTile() { - super("FPIX-PLAC-0001", "Black Tile", "The black tile", "edu/rpi/legup/images/fillapix/tiles/BlackTile.png"); + super( + "FPIX-PLAC-0001", + "Black Tile", + "The black tile", + "edu/rpi/legup/images/fillapix/tiles/BlackTile.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/NumberTile.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/NumberTile.java index beee70e21..e869aeaf9 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/NumberTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/NumberTile.java @@ -6,7 +6,11 @@ public class NumberTile extends NonPlaceableElement { private int object_num; public NumberTile() { - super("FPIX-UNPL-0001", "Number Tile", "A numbered tile", "edu/rpi/legup/images/fillapix/tiles/NumberTile.png"); + super( + "FPIX-UNPL-0001", + "Number Tile", + "A numbered tile", + "edu/rpi/legup/images/fillapix/tiles/NumberTile.png"); object_num = 0; } @@ -23,5 +27,4 @@ public int getTileNumber() { public void setTileNumber(int num) { object_num = num; } - } diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/UnknownTile.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/UnknownTile.java index ef754782f..6778c1758 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/UnknownTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/UnknownTile.java @@ -4,6 +4,10 @@ public class UnknownTile extends NonPlaceableElement { public UnknownTile() { - super("FPIX-UNPL-0002", "Unknown Tile", "A blank tile", "edu/rpi/legup/images/fillapix/tiles/UnknownTile.png"); + super( + "FPIX-UNPL-0002", + "Unknown Tile", + "A blank tile", + "edu/rpi/legup/images/fillapix/tiles/UnknownTile.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/WhiteTile.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/WhiteTile.java index dd27d2834..67065a7e9 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/WhiteTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/elements/WhiteTile.java @@ -4,6 +4,10 @@ public class WhiteTile extends PlaceableElement { public WhiteTile() { - super("FPIX-PLAC-0002", "White Tile", "The white tile", "edu/rpi/legup/images/fillapix/tiles/WhiteTile.png"); + super( + "FPIX-PLAC-0002", + "White Tile", + "The white tile", + "edu/rpi/legup/images/fillapix/tiles/WhiteTile.png"); } } 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 1e5151c48..860a6c011 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 @@ -8,13 +8,13 @@ import edu.rpi.legup.puzzle.fillapix.FillapixBoard; import edu.rpi.legup.puzzle.fillapix.FillapixCell; import edu.rpi.legup.puzzle.fillapix.FillapixCellType; - import java.util.ArrayList; import java.util.List; public class BlackOrWhiteCaseRule extends CaseRule { public BlackOrWhiteCaseRule() { - super("FPIX-CASE-0001", + super( + "FPIX-CASE-0001", "Black or White", "Each cell is either black or white.", "edu/rpi/legup/images/fillapix/cases/BlackOrWhite.png"); @@ -62,20 +62,24 @@ public String checkRuleRaw(TreeTransition transition) { TreeTransition case1 = childTransitions.get(0); TreeTransition case2 = childTransitions.get(1); - if (case1.getBoard().getModifiedData().size() != 1 || - case2.getBoard().getModifiedData().size() != 1) { - return super.getInvalidUseOfRuleMessage() + ": This case rule must have 1 modified cell for each case."; + if (case1.getBoard().getModifiedData().size() != 1 + || case2.getBoard().getModifiedData().size() != 1) { + 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 super.getInvalidUseOfRuleMessage() + ": 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 super.getInvalidUseOfRuleMessage() + ": This case rule must an empty cell and a lit cell."; + || (mod2.getType() == FillapixCellType.BLACK + && mod1.getType() == FillapixCellType.WHITE))) { + return super.getInvalidUseOfRuleMessage() + + ": This case rule must an empty cell and a lit cell."; } return null; @@ -85,4 +89,4 @@ public String checkRuleRaw(TreeTransition transition) { public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { return null; } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithBlackDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithBlackDirectRule.java index 06a8045ed..ccc002f46 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithBlackDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithBlackDirectRule.java @@ -1,63 +1,66 @@ -package edu.rpi.legup.puzzle.fillapix.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.fillapix.FillapixBoard; -import edu.rpi.legup.puzzle.fillapix.FillapixCell; -import edu.rpi.legup.puzzle.fillapix.FillapixCellType; -import edu.rpi.legup.puzzle.fillapix.FillapixUtilities; - -public class FinishWithBlackDirectRule extends DirectRule { - public FinishWithBlackDirectRule() { - super("FPIX-BASC-0001", - "Finish with Black", - "The remaining unknowns around and on a cell must be black to satisfy the number", - "edu/rpi/legup/images/fillapix/rules/FinishWithBlack.png"); - } - - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - FillapixBoard board = (FillapixBoard) transition.getBoard(); - FillapixBoard parentBoard = (FillapixBoard) transition.getParents().get(0).getBoard(); - FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement); - FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement); - - if (!(parentCell.getType() == FillapixCellType.UNKNOWN && cell.getType() == FillapixCellType.BLACK)) { - return super.getInvalidUseOfRuleMessage() + ": This cell must be black to be applicable with this rule."; - } - - if (FillapixUtilities.isForcedBlack(parentBoard, cell)) { - return null; - } - else { - return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be black"; - } - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - FillapixBoard fillapixBoard = (FillapixBoard) node.getBoard().copy(); - for (PuzzleElement element : fillapixBoard.getPuzzleElements()) { - FillapixCell cell = (FillapixCell) element; - if (cell.getType() == FillapixCellType.UNKNOWN && FillapixUtilities.isForcedBlack((FillapixBoard) node.getBoard(), cell)) { - cell.setCellType(FillapixCellType.BLACK); - fillapixBoard.addModifiedData(cell); - } - } - if (fillapixBoard.getModifiedData().isEmpty()) { - return null; - } - else { - return fillapixBoard; - } - } -} \ No newline at end of file +package edu.rpi.legup.puzzle.fillapix.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.fillapix.FillapixBoard; +import edu.rpi.legup.puzzle.fillapix.FillapixCell; +import edu.rpi.legup.puzzle.fillapix.FillapixCellType; +import edu.rpi.legup.puzzle.fillapix.FillapixUtilities; + +public class FinishWithBlackDirectRule extends DirectRule { + public FinishWithBlackDirectRule() { + super( + "FPIX-BASC-0001", + "Finish with Black", + "The remaining unknowns around and on a cell must be black to satisfy the number", + "edu/rpi/legup/images/fillapix/rules/FinishWithBlack.png"); + } + + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + FillapixBoard board = (FillapixBoard) transition.getBoard(); + FillapixBoard parentBoard = (FillapixBoard) transition.getParents().get(0).getBoard(); + FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement); + FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement); + + if (!(parentCell.getType() == FillapixCellType.UNKNOWN + && cell.getType() == FillapixCellType.BLACK)) { + return super.getInvalidUseOfRuleMessage() + + ": This cell must be black to be applicable with this rule."; + } + + if (FillapixUtilities.isForcedBlack(parentBoard, cell)) { + return null; + } else { + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be black"; + } + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + FillapixBoard fillapixBoard = (FillapixBoard) node.getBoard().copy(); + for (PuzzleElement element : fillapixBoard.getPuzzleElements()) { + FillapixCell cell = (FillapixCell) element; + if (cell.getType() == FillapixCellType.UNKNOWN + && FillapixUtilities.isForcedBlack((FillapixBoard) node.getBoard(), cell)) { + cell.setCellType(FillapixCellType.BLACK); + fillapixBoard.addModifiedData(cell); + } + } + if (fillapixBoard.getModifiedData().isEmpty()) { + return null; + } else { + return fillapixBoard; + } + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithWhiteDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithWhiteDirectRule.java index 7e213a59c..6735fb8f4 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithWhiteDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/FinishWithWhiteDirectRule.java @@ -1,63 +1,66 @@ -package edu.rpi.legup.puzzle.fillapix.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.fillapix.FillapixBoard; -import edu.rpi.legup.puzzle.fillapix.FillapixCell; -import edu.rpi.legup.puzzle.fillapix.FillapixCellType; -import edu.rpi.legup.puzzle.fillapix.FillapixUtilities; - -public class FinishWithWhiteDirectRule extends DirectRule { - public FinishWithWhiteDirectRule() { - super("FPIX-BASC-0002", - "Finish with White", - "The remaining unknowns around and on a cell must be white to satisfy the number", - "edu/rpi/legup/images/fillapix/rules/FinishWithWhite.png"); - } - - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - FillapixBoard board = (FillapixBoard) transition.getBoard(); - FillapixBoard parentBoard = (FillapixBoard) transition.getParents().get(0).getBoard(); - FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement); - FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement); - - if (!(parentCell.getType() == FillapixCellType.UNKNOWN && cell.getType() == FillapixCellType.WHITE)) { - return super.getInvalidUseOfRuleMessage() + ": This cell must be white to be applicable with this rule"; - } - - if (FillapixUtilities.isForcedWhite(parentBoard, cell)) { - return null; - } - else { - return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be white"; - } - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - FillapixBoard fillapixBoard = (FillapixBoard) node.getBoard().copy(); - for (PuzzleElement element : fillapixBoard.getPuzzleElements()) { - FillapixCell cell = (FillapixCell) element; - if (cell.getType() == FillapixCellType.UNKNOWN && FillapixUtilities.isForcedWhite((FillapixBoard) node.getBoard(), cell)) { - cell.setCellType(FillapixCellType.WHITE); - fillapixBoard.addModifiedData(cell); - } - } - if (fillapixBoard.getModifiedData().isEmpty()) { - return null; - } - else { - return fillapixBoard; - } - } -} \ No newline at end of file +package edu.rpi.legup.puzzle.fillapix.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.fillapix.FillapixBoard; +import edu.rpi.legup.puzzle.fillapix.FillapixCell; +import edu.rpi.legup.puzzle.fillapix.FillapixCellType; +import edu.rpi.legup.puzzle.fillapix.FillapixUtilities; + +public class FinishWithWhiteDirectRule extends DirectRule { + public FinishWithWhiteDirectRule() { + super( + "FPIX-BASC-0002", + "Finish with White", + "The remaining unknowns around and on a cell must be white to satisfy the number", + "edu/rpi/legup/images/fillapix/rules/FinishWithWhite.png"); + } + + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + FillapixBoard board = (FillapixBoard) transition.getBoard(); + FillapixBoard parentBoard = (FillapixBoard) transition.getParents().get(0).getBoard(); + FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement); + FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement); + + if (!(parentCell.getType() == FillapixCellType.UNKNOWN + && cell.getType() == FillapixCellType.WHITE)) { + return super.getInvalidUseOfRuleMessage() + + ": This cell must be white to be applicable with this rule"; + } + + if (FillapixUtilities.isForcedWhite(parentBoard, cell)) { + return null; + } else { + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be white"; + } + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + FillapixBoard fillapixBoard = (FillapixBoard) node.getBoard().copy(); + for (PuzzleElement element : fillapixBoard.getPuzzleElements()) { + FillapixCell cell = (FillapixCell) element; + if (cell.getType() == FillapixCellType.UNKNOWN + && FillapixUtilities.isForcedWhite((FillapixBoard) node.getBoard(), cell)) { + cell.setCellType(FillapixCellType.WHITE); + fillapixBoard.addModifiedData(cell); + } + } + if (fillapixBoard.getModifiedData().isEmpty()) { + return null; + } else { + return fillapixBoard; + } + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/MirrorDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/MirrorDirectRule.java index 656cedb3f..e91931bd4 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/MirrorDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/MirrorDirectRule.java @@ -1,103 +1,107 @@ -package edu.rpi.legup.puzzle.fillapix.rules; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.CaseRule; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.fillapix.FillapixBoard; -import edu.rpi.legup.puzzle.fillapix.FillapixCell; -import edu.rpi.legup.puzzle.fillapix.FillapixCellType; -import edu.rpi.legup.puzzle.fillapix.FillapixUtilities; - -public class MirrorDirectRule extends DirectRule { - public MirrorDirectRule() { - super("FPIX-BASC-0003", - "Mirror", - "Two adjacent clues with the same value must have the same number of black squares in their unshared regions", - "edu/rpi/legup/images/fillapix/rules/Mirror.png"); - } - - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - FillapixBoard board = (FillapixBoard) transition.getBoard(); - FillapixBoard parentBoard = (FillapixBoard) transition.getParents().get(0).getBoard().copy(); - FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement); - FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement); - - // cell has to have been empty before - if (parentCell.getType() != FillapixCellType.UNKNOWN) { - return super.getInvalidUseOfRuleMessage(); - } - - // parentBoard cannot have any contradictions - if (FillapixUtilities.checkBoardForContradiction(parentBoard)) { - return super.getInvalidUseOfRuleMessage(); - } - - // find all cells adjacent to cell that are numbered - ArrayList adjCells = FillapixUtilities.getAdjacentCells(parentBoard, parentCell); - ArrayList adjNums = new ArrayList(); - for (int i=0; i < adjCells.size(); i++) { - if ((adjCells.get(i)).getNumber() >= 0 && adjCells.get(i).getNumber() < 10) { - adjNums.add(adjCells.get(i)); - } - } - // the numbered cells must be next to another numbered cell of the same value - Iterator itr = adjNums.iterator(); - while (itr.hasNext()) { - FillapixCell adjNum = itr.next(); - adjCells = FillapixUtilities.getAdjacentCells(parentBoard, adjNum); - boolean found = false; - for (FillapixCell adjCell : adjCells) { - if (adjCell.getNumber() == adjNum.getNumber() && adjCell.getIndex() != adjNum.getIndex()) { - found = true; - } - } - if (!found) { - itr.remove(); - } - } - - // change the color of the parentCell, and check if there exists a valid board - if (cell.getType() == FillapixCellType.BLACK) { - parentCell.setCellType(FillapixCellType.WHITE); - } - else { - parentCell.setCellType(FillapixCellType.BLACK); - } - parentBoard.addModifiedData(parentCell); - CaseRule completeClue = new SatisfyClueCaseRule(); - List caseBoards; - for (FillapixCell adjNum : adjNums) { - caseBoards = completeClue.getCases(parentBoard, adjNum); - boolean found = true; - for (Board b : caseBoards) { - if (!FillapixUtilities.checkBoardForContradiction((FillapixBoard) b)) { - found = false; - } - } - if (found) { - return null; - } - } - - return super.getInvalidUseOfRuleMessage(); - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} \ No newline at end of file +package edu.rpi.legup.puzzle.fillapix.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.CaseRule; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.fillapix.FillapixBoard; +import edu.rpi.legup.puzzle.fillapix.FillapixCell; +import edu.rpi.legup.puzzle.fillapix.FillapixCellType; +import edu.rpi.legup.puzzle.fillapix.FillapixUtilities; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class MirrorDirectRule extends DirectRule { + public MirrorDirectRule() { + super( + "FPIX-BASC-0003", + "Mirror", + "Two adjacent clues with the same value must have the same number of black squares" + + " in their unshared regions", + "edu/rpi/legup/images/fillapix/rules/Mirror.png"); + } + + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + FillapixBoard board = (FillapixBoard) transition.getBoard(); + FillapixBoard parentBoard = + (FillapixBoard) transition.getParents().get(0).getBoard().copy(); + FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement); + FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement); + + // cell has to have been empty before + if (parentCell.getType() != FillapixCellType.UNKNOWN) { + return super.getInvalidUseOfRuleMessage(); + } + + // parentBoard cannot have any contradictions + if (FillapixUtilities.checkBoardForContradiction(parentBoard)) { + return super.getInvalidUseOfRuleMessage(); + } + + // find all cells adjacent to cell that are numbered + ArrayList adjCells = + FillapixUtilities.getAdjacentCells(parentBoard, parentCell); + ArrayList adjNums = new ArrayList(); + for (int i = 0; i < adjCells.size(); i++) { + if ((adjCells.get(i)).getNumber() >= 0 && adjCells.get(i).getNumber() < 10) { + adjNums.add(adjCells.get(i)); + } + } + // the numbered cells must be next to another numbered cell of the same value + Iterator itr = adjNums.iterator(); + while (itr.hasNext()) { + FillapixCell adjNum = itr.next(); + adjCells = FillapixUtilities.getAdjacentCells(parentBoard, adjNum); + boolean found = false; + for (FillapixCell adjCell : adjCells) { + if (adjCell.getNumber() == adjNum.getNumber() + && adjCell.getIndex() != adjNum.getIndex()) { + found = true; + } + } + if (!found) { + itr.remove(); + } + } + + // change the color of the parentCell, and check if there exists a valid board + if (cell.getType() == FillapixCellType.BLACK) { + parentCell.setCellType(FillapixCellType.WHITE); + } else { + parentCell.setCellType(FillapixCellType.BLACK); + } + parentBoard.addModifiedData(parentCell); + CaseRule completeClue = new SatisfyClueCaseRule(); + List caseBoards; + for (FillapixCell adjNum : adjNums) { + caseBoards = completeClue.getCases(parentBoard, adjNum); + boolean found = true; + for (Board b : caseBoards) { + if (!FillapixUtilities.checkBoardForContradiction((FillapixBoard) b)) { + found = false; + } + } + if (found) { + return null; + } + } + + return super.getInvalidUseOfRuleMessage(); + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/NonTouchingSharedDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/NonTouchingSharedDirectRule.java index fe94dbcb4..71a85a95b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/NonTouchingSharedDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/NonTouchingSharedDirectRule.java @@ -1,99 +1,103 @@ -package edu.rpi.legup.puzzle.fillapix.rules; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.CaseRule; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.fillapix.FillapixBoard; -import edu.rpi.legup.puzzle.fillapix.FillapixCell; -import edu.rpi.legup.puzzle.fillapix.FillapixCellType; -import edu.rpi.legup.puzzle.fillapix.FillapixUtilities; - -public class NonTouchingSharedDirectRule extends DirectRule { - public NonTouchingSharedDirectRule() { - super("FPIX-BASC-0005", - "NonTouching Shared", - "Clues with shared cells have the same difference in black cells in their unshared regions as the difference in their numbers", - "edu/rpi/legup/images/fillapix/rules/TouchingSides.png"); - } - - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - FillapixBoard board = (FillapixBoard) transition.getBoard(); - FillapixBoard parentBoard = (FillapixBoard) transition.getParents().get(0).getBoard().copy(); - FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement); - FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement); - - // cell has to have been empty before - if (parentCell.getType() != FillapixCellType.UNKNOWN) { - return super.getInvalidUseOfRuleMessage(); - } - - // parentBoard cannot have any contradictions - if (FillapixUtilities.checkBoardForContradiction(parentBoard)) { - return super.getInvalidUseOfRuleMessage(); - } - - // get all adjCells that have a number - ArrayList adjCells = FillapixUtilities.getAdjacentCells(parentBoard, parentCell); - adjCells.removeIf(x -> x.getNumber() < 0 || x.getNumber() >= 10); - /* remove any number cell that does not have another number cell not - * touching, but sharing cells */ - Iterator itr = adjCells.iterator(); - while (itr.hasNext()) { - ArrayList sharingCells = FillapixUtilities.getCellsAtDistance(parentBoard, parentCell, 1); - boolean found = false; - for (FillapixCell sharingCell : sharingCells) { - if (sharingCell.getNumber() >= 0 && sharingCell.getNumber() < 10) { - found = true; - } - } - if (!found) { - itr.remove(); - } - } - - // change the cell to the opposite color - if (cell.getType() == FillapixCellType.BLACK) { - parentCell.setCellType(FillapixCellType.WHITE); - } - else { - parentCell.setCellType(FillapixCellType.BLACK); - } - // check for some contradiction in all cases - parentBoard.addModifiedData(parentCell); - CaseRule completeClue = new SatisfyClueCaseRule(); - List caseBoards; - for (FillapixCell adjCell : adjCells) { - caseBoards = completeClue.getCases(parentBoard, adjCell); - boolean found = true; - for (Board b : caseBoards) { - if (!FillapixUtilities.checkBoardForContradiction((FillapixBoard) b)) { - found = false; - } - } - if (found) { - return null; - } - } - - return super.getInvalidUseOfRuleMessage(); - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} \ No newline at end of file +package edu.rpi.legup.puzzle.fillapix.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.CaseRule; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.fillapix.FillapixBoard; +import edu.rpi.legup.puzzle.fillapix.FillapixCell; +import edu.rpi.legup.puzzle.fillapix.FillapixCellType; +import edu.rpi.legup.puzzle.fillapix.FillapixUtilities; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class NonTouchingSharedDirectRule extends DirectRule { + public NonTouchingSharedDirectRule() { + super( + "FPIX-BASC-0005", + "NonTouching Shared", + "Clues with shared cells have the same difference in black cells in their unshared" + + " regions as the difference in their numbers", + "edu/rpi/legup/images/fillapix/rules/TouchingSides.png"); + } + + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + FillapixBoard board = (FillapixBoard) transition.getBoard(); + FillapixBoard parentBoard = + (FillapixBoard) transition.getParents().get(0).getBoard().copy(); + FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement); + FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement); + + // cell has to have been empty before + if (parentCell.getType() != FillapixCellType.UNKNOWN) { + return super.getInvalidUseOfRuleMessage(); + } + + // parentBoard cannot have any contradictions + if (FillapixUtilities.checkBoardForContradiction(parentBoard)) { + return super.getInvalidUseOfRuleMessage(); + } + + // get all adjCells that have a number + ArrayList adjCells = + FillapixUtilities.getAdjacentCells(parentBoard, parentCell); + adjCells.removeIf(x -> x.getNumber() < 0 || x.getNumber() >= 10); + /* remove any number cell that does not have another number cell not + * touching, but sharing cells */ + Iterator itr = adjCells.iterator(); + while (itr.hasNext()) { + ArrayList sharingCells = + FillapixUtilities.getCellsAtDistance(parentBoard, parentCell, 1); + boolean found = false; + for (FillapixCell sharingCell : sharingCells) { + if (sharingCell.getNumber() >= 0 && sharingCell.getNumber() < 10) { + found = true; + } + } + if (!found) { + itr.remove(); + } + } + + // change the cell to the opposite color + if (cell.getType() == FillapixCellType.BLACK) { + parentCell.setCellType(FillapixCellType.WHITE); + } else { + parentCell.setCellType(FillapixCellType.BLACK); + } + // check for some contradiction in all cases + parentBoard.addModifiedData(parentCell); + CaseRule completeClue = new SatisfyClueCaseRule(); + List caseBoards; + for (FillapixCell adjCell : adjCells) { + caseBoards = completeClue.getCases(parentBoard, adjCell); + boolean found = true; + for (Board b : caseBoards) { + if (!FillapixUtilities.checkBoardForContradiction((FillapixBoard) b)) { + found = false; + } + } + if (found) { + return null; + } + } + + return super.getInvalidUseOfRuleMessage(); + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/SatisfyClueCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/SatisfyClueCaseRule.java index 4520add31..7db833f76 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/SatisfyClueCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/SatisfyClueCaseRule.java @@ -1,12 +1,5 @@ package edu.rpi.legup.puzzle.fillapix.rules; -import java.awt.Point; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; - import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.CaseBoard; import edu.rpi.legup.model.gameboard.PuzzleElement; @@ -17,13 +10,20 @@ import edu.rpi.legup.puzzle.fillapix.FillapixCell; import edu.rpi.legup.puzzle.fillapix.FillapixCellType; import edu.rpi.legup.puzzle.fillapix.FillapixUtilities; +import java.awt.Point; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; public class SatisfyClueCaseRule extends CaseRule { public SatisfyClueCaseRule() { - super("FPIX-CASE-0002", - "Satisfy Clue", - "Each clue must touch that number of squares.", - "edu/rpi/legup/images/fillapix/cases/SatisfyClue.png"); + super( + "FPIX-CASE-0002", + "Satisfy Clue", + "Each clue must touch that number of squares.", + "edu/rpi/legup/images/fillapix/cases/SatisfyClue.png"); } @Override @@ -33,7 +33,9 @@ public CaseBoard getCaseBoard(Board board) { fillapixBoard.setModifiable(false); for (PuzzleElement data : fillapixBoard.getPuzzleElements()) { FillapixCell cell = (FillapixCell) data; - if (cell.getNumber() >= 0 && cell.getNumber() <= 9 && FillapixUtilities.hasEmptyAdjacent(fillapixBoard, cell)) { + if (cell.getNumber() >= 0 + && cell.getNumber() <= 9 + && FillapixUtilities.hasEmptyAdjacent(fillapixBoard, cell)) { caseBoard.addPickableElement(data); } } @@ -70,26 +72,25 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { if (cellNumBlack > cellMaxBlack || cellNumEmpty == 0) { return cases; } - + // generate all cases as boolean expressions ArrayList combinations; combinations = FillapixUtilities.getCombinations(cellMaxBlack - cellNumBlack, cellNumEmpty); - for (int i=0; i < combinations.size(); i++) { + for (int i = 0; i < combinations.size(); i++) { Board case_ = board.copy(); - for (int j=0; j < combinations.get(i).length; j++) { + for (int j = 0; j < combinations.get(i).length; j++) { cell = (FillapixCell) case_.getPuzzleElement(emptyCells.get(j)); if (combinations.get(i)[j]) { cell.setCellType(FillapixCellType.BLACK); - } - else { + } else { cell.setCellType(FillapixCellType.WHITE); } case_.addModifiedData(cell); } cases.add(case_); } - + return cases; } @@ -99,26 +100,24 @@ public String checkRuleRaw(TreeTransition transition) { List childTransitions = parent.getChildren(); /* - * In order for the transition to be valid, it can only be applied to + * In order for the transition to be valid, it can only be applied to * one cell, thus: * * there must be modified cells * * all modified cells must share at least one common adjacent * cell * * all modified cells must fit within a 3X3 square - * * the center of one of the possible squaress must be a cell + * * the center of one of the possible squaress must be a cell * with a number * * that cells possible combinations must match the transitions * If all the above is verified, then the transition is valid */ - /* ensure there are modified cells */ Set modCells = transition.getBoard().getModifiedData(); if (modCells.size() <= 0) { return super.getInvalidUseOfRuleMessage(); } - /* ensure modified cells occur within a 3X3 square */ int minVertLoc = Integer.MAX_VALUE, maxVertLoc = Integer.MIN_VALUE; int minHorzLoc = Integer.MAX_VALUE, maxHorzLoc = Integer.MIN_VALUE; @@ -141,14 +140,16 @@ public String checkRuleRaw(TreeTransition transition) { return super.getInvalidUseOfRuleMessage(); } - - /* get the center of all possible 3X3 squares, + /* get the center of all possible 3X3 squares, * and collect all that have numbers */ FillapixBoard board = (FillapixBoard) transition.getParents().get(0).getBoard(); Set possibleCenters = new TreeSet(); - possibleCenters.addAll(FillapixUtilities.getAdjacentCells(board, (FillapixCell) modCells.iterator().next())); + possibleCenters.addAll( + FillapixUtilities.getAdjacentCells( + board, (FillapixCell) modCells.iterator().next())); for (PuzzleElement modCell : modCells) { - possibleCenters.retainAll((FillapixUtilities.getAdjacentCells(board, (FillapixCell) modCell))); + possibleCenters.retainAll( + (FillapixUtilities.getAdjacentCells(board, (FillapixCell) modCell))); } // removing all elements without a valid number possibleCenters.removeIf(x -> x.getNumber() < 0 || x.getNumber() >= 10); @@ -156,7 +157,6 @@ public String checkRuleRaw(TreeTransition transition) { return super.getInvalidUseOfRuleMessage(); } - /* Now go through the remaining centers, and check if their combinations * match the transitions */ for (FillapixCell possibleCenter : possibleCenters) { @@ -176,7 +176,8 @@ public String checkRuleRaw(TreeTransition transition) { continue; } - ArrayList combinations = FillapixUtilities.getCombinations(maxBlack - numBlack, numEmpty); + ArrayList combinations = + FillapixUtilities.getCombinations(maxBlack - numBlack, numEmpty); if (combinations.size() != childTransitions.size()) { // not this center because combinations do not match transitions continue; @@ -192,11 +193,10 @@ public String checkRuleRaw(TreeTransition transition) { } boolean[] translatedModCells = new boolean[transModCells.size()]; - for (int i=0; i < transModCells.size(); i++) { + for (int i = 0; i < transModCells.size(); i++) { if (transModCells.get(i).getType() == FillapixCellType.BLACK) { translatedModCells[i] = true; - } - else { + } else { translatedModCells[i] = false; } } @@ -226,9 +226,8 @@ public String checkRuleRaw(TreeTransition transition) { return super.getInvalidUseOfRuleMessage(); } - @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { return null; } -} \ No newline at end of file +} 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 c37050978..df5954d63 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 @@ -7,25 +7,26 @@ import edu.rpi.legup.puzzle.fillapix.FillapixCell; import edu.rpi.legup.puzzle.fillapix.FillapixCellType; import edu.rpi.legup.puzzle.fillapix.FillapixUtilities; - import java.util.ArrayList; public class TooFewBlackCellsContradictionRule extends ContradictionRule { public TooFewBlackCellsContradictionRule() { - super("FPIX-CONT-0001", + super( + "FPIX-CONT-0001", "Too Few Black Cells", "There may not be fewer black cells than the number.", "edu/rpi/legup/images/fillapix/contradictions/TooFewBlackCells.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { 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 68395ce7f..38b47c972 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 @@ -7,25 +7,26 @@ import edu.rpi.legup.puzzle.fillapix.FillapixCell; import edu.rpi.legup.puzzle.fillapix.FillapixCellType; import edu.rpi.legup.puzzle.fillapix.FillapixUtilities; - import java.util.ArrayList; public class TooManyBlackCellsContradictionRule extends ContradictionRule { public TooManyBlackCellsContradictionRule() { - super("FPIX-CONT-0002", + super( + "FPIX-CONT-0002", "Too Many Black Cells", "There may not be more black cells than the number", "edu/rpi/legup/images/fillapix/contradictions/TooManyBlackCells.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { @@ -45,8 +46,8 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { } if (numBlack > cellNum) { return null; - } - + } + return super.getNoContradictionMessage(); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TouchingCornersDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TouchingCornersDirectRule.java index 6f4be7842..72e2def47 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TouchingCornersDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TouchingCornersDirectRule.java @@ -1,108 +1,113 @@ -package edu.rpi.legup.puzzle.fillapix.rules; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.CaseRule; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.fillapix.FillapixBoard; -import edu.rpi.legup.puzzle.fillapix.FillapixCell; -import edu.rpi.legup.puzzle.fillapix.FillapixCellType; -import edu.rpi.legup.puzzle.fillapix.FillapixUtilities; - -public class TouchingCornersDirectRule extends DirectRule { - public TouchingCornersDirectRule() { - super("FPIX-BASC-0005", - "Touching Corners", - "Clues with touching corners have the same difference in black cells in their unshared regions as the difference in their numbers", - "edu/rpi/legup/images/fillapix/rules/TouchingCorners.png"); - } - - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - FillapixBoard board = (FillapixBoard) transition.getBoard(); - FillapixBoard parentBoard = (FillapixBoard) transition.getParents().get(0).getBoard().copy(); - FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement); - FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement); - - // cell has to have been empty before - if (parentCell.getType() != FillapixCellType.UNKNOWN) { - return super.getInvalidUseOfRuleMessage(); - } - - // parentBoard cannot have any contradictions - if (FillapixUtilities.checkBoardForContradiction(parentBoard)) { - return super.getInvalidUseOfRuleMessage(); - } - - // get all adjCells that have a number - ArrayList adjCells = FillapixUtilities.getAdjacentCells(parentBoard, parentCell); - adjCells.removeIf(x -> x.getNumber() < 0 || x.getNumber() >= 10); - /* remove any number cell that does not have another number cell diagonally - * adjacent to it on the opposite side of the modified cell */ - Iterator itr = adjCells.iterator(); - while (itr.hasNext()) { - FillapixCell adjCell = itr.next(); - - boolean found = false; - ArrayList adjAdjCells = FillapixUtilities.getAdjacentCells(parentBoard, adjCell); - for (FillapixCell adjAdjCell : adjAdjCells) { - if (adjAdjCell.getLocation().x != adjCell.getLocation().x && - adjAdjCell.getLocation().y != adjCell.getLocation().y && - adjAdjCell.getNumber() >= 0 && adjAdjCell.getNumber() < 10 && - adjAdjCell.getIndex() != parentCell.getIndex()) { - // adjAdjCell is diagonally adjacent to adjCell && it has a - // number && it is not parentCell - found = true; - } - } - - // does not qualify for this rule - if (!found) { - itr.remove(); - } - } - - // change the cell to the opposite color - if (cell.getType() == FillapixCellType.BLACK) { - parentCell.setCellType(FillapixCellType.WHITE); - } - else { - parentCell.setCellType(FillapixCellType.BLACK); - } - // check for some contradiction in all cases - parentBoard.addModifiedData(parentCell); - CaseRule completeClue = new SatisfyClueCaseRule(); - List caseBoards; - for (FillapixCell adjCell : adjCells) { - caseBoards = completeClue.getCases(parentBoard, adjCell); - boolean found = true; - for (Board b : caseBoards) { - if (!FillapixUtilities.checkBoardForContradiction((FillapixBoard) b)) { - found = false; - } - } - if (found) { - return null; - } - } - - return super.getInvalidUseOfRuleMessage(); - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} \ No newline at end of file +package edu.rpi.legup.puzzle.fillapix.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.CaseRule; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.fillapix.FillapixBoard; +import edu.rpi.legup.puzzle.fillapix.FillapixCell; +import edu.rpi.legup.puzzle.fillapix.FillapixCellType; +import edu.rpi.legup.puzzle.fillapix.FillapixUtilities; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class TouchingCornersDirectRule extends DirectRule { + public TouchingCornersDirectRule() { + super( + "FPIX-BASC-0005", + "Touching Corners", + "Clues with touching corners have the same difference in black cells in their" + + " unshared regions as the difference in their numbers", + "edu/rpi/legup/images/fillapix/rules/TouchingCorners.png"); + } + + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + FillapixBoard board = (FillapixBoard) transition.getBoard(); + FillapixBoard parentBoard = + (FillapixBoard) transition.getParents().get(0).getBoard().copy(); + FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement); + FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement); + + // cell has to have been empty before + if (parentCell.getType() != FillapixCellType.UNKNOWN) { + return super.getInvalidUseOfRuleMessage(); + } + + // parentBoard cannot have any contradictions + if (FillapixUtilities.checkBoardForContradiction(parentBoard)) { + return super.getInvalidUseOfRuleMessage(); + } + + // get all adjCells that have a number + ArrayList adjCells = + FillapixUtilities.getAdjacentCells(parentBoard, parentCell); + adjCells.removeIf(x -> x.getNumber() < 0 || x.getNumber() >= 10); + /* remove any number cell that does not have another number cell diagonally + * adjacent to it on the opposite side of the modified cell */ + Iterator itr = adjCells.iterator(); + while (itr.hasNext()) { + FillapixCell adjCell = itr.next(); + + boolean found = false; + ArrayList adjAdjCells = + FillapixUtilities.getAdjacentCells(parentBoard, adjCell); + for (FillapixCell adjAdjCell : adjAdjCells) { + if (adjAdjCell.getLocation().x != adjCell.getLocation().x + && adjAdjCell.getLocation().y != adjCell.getLocation().y + && adjAdjCell.getNumber() >= 0 + && adjAdjCell.getNumber() < 10 + && adjAdjCell.getIndex() != parentCell.getIndex()) { + // adjAdjCell is diagonally adjacent to adjCell && it has a + // number && it is not parentCell + found = true; + } + } + + // does not qualify for this rule + if (!found) { + itr.remove(); + } + } + + // change the cell to the opposite color + if (cell.getType() == FillapixCellType.BLACK) { + parentCell.setCellType(FillapixCellType.WHITE); + } else { + parentCell.setCellType(FillapixCellType.BLACK); + } + // check for some contradiction in all cases + parentBoard.addModifiedData(parentCell); + CaseRule completeClue = new SatisfyClueCaseRule(); + List caseBoards; + for (FillapixCell adjCell : adjCells) { + caseBoards = completeClue.getCases(parentBoard, adjCell); + boolean found = true; + for (Board b : caseBoards) { + if (!FillapixUtilities.checkBoardForContradiction((FillapixBoard) b)) { + found = false; + } + } + if (found) { + return null; + } + } + + return super.getInvalidUseOfRuleMessage(); + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TouchingSidesDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TouchingSidesDirectRule.java index bd6dd0169..281dd5392 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TouchingSidesDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/rules/TouchingSidesDirectRule.java @@ -1,115 +1,126 @@ -package edu.rpi.legup.puzzle.fillapix.rules; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.CaseRule; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.fillapix.FillapixBoard; -import edu.rpi.legup.puzzle.fillapix.FillapixCell; -import edu.rpi.legup.puzzle.fillapix.FillapixCellType; -import edu.rpi.legup.puzzle.fillapix.FillapixUtilities; - -public class TouchingSidesDirectRule extends DirectRule { - public TouchingSidesDirectRule() { - super("FPIX-BASC-0004", - "Touching Sides", - "Clues with touching sides have the same difference in black cells in their unshared regions as the difference in their numbers", - "edu/rpi/legup/images/fillapix/rules/TouchingSides.png"); - } - - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - FillapixBoard board = (FillapixBoard) transition.getBoard(); - FillapixBoard parentBoard = (FillapixBoard) transition.getParents().get(0).getBoard().copy(); - FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement); - FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement); - - // cell has to have been empty before - if (parentCell.getType() != FillapixCellType.UNKNOWN) { - return super.getInvalidUseOfRuleMessage(); - } - - // parentBoard cannot have any contradictions - if (FillapixUtilities.checkBoardForContradiction(parentBoard)) { - return super.getInvalidUseOfRuleMessage(); - } - - // get all adjCells that have a number - ArrayList adjCells = FillapixUtilities.getAdjacentCells(parentBoard, parentCell); - adjCells.removeIf(x -> x.getNumber() < 0 || x.getNumber() >= 10); - /* remove any number cell that does not have another number cell adjacent - * to it on the opposite side of the modified cell */ - Iterator itr = adjCells.iterator(); - while (itr.hasNext()) { - // calculate x and y offset of adjCell from cell - FillapixCell adjCell = itr.next(); - int xOffset = adjCell.getLocation().x - cell.getLocation().x; - int yOffset = adjCell.getLocation().y - cell.getLocation().y; - - boolean found = false; - // check vertically for numbered cell in opposite direction of cell - if (adjCell.getLocation().x + xOffset >= 0 && adjCell.getLocation().x < parentBoard.getWidth()) { - int adjNum = parentBoard.getCell(adjCell.getLocation().x + xOffset, adjCell.getLocation().y).getNumber(); - if (adjNum >= 0 && adjNum < 10) { - found = true; - } - } - // check horizontally for numbered cell in opposite direction of cell - if (adjCell.getLocation().y + yOffset >= 0 && adjCell.getLocation().y < parentBoard.getHeight()) { - int adjNum = parentBoard.getCell(adjCell.getLocation().x, adjCell.getLocation().y + yOffset).getNumber(); - if (adjNum >= 0 && adjNum < 10) { - found = true; - } - } - - // if no horizontally or vertically adjacent cell on opposite side of 'cell' has number, - // then adjCell is not valid, so should be removed - if (!found) { - itr.remove(); - } - } - - // change the cell to the opposite color - if (cell.getType() == FillapixCellType.BLACK) { - parentCell.setCellType(FillapixCellType.WHITE); - } - else { - parentCell.setCellType(FillapixCellType.BLACK); - } - // check for some contradiction in all cases - parentBoard.addModifiedData(parentCell); - CaseRule completeClue = new SatisfyClueCaseRule(); - List caseBoards; - for (FillapixCell adjCell : adjCells) { - caseBoards = completeClue.getCases(parentBoard, adjCell); - boolean found = true; - for (Board b : caseBoards) { - if (!FillapixUtilities.checkBoardForContradiction((FillapixBoard) b)) { - found = false; - } - } - if (found) { - return null; - } - } - - return super.getInvalidUseOfRuleMessage(); - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} \ No newline at end of file +package edu.rpi.legup.puzzle.fillapix.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.CaseRule; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.fillapix.FillapixBoard; +import edu.rpi.legup.puzzle.fillapix.FillapixCell; +import edu.rpi.legup.puzzle.fillapix.FillapixCellType; +import edu.rpi.legup.puzzle.fillapix.FillapixUtilities; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class TouchingSidesDirectRule extends DirectRule { + public TouchingSidesDirectRule() { + super( + "FPIX-BASC-0004", + "Touching Sides", + "Clues with touching sides have the same difference in black cells in their" + + " unshared regions as the difference in their numbers", + "edu/rpi/legup/images/fillapix/rules/TouchingSides.png"); + } + + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + FillapixBoard board = (FillapixBoard) transition.getBoard(); + FillapixBoard parentBoard = + (FillapixBoard) transition.getParents().get(0).getBoard().copy(); + FillapixCell cell = (FillapixCell) board.getPuzzleElement(puzzleElement); + FillapixCell parentCell = (FillapixCell) parentBoard.getPuzzleElement(puzzleElement); + + // cell has to have been empty before + if (parentCell.getType() != FillapixCellType.UNKNOWN) { + return super.getInvalidUseOfRuleMessage(); + } + + // parentBoard cannot have any contradictions + if (FillapixUtilities.checkBoardForContradiction(parentBoard)) { + return super.getInvalidUseOfRuleMessage(); + } + + // get all adjCells that have a number + ArrayList adjCells = + FillapixUtilities.getAdjacentCells(parentBoard, parentCell); + adjCells.removeIf(x -> x.getNumber() < 0 || x.getNumber() >= 10); + /* remove any number cell that does not have another number cell adjacent + * to it on the opposite side of the modified cell */ + Iterator itr = adjCells.iterator(); + while (itr.hasNext()) { + // calculate x and y offset of adjCell from cell + FillapixCell adjCell = itr.next(); + int xOffset = adjCell.getLocation().x - cell.getLocation().x; + int yOffset = adjCell.getLocation().y - cell.getLocation().y; + + boolean found = false; + // check vertically for numbered cell in opposite direction of cell + if (adjCell.getLocation().x + xOffset >= 0 + && adjCell.getLocation().x < parentBoard.getWidth()) { + int adjNum = + parentBoard + .getCell(adjCell.getLocation().x + xOffset, adjCell.getLocation().y) + .getNumber(); + if (adjNum >= 0 && adjNum < 10) { + found = true; + } + } + // check horizontally for numbered cell in opposite direction of cell + if (adjCell.getLocation().y + yOffset >= 0 + && adjCell.getLocation().y < parentBoard.getHeight()) { + int adjNum = + parentBoard + .getCell(adjCell.getLocation().x, adjCell.getLocation().y + yOffset) + .getNumber(); + if (adjNum >= 0 && adjNum < 10) { + found = true; + } + } + + // if no horizontally or vertically adjacent cell on opposite side of 'cell' has number, + // then adjCell is not valid, so should be removed + if (!found) { + itr.remove(); + } + } + + // change the cell to the opposite color + if (cell.getType() == FillapixCellType.BLACK) { + parentCell.setCellType(FillapixCellType.WHITE); + } else { + parentCell.setCellType(FillapixCellType.BLACK); + } + // check for some contradiction in all cases + parentBoard.addModifiedData(parentCell); + CaseRule completeClue = new SatisfyClueCaseRule(); + List caseBoards; + for (FillapixCell adjCell : adjCells) { + caseBoards = completeClue.getCases(parentBoard, adjCell); + boolean found = true; + for (Board b : caseBoards) { + if (!FillapixUtilities.checkBoardForContradiction((FillapixBoard) b)) { + found = false; + } + } + if (found) { + return null; + } + } + + return super.getInvalidUseOfRuleMessage(); + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/Heyawake.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/Heyawake.java index fc52a6fff..afe3dd652 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/Heyawake.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/Heyawake.java @@ -16,9 +16,7 @@ public Heyawake() { this.importer = new HeyawakeImporter(this); } - /** - * Initializes the view. Called by the invoker of the class - */ + /** Initializes the view. Called by the invoker of the class */ @Override public void initializeView() { boardView = new HeyawakeView((HeyawakeBoard) currentBoard); @@ -39,8 +37,8 @@ public Board generatePuzzle(int difficulty) { /** * Determines if the given dimensions are valid for HeyAwake * - * @param rows the number of rows - * @param columns the number of columns + * @param rows the number of rows + * @param columns the number of columns * @return true if the given dimensions are valid for HeyAwake, false otherwise */ public boolean isValidDimensions(int rows, int columns) { @@ -65,7 +63,5 @@ public boolean isBoardComplete(Board board) { * @param board the board that has changed */ @Override - public void onBoardChange(Board board) { - - } + public void onBoardChange(Board board) {} } diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeBoard.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeBoard.java index 2f15213ec..cedb3a91b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeBoard.java @@ -2,7 +2,6 @@ import edu.rpi.legup.model.gameboard.GridBoard; import edu.rpi.legup.model.gameboard.PuzzleElement; - import java.awt.*; import java.util.ArrayList; import java.util.HashMap; diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeCell.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeCell.java index ce8c73424..480e2e39b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeCell.java @@ -1,7 +1,6 @@ package edu.rpi.legup.puzzle.heyawake; import edu.rpi.legup.model.gameboard.GridCell; - import java.awt.*; public class HeyawakeCell extends GridCell { diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeController.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeController.java index 2bad91933..2d081d7da 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeController.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeController.java @@ -2,5 +2,4 @@ import edu.rpi.legup.controller.ElementController; -public class HeyawakeController extends ElementController { -} +public class HeyawakeController extends ElementController {} diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeElementView.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeElementView.java index 5efec44ff..d30159856 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeElementView.java @@ -1,7 +1,6 @@ package edu.rpi.legup.puzzle.heyawake; import edu.rpi.legup.ui.boardview.GridElementView; - import java.awt.*; public class HeyawakeElementView extends GridElementView { @@ -39,7 +38,8 @@ public void drawElement(Graphics2D graphics2D) { FontMetrics metrics = graphics2D.getFontMetrics(FONT); String value = String.valueOf(puzzleElement.getData()); int xText = location.x + (size.width - metrics.stringWidth(value)) / 2; - int yText = location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent(); + int yText = + location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent(); graphics2D.drawString(String.valueOf(puzzleElement.getData()), xText, yText); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeExporter.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeExporter.java index 344a0be92..4470d77be 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeExporter.java @@ -2,7 +2,6 @@ import edu.rpi.legup.model.PuzzleExporter; import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; import org.w3c.dom.Document; public class HeyawakeExporter extends PuzzleExporter { @@ -16,8 +15,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { HeyawakeBoard board; if (puzzle.getTree() != null) { board = (HeyawakeBoard) puzzle.getTree().getRootNode().getBoard(); - } - else { + } else { board = (HeyawakeBoard) puzzle.getBoardView().getBoard(); } @@ -29,7 +27,8 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { for (PuzzleElement puzzleElement : board.getPuzzleElements()) { HeyawakeCell cell = (HeyawakeCell) puzzleElement; if (cell.getData() != -2) { - org.w3c.dom.Element cellElement = puzzle.getFactory().exportCell(newDocument, puzzleElement); + org.w3c.dom.Element cellElement = + puzzle.getFactory().exportCell(newDocument, puzzleElement); cellsElement.appendChild(cellElement); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeFactory.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeFactory.java index 96fc20e6f..8ecf24135 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeFactory.java @@ -4,17 +4,16 @@ import edu.rpi.legup.model.gameboard.ElementFactory; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; -import java.awt.*; - public class HeyawakeFactory extends ElementFactory { /** * Creates a puzzleElement based on the xml document Node and adds it to the board * - * @param node node that represents the puzzleElement + * @param node node that represents the puzzleElement * @param board board to add the newly created cell * @return newly created cell from the xml document Node * @throws InvalidFileFormatException if file is invalid @@ -23,7 +22,8 @@ public class HeyawakeFactory extends ElementFactory { public HeyawakeCell importCell(Node node, Board board) throws InvalidFileFormatException { try { if (!node.getNodeName().equalsIgnoreCase("cell")) { - throw new InvalidFileFormatException("Heyawake Factory: unknown puzzleElement puzzleElement"); + throw new InvalidFileFormatException( + "Heyawake Factory: unknown puzzleElement puzzleElement"); } HeyawakeBoard heyawakeBoard = (HeyawakeBoard) board; @@ -36,7 +36,8 @@ public HeyawakeCell importCell(Node node, Board board) throws InvalidFileFormatE int y = Integer.valueOf(attributeList.getNamedItem("y").getNodeValue()); int regionIndex = Integer.valueOf(attributeList.getNamedItem("region").getNodeValue()); if (x >= width || y >= height) { - throw new InvalidFileFormatException("Heyawake Factory: cell location out of bounds"); + throw new InvalidFileFormatException( + "Heyawake Factory: cell location out of bounds"); } if (value < -4 || value > 4) { throw new InvalidFileFormatException("Heyawake Factory: cell unknown value"); @@ -46,11 +47,10 @@ public HeyawakeCell importCell(Node node, Board board) throws InvalidFileFormatE cell.setIndex(y * height + x); heyawakeBoard.getRegions(); return cell; - } - catch (NumberFormatException e) { - throw new InvalidFileFormatException("Heyawake Factory: unknown value where integer expected"); - } - catch (NullPointerException e) { + } catch (NumberFormatException e) { + throw new InvalidFileFormatException( + "Heyawake Factory: unknown value where integer expected"); + } catch (NullPointerException e) { throw new InvalidFileFormatException("Heyawake Factory: could not find attribute(s)"); } } @@ -58,7 +58,7 @@ public HeyawakeCell importCell(Node node, Board board) throws InvalidFileFormatE /** * Creates a xml document puzzleElement from a cell for exporting * - * @param document xml document + * @param document xml document * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeImporter.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeImporter.java index 7527c717f..6bbabd54d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeImporter.java @@ -2,12 +2,11 @@ import edu.rpi.legup.model.PuzzleImporter; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import java.awt.*; - public class HeyawakeImporter extends PuzzleImporter { public HeyawakeImporter(Heyawake heyawake) { @@ -27,14 +26,12 @@ public boolean acceptsTextInput() { /** * Creates an empty board for building * - * @param rows the number of rows on the board + * @param rows the number of rows on the board * @param columns the number of columns on the board * @throws RuntimeException if board can not be created */ @Override - public void initializeBoard(int rows, int columns) { - - } + public void initializeBoard(int rows, int columns) {} /** * Creates the board for building @@ -46,11 +43,13 @@ public void initializeBoard(int rows, int columns) { public void initializeBoard(Node node) throws InvalidFileFormatException { try { if (!node.getNodeName().equalsIgnoreCase("board")) { - throw new InvalidFileFormatException("Heyawake Importer: cannot find board puzzleElement"); + throw new InvalidFileFormatException( + "Heyawake Importer: cannot find board puzzleElement"); } Element boardElement = (Element) node; if (boardElement.getElementsByTagName("cells").getLength() == 0) { - throw new InvalidFileFormatException("Heyawake Importer: no puzzleElement found for board"); + throw new InvalidFileFormatException( + "Heyawake Importer: no puzzleElement found for board"); } Element dataElement = (Element) boardElement.getElementsByTagName("cells").item(0); NodeList elementDataList = dataElement.getElementsByTagName("cell"); @@ -59,9 +58,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { if (!boardElement.getAttribute("size").isEmpty()) { int size = Integer.valueOf(boardElement.getAttribute("size")); heyawakeBoard = new HeyawakeBoard(size); - } - else { - if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { + } else { + if (!boardElement.getAttribute("width").isEmpty() + && !boardElement.getAttribute("height").isEmpty()) { int width = Integer.valueOf(boardElement.getAttribute("width")); int height = Integer.valueOf(boardElement.getAttribute("height")); heyawakeBoard = new HeyawakeBoard(width, height); @@ -76,7 +75,10 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { int height = heyawakeBoard.getHeight(); for (int i = 0; i < elementDataList.getLength(); i++) { - HeyawakeCell cell = (HeyawakeCell) puzzle.getFactory().importCell(elementDataList.item(i), heyawakeBoard); + HeyawakeCell cell = + (HeyawakeCell) + puzzle.getFactory() + .importCell(elementDataList.item(i), heyawakeBoard); Point loc = cell.getLocation(); if (cell.getData() != -2) { cell.setModifiable(false); @@ -96,9 +98,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { } } puzzle.setCurrentBoard(heyawakeBoard); - } - catch (NumberFormatException e) { - throw new InvalidFileFormatException("Heyawake Importer: unknown value where integer expected"); + } catch (NumberFormatException e) { + throw new InvalidFileFormatException( + "Heyawake Importer: unknown value where integer expected"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeView.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeView.java index 00506df0f..fba5f0eb7 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeView.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeView.java @@ -4,7 +4,6 @@ import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.ui.boardview.ElementView; import edu.rpi.legup.ui.boardview.GridBoardView; - import java.awt.*; import java.awt.geom.Area; import java.util.HashMap; @@ -25,14 +24,14 @@ public HeyawakeView(HeyawakeBoard board) { HeyawakeElementView elementView = new HeyawakeElementView(cell); elementView.setIndex(cell.getIndex()); elementView.setSize(elementSize); - elementView.setLocation(new Point(loc.x * elementSize.width, loc.y * elementSize.height)); + elementView.setLocation( + new Point(loc.x * elementSize.width, loc.y * elementSize.height)); elementViews.add(elementView); int regionIndex = cell.getRegionIndex(); if (regionsBoundaries.get(regionIndex) == null) { regionsBoundaries.put(regionIndex, new Area(elementView.getBounds())); - } - else { + } else { regionsBoundaries.get(regionIndex).add(new Area(elementView.getBounds())); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/AdjacentBlacksContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/AdjacentBlacksContradictionRule.java index d2eceb7a1..88d293f5e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/AdjacentBlacksContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/AdjacentBlacksContradictionRule.java @@ -7,18 +7,21 @@ public class AdjacentBlacksContradictionRule extends ContradictionRule { public AdjacentBlacksContradictionRule() { - super("HEYA-CONT-0001", "Adjacent Blacks", + super( + "HEYA-CONT-0001", + "Adjacent Blacks", "", "edu/rpi/legup/images/heyawake/contradictions/adjacentBlacks.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackOrWhiteCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackOrWhiteCaseRule.java index 0e7552dd2..251be46ee 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackOrWhiteCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackOrWhiteCaseRule.java @@ -5,21 +5,21 @@ import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.rules.CaseRule; import edu.rpi.legup.model.tree.TreeTransition; - import java.util.List; public class BlackOrWhiteCaseRule extends CaseRule { public BlackOrWhiteCaseRule() { - super("HEYA-CASE-0001", + super( + "HEYA-CASE-0001", "Black or White", "", "edu/rpi/legup/images/heyawake/cases/BlackOrWhite.png"); } /** - * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. This method is - * the one that should overridden in child classes. + * Checks whether the {@link TreeTransition} logically follows from the parent node using this + * rule. This method is the one that should overridden in child classes. * * @param transition transition to check * @return null if the child node logically follow from the parent node, otherwise error message @@ -30,13 +30,14 @@ public String checkRuleRaw(TreeTransition transition) { } /** - * Checks whether the child node logically follows from the parent node at the specific puzzleElement index using - * this rule. This method is the one that should overridden in child classes. + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule. This method is the one that should overridden in child + * classes. * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { @@ -44,7 +45,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem } /** - * Gets the case board that indicates where this case rule can be applied on the given {@link Board}. + * Gets the case board that indicates where this case rule can be applied on the given {@link + * Board}. * * @param board board to find locations where this case rule can be applied * @return a case board @@ -55,9 +57,10 @@ public CaseBoard getCaseBoard(Board board) { } /** - * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on this case rule. + * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on + * this case rule. * - * @param board the current board state + * @param board the current board state * @param puzzleElement equivalent puzzleElement * @return a list of elements the specified could be */ diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackPathDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackPathDirectRule.java index 474bdccdd..1fc3d0776 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackPathDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BlackPathDirectRule.java @@ -1,7 +1,7 @@ -package edu.rpi.legup.puzzle.heyawake.rules; - -public class BlackPathDirectRule { - public BlackPathDirectRule() { - throw new RuntimeException("This rule has not been implemented"); - } -} +package edu.rpi.legup.puzzle.heyawake.rules; + +public class BlackPathDirectRule { + public BlackPathDirectRule() { + throw new RuntimeException("This rule has not been implemented"); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BottleNeckDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BottleNeckDirectRule.java index f2e7fef5c..41d950378 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BottleNeckDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/BottleNeckDirectRule.java @@ -1,7 +1,7 @@ -package edu.rpi.legup.puzzle.heyawake.rules; - -public class BottleNeckDirectRule { - public BottleNeckDirectRule() { - throw new RuntimeException("This rule has not been implemented"); - } -} +package edu.rpi.legup.puzzle.heyawake.rules; + +public class BottleNeckDirectRule { + public BottleNeckDirectRule() { + throw new RuntimeException("This rule has not been implemented"); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomBlackDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomBlackDirectRule.java index 828739160..aee1ae4bf 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomBlackDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomBlackDirectRule.java @@ -1,43 +1,45 @@ -package edu.rpi.legup.puzzle.heyawake.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; - -public class FillRoomBlackDirectRule extends DirectRule { - - public FillRoomBlackDirectRule() { - super("HEYA-BASC-0003", - "Fill Room Black", - "", - "edu/rpi/legup/images/heyawake/rules/FillRoomBlack.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * This method is the one that should overridden in child classes - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - return null; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.heyawake.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; + +public class FillRoomBlackDirectRule extends DirectRule { + + public FillRoomBlackDirectRule() { + super( + "HEYA-BASC-0003", + "Fill Room Black", + "", + "edu/rpi/legup/images/heyawake/rules/FillRoomBlack.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule This method is the one that should overridden in child + * classes + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + return null; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomWhiteDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomWhiteDirectRule.java index 6b1a11c29..c4609b239 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomWhiteDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/FillRoomWhiteDirectRule.java @@ -1,43 +1,45 @@ -package edu.rpi.legup.puzzle.heyawake.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; - -public class FillRoomWhiteDirectRule extends DirectRule { - - public FillRoomWhiteDirectRule() { - super("HEYA-BASC-0004", - "Fill Room White", - "", - "edu/rpi/legup/images/heyawake/rules/FillRoomWhite.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * This method is the one that should overridden in child classes - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - return null; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.heyawake.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; + +public class FillRoomWhiteDirectRule extends DirectRule { + + public FillRoomWhiteDirectRule() { + super( + "HEYA-BASC-0004", + "Fill Room White", + "", + "edu/rpi/legup/images/heyawake/rules/FillRoomWhite.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule This method is the one that should overridden in child + * classes + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + return null; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/OneRowDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/OneRowDirectRule.java index 3e8c07a4d..8b6f21564 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/OneRowDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/OneRowDirectRule.java @@ -1,7 +1,7 @@ -package edu.rpi.legup.puzzle.heyawake.rules; - -public class OneRowDirectRule { - public OneRowDirectRule() { - throw new RuntimeException("This rule has not been implemented"); - } -} +package edu.rpi.legup.puzzle.heyawake.rules; + +public class OneRowDirectRule { + public OneRowDirectRule() { + throw new RuntimeException("This rule has not been implemented"); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/PreventWhiteLineDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/PreventWhiteLineDirectRule.java index 0efd90694..f5d4e78b7 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/PreventWhiteLineDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/PreventWhiteLineDirectRule.java @@ -1,7 +1,7 @@ -package edu.rpi.legup.puzzle.heyawake.rules; - -public class PreventWhiteLineDirectRule { - public PreventWhiteLineDirectRule() { - throw new RuntimeException("This rule has not been implemented"); - } -} +package edu.rpi.legup.puzzle.heyawake.rules; + +public class PreventWhiteLineDirectRule { + public PreventWhiteLineDirectRule() { + throw new RuntimeException("This rule has not been implemented"); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooEmptyContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooEmptyContradictionRule.java index 0e0beaeb2..762b435a2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooEmptyContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooEmptyContradictionRule.java @@ -7,19 +7,21 @@ public class RoomTooEmptyContradictionRule extends ContradictionRule { public RoomTooEmptyContradictionRule() { - super("HEYA-CONT-0002", + super( + "HEYA-CONT-0002", "Room too Empty", "", "edu/rpi/legup/images/heyawake/contradictions/RoomTooEmpty.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooFullContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooFullContradictionRule.java index 1de746cb2..643f75f13 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooFullContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/RoomTooFullContradictionRule.java @@ -7,19 +7,21 @@ public class RoomTooFullContradictionRule extends ContradictionRule { public RoomTooFullContradictionRule() { - super("HEYA-CONT-0003", + super( + "HEYA-CONT-0003", "Room too Full", "", "edu/rpi/legup/images/heyawake/contradictions/RoomTooFull.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ThreeByThreeDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ThreeByThreeDirectRule.java index 6dee3fc83..cf2c241e3 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ThreeByThreeDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ThreeByThreeDirectRule.java @@ -1,7 +1,7 @@ -package edu.rpi.legup.puzzle.heyawake.rules; - -public class ThreeByThreeDirectRule { - public ThreeByThreeDirectRule() { - throw new RuntimeException("This rule has not been implemented"); - } -} +package edu.rpi.legup.puzzle.heyawake.rules; + +public class ThreeByThreeDirectRule { + public ThreeByThreeDirectRule() { + throw new RuntimeException("This rule has not been implemented"); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/TwoInCornerDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/TwoInCornerDirectRule.java index 8e2776fc7..83f1ca72f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/TwoInCornerDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/TwoInCornerDirectRule.java @@ -1,7 +1,7 @@ -package edu.rpi.legup.puzzle.heyawake.rules; - -public class TwoInCornerDirectRule { - public TwoInCornerDirectRule() { - throw new RuntimeException("This rule has not been implemented"); - } -} +package edu.rpi.legup.puzzle.heyawake.rules; + +public class TwoInCornerDirectRule { + public TwoInCornerDirectRule() { + throw new RuntimeException("This rule has not been implemented"); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAreaContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAreaContradictionRule.java index a287d9c78..c0987d4f9 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAreaContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAreaContradictionRule.java @@ -7,19 +7,21 @@ public class WhiteAreaContradictionRule extends ContradictionRule { public WhiteAreaContradictionRule() { - super("HEYA-CONT-0004", + super( + "HEYA-CONT-0004", "White Area", "", "edu/rpi/legup/images/heyawake/contradictions/WhiteArea.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAroundBlackDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAroundBlackDirectRule.java index 21a698d41..2e3bc1812 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAroundBlackDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteAroundBlackDirectRule.java @@ -1,43 +1,45 @@ -package edu.rpi.legup.puzzle.heyawake.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; - -public class WhiteAroundBlackDirectRule extends DirectRule { - - public WhiteAroundBlackDirectRule() { - super("HEYA-BASC-0009", - "White Around Black", - "", - "edu/rpi/legup/images/heyawake/rules/WhiteAroundBlack.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * This method is the one that should overridden in child classes - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - return null; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.heyawake.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; + +public class WhiteAroundBlackDirectRule extends DirectRule { + + public WhiteAroundBlackDirectRule() { + super( + "HEYA-BASC-0009", + "White Around Black", + "", + "edu/rpi/legup/images/heyawake/rules/WhiteAroundBlack.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule This method is the one that should overridden in child + * classes + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + return null; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteEscapeDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteEscapeDirectRule.java index 231d353e6..f151ec12a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteEscapeDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteEscapeDirectRule.java @@ -1,7 +1,7 @@ -package edu.rpi.legup.puzzle.heyawake.rules; - -public class WhiteEscapeDirectRule { - public WhiteEscapeDirectRule() { - throw new RuntimeException("This rule has not been implemented"); - } -} +package edu.rpi.legup.puzzle.heyawake.rules; + +public class WhiteEscapeDirectRule { + public WhiteEscapeDirectRule() { + throw new RuntimeException("This rule has not been implemented"); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteLineContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteLineContradictionRule.java index 835bce98c..b695b8206 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteLineContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/WhiteLineContradictionRule.java @@ -7,20 +7,21 @@ public class WhiteLineContradictionRule extends ContradictionRule { public WhiteLineContradictionRule() { - super("HEYA-CONT-0005", + super( + "HEYA-CONT-0005", "White Line", "", "edu/rpi/legup/images/heyawake/contradictions/WhiteLine.png"); - } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ZigZagWhiteDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ZigZagWhiteDirectRule.java index 22a76b9a9..9df735b0b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ZigZagWhiteDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/rules/ZigZagWhiteDirectRule.java @@ -1,7 +1,7 @@ -package edu.rpi.legup.puzzle.heyawake.rules; - -public class ZigZagWhiteDirectRule { - public ZigZagWhiteDirectRule() { - throw new RuntimeException("This rule has not been implemented"); - } -} +package edu.rpi.legup.puzzle.heyawake.rules; + +public class ZigZagWhiteDirectRule { + public ZigZagWhiteDirectRule() { + throw new RuntimeException("This rule has not been implemented"); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUp.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUp.java index 6a67d28ca..ab95c4658 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUp.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUp.java @@ -19,9 +19,7 @@ public LightUp() { this.factory = new LightUpCellFactory(); } - /** - * Initializes the game board. Called by the invoker of the class - */ + /** Initializes the game board. Called by the invoker of the class */ @Override public void initializeView() { boardView = new LightUpView((LightUpBoard) currentBoard); @@ -44,8 +42,8 @@ public Board generatePuzzle(int difficulty) { /** * Determines if the given dimensions are valid for Light Up * - * @param rows the number of rows - * @param columns the number of columns + * @param rows the number of rows + * @param columns the number of columns * @return true if the given dimensions are valid for Light Up, false otherwise */ public boolean isValidDimensions(int rows, int columns) { @@ -71,7 +69,9 @@ public boolean isBoardComplete(Board board) { } for (PuzzleElement data : lightUpBoard.getPuzzleElements()) { LightUpCell cell = (LightUpCell) data; - if ((cell.getType() == LightUpCellType.UNKNOWN || cell.getType() == LightUpCellType.EMPTY) && !cell.isLite()) { + if ((cell.getType() == LightUpCellType.UNKNOWN + || cell.getType() == LightUpCellType.EMPTY) + && !cell.isLite()) { return false; } } @@ -84,7 +84,5 @@ public boolean isBoardComplete(Board board) { * @param board the board that has changed */ @Override - public void onBoardChange(Board board) { - - } + public void onBoardChange(Board board) {} } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpBoard.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpBoard.java index b15f49919..217ef79a8 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpBoard.java @@ -2,7 +2,6 @@ import edu.rpi.legup.model.gameboard.GridBoard; import edu.rpi.legup.model.gameboard.PuzzleElement; - import java.awt.*; import java.util.HashSet; import java.util.Set; @@ -17,7 +16,8 @@ public LightUpBoard(int size) { } /** - * Sets cells in board to lite depending on whether there is a bulb cell in the current row or column + * Sets cells in board to lite depending on whether there is a bulb cell in the current row or + * column */ public void fillWithLight() { for (int y = 0; y < this.dimension.height; y++) { @@ -33,28 +33,32 @@ public void fillWithLight() { cell.setLite(true); for (int i = x + 1; i < this.dimension.width; i++) { LightUpCell c = getCell(i, y); - if (c.getType() == LightUpCellType.NUMBER || c.getType() == LightUpCellType.BLACK) { + if (c.getType() == LightUpCellType.NUMBER + || c.getType() == LightUpCellType.BLACK) { break; } c.setLite(true); } for (int i = x - 1; i >= 0; i--) { LightUpCell c = getCell(i, y); - if (c.getType() == LightUpCellType.NUMBER || c.getType() == LightUpCellType.BLACK) { + if (c.getType() == LightUpCellType.NUMBER + || c.getType() == LightUpCellType.BLACK) { break; } c.setLite(true); } for (int i = y + 1; i < this.dimension.height; i++) { LightUpCell c = getCell(x, i); - if (c.getType() == LightUpCellType.NUMBER || c.getType() == LightUpCellType.BLACK) { + if (c.getType() == LightUpCellType.NUMBER + || c.getType() == LightUpCellType.BLACK) { break; } c.setLite(true); } for (int i = y - 1; i >= 0; i--) { LightUpCell c = getCell(x, i); - if (c.getType() == LightUpCellType.NUMBER || c.getType() == LightUpCellType.BLACK) { + if (c.getType() == LightUpCellType.NUMBER + || c.getType() == LightUpCellType.BLACK) { break; } c.setLite(true); diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCell.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCell.java index 36e5a5088..8adf84cb4 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCell.java @@ -2,7 +2,6 @@ import edu.rpi.legup.model.elements.Element; import edu.rpi.legup.model.gameboard.GridCell; - import java.awt.*; import java.awt.event.MouseEvent; @@ -27,20 +26,18 @@ public void setType(Element e, MouseEvent m) { this.data = -2; break; case "LTUP-UNPL-0001": - switch (m.getButton()){ + switch (m.getButton()) { case MouseEvent.BUTTON1: if (this.data < 0 || this.data > 3) { this.data = 0; - } - else { + } else { this.data = this.data + 1; } break; case MouseEvent.BUTTON3: if (this.data > 0) { this.data = this.data - 1; - } - else { + } else { this.data = 4; } break; diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellController.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellController.java index 9c94b24f7..d4049897d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellController.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellController.java @@ -2,7 +2,6 @@ import edu.rpi.legup.controller.ElementController; import edu.rpi.legup.model.gameboard.PuzzleElement; - import java.awt.event.MouseEvent; public class LightUpCellController extends ElementController { @@ -11,32 +10,31 @@ public void changeCell(MouseEvent e, PuzzleElement data) { LightUpCell cell = (LightUpCell) data; if (e.getButton() == MouseEvent.BUTTON1) { if (e.isControlDown()) { - this.boardView.getSelectionPopupMenu().show(boardView, this.boardView.getCanvas().getX() + e.getX(), this.boardView.getCanvas().getY() + e.getY()); - } - else { + this.boardView + .getSelectionPopupMenu() + .show( + boardView, + this.boardView.getCanvas().getX() + e.getX(), + this.boardView.getCanvas().getY() + e.getY()); + } else { if (cell.getData() == -2) { data.setData(-4); - } - else { + } else { if (cell.getData() == -4) { data.setData(-3); - } - else { + } else { data.setData(-2); } } } - } - else { + } else { if (e.getButton() == MouseEvent.BUTTON3) { if (cell.getData() == -4) { data.setData(-2); - } - else { + } else { if (cell.getData() == -2) { data.setData(-3); - } - else { + } else { data.setData(-4); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellFactory.java index 4914facfa..384aa2b74 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellFactory.java @@ -4,17 +4,16 @@ import edu.rpi.legup.model.gameboard.ElementFactory; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; -import java.awt.*; - public class LightUpCellFactory extends ElementFactory { /** * Creates a puzzleElement based on the xml document Node and adds it to the board * - * @param node node that represents the puzzleElement + * @param node node that represents the puzzleElement * @param board board to add the newly created cell * @return newly created cell from the xml document Node * @throws InvalidFileFormatException if file is invalid @@ -23,7 +22,8 @@ public class LightUpCellFactory extends ElementFactory { public LightUpCell importCell(Node node, Board board) throws InvalidFileFormatException { try { if (!node.getNodeName().equalsIgnoreCase("cell")) { - throw new InvalidFileFormatException("lightup Factory: unknown puzzleElement puzzleElement"); + throw new InvalidFileFormatException( + "lightup Factory: unknown puzzleElement puzzleElement"); } LightUpBoard lightUpBoard = (LightUpBoard) board; @@ -35,7 +35,8 @@ public LightUpCell importCell(Node node, Board board) throws InvalidFileFormatEx int x = Integer.valueOf(attributeList.getNamedItem("x").getNodeValue()); int y = Integer.valueOf(attributeList.getNamedItem("y").getNodeValue()); if (x >= width || y >= height) { - throw new InvalidFileFormatException("lightup Factory: cell location out of bounds"); + throw new InvalidFileFormatException( + "lightup Factory: cell location out of bounds"); } if (value < -4 || value > 4) { throw new InvalidFileFormatException("lightup Factory: cell unknown value"); @@ -44,11 +45,10 @@ public LightUpCell importCell(Node node, Board board) throws InvalidFileFormatEx LightUpCell cell = new LightUpCell(value, new Point(x, y)); cell.setIndex(y * height + x); return cell; - } - catch (NumberFormatException e) { - throw new InvalidFileFormatException("lightup Factory: unknown value where integer expected"); - } - catch (NullPointerException e) { + } catch (NumberFormatException e) { + throw new InvalidFileFormatException( + "lightup Factory: unknown value where integer expected"); + } catch (NullPointerException e) { throw new InvalidFileFormatException("lightup Factory: could not find attribute(s)"); } } @@ -56,7 +56,7 @@ public LightUpCell importCell(Node node, Board board) throws InvalidFileFormatEx /** * Creates a xml document puzzleElement from a cell for exporting * - * @param document xml document + * @param document xml document * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellType.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellType.java index b0825910d..8472be7a6 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellType.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellType.java @@ -1,7 +1,11 @@ package edu.rpi.legup.puzzle.lightup; public enum LightUpCellType { - BULB(-4), EMPTY(-3), UNKNOWN(-2), BLACK(-1), NUMBER(0); + BULB(-4), + EMPTY(-3), + UNKNOWN(-2), + BLACK(-1), + NUMBER(0); public int value; diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpElementView.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpElementView.java index 7f35d46a6..1b00b007d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpElementView.java @@ -1,7 +1,6 @@ package edu.rpi.legup.puzzle.lightup; import edu.rpi.legup.ui.boardview.GridElementView; - import java.awt.*; public class LightUpElementView extends GridElementView { @@ -40,37 +39,45 @@ public void drawElement(Graphics2D graphics2D) { FontMetrics metrics = graphics2D.getFontMetrics(FONT); String value = String.valueOf(puzzleElement.getData()); int xText = location.x + (size.width - metrics.stringWidth(value)) / 2; - int yText = location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent(); + int yText = + location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent(); graphics2D.drawString(String.valueOf(puzzleElement.getData()), xText, yText); - } - else { + } else { if (type == LightUpCellType.BLACK) { graphics2D.setStroke(new BasicStroke(1)); graphics2D.setColor(BLACK_COLOR); graphics2D.fillRect(location.x, location.y, size.width, size.height); - } - else { + } else { if (type == LightUpCellType.EMPTY) { graphics2D.setStroke(new BasicStroke(1)); graphics2D.setColor(cell.isLite() ? LITE : WHITE_COLOR); graphics2D.fillRect(location.x, location.y, size.width, size.height); graphics2D.setColor(BLACK_COLOR); - graphics2D.fillRect(location.x + size.width * 7 / 16, location.y + size.height * 7 / 16, size.width / 8, size.height / 8); + graphics2D.fillRect( + location.x + size.width * 7 / 16, + location.y + size.height * 7 / 16, + size.width / 8, + size.height / 8); graphics2D.drawRect(location.x, location.y, size.width, size.height); - } - else { + } else { if (type == LightUpCellType.UNKNOWN) { graphics2D.setStroke(new BasicStroke(1)); graphics2D.setColor(cell.isLite() ? LITE : Color.LIGHT_GRAY); graphics2D.fillRect(location.x, location.y, size.width, size.height); graphics2D.setColor(Color.BLACK); graphics2D.drawRect(location.x, location.y, size.width, size.height); - } - else { + } else { if (type == LightUpCellType.BULB) { graphics2D.setColor(Color.LIGHT_GRAY); graphics2D.fillRect(location.x, location.y, size.width, size.height); - graphics2D.drawImage(LightUpView.lightImage, location.x, location.y, size.width, size.height, LITE, null); + graphics2D.drawImage( + LightUpView.lightImage, + location.x, + location.y, + size.width, + size.height, + LITE, + null); graphics2D.setColor(BLACK_COLOR); graphics2D.drawRect(location.x, location.y, size.width, size.height); } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpExporter.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpExporter.java index 89024ad6c..0e8987020 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpExporter.java @@ -2,7 +2,6 @@ import edu.rpi.legup.model.PuzzleExporter; import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; import org.w3c.dom.Document; public class LightUpExporter extends PuzzleExporter { @@ -16,8 +15,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { LightUpBoard board; if (puzzle.getTree() != null) { board = (LightUpBoard) puzzle.getTree().getRootNode().getBoard(); - } - else { + } else { board = (LightUpBoard) puzzle.getBoardView().getBoard(); } @@ -29,7 +27,8 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { for (PuzzleElement puzzleElement : board.getPuzzleElements()) { LightUpCell cell = (LightUpCell) puzzleElement; if (cell.getData() != -2) { - org.w3c.dom.Element cellElement = puzzle.getFactory().exportCell(newDocument, puzzleElement); + org.w3c.dom.Element cellElement = + puzzle.getFactory().exportCell(newDocument, puzzleElement); cellsElement.appendChild(cellElement); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpImporter.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpImporter.java index 7ef24ca69..336b063f6 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpImporter.java @@ -2,12 +2,11 @@ import edu.rpi.legup.model.PuzzleImporter; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import java.awt.*; - public class LightUpImporter extends PuzzleImporter { public LightUpImporter(LightUp lightUp) { super(lightUp); @@ -26,7 +25,7 @@ public boolean acceptsTextInput() { /** * Creates an empty board for building * - * @param rows the number of rows on the board + * @param rows the number of rows on the board * @param columns the number of columns on the board * @throws RuntimeException if board can not be created */ @@ -57,11 +56,13 @@ public void initializeBoard(int rows, int columns) { public void initializeBoard(Node node) throws InvalidFileFormatException { try { if (!node.getNodeName().equalsIgnoreCase("board")) { - throw new InvalidFileFormatException("lightup Importer: cannot find board puzzleElement"); + throw new InvalidFileFormatException( + "lightup Importer: cannot find board puzzleElement"); } Element boardElement = (Element) node; if (boardElement.getElementsByTagName("cells").getLength() == 0) { - throw new InvalidFileFormatException("lightup Importer: no puzzleElement found for board"); + throw new InvalidFileFormatException( + "lightup Importer: no puzzleElement found for board"); } Element dataElement = (Element) boardElement.getElementsByTagName("cells").item(0); NodeList elementDataList = dataElement.getElementsByTagName("cell"); @@ -70,9 +71,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { if (!boardElement.getAttribute("size").isEmpty()) { int size = Integer.valueOf(boardElement.getAttribute("size")); lightUpBoard = new LightUpBoard(size); - } - else { - if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { + } else { + if (!boardElement.getAttribute("width").isEmpty() + && !boardElement.getAttribute("height").isEmpty()) { int width = Integer.valueOf(boardElement.getAttribute("width")); int height = Integer.valueOf(boardElement.getAttribute("height")); lightUpBoard = new LightUpBoard(width, height); @@ -87,7 +88,10 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { int height = lightUpBoard.getHeight(); for (int i = 0; i < elementDataList.getLength(); i++) { - LightUpCell cell = (LightUpCell) puzzle.getFactory().importCell(elementDataList.item(i), lightUpBoard); + LightUpCell cell = + (LightUpCell) + puzzle.getFactory() + .importCell(elementDataList.item(i), lightUpBoard); Point loc = cell.getLocation(); if (cell.getData() != -2) { cell.setModifiable(false); @@ -107,9 +111,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { } } puzzle.setCurrentBoard(lightUpBoard); - } - catch (NumberFormatException e) { - throw new InvalidFileFormatException("lightup Importer: unknown value where integer expected"); + } catch (NumberFormatException e) { + throw new InvalidFileFormatException( + "lightup Importer: unknown value where integer expected"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpView.java b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpView.java index 0fd57e705..ebce6a682 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpView.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpView.java @@ -7,23 +7,24 @@ import edu.rpi.legup.ui.boardview.DataSelectionView; import edu.rpi.legup.ui.boardview.GridBoardView; import edu.rpi.legup.ui.boardview.SelectionItemView; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import javax.imageio.ImageIO; -import javax.swing.*; import java.awt.*; import java.io.IOException; +import javax.imageio.ImageIO; +import javax.swing.*; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class LightUpView extends GridBoardView { - private final static Logger LOGGER = LogManager.getLogger(LightUpView.class.getName()); + private static final Logger LOGGER = LogManager.getLogger(LightUpView.class.getName()); static Image lightImage; static { try { - lightImage = ImageIO.read(ClassLoader.getSystemClassLoader().getResource("edu/rpi/legup/images/lightup/light.png")); - } - catch (IOException e) { + lightImage = + ImageIO.read( + ClassLoader.getSystemClassLoader() + .getResource("edu/rpi/legup/images/lightup/light.png")); + } catch (IOException e) { LOGGER.error("Failed to open TreeTent images"); } } @@ -37,7 +38,8 @@ public LightUpView(LightUpBoard board) { LightUpElementView elementView = new LightUpElementView(cell); elementView.setIndex(cell.getIndex()); elementView.setSize(elementSize); - elementView.setLocation(new Point(loc.x * elementSize.width, loc.y * elementSize.height)); + elementView.setLocation( + new Point(loc.x * elementSize.width, loc.y * elementSize.height)); elementViews.add(elementView); } } @@ -50,14 +52,15 @@ public LightUpView(LightUpBoard board) { @Override public void onTreeElementChanged(TreeElement treeElement) { super.onTreeElementChanged(treeElement); - LightUpBoard lightUpBoard = board instanceof CaseBoard ? (LightUpBoard) ((CaseBoard) board).getBaseBoard() : (LightUpBoard) board; + LightUpBoard lightUpBoard = + board instanceof CaseBoard + ? (LightUpBoard) ((CaseBoard) board).getBaseBoard() + : (LightUpBoard) board; lightUpBoard.fillWithLight(); repaint(); } - /** - * Returns a DataSelectionView popup menu - */ + /** Returns a DataSelectionView popup menu */ public DataSelectionView getSelectionPopupMenu() { DataSelectionView selectionView = new DataSelectionView(elementController); GridLayout layout = new GridLayout(3, 1); @@ -69,7 +72,9 @@ public DataSelectionView getSelectionPopupMenu() { LightUpElementView element1 = new LightUpElementView(new LightUpCell(-2, null)); element1.setSize(iconSize); element1.setLocation(loc); - SelectionItemView item1 = new SelectionItemView(element1.getPuzzleElement(), new ImageIcon(element1.getImage())); + SelectionItemView item1 = + new SelectionItemView( + element1.getPuzzleElement(), new ImageIcon(element1.getImage())); item1.addActionListener(elementController); item1.setHorizontalTextPosition(SwingConstants.CENTER); selectionView.add(item1); @@ -77,7 +82,9 @@ public DataSelectionView getSelectionPopupMenu() { LightUpElementView element2 = new LightUpElementView(new LightUpCell(-4, null)); element2.setSize(iconSize); element2.setLocation(loc); - SelectionItemView item2 = new SelectionItemView(element2.getPuzzleElement(), new ImageIcon(element2.getImage())); + SelectionItemView item2 = + new SelectionItemView( + element2.getPuzzleElement(), new ImageIcon(element2.getImage())); item2.addActionListener(elementController); item2.setHorizontalTextPosition(SwingConstants.CENTER); selectionView.add(item2); @@ -85,7 +92,9 @@ public DataSelectionView getSelectionPopupMenu() { LightUpElementView element3 = new LightUpElementView(new LightUpCell(-3, null)); element3.setSize(iconSize); element3.setLocation(loc); - SelectionItemView item3 = new SelectionItemView(element3.getPuzzleElement(), new ImageIcon(element3.getImage())); + SelectionItemView item3 = + new SelectionItemView( + element3.getPuzzleElement(), new ImageIcon(element3.getImage())); item3.addActionListener(elementController); item3.setHorizontalTextPosition(SwingConstants.CENTER); selectionView.add(item3); diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/elements/BlackTile.java b/src/main/java/edu/rpi/legup/puzzle/lightup/elements/BlackTile.java index d3e8cf506..2ddb4f754 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/elements/BlackTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/elements/BlackTile.java @@ -4,6 +4,10 @@ public class BlackTile extends NonPlaceableElement { public BlackTile() { - super("LTUP-UNPL-0002", "Black Tile", "The black tile", "edu/rpi/legup/images/lightup/black.gif"); + super( + "LTUP-UNPL-0002", + "Black Tile", + "The black tile", + "edu/rpi/legup/images/lightup/black.gif"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/elements/BulbTile.java b/src/main/java/edu/rpi/legup/puzzle/lightup/elements/BulbTile.java index 5fc4a334f..d238baa56 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/elements/BulbTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/elements/BulbTile.java @@ -4,6 +4,10 @@ public class BulbTile extends PlaceableElement { public BulbTile() { - super("LTUP-PLAC-0001", "Bulb Tile", "The bulb tile", "edu/rpi/legup/images/lightup/light.png"); + super( + "LTUP-PLAC-0001", + "Bulb Tile", + "The bulb tile", + "edu/rpi/legup/images/lightup/light.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/elements/NumberTile.java b/src/main/java/edu/rpi/legup/puzzle/lightup/elements/NumberTile.java index e96a969e5..ae314a4cf 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/elements/NumberTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/elements/NumberTile.java @@ -8,11 +8,19 @@ public class NumberTile extends NonPlaceableElement { // Follow the default format and resolves the NoSuchMethod error public NumberTile() { - super("LTUP-UNPL-0001", "Number Tile", "The number tile", "edu/rpi/legup/images/lightup/1.gif"); + super( + "LTUP-UNPL-0001", + "Number Tile", + "The number tile", + "edu/rpi/legup/images/lightup/1.gif"); } public NumberTile(int num) { - super("LTUP-UNPL-0001", "Number Tile", "The number tile", "edu/rpi/legup/images/lightup/" + num + ".gif"); + super( + "LTUP-UNPL-0001", + "Number Tile", + "The number tile", + "edu/rpi/legup/images/lightup/" + num + ".gif"); if (num > 3 || num < 1) num = 1; object_number = num; } diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/elements/UnknownTile.java b/src/main/java/edu/rpi/legup/puzzle/lightup/elements/UnknownTile.java index 6839e70de..24d420fe8 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/elements/UnknownTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/elements/UnknownTile.java @@ -4,6 +4,10 @@ public class UnknownTile extends NonPlaceableElement { public UnknownTile() { - super("LTUP-UNPL-0003", "Unknown Tile", "A blank tile", "edu/rpi/legup/images/lightup/UnknownTile.png"); + super( + "LTUP-UNPL-0003", + "Unknown Tile", + "A blank tile", + "edu/rpi/legup/images/lightup/UnknownTile.png"); } } 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 2804e6eab..90652888c 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 @@ -6,24 +6,26 @@ import edu.rpi.legup.puzzle.lightup.LightUpBoard; import edu.rpi.legup.puzzle.lightup.LightUpCell; import edu.rpi.legup.puzzle.lightup.LightUpCellType; - import java.awt.*; public class BulbsInPathContradictionRule extends ContradictionRule { public BulbsInPathContradictionRule() { - super("LTUP-CONT-0001", "Bulbs In Path", + super( + "LTUP-CONT-0001", + "Bulbs In Path", "A bulb cannot be placed in another bulb's path.", "edu/rpi/legup/images/lightup/contradictions/BulbsInPath.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { @@ -38,8 +40,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { LightUpCell c = lightUpBoard.getCell(i, location.y); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } - else { + } else { if (c.getType() == LightUpCellType.BULB) { return null; } @@ -49,8 +50,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { LightUpCell c = lightUpBoard.getCell(i, location.y); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } - else { + } else { if (c.getType() == LightUpCellType.BULB) { return null; } @@ -60,8 +60,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { LightUpCell c = lightUpBoard.getCell(location.x, i); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } - else { + } else { if (c.getType() == LightUpCellType.BULB) { return null; } @@ -71,8 +70,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { LightUpCell c = lightUpBoard.getCell(location.x, i); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } - else { + } else { if (c.getType() == LightUpCellType.BULB) { return null; } 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 011bf1c0a..0ed88636c 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 @@ -6,24 +6,26 @@ import edu.rpi.legup.puzzle.lightup.LightUpBoard; import edu.rpi.legup.puzzle.lightup.LightUpCell; import edu.rpi.legup.puzzle.lightup.LightUpCellType; - import java.awt.*; public class CannotLightACellContradictionRule extends ContradictionRule { public CannotLightACellContradictionRule() { - super("LTUP-CONT-0002", "Cannot Light A Cell", + super( + "LTUP-CONT-0002", + "Cannot Light A Cell", "All cells must be able to be lit.", "edu/rpi/legup/images/lightup/contradictions/CannotLightACell.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { @@ -42,8 +44,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { LightUpCell c = lightUpBoard.getCell(i, location.y); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } - else { + } else { if (c.getType() == LightUpCellType.UNKNOWN && !c.isLite()) { hor_count += 1; } @@ -53,8 +54,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { LightUpCell c = lightUpBoard.getCell(i, location.y); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } - else { + } else { if (c.getType() == LightUpCellType.UNKNOWN && !c.isLite()) { hor_count += 1; } @@ -64,8 +64,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { LightUpCell c = lightUpBoard.getCell(location.x, i); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } - else { + } else { if (c.getType() == LightUpCellType.UNKNOWN && !c.isLite()) { ver_count += 1; } @@ -75,8 +74,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { LightUpCell c = lightUpBoard.getCell(location.x, i); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } - else { + } else { if (c.getType() == LightUpCellType.UNKNOWN && !c.isLite()) { ver_count += 1; } @@ -88,4 +86,4 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { } return super.getNoContradictionMessage(); } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCellinLightDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCellinLightDirectRule.java index a40ede284..269ef0ad5 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCellinLightDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCellinLightDirectRule.java @@ -1,64 +1,68 @@ -package edu.rpi.legup.puzzle.lightup.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.lightup.LightUpBoard; -import edu.rpi.legup.puzzle.lightup.LightUpCell; -import edu.rpi.legup.puzzle.lightup.LightUpCellType; - -public class EmptyCellinLightDirectRule extends DirectRule { - - public EmptyCellinLightDirectRule() { - super("LTUP-BASC-0002", "Empty Cells in Light", - "Cells in light must be empty.", - "edu/rpi/legup/images/lightup/rules/EmptyCellInLight.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement index of the puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - LightUpBoard initialBoard = (LightUpBoard) transition.getParents().get(0).getBoard(); - initialBoard.fillWithLight(); - LightUpCell initCell = (LightUpCell) initialBoard.getPuzzleElement(puzzleElement); - LightUpCell finalCell = (LightUpCell) transition.getBoard().getPuzzleElement(puzzleElement); - if (finalCell.getType() == LightUpCellType.EMPTY && initCell.getType() == LightUpCellType.UNKNOWN && initCell.isLite()) { - return null; - } - return super.getInvalidUseOfRuleMessage() + ": Cell is not forced to be empty"; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - LightUpBoard lightUpBoard = (LightUpBoard) node.getBoard().copy(); - for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { - LightUpCell cell = (LightUpCell) element; - if (cell.getType() == LightUpCellType.UNKNOWN && cell.isLite()) { - cell.setData(LightUpCellType.EMPTY.value); - lightUpBoard.addModifiedData(cell); - } - } - if (lightUpBoard.getModifiedData().isEmpty()) { - return null; - } - else { - return lightUpBoard; - } - } -} +package edu.rpi.legup.puzzle.lightup.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.lightup.LightUpBoard; +import edu.rpi.legup.puzzle.lightup.LightUpCell; +import edu.rpi.legup.puzzle.lightup.LightUpCellType; + +public class EmptyCellinLightDirectRule extends DirectRule { + + public EmptyCellinLightDirectRule() { + super( + "LTUP-BASC-0002", + "Empty Cells in Light", + "Cells in light must be empty.", + "edu/rpi/legup/images/lightup/rules/EmptyCellInLight.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement index of the puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + LightUpBoard initialBoard = (LightUpBoard) transition.getParents().get(0).getBoard(); + initialBoard.fillWithLight(); + LightUpCell initCell = (LightUpCell) initialBoard.getPuzzleElement(puzzleElement); + LightUpCell finalCell = (LightUpCell) transition.getBoard().getPuzzleElement(puzzleElement); + if (finalCell.getType() == LightUpCellType.EMPTY + && initCell.getType() == LightUpCellType.UNKNOWN + && initCell.isLite()) { + return null; + } + return super.getInvalidUseOfRuleMessage() + ": Cell is not forced to be empty"; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + LightUpBoard lightUpBoard = (LightUpBoard) node.getBoard().copy(); + for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { + LightUpCell cell = (LightUpCell) element; + if (cell.getType() == LightUpCellType.UNKNOWN && cell.isLite()) { + cell.setData(LightUpCellType.EMPTY.value); + lightUpBoard.addModifiedData(cell); + } + } + if (lightUpBoard.getModifiedData().isEmpty()) { + return null; + } else { + return lightUpBoard; + } + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCornersDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCornersDirectRule.java index 04c493f08..702c116c1 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCornersDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/EmptyCornersDirectRule.java @@ -1,115 +1,117 @@ -package edu.rpi.legup.puzzle.lightup.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.lightup.LightUpBoard; -import edu.rpi.legup.puzzle.lightup.LightUpCell; -import edu.rpi.legup.puzzle.lightup.LightUpCellType; - -import java.awt.*; -import java.util.ArrayList; -import java.util.List; - -public class EmptyCornersDirectRule extends DirectRule { - - public EmptyCornersDirectRule() { - super("LTUP-BASC-0003", "Empty Corners", - "Cells on the corners of a number must be empty if placing bulbs would prevent the number from being satisfied.", - "edu/rpi/legup/images/lightup/rules/EmptyCorners.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement index of the puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - LightUpBoard initialBoard = (LightUpBoard) transition.getParents().get(0).getBoard(); - LightUpCell cell = (LightUpCell) initialBoard.getPuzzleElement(puzzleElement); - LightUpBoard finalBoard = (LightUpBoard) transition.getBoard(); - LightUpCell finalCell = (LightUpCell) finalBoard.getPuzzleElement(puzzleElement); - - if (!(cell.getType() == LightUpCellType.UNKNOWN && finalCell.getType() == LightUpCellType.EMPTY)) { - return super.getInvalidUseOfRuleMessage() + ": This cell must be an empty cell"; - } - - Point loc = finalCell.getLocation(); - List numberedCells = new ArrayList<>(); - LightUpCell upperRight = finalBoard.getCell(loc.x + 1, loc.y - 1); - if (upperRight != null && upperRight.getType() == LightUpCellType.NUMBER) { - numberedCells.add(upperRight); - } - LightUpCell upperLeft = finalBoard.getCell(loc.x - 1, loc.y - 1); - if (upperLeft != null && upperLeft.getType() == LightUpCellType.NUMBER) { - numberedCells.add(upperLeft); - } - LightUpCell lowerRight = finalBoard.getCell(loc.x + 1, loc.y + 1); - if (lowerRight != null && lowerRight.getType() == LightUpCellType.NUMBER) { - numberedCells.add(lowerRight); - } - LightUpCell lowerLeft = finalBoard.getCell(loc.x - 1, loc.y + 1); - if (lowerLeft != null && lowerLeft.getType() == LightUpCellType.NUMBER) { - numberedCells.add(lowerLeft); - } - if (numberedCells.isEmpty()) { - return super.getInvalidUseOfRuleMessage() + ": This cell must diagonal to a numbered cell"; - } - - TooFewBulbsContradictionRule tooFew = new TooFewBulbsContradictionRule(); - LightUpBoard bulbCaseBoard = finalBoard.copy(); - LightUpCell bulbCaseCell = (LightUpCell) bulbCaseBoard.getPuzzleElement(puzzleElement); - bulbCaseCell.setData(LightUpCellType.BULB.value); - bulbCaseBoard.fillWithLight(); - - boolean createsContra = false; - for (LightUpCell c : numberedCells) { - createsContra |= tooFew.checkContradictionAt(bulbCaseBoard, c) == null; - } - if (createsContra) { - return null; - } - else { - return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be empty"; - } - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - LightUpBoard lightUpBoard = (LightUpBoard) node.getBoard().copy(); - LightUpBoard lightUpBoardCopy = (LightUpBoard) node.getBoard().copy(); - TreeTransition transition = new TreeTransition(node, lightUpBoardCopy); - for (PuzzleElement element : lightUpBoardCopy.getPuzzleElements()) { - LightUpCell cell = (LightUpCell) element; - int temp = cell.getData(); - cell.setData(LightUpCellType.EMPTY.value); - if (checkRuleRawAt(transition, cell) == null) { - LightUpCell modCell = (LightUpCell) lightUpBoard.getPuzzleElement(cell); - modCell.setData(LightUpCellType.EMPTY.value); - lightUpBoard.addModifiedData(modCell); - } - else { - cell.setData(temp); - } - } - if (lightUpBoard.getModifiedData().isEmpty()) { - return null; - } - else { - return lightUpBoard; - } - } -} +package edu.rpi.legup.puzzle.lightup.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.lightup.LightUpBoard; +import edu.rpi.legup.puzzle.lightup.LightUpCell; +import edu.rpi.legup.puzzle.lightup.LightUpCellType; +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + +public class EmptyCornersDirectRule extends DirectRule { + + public EmptyCornersDirectRule() { + super( + "LTUP-BASC-0003", + "Empty Corners", + "Cells on the corners of a number must be empty if placing bulbs would prevent the" + + " number from being satisfied.", + "edu/rpi/legup/images/lightup/rules/EmptyCorners.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement index of the puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + LightUpBoard initialBoard = (LightUpBoard) transition.getParents().get(0).getBoard(); + LightUpCell cell = (LightUpCell) initialBoard.getPuzzleElement(puzzleElement); + LightUpBoard finalBoard = (LightUpBoard) transition.getBoard(); + LightUpCell finalCell = (LightUpCell) finalBoard.getPuzzleElement(puzzleElement); + + if (!(cell.getType() == LightUpCellType.UNKNOWN + && finalCell.getType() == LightUpCellType.EMPTY)) { + return super.getInvalidUseOfRuleMessage() + ": This cell must be an empty cell"; + } + + Point loc = finalCell.getLocation(); + List numberedCells = new ArrayList<>(); + LightUpCell upperRight = finalBoard.getCell(loc.x + 1, loc.y - 1); + if (upperRight != null && upperRight.getType() == LightUpCellType.NUMBER) { + numberedCells.add(upperRight); + } + LightUpCell upperLeft = finalBoard.getCell(loc.x - 1, loc.y - 1); + if (upperLeft != null && upperLeft.getType() == LightUpCellType.NUMBER) { + numberedCells.add(upperLeft); + } + LightUpCell lowerRight = finalBoard.getCell(loc.x + 1, loc.y + 1); + if (lowerRight != null && lowerRight.getType() == LightUpCellType.NUMBER) { + numberedCells.add(lowerRight); + } + LightUpCell lowerLeft = finalBoard.getCell(loc.x - 1, loc.y + 1); + if (lowerLeft != null && lowerLeft.getType() == LightUpCellType.NUMBER) { + numberedCells.add(lowerLeft); + } + if (numberedCells.isEmpty()) { + return super.getInvalidUseOfRuleMessage() + + ": This cell must diagonal to a numbered cell"; + } + + TooFewBulbsContradictionRule tooFew = new TooFewBulbsContradictionRule(); + LightUpBoard bulbCaseBoard = finalBoard.copy(); + LightUpCell bulbCaseCell = (LightUpCell) bulbCaseBoard.getPuzzleElement(puzzleElement); + bulbCaseCell.setData(LightUpCellType.BULB.value); + bulbCaseBoard.fillWithLight(); + + boolean createsContra = false; + for (LightUpCell c : numberedCells) { + createsContra |= tooFew.checkContradictionAt(bulbCaseBoard, c) == null; + } + if (createsContra) { + return null; + } else { + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be empty"; + } + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + LightUpBoard lightUpBoard = (LightUpBoard) node.getBoard().copy(); + LightUpBoard lightUpBoardCopy = (LightUpBoard) node.getBoard().copy(); + TreeTransition transition = new TreeTransition(node, lightUpBoardCopy); + for (PuzzleElement element : lightUpBoardCopy.getPuzzleElements()) { + LightUpCell cell = (LightUpCell) element; + int temp = cell.getData(); + cell.setData(LightUpCellType.EMPTY.value); + if (checkRuleRawAt(transition, cell) == null) { + LightUpCell modCell = (LightUpCell) lightUpBoard.getPuzzleElement(cell); + modCell.setData(LightUpCellType.EMPTY.value); + lightUpBoard.addModifiedData(modCell); + } else { + cell.setData(temp); + } + } + if (lightUpBoard.getModifiedData().isEmpty()) { + return null; + } else { + return lightUpBoard; + } + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithBulbsDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithBulbsDirectRule.java index cdea7880f..3f884d459 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithBulbsDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithBulbsDirectRule.java @@ -1,107 +1,110 @@ -package edu.rpi.legup.puzzle.lightup.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.lightup.LightUpBoard; -import edu.rpi.legup.puzzle.lightup.LightUpCell; -import edu.rpi.legup.puzzle.lightup.LightUpCellType; - -import java.util.Set; - -public class FinishWithBulbsDirectRule extends DirectRule { - - public FinishWithBulbsDirectRule() { - super("LTUP-BASC-0004", "Finish with Bulbs", - "The remaining unknowns around a block must be bulbs to satisfy the number.", - "edu/rpi/legup/images/lightup/rules/FinishWithBulbs.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement index of the puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - LightUpBoard initialBoard = (LightUpBoard) transition.getParents().get(0).getBoard(); - LightUpCell initCell = (LightUpCell) initialBoard.getPuzzleElement(puzzleElement); - LightUpBoard finalBoard = (LightUpBoard) transition.getBoard(); - LightUpCell finalCell = (LightUpCell) finalBoard.getPuzzleElement(puzzleElement); - if (!(initCell.getType() == LightUpCellType.UNKNOWN && finalCell.getType() == LightUpCellType.BULB)) { - return super.getInvalidUseOfRuleMessage() + ": Modified cells must be bulbs"; - } - - Set adjCells = finalBoard.getAdj(finalCell); - adjCells.removeIf(cell -> cell.getType() != LightUpCellType.NUMBER); - if (adjCells.isEmpty()) { - return super.getInvalidUseOfRuleMessage() + ": This cell is not adjacent to a numbered cell"; - } - - LightUpBoard emptyCase = initialBoard.copy(); - emptyCase.getPuzzleElement(finalCell).setData(LightUpCellType.EMPTY.value); - TooFewBulbsContradictionRule tooFew = new TooFewBulbsContradictionRule(); - for (LightUpCell c : adjCells) { - if (tooFew.checkContradictionAt(emptyCase, c) == null) { - return null; - } - } - return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be a bulb"; - } - - /** - * Determines whether the specified cell is forced to be a bulb or not - * - * @param board the entire board - * @param cell specified cell - * @return whether cell is forced to be a bulb or not - */ - private boolean isForced(LightUpBoard board, LightUpCell cell) { - Set adjCells = board.getAdj(cell); - adjCells.removeIf(c -> c.getType() != LightUpCellType.NUMBER); - if (adjCells.isEmpty()) { - return false; - } - - LightUpBoard emptyCase = board.copy(); - emptyCase.getPuzzleElement(cell).setData(LightUpCellType.EMPTY.value); - TooFewBulbsContradictionRule tooFew = new TooFewBulbsContradictionRule(); - for (LightUpCell c : adjCells) { - if (tooFew.checkContradictionAt(emptyCase, c) == null) { - return true; - } - } - return false; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - LightUpBoard initialBoard = (LightUpBoard) node.getBoard(); - LightUpBoard lightUpBoard = (LightUpBoard) node.getBoard().copy(); - for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { - LightUpCell cell = (LightUpCell) element; - if (cell.getType() == LightUpCellType.UNKNOWN && isForced(initialBoard, cell)) { - cell.setData(LightUpCellType.BULB.value); - lightUpBoard.addModifiedData(cell); - } - } - if (lightUpBoard.getModifiedData().isEmpty()) { - return null; - } - else { - return lightUpBoard; - } - } -} +package edu.rpi.legup.puzzle.lightup.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.lightup.LightUpBoard; +import edu.rpi.legup.puzzle.lightup.LightUpCell; +import edu.rpi.legup.puzzle.lightup.LightUpCellType; +import java.util.Set; + +public class FinishWithBulbsDirectRule extends DirectRule { + + public FinishWithBulbsDirectRule() { + super( + "LTUP-BASC-0004", + "Finish with Bulbs", + "The remaining unknowns around a block must be bulbs to satisfy the number.", + "edu/rpi/legup/images/lightup/rules/FinishWithBulbs.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement index of the puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + LightUpBoard initialBoard = (LightUpBoard) transition.getParents().get(0).getBoard(); + LightUpCell initCell = (LightUpCell) initialBoard.getPuzzleElement(puzzleElement); + LightUpBoard finalBoard = (LightUpBoard) transition.getBoard(); + LightUpCell finalCell = (LightUpCell) finalBoard.getPuzzleElement(puzzleElement); + if (!(initCell.getType() == LightUpCellType.UNKNOWN + && finalCell.getType() == LightUpCellType.BULB)) { + return super.getInvalidUseOfRuleMessage() + ": Modified cells must be bulbs"; + } + + Set adjCells = finalBoard.getAdj(finalCell); + adjCells.removeIf(cell -> cell.getType() != LightUpCellType.NUMBER); + if (adjCells.isEmpty()) { + return super.getInvalidUseOfRuleMessage() + + ": This cell is not adjacent to a numbered cell"; + } + + LightUpBoard emptyCase = initialBoard.copy(); + emptyCase.getPuzzleElement(finalCell).setData(LightUpCellType.EMPTY.value); + TooFewBulbsContradictionRule tooFew = new TooFewBulbsContradictionRule(); + for (LightUpCell c : adjCells) { + if (tooFew.checkContradictionAt(emptyCase, c) == null) { + return null; + } + } + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be a bulb"; + } + + /** + * Determines whether the specified cell is forced to be a bulb or not + * + * @param board the entire board + * @param cell specified cell + * @return whether cell is forced to be a bulb or not + */ + private boolean isForced(LightUpBoard board, LightUpCell cell) { + Set adjCells = board.getAdj(cell); + adjCells.removeIf(c -> c.getType() != LightUpCellType.NUMBER); + if (adjCells.isEmpty()) { + return false; + } + + LightUpBoard emptyCase = board.copy(); + emptyCase.getPuzzleElement(cell).setData(LightUpCellType.EMPTY.value); + TooFewBulbsContradictionRule tooFew = new TooFewBulbsContradictionRule(); + for (LightUpCell c : adjCells) { + if (tooFew.checkContradictionAt(emptyCase, c) == null) { + return true; + } + } + return false; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + LightUpBoard initialBoard = (LightUpBoard) node.getBoard(); + LightUpBoard lightUpBoard = (LightUpBoard) node.getBoard().copy(); + for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { + LightUpCell cell = (LightUpCell) element; + if (cell.getType() == LightUpCellType.UNKNOWN && isForced(initialBoard, cell)) { + cell.setData(LightUpCellType.BULB.value); + lightUpBoard.addModifiedData(cell); + } + } + if (lightUpBoard.getModifiedData().isEmpty()) { + return null; + } else { + return lightUpBoard; + } + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithEmptyDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithEmptyDirectRule.java index f7433150c..678ee67a2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithEmptyDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/FinishWithEmptyDirectRule.java @@ -1,118 +1,122 @@ -package edu.rpi.legup.puzzle.lightup.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.lightup.LightUpBoard; -import edu.rpi.legup.puzzle.lightup.LightUpCell; -import edu.rpi.legup.puzzle.lightup.LightUpCellType; - -import java.awt.*; - -public class FinishWithEmptyDirectRule extends DirectRule { - - public FinishWithEmptyDirectRule() { - super("LTUP-BASC-0005", "Finish with Empty", - "The remaining unknowns around a block must be empty if the number is satisfied.", - "edu/rpi/legup/images/lightup/rules/FinishWithEmpty.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement index of the puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - LightUpBoard initialBoard = (LightUpBoard) transition.getParents().get(0).getBoard(); - LightUpBoard finalBoard = (LightUpBoard) transition.getBoard(); - LightUpCell cell = (LightUpCell) finalBoard.getPuzzleElement(puzzleElement); - if (cell.getType() != LightUpCellType.EMPTY) { - return super.getInvalidUseOfRuleMessage() + ": Modified cells must be empty"; - } - - if (isForced(initialBoard, cell.getLocation())) { - return null; - } - return super.getInvalidUseOfRuleMessage() + ": Empty is not forced"; - } - - /** - * Checks whether a certain cell is forced to not be a bulb - * - * @param board specified board - * @param location location of cell to check - * @return boolean value based on whether a certain cell has an adjacent cell that has the required amount of adjacent bulbs - */ - private boolean isForced(LightUpBoard board, Point location) { - return isForcedEmpty(board, new Point(location.x + 1, location.y)) || - isForcedEmpty(board, new Point(location.x, location.y + 1)) || - isForcedEmpty(board, new Point(location.x - 1, location.y)) || - isForcedEmpty(board, new Point(location.x, location.y - 1)); - } - - /** - * Checks whether a certain cell has the required amount of adjacent bulbs - * - * @param board specified board - * @param loc location of cell to check - * @return boolean value based on whether a certain cell has the required amount of adjacent bulbs - */ - private boolean isForcedEmpty(LightUpBoard board, Point loc) { - LightUpCell cell = board.getCell(loc.x, loc.y); - if (cell == null || cell.getType() != LightUpCellType.NUMBER) { - return false; - } - - int bulbs = 0; - int bulbsNeeded = cell.getData(); - cell = board.getCell(loc.x + 1, loc.y); - if (cell != null && cell.getType() == LightUpCellType.BULB) { - bulbs++; - } - cell = board.getCell(loc.x, loc.y + 1); - if (cell != null && cell.getType() == LightUpCellType.BULB) { - bulbs++; - } - cell = board.getCell(loc.x - 1, loc.y); - if (cell != null && cell.getType() == LightUpCellType.BULB) { - bulbs++; - } - cell = board.getCell(loc.x, loc.y - 1); - if (cell != null && cell.getType() == LightUpCellType.BULB) { - bulbs++; - } - return bulbs == bulbsNeeded; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - LightUpBoard initialBoard = (LightUpBoard) node.getBoard(); - LightUpBoard lightUpBoard = (LightUpBoard) node.getBoard().copy(); - for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { - LightUpCell cell = (LightUpCell) element; - if (cell.getType() == LightUpCellType.UNKNOWN && isForced(initialBoard, cell.getLocation())) { - cell.setData(LightUpCellType.EMPTY.value); - lightUpBoard.addModifiedData(cell); - } - } - if (lightUpBoard.getModifiedData().isEmpty()) { - return null; - } - else { - return lightUpBoard; - } - } -} +package edu.rpi.legup.puzzle.lightup.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.lightup.LightUpBoard; +import edu.rpi.legup.puzzle.lightup.LightUpCell; +import edu.rpi.legup.puzzle.lightup.LightUpCellType; +import java.awt.*; + +public class FinishWithEmptyDirectRule extends DirectRule { + + public FinishWithEmptyDirectRule() { + super( + "LTUP-BASC-0005", + "Finish with Empty", + "The remaining unknowns around a block must be empty if the number is satisfied.", + "edu/rpi/legup/images/lightup/rules/FinishWithEmpty.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement index of the puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + LightUpBoard initialBoard = (LightUpBoard) transition.getParents().get(0).getBoard(); + LightUpBoard finalBoard = (LightUpBoard) transition.getBoard(); + LightUpCell cell = (LightUpCell) finalBoard.getPuzzleElement(puzzleElement); + if (cell.getType() != LightUpCellType.EMPTY) { + return super.getInvalidUseOfRuleMessage() + ": Modified cells must be empty"; + } + + if (isForced(initialBoard, cell.getLocation())) { + return null; + } + return super.getInvalidUseOfRuleMessage() + ": Empty is not forced"; + } + + /** + * Checks whether a certain cell is forced to not be a bulb + * + * @param board specified board + * @param location location of cell to check + * @return boolean value based on whether a certain cell has an adjacent cell that has the + * required amount of adjacent bulbs + */ + private boolean isForced(LightUpBoard board, Point location) { + return isForcedEmpty(board, new Point(location.x + 1, location.y)) + || isForcedEmpty(board, new Point(location.x, location.y + 1)) + || isForcedEmpty(board, new Point(location.x - 1, location.y)) + || isForcedEmpty(board, new Point(location.x, location.y - 1)); + } + + /** + * Checks whether a certain cell has the required amount of adjacent bulbs + * + * @param board specified board + * @param loc location of cell to check + * @return boolean value based on whether a certain cell has the required amount of adjacent + * bulbs + */ + private boolean isForcedEmpty(LightUpBoard board, Point loc) { + LightUpCell cell = board.getCell(loc.x, loc.y); + if (cell == null || cell.getType() != LightUpCellType.NUMBER) { + return false; + } + + int bulbs = 0; + int bulbsNeeded = cell.getData(); + cell = board.getCell(loc.x + 1, loc.y); + if (cell != null && cell.getType() == LightUpCellType.BULB) { + bulbs++; + } + cell = board.getCell(loc.x, loc.y + 1); + if (cell != null && cell.getType() == LightUpCellType.BULB) { + bulbs++; + } + cell = board.getCell(loc.x - 1, loc.y); + if (cell != null && cell.getType() == LightUpCellType.BULB) { + bulbs++; + } + cell = board.getCell(loc.x, loc.y - 1); + if (cell != null && cell.getType() == LightUpCellType.BULB) { + bulbs++; + } + return bulbs == bulbsNeeded; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + LightUpBoard initialBoard = (LightUpBoard) node.getBoard(); + LightUpBoard lightUpBoard = (LightUpBoard) node.getBoard().copy(); + for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { + LightUpCell cell = (LightUpCell) element; + if (cell.getType() == LightUpCellType.UNKNOWN + && isForced(initialBoard, cell.getLocation())) { + cell.setData(LightUpCellType.EMPTY.value); + lightUpBoard.addModifiedData(cell); + } + } + if (lightUpBoard.getModifiedData().isEmpty()) { + return null; + } else { + return lightUpBoard; + } + } +} 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 410c30e9c..4ba754731 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 @@ -8,14 +8,15 @@ import edu.rpi.legup.puzzle.lightup.LightUpBoard; import edu.rpi.legup.puzzle.lightup.LightUpCell; import edu.rpi.legup.puzzle.lightup.LightUpCellType; - import java.util.ArrayList; import java.util.List; public class LightOrEmptyCaseRule extends CaseRule { public LightOrEmptyCaseRule() { - super("LTUP-CASE-0001", "Light or Empty", + super( + "LTUP-CASE-0001", + "Light or Empty", "Each blank cell is either a light or empty.", "edu/rpi/legup/images/lightup/cases/LightOrEmpty.png"); } @@ -36,7 +37,7 @@ public CaseBoard getCaseBoard(Board board) { /** * Gets the possible cases at a specific location based on this case rule * - * @param board the current board state + * @param board the current board state * @param puzzleElement puzzleElement to determine the possible cases for * @return a list of elements the specified could be */ @@ -73,33 +74,37 @@ public String checkRuleRaw(TreeTransition transition) { TreeTransition case1 = childTransitions.get(0); TreeTransition case2 = childTransitions.get(1); - if (case1.getBoard().getModifiedData().size() != 1 || - case2.getBoard().getModifiedData().size() != 1) { - return super.getInvalidUseOfRuleMessage() + ": This case rule must have 1 modified cell for each case"; + if (case1.getBoard().getModifiedData().size() != 1 + || case2.getBoard().getModifiedData().size() != 1) { + 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 super.getInvalidUseOfRuleMessage() + ": 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 super.getInvalidUseOfRuleMessage() + ": This case rule must an empty cell and a bulb cell"; + if (!((mod1.getType() == LightUpCellType.EMPTY && mod2.getType() == LightUpCellType.BULB) + || (mod2.getType() == LightUpCellType.EMPTY + && mod1.getType() == LightUpCellType.BULB))) { + return super.getInvalidUseOfRuleMessage() + + ": This case rule must an empty cell and a bulb cell"; } return null; } /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement index of the puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/MustLightDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/MustLightDirectRule.java index f0f943401..bf1843728 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/rules/MustLightDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/rules/MustLightDirectRule.java @@ -1,149 +1,153 @@ -package edu.rpi.legup.puzzle.lightup.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.lightup.LightUpBoard; -import edu.rpi.legup.puzzle.lightup.LightUpCell; -import edu.rpi.legup.puzzle.lightup.LightUpCellType; - -import java.awt.*; - -public class MustLightDirectRule extends DirectRule { - - public MustLightDirectRule() { - super("LTUP-BASC-0006", "Must Light", - "A cell must be a bulb if it is the only cell to be able to light another.", - "edu/rpi/legup/images/lightup/rules/MustLight.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement index of the puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - LightUpBoard parentBoard = (LightUpBoard) transition.getParents().get(0).getBoard(); - LightUpBoard finalBoard = (LightUpBoard) transition.getBoard(); - LightUpCell parentCell = (LightUpCell) parentBoard.getPuzzleElement(puzzleElement); - LightUpCell finalCell = (LightUpCell) finalBoard.getPuzzleElement(puzzleElement); - if (!(parentCell.getType() == LightUpCellType.UNKNOWN && !parentCell.isLite() && finalCell.getType() == LightUpCellType.BULB)) { - return super.getInvalidUseOfRuleMessage() + ": Modified cells must be bulbs"; - } - - finalBoard.fillWithLight(); - boolean isForced = isForcedBulb(parentBoard, parentCell.getLocation()); - finalCell.setData(LightUpCellType.BULB.value); - finalBoard.fillWithLight(); - - if (isForced) { - return null; - } - else { - return super.getInvalidUseOfRuleMessage() + ": This cell can be lit by another cell"; - } - } - - private boolean isForcedBulb(LightUpBoard board, Point loc) { - CannotLightACellContradictionRule cannotLite = new CannotLightACellContradictionRule(); - LightUpBoard modifiedBoard = board.copy(); - LightUpCell modifiedCell = modifiedBoard.getCell(loc.x, loc.y); - modifiedCell.setData(LightUpCellType.EMPTY.value); - //Check if this cell itself (the one with the bulb) has no other lighting option - if ((modifiedCell.getType() == LightUpCellType.EMPTY || modifiedCell.getType() == LightUpCellType.UNKNOWN) && - !modifiedCell.isLite() && cannotLite.checkContradictionAt(modifiedBoard, modifiedCell) == null) { - return true; - } - //Look right - for (int i = loc.x + 1; i < modifiedBoard.getWidth(); i++) { - LightUpCell c = modifiedBoard.getCell(i, loc.y); - if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { - break; - } - else { - if (c.getType() == LightUpCellType.EMPTY && - !c.isLite() && cannotLite.checkContradictionAt(modifiedBoard, c) == null) { - return true; - } - } - } - //Look left - for (int i = loc.x - 1; i >= 0; i--) { - LightUpCell c = modifiedBoard.getCell(i, loc.y); - if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { - break; - } - else { - if (c.getType() == LightUpCellType.EMPTY && - !c.isLite() && cannotLite.checkContradictionAt(modifiedBoard, c) == null) { - return true; - } - } - } - //Look down - for (int i = loc.y + 1; i < modifiedBoard.getHeight(); i++) { - LightUpCell c = modifiedBoard.getCell(loc.x, i); - if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { - break; - } - else { - if (c.getType() == LightUpCellType.EMPTY && - !c.isLite() && cannotLite.checkContradictionAt(modifiedBoard, c) == null) { - return true; - } - } - } - //Look up - for (int i = loc.y - 1; i >= 0; i--) { - LightUpCell c = modifiedBoard.getCell(loc.x, i); - if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { - break; - } - else { - if (c.getType() == LightUpCellType.EMPTY && - !c.isLite() && cannotLite.checkContradictionAt(modifiedBoard, c) == null) { - return true; - } - } - } - return false; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - LightUpBoard initialBoard = (LightUpBoard) node.getBoard(); - LightUpBoard tempBoard = (LightUpBoard) node.getBoard().copy(); - LightUpBoard lightUpBoard = (LightUpBoard) node.getBoard().copy(); - for (PuzzleElement element : tempBoard.getPuzzleElements()) { - LightUpCell cell = (LightUpCell) element; - if (cell.getType() == LightUpCellType.UNKNOWN && !cell.isLite()) { - cell.setData(LightUpCellType.EMPTY.value); - if (isForcedBulb(initialBoard, cell.getLocation())) { - LightUpCell modCell = (LightUpCell) lightUpBoard.getPuzzleElement(cell); - modCell.setData(LightUpCellType.BULB.value); - lightUpBoard.addModifiedData(modCell); - } - cell.setData(LightUpCellType.UNKNOWN.value); - } - } - if (lightUpBoard.getModifiedData().isEmpty()) { - return null; - } - else { - return lightUpBoard; - } - } -} +package edu.rpi.legup.puzzle.lightup.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.lightup.LightUpBoard; +import edu.rpi.legup.puzzle.lightup.LightUpCell; +import edu.rpi.legup.puzzle.lightup.LightUpCellType; +import java.awt.*; + +public class MustLightDirectRule extends DirectRule { + + public MustLightDirectRule() { + super( + "LTUP-BASC-0006", + "Must Light", + "A cell must be a bulb if it is the only cell to be able to light another.", + "edu/rpi/legup/images/lightup/rules/MustLight.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement index of the puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + LightUpBoard parentBoard = (LightUpBoard) transition.getParents().get(0).getBoard(); + LightUpBoard finalBoard = (LightUpBoard) transition.getBoard(); + LightUpCell parentCell = (LightUpCell) parentBoard.getPuzzleElement(puzzleElement); + LightUpCell finalCell = (LightUpCell) finalBoard.getPuzzleElement(puzzleElement); + if (!(parentCell.getType() == LightUpCellType.UNKNOWN + && !parentCell.isLite() + && finalCell.getType() == LightUpCellType.BULB)) { + return super.getInvalidUseOfRuleMessage() + ": Modified cells must be bulbs"; + } + + finalBoard.fillWithLight(); + boolean isForced = isForcedBulb(parentBoard, parentCell.getLocation()); + finalCell.setData(LightUpCellType.BULB.value); + finalBoard.fillWithLight(); + + if (isForced) { + return null; + } else { + return super.getInvalidUseOfRuleMessage() + ": This cell can be lit by another cell"; + } + } + + private boolean isForcedBulb(LightUpBoard board, Point loc) { + CannotLightACellContradictionRule cannotLite = new CannotLightACellContradictionRule(); + LightUpBoard modifiedBoard = board.copy(); + LightUpCell modifiedCell = modifiedBoard.getCell(loc.x, loc.y); + modifiedCell.setData(LightUpCellType.EMPTY.value); + // Check if this cell itself (the one with the bulb) has no other lighting option + if ((modifiedCell.getType() == LightUpCellType.EMPTY + || modifiedCell.getType() == LightUpCellType.UNKNOWN) + && !modifiedCell.isLite() + && cannotLite.checkContradictionAt(modifiedBoard, modifiedCell) == null) { + return true; + } + // Look right + for (int i = loc.x + 1; i < modifiedBoard.getWidth(); i++) { + LightUpCell c = modifiedBoard.getCell(i, loc.y); + if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { + break; + } else { + if (c.getType() == LightUpCellType.EMPTY + && !c.isLite() + && cannotLite.checkContradictionAt(modifiedBoard, c) == null) { + return true; + } + } + } + // Look left + for (int i = loc.x - 1; i >= 0; i--) { + LightUpCell c = modifiedBoard.getCell(i, loc.y); + if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { + break; + } else { + if (c.getType() == LightUpCellType.EMPTY + && !c.isLite() + && cannotLite.checkContradictionAt(modifiedBoard, c) == null) { + return true; + } + } + } + // Look down + for (int i = loc.y + 1; i < modifiedBoard.getHeight(); i++) { + LightUpCell c = modifiedBoard.getCell(loc.x, i); + if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { + break; + } else { + if (c.getType() == LightUpCellType.EMPTY + && !c.isLite() + && cannotLite.checkContradictionAt(modifiedBoard, c) == null) { + return true; + } + } + } + // Look up + for (int i = loc.y - 1; i >= 0; i--) { + LightUpCell c = modifiedBoard.getCell(loc.x, i); + if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { + break; + } else { + if (c.getType() == LightUpCellType.EMPTY + && !c.isLite() + && cannotLite.checkContradictionAt(modifiedBoard, c) == null) { + return true; + } + } + } + return false; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + LightUpBoard initialBoard = (LightUpBoard) node.getBoard(); + LightUpBoard tempBoard = (LightUpBoard) node.getBoard().copy(); + LightUpBoard lightUpBoard = (LightUpBoard) node.getBoard().copy(); + for (PuzzleElement element : tempBoard.getPuzzleElements()) { + LightUpCell cell = (LightUpCell) element; + if (cell.getType() == LightUpCellType.UNKNOWN && !cell.isLite()) { + cell.setData(LightUpCellType.EMPTY.value); + if (isForcedBulb(initialBoard, cell.getLocation())) { + LightUpCell modCell = (LightUpCell) lightUpBoard.getPuzzleElement(cell); + modCell.setData(LightUpCellType.BULB.value); + lightUpBoard.addModifiedData(modCell); + } + cell.setData(LightUpCellType.UNKNOWN.value); + } + } + if (lightUpBoard.getModifiedData().isEmpty()) { + return null; + } else { + return lightUpBoard; + } + } +} 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 cf7b70ccd..ac656721d 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 @@ -9,7 +9,6 @@ import edu.rpi.legup.puzzle.lightup.LightUpBoard; import edu.rpi.legup.puzzle.lightup.LightUpCell; import edu.rpi.legup.puzzle.lightup.LightUpCellType; - import java.awt.*; import java.util.ArrayList; import java.util.Iterator; @@ -19,7 +18,9 @@ public class SatisfyNumberCaseRule extends CaseRule { public SatisfyNumberCaseRule() { - super("LTUP-CASE-0002", "Satisfy Number", + super( + "LTUP-CASE-0002", + "Satisfy Number", "The different ways a blocks number can be satisfied.", "edu/rpi/legup/images/lightup/cases/SatisfyNumber.png"); } @@ -40,7 +41,7 @@ public CaseBoard getCaseBoard(Board board) { /** * Gets the possible cases at a specific location based on this case rule * - * @param board the current board state + * @param board the current board state * @param puzzleElement puzzleElement to determine the possible cases for * @return a list of elements the specified could be */ @@ -58,8 +59,7 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { if (checkCell != null) { if (checkCell.getType() == LightUpCellType.UNKNOWN && !checkCell.isLite()) { openSpots.add(checkCell); - } - else { + } else { if (checkCell.getType() == LightUpCellType.BULB) { numNeeded--; } @@ -69,8 +69,7 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { if (checkCell != null) { if (checkCell.getType() == LightUpCellType.UNKNOWN && !checkCell.isLite()) { openSpots.add(checkCell); - } - else { + } else { if (checkCell.getType() == LightUpCellType.BULB) { numNeeded--; } @@ -80,8 +79,7 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { if (checkCell != null) { if (checkCell.getType() == LightUpCellType.UNKNOWN && !checkCell.isLite()) { openSpots.add(checkCell); - } - else { + } else { if (checkCell.getType() == LightUpCellType.BULB) { numNeeded--; } @@ -91,8 +89,7 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { if (checkCell != null) { if (checkCell.getType() == LightUpCellType.UNKNOWN && !checkCell.isLite()) { openSpots.add(checkCell); - } - else { + } else { if (checkCell.getType() == LightUpCellType.BULB) { numNeeded--; } @@ -109,7 +106,11 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { return cases; } - private void generateCases(final LightUpBoard board, final int num, List openSpots, List cases) { + private void generateCases( + final LightUpBoard board, + final int num, + List openSpots, + List cases) { if (num > openSpots.size()) { return; } @@ -128,7 +129,13 @@ private void generateCases(final LightUpBoard board, final int num, List openSpots, List cases, LightUpBoard curBoard, int index) { + private void generateCases( + final LightUpBoard board, + final int num, + List openSpots, + List cases, + LightUpBoard curBoard, + int index) { if (num <= curBoard.getModifiedData().size()) { cases.add(curBoard); return; @@ -197,8 +204,9 @@ public String checkRuleRaw(TreeTransition transition) { boolean foundCell = false; for (PuzzleElement posEle : posCase.getModifiedData()) { LightUpCell posCell = (LightUpCell) posEle; - if (actCell.getType() == posCell.getType() && - actCell.getLocation().equals(posCell.getLocation())) { + if (actCell.getType() == posCell.getType() + && actCell.getLocation() + .equals(posCell.getLocation())) { foundCell = true; break; } @@ -228,13 +236,13 @@ public String checkRuleRaw(TreeTransition transition) { } /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement index of the puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { @@ -245,7 +253,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem * Gets all cells in the TreeTransition board that are adjacent to all modified cells * * @param transition TreeTransition object - * @return list of cells that are adjacent to all modified cells, returns null if the number of modified cells is =0 || >4 + * @return list of cells that are adjacent to all modified cells, returns null if the number of + * modified cells is =0 || >4 */ private List getPossibleSpots(TreeTransition transition) { LightUpBoard board = (LightUpBoard) transition.getBoard(); @@ -254,8 +263,7 @@ private List getPossibleSpots(TreeTransition transition) { int size = modCells.size(); if (size == 0 || size > 4) { return null; - } - else { + } else { Iterator it = modCells.iterator(); List spots = getAdjacentCells(board, (LightUpCell) it.next()); @@ -289,33 +297,32 @@ private List getAdjacentCells(LightUpBoard board, LightUpCell cell) } /** - * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid - * Overridden by case rules dependent on more than just the modified data + * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be + * valid Overridden by case rules dependent on more than just the modified data * - * @param board board state at application + * @param board board state at application * @param puzzleElement selected puzzleElement - * @return List of puzzle elements (typically cells) this application of the case rule depends upon. - * Defaults to any element modified by any case + * @return List of puzzle elements (typically cells) this application of the case rule depends + * upon. Defaults to any element modified by any case */ @Override public List dependentElements(Board board, PuzzleElement puzzleElement) { List elements = new ArrayList<>(); LightUpBoard puzzleBoard = (LightUpBoard) board; - LightUpCell point = (LightUpCell)puzzleBoard.getPuzzleElement(puzzleElement); + LightUpCell point = (LightUpCell) puzzleBoard.getPuzzleElement(puzzleElement); - List cells = getAdjacentCells(puzzleBoard,point); + List cells = getAdjacentCells(puzzleBoard, point); for (LightUpCell cell : cells) { - //add cells that can light adjacents from any direction + // add cells that can light adjacents from any direction Point location = cell.getLocation(); for (int i = location.x; i < puzzleBoard.getWidth(); i++) { System.out.println(i); LightUpCell c = puzzleBoard.getCell(i, location.y); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } - else if (!elements.contains(board.getPuzzleElement(c))) { + } else if (!elements.contains(board.getPuzzleElement(c))) { elements.add(board.getPuzzleElement(c)); } } @@ -323,8 +330,7 @@ else if (!elements.contains(board.getPuzzleElement(c))) { LightUpCell c = puzzleBoard.getCell(i, location.y); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } - else if (!elements.contains(board.getPuzzleElement(c))) { + } else if (!elements.contains(board.getPuzzleElement(c))) { elements.add(board.getPuzzleElement(c)); } } @@ -332,8 +338,7 @@ else if (!elements.contains(board.getPuzzleElement(c))) { LightUpCell c = puzzleBoard.getCell(location.x, i); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } - else if (!elements.contains(board.getPuzzleElement(c))) { + } else if (!elements.contains(board.getPuzzleElement(c))) { elements.add(board.getPuzzleElement(c)); } } @@ -341,8 +346,7 @@ else if (!elements.contains(board.getPuzzleElement(c))) { LightUpCell c = puzzleBoard.getCell(location.x, i); if (c.getType() == LightUpCellType.BLACK || c.getType() == LightUpCellType.NUMBER) { break; - } - else if (!elements.contains(board.getPuzzleElement(c))) { + } else if (!elements.contains(board.getPuzzleElement(c))) { elements.add(board.getPuzzleElement(c)); } } 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 f36c4ca57..8cf68e570 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 @@ -6,24 +6,26 @@ import edu.rpi.legup.puzzle.lightup.LightUpBoard; import edu.rpi.legup.puzzle.lightup.LightUpCell; import edu.rpi.legup.puzzle.lightup.LightUpCellType; - import java.awt.*; public class TooFewBulbsContradictionRule extends ContradictionRule { public TooFewBulbsContradictionRule() { - super("LTUP-CONT-0003", "Too Few Bulbs", + super( + "LTUP-CONT-0003", + "Too Few Bulbs", "There cannot be less bulbs around a block than its number states.", "edu/rpi/legup/images/lightup/contradictions/TooFewBulbs.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { 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 ffe7ca4d1..64cd4adcb 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 @@ -6,24 +6,26 @@ import edu.rpi.legup.puzzle.lightup.LightUpBoard; import edu.rpi.legup.puzzle.lightup.LightUpCell; import edu.rpi.legup.puzzle.lightup.LightUpCellType; - import java.awt.*; public class TooManyBulbsContradictionRule extends ContradictionRule { public TooManyBulbsContradictionRule() { - super("LTUP-CONT-0004", "Too Many Bulbs", + super( + "LTUP-CONT-0004", + "Too Many Bulbs", "There cannot be more bulbs around a block than its number states.", "edu/rpi/legup/images/lightup/contradictions/TooManyBulbs.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/EditLineCommand.java b/src/main/java/edu/rpi/legup/puzzle/masyu/EditLineCommand.java index 827be37ff..9986a1eda 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/EditLineCommand.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/EditLineCommand.java @@ -1,5 +1,7 @@ package edu.rpi.legup.puzzle.masyu; +import static edu.rpi.legup.app.GameBoardFacade.getInstance; + import edu.rpi.legup.history.PuzzleCommand; import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.gameboard.Board; @@ -12,11 +14,8 @@ import edu.rpi.legup.ui.boardview.BoardView; import edu.rpi.legup.ui.boardview.ElementView; import edu.rpi.legup.ui.proofeditorui.treeview.*; - import java.awt.event.MouseEvent; -import static edu.rpi.legup.app.GameBoardFacade.getInstance; - public class EditLineCommand extends PuzzleCommand { private TreeTransition transition; private PuzzleElement oldData; @@ -29,7 +28,11 @@ public class EditLineCommand extends PuzzleCommand { private TreeTransitionView transitionView; - public EditLineCommand(ElementView elementView, TreeElementView selectedView, MouseEvent event, MasyuLine line) { + public EditLineCommand( + ElementView elementView, + TreeElementView selectedView, + MouseEvent event, + MasyuLine line) { this.elementView = elementView; this.selectedView = selectedView; this.event = event; @@ -38,9 +41,7 @@ public EditLineCommand(ElementView elementView, TreeElementView selectedView, Mo this.transition = null; } - /** - * Executes a command - */ + /** Executes a command */ @Override public void executeCommand() { Tree tree = getInstance().getTree(); @@ -61,18 +62,19 @@ public void executeCommand() { } treeNode.getChildren().add(transition); - puzzle.notifyTreeListeners((ITreeListener listener) -> listener.onTreeElementAdded(transition)); + puzzle.notifyTreeListeners( + (ITreeListener listener) -> listener.onTreeElementAdded(transition)); transitionView = (TreeTransitionView) treeView.getElementView(transition); selection.newSelection(transitionView); - puzzle.notifyTreeListeners((ITreeListener listener) -> listener.onTreeSelectionChanged(selection)); + puzzle.notifyTreeListeners( + (ITreeListener listener) -> listener.onTreeSelectionChanged(selection)); getInstance().getLegupUI().repaintTree(); board = (MasyuBoard) transition.getBoard(); getInstance().getPuzzleModule().setCurrentBoard(board); oldData = newData.copy(); - } - else { + } else { transitionView = (TreeTransitionView) selectedView; transition = transitionView.getTreeElement(); } @@ -100,13 +102,14 @@ public void executeCommand() { System.out.println("delete"); board.getModifiedData().remove(dup_line); board.getLines().remove(dup_line); -// puzzle.notifyBoardListeners((IBoardListener listener) -> listener.onTreeElementChanged(editBoard)); - } - else { + // puzzle.notifyBoardListeners((IBoardListener listener) -> + // listener.onTreeElementChanged(editBoard)); + } else { System.out.println("adding"); board.getModifiedData().add(newData); board.getLines().add((MasyuLine) newData); -// puzzle.notifyBoardListeners((IBoardListener listener) -> listener.onTreeElementChanged(editBoard)); + // puzzle.notifyBoardListeners((IBoardListener listener) -> + // listener.onTreeElementChanged(editBoard)); } transition.propagateChange(newData); @@ -116,15 +119,14 @@ public void executeCommand() { * Gets the reason why the command cannot be executed * * @return if command cannot be executed, returns reason for why the command cannot be executed, - * otherwise null if command can be executed + * otherwise null if command can be executed */ @Override public String getErrorString() { Board board = selectedView.getTreeElement().getBoard(); if (!board.isModifiable()) { return "Board is not modifiable"; - } - else { + } else { if (!board.getPuzzleElement(elementView.getPuzzleElement()).isModifiable()) { return "Data is not modifiable"; } @@ -132,9 +134,7 @@ public String getErrorString() { return null; } - /** - * Undoes an command - */ + /** Undoes an command */ @Override public void undoCommand() { Tree tree = getInstance().getTree(); @@ -156,17 +156,16 @@ public void undoCommand() { getInstance().getPuzzleModule().setCurrentBoard(treeNode.getBoard()); } - Board prevBoard = null;// transition.getParentNode().getBoard(); + Board prevBoard = null; // transition.getParentNode().getBoard(); newData.setData(oldData.getData()); board.notifyChange(newData); - //System.err.println(newData.getData() + " : " + oldData.getData()); + // System.err.println(newData.getData() + " : " + oldData.getData()); if (prevBoard.getPuzzleElement(elementView.getPuzzleElement()).equalsData(newData)) { board.removeModifiedData(newData); - } - else { + } else { board.addModifiedData(newData); } transition.propagateChange(newData); diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/Masyu.java b/src/main/java/edu/rpi/legup/puzzle/masyu/Masyu.java index b339630e9..1ab74d56b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/Masyu.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/Masyu.java @@ -14,12 +14,9 @@ public Masyu() { this.exporter = new MasyuExporter(this); this.factory = new MasyuCellFactory(); - } - /** - * Initializes the game board. Called by the invoker of the class - */ + /** Initializes the game board. Called by the invoker of the class */ @Override public void initializeView() { boardView = new MasyuView((MasyuBoard) currentBoard); @@ -40,8 +37,8 @@ public Board generatePuzzle(int difficulty) { /** * Determines if the given dimensions are valid for Masyu * - * @param rows the number of rows - * @param columns the number of columns + * @param rows the number of rows + * @param columns the number of columns * @return true if the given dimensions are valid for Masyu, false otherwise */ public boolean isValidDimensions(int rows, int columns) { @@ -66,7 +63,5 @@ public boolean isBoardComplete(Board board) { * @param board the board that has changed */ @Override - public void onBoardChange(Board board) { - - } + public void onBoardChange(Board board) {} } diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuBoard.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuBoard.java index 96183bcfe..f347ff4c4 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuBoard.java @@ -2,7 +2,6 @@ import edu.rpi.legup.model.gameboard.GridBoard; import edu.rpi.legup.model.gameboard.PuzzleElement; - import java.util.ArrayList; import java.util.List; @@ -36,8 +35,7 @@ public void setLines(List lines) { public void notifyChange(PuzzleElement puzzleElement) { if (puzzleElement instanceof MasyuLine) { lines.add((MasyuLine) puzzleElement); - } - else { + } else { super.notifyChange(puzzleElement); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCell.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCell.java index af32dbfb6..af0811c55 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCell.java @@ -1,7 +1,6 @@ package edu.rpi.legup.puzzle.masyu; import edu.rpi.legup.model.gameboard.GridCell; - import java.awt.*; public class MasyuCell extends GridCell { diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCellFactory.java index 5278e0036..50e3c4cc0 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCellFactory.java @@ -4,17 +4,16 @@ import edu.rpi.legup.model.gameboard.ElementFactory; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; -import java.awt.*; - public class MasyuCellFactory extends ElementFactory { /** * Creates a puzzleElement based on the xml document Node and adds it to the board * - * @param node node that represents the puzzleElement + * @param node node that represents the puzzleElement * @param board board to add the newly created cell * @return newly created cell from the xml document Node * @throws InvalidFileFormatException if file is invalid @@ -23,7 +22,8 @@ public class MasyuCellFactory extends ElementFactory { public MasyuCell importCell(Node node, Board board) throws InvalidFileFormatException { try { if (!node.getNodeName().equalsIgnoreCase("cell")) { - throw new InvalidFileFormatException("Masyu Factory: unknown puzzleElement puzzleElement"); + throw new InvalidFileFormatException( + "Masyu Factory: unknown puzzleElement puzzleElement"); } MasyuBoard masyuBoard = (MasyuBoard) board; @@ -44,11 +44,10 @@ public MasyuCell importCell(Node node, Board board) throws InvalidFileFormatExce MasyuCell cell = new MasyuCell(MasyuType.convertToMasyuType(value), new Point(x, y)); cell.setIndex(y * height + x); return cell; - } - catch (NumberFormatException e) { - throw new InvalidFileFormatException("Masyu Factory: unknown value where integer expected"); - } - catch (NullPointerException e) { + } catch (NumberFormatException e) { + throw new InvalidFileFormatException( + "Masyu Factory: unknown value where integer expected"); + } catch (NullPointerException e) { throw new InvalidFileFormatException("Masyu Factory: could not find attribute(s)"); } } @@ -56,7 +55,7 @@ public MasyuCell importCell(Node node, Board board) throws InvalidFileFormatExce /** * Creates a xml document puzzleElement from a cell for exporting * - * @param document xml document + * @param document xml document * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuController.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuController.java index 02328c691..202c43a1e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuController.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuController.java @@ -1,18 +1,17 @@ package edu.rpi.legup.puzzle.masyu; +import static edu.rpi.legup.app.GameBoardFacade.getInstance; + import edu.rpi.legup.app.GameBoardFacade; import edu.rpi.legup.controller.ElementController; import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.ui.boardview.BoardView; - import java.awt.*; import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; -import static edu.rpi.legup.app.GameBoardFacade.getInstance; - public class MasyuController extends ElementController { private MasyuElementView mousePressedCell; @@ -52,19 +51,25 @@ public void mouseDragged(MouseEvent e) { if (Math.abs(p1.x - p2.x) == 1 ^ Math.abs(p1.y - p2.y) == 1) { masyuLine.add(elementView); - MasyuLine newLine = new MasyuLine(mousePressedCell.getPuzzleElement(), mouseDraggedCell.getPuzzleElement()); + MasyuLine newLine = + new MasyuLine( + mousePressedCell.getPuzzleElement(), + mouseDraggedCell.getPuzzleElement()); puzzle.notifyBoardListeners(listener -> listener.onBoardDataChanged(newLine)); } - } - else { + } else { if (mouseDraggedCell != elementView) { Point p1 = mouseDraggedCell.getPuzzleElement().getLocation(); Point p2 = elementView.getPuzzleElement().getLocation(); if (Math.abs(p1.x - p2.x) == 1 ^ Math.abs(p1.y - p2.y) == 1) { masyuLine.add(elementView); - MasyuLine newLine = new MasyuLine(mouseDraggedCell.getPuzzleElement(), elementView.getPuzzleElement()); - puzzle.notifyBoardListeners(listener -> listener.onBoardDataChanged(newLine)); + MasyuLine newLine = + new MasyuLine( + mouseDraggedCell.getPuzzleElement(), + elementView.getPuzzleElement()); + puzzle.notifyBoardListeners( + listener -> listener.onBoardDataChanged(newLine)); } mouseDraggedCell = elementView; } @@ -83,7 +88,7 @@ public void mouseReleased(MouseEvent e) { /** * Alters the cells as they are being dragged over or clicked * - * @param e Mouse event being used + * @param e Mouse event being used * @param data Data of selected cell */ @Override @@ -94,8 +99,7 @@ public void changeCell(MouseEvent e, PuzzleElement data) { } if (cell.getData() == MasyuType.UNKNOWN) { data.setData(3); - } - else { + } else { data.setData(0); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuElementView.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuElementView.java index b2f1f8902..942e1ffd2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuElementView.java @@ -1,7 +1,6 @@ package edu.rpi.legup.puzzle.masyu; import edu.rpi.legup.ui.boardview.GridElementView; - import java.awt.*; public class MasyuElementView extends GridElementView { @@ -24,8 +23,7 @@ public void drawElement(Graphics2D graphics2D) { graphics2D.fillRect(location.x, location.y, size.width, size.height); graphics2D.setColor(Color.BLACK); graphics2D.drawRect(location.x, location.y, size.width, size.height); - } - else { + } else { if (type == MasyuType.BLACK) { graphics2D.setStroke(new BasicStroke(1)); graphics2D.setColor(Color.LIGHT_GRAY); @@ -34,8 +32,7 @@ public void drawElement(Graphics2D graphics2D) { graphics2D.fillOval(location.x + 5, location.y + 5, 20, 20); graphics2D.setColor(Color.BLACK); graphics2D.drawRect(location.x, location.y, size.width, size.height); - } - else { + } else { if (type == MasyuType.WHITE) { graphics2D.setStroke(new BasicStroke(2)); graphics2D.setColor(Color.LIGHT_GRAY); diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuExporter.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuExporter.java index e5fb071b4..0c692193a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuExporter.java @@ -2,7 +2,6 @@ import edu.rpi.legup.model.PuzzleExporter; import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; import org.w3c.dom.Document; public class MasyuExporter extends PuzzleExporter { @@ -16,8 +15,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { MasyuBoard board; if (puzzle.getTree() != null) { board = (MasyuBoard) puzzle.getTree().getRootNode().getBoard(); - } - else { + } else { board = (MasyuBoard) puzzle.getBoardView().getBoard(); } @@ -28,7 +26,8 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { org.w3c.dom.Element cellsElement = newDocument.createElement("cells"); for (PuzzleElement puzzleElement : board.getPuzzleElements()) { MasyuCell cell = (MasyuCell) puzzleElement; - org.w3c.dom.Element cellElement = puzzle.getFactory().exportCell(newDocument, puzzleElement); + org.w3c.dom.Element cellElement = + puzzle.getFactory().exportCell(newDocument, puzzleElement); cellsElement.appendChild(cellElement); } diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuImporter.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuImporter.java index 3e0d328c4..2170da3ee 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuImporter.java @@ -2,12 +2,11 @@ import edu.rpi.legup.model.PuzzleImporter; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import java.awt.*; - public class MasyuImporter extends PuzzleImporter { public MasyuImporter(Masyu masyu) { super(masyu); @@ -26,14 +25,12 @@ public boolean acceptsTextInput() { /** * Creates an empty board for building * - * @param rows the number of rows on the board + * @param rows the number of rows on the board * @param columns the number of columns on the board * @throws RuntimeException if board can not be created */ @Override - public void initializeBoard(int rows, int columns) { - - } + public void initializeBoard(int rows, int columns) {} /** * Creates the board for building @@ -45,11 +42,13 @@ public void initializeBoard(int rows, int columns) { public void initializeBoard(Node node) throws InvalidFileFormatException { try { if (!node.getNodeName().equalsIgnoreCase("board")) { - throw new InvalidFileFormatException("Masyu Importer: cannot find board puzzleElement"); + throw new InvalidFileFormatException( + "Masyu Importer: cannot find board puzzleElement"); } Element boardElement = (Element) node; if (boardElement.getElementsByTagName("cells").getLength() == 0) { - throw new InvalidFileFormatException("Masyu Importer: no puzzleElement found for board"); + throw new InvalidFileFormatException( + "Masyu Importer: no puzzleElement found for board"); } Element dataElement = (Element) boardElement.getElementsByTagName("cells").item(0); NodeList elementDataList = dataElement.getElementsByTagName("cell"); @@ -58,9 +57,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { if (!boardElement.getAttribute("size").isEmpty()) { int size = Integer.valueOf(boardElement.getAttribute("size")); masyuBoard = new MasyuBoard(size); - } - else { - if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { + } else { + if (!boardElement.getAttribute("width").isEmpty() + && !boardElement.getAttribute("height").isEmpty()) { int width = Integer.valueOf(boardElement.getAttribute("width")); int height = Integer.valueOf(boardElement.getAttribute("height")); masyuBoard = new MasyuBoard(width, height); @@ -75,7 +74,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { int height = masyuBoard.getHeight(); for (int i = 0; i < elementDataList.getLength(); i++) { - MasyuCell cell = (MasyuCell) puzzle.getFactory().importCell(elementDataList.item(i), masyuBoard); + MasyuCell cell = + (MasyuCell) + puzzle.getFactory().importCell(elementDataList.item(i), masyuBoard); Point loc = cell.getLocation(); if (cell.getData() != MasyuType.UNKNOWN) { cell.setModifiable(false); @@ -95,9 +96,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { } } puzzle.setCurrentBoard(masyuBoard); - } - catch (NumberFormatException e) { - throw new InvalidFileFormatException("Masyu Importer: unknown value where integer expected"); + } catch (NumberFormatException e) { + throw new InvalidFileFormatException( + "Masyu Importer: unknown value where integer expected"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuLine.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuLine.java index d8c3240c7..eda51c839 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuLine.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuLine.java @@ -25,8 +25,10 @@ public void setC2(MasyuCell c2) { } public boolean compare(MasyuLine line) { - return ((line.getC1().getLocation().equals(data.getKey().getLocation()) && line.getC2().getLocation().equals(data.getValue().getLocation())) || - (line.getC1().getLocation().equals(data.getValue().getLocation()) && line.getC2().getLocation().equals(data.getKey().getLocation()))); + return ((line.getC1().getLocation().equals(data.getKey().getLocation()) + && line.getC2().getLocation().equals(data.getValue().getLocation())) + || (line.getC1().getLocation().equals(data.getValue().getLocation()) + && line.getC2().getLocation().equals(data.getKey().getLocation()))); } /** diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuLineView.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuLineView.java index d527ca414..c967f4865 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuLineView.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuLineView.java @@ -1,7 +1,6 @@ package edu.rpi.legup.puzzle.masyu; import edu.rpi.legup.ui.boardview.ElementView; - import java.awt.*; public class MasyuLineView extends ElementView { diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuType.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuType.java index 264350a95..4029d259d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuType.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuType.java @@ -1,9 +1,10 @@ package edu.rpi.legup.puzzle.masyu; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType; - public enum MasyuType { - UNKNOWN, BLACK, WHITE, LINE; + UNKNOWN, + BLACK, + WHITE, + LINE; public static MasyuType convertToMasyuType(int num) { switch (num) { @@ -18,4 +19,3 @@ public static MasyuType convertToMasyuType(int num) { } } } - diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuView.java b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuView.java index ac60dbe66..e962a6ebf 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuView.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuView.java @@ -3,7 +3,6 @@ import edu.rpi.legup.controller.BoardController; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.ui.boardview.GridBoardView; - import java.awt.*; import java.util.ArrayList; import java.util.List; @@ -20,7 +19,8 @@ public MasyuView(MasyuBoard board) { MasyuElementView elementView = new MasyuElementView(cell); elementView.setIndex(cell.getIndex()); elementView.setSize(elementSize); - elementView.setLocation(new Point(loc.x * elementSize.width, loc.y * elementSize.height)); + elementView.setLocation( + new Point(loc.x * elementSize.width, loc.y * elementSize.height)); elementViews.add(elementView); } lineViews = new ArrayList<>(); @@ -33,7 +33,8 @@ public MasyuView(MasyuBoard board) { @Override public void drawBoard(Graphics2D graphics2D) { - graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + graphics2D.setRenderingHint( + RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); super.drawBoard(graphics2D); lineViews.forEach(masyuLineView -> masyuLineView.draw(graphics2D)); } diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BadLoopingContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BadLoopingContradictionRule.java index 0da4dffe2..1681446cd 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BadLoopingContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BadLoopingContradictionRule.java @@ -7,18 +7,21 @@ public class BadLoopingContradictionRule extends ContradictionRule { public BadLoopingContradictionRule() { - super("MASY-CONT-0001", "Bad Looping", + super( + "MASY-CONT-0001", + "Bad Looping", "", "edu/rpi/legup/images/masyu/ContradictionBadLooping.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackContradictionRule.java index b4d32a46a..c219eeaa3 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackContradictionRule.java @@ -7,18 +7,17 @@ public class BlackContradictionRule extends ContradictionRule { public BlackContradictionRule() { - super("MASY-CONT-0002", "Black", - "", - "edu/rpi/legup/images/masyu/ContradictionBlack.png"); + super("MASY-CONT-0002", "Black", "", "edu/rpi/legup/images/masyu/ContradictionBlack.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackEdgeDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackEdgeDirectRule.java index b35dceaa7..665a74204 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackEdgeDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackEdgeDirectRule.java @@ -1,42 +1,41 @@ -package edu.rpi.legup.puzzle.masyu.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; - -public class BlackEdgeDirectRule extends DirectRule { - - public BlackEdgeDirectRule() { - super("MASY-BASC-0001", "Black Edge", - "", - "edu/rpi/legup/images/masyu/RuleBlackEdge.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * This method is the one that should overridden in child classes - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - return null; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.masyu.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; + +public class BlackEdgeDirectRule extends DirectRule { + + public BlackEdgeDirectRule() { + super("MASY-BASC-0001", "Black Edge", "", "edu/rpi/legup/images/masyu/RuleBlackEdge.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule This method is the one that should overridden in child + * classes + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + return null; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackSplitCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackSplitCaseRule.java index 3db89ef58..c7e3ff500 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackSplitCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlackSplitCaseRule.java @@ -5,20 +5,17 @@ import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.rules.CaseRule; import edu.rpi.legup.model.tree.TreeTransition; - import java.util.List; public class BlackSplitCaseRule extends CaseRule { public BlackSplitCaseRule() { - super("MASY-CASE-0001", "Black Split", - "", - "edu/rpi/legup/images/masyu/CaseBlackSplit.png"); + super("MASY-CASE-0001", "Black Split", "", "edu/rpi/legup/images/masyu/CaseBlackSplit.png"); } /** - * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. This method is - * the one that should overridden in child classes. + * Checks whether the {@link TreeTransition} logically follows from the parent node using this + * rule. This method is the one that should overridden in child classes. * * @param transition transition to check * @return null if the child node logically follow from the parent node, otherwise error message @@ -29,13 +26,14 @@ public String checkRuleRaw(TreeTransition transition) { } /** - * Checks whether the child node logically follows from the parent node at the specific puzzleElement index using - * this rule. This method is the one that should overridden in child classes. + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule. This method is the one that should overridden in child + * classes. * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { @@ -43,7 +41,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem } /** - * Gets the case board that indicates where this case rule can be applied on the given {@link Board}. + * Gets the case board that indicates where this case rule can be applied on the given {@link + * Board}. * * @param board board to find locations where this case rule can be applied * @return a case board @@ -54,9 +53,10 @@ public CaseBoard getCaseBoard(Board board) { } /** - * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on this case rule. + * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on + * this case rule. * - * @param board the current board state + * @param board the current board state * @param puzzleElement equivalent puzzleElement * @return a list of elements the specified could be */ diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlockedBlackDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlockedBlackDirectRule.java index 4364d016c..5c284eb45 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlockedBlackDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/BlockedBlackDirectRule.java @@ -1,42 +1,45 @@ -package edu.rpi.legup.puzzle.masyu.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; - -public class BlockedBlackDirectRule extends DirectRule { - - public BlockedBlackDirectRule() { - super("MASY-BASC-0002", "Blocked Black", - "", - "edu/rpi/legup/images/masyu/RuleBlockedBlack.gif"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * This method is the one that should overridden in child classes - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - return null; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.masyu.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; + +public class BlockedBlackDirectRule extends DirectRule { + + public BlockedBlackDirectRule() { + super( + "MASY-BASC-0002", + "Blocked Black", + "", + "edu/rpi/legup/images/masyu/RuleBlockedBlack.gif"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule This method is the one that should overridden in child + * classes + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + return null; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/ConnectedCellsDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/ConnectedCellsDirectRule.java index 49949ecec..6aee8ba5f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/ConnectedCellsDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/ConnectedCellsDirectRule.java @@ -1,42 +1,45 @@ -package edu.rpi.legup.puzzle.masyu.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; - -public class ConnectedCellsDirectRule extends DirectRule { - - public ConnectedCellsDirectRule() { - super("MASY-BASC-0003", "Connected Cells", - "", - "edu/rpi/legup/images/masyu/RuleConnectedCells.gif"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * This method is the one that should overridden in child classes - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - return null; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.masyu.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; + +public class ConnectedCellsDirectRule extends DirectRule { + + public ConnectedCellsDirectRule() { + super( + "MASY-BASC-0003", + "Connected Cells", + "", + "edu/rpi/legup/images/masyu/RuleConnectedCells.gif"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule This method is the one that should overridden in child + * classes + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + return null; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/FinishPathDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/FinishPathDirectRule.java index e04301ce2..27b39bc04 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/FinishPathDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/FinishPathDirectRule.java @@ -1,42 +1,45 @@ -package edu.rpi.legup.puzzle.masyu.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; - -public class FinishPathDirectRule extends DirectRule { - - public FinishPathDirectRule() { - super("MASY-BASC-0004", "Finished Path", - "", - "edu/rpi/legup/images/masyu/RuleFinishPath.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * This method is the one that should overridden in child classes - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - return null; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.masyu.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; + +public class FinishPathDirectRule extends DirectRule { + + public FinishPathDirectRule() { + super( + "MASY-BASC-0004", + "Finished Path", + "", + "edu/rpi/legup/images/masyu/RuleFinishPath.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule This method is the one that should overridden in child + * classes + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + return null; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NearWhiteDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NearWhiteDirectRule.java index 7cf707d0d..6a565bc82 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NearWhiteDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NearWhiteDirectRule.java @@ -1,42 +1,41 @@ -package edu.rpi.legup.puzzle.masyu.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; - -public class NearWhiteDirectRule extends DirectRule { - - public NearWhiteDirectRule() { - super("MASY-BASC-0005", "Near White", - "", - "edu/rpi/legup/images/masyu/RuleNearWhite.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * This method is the one that should overridden in child classes - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - return null; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.masyu.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; + +public class NearWhiteDirectRule extends DirectRule { + + public NearWhiteDirectRule() { + super("MASY-BASC-0005", "Near White", "", "edu/rpi/legup/images/masyu/RuleNearWhite.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule This method is the one that should overridden in child + * classes + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + return null; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NoOptionsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NoOptionsContradictionRule.java index 19da790aa..c41999b9c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NoOptionsContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NoOptionsContradictionRule.java @@ -7,18 +7,21 @@ public class NoOptionsContradictionRule extends ContradictionRule { public NoOptionsContradictionRule() { - super("MASY-CONT-0003", "No Options", + super( + "MASY-CONT-0003", + "No Options", "", "edu/rpi/legup/images/masyu/ContradictionNoOptions.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NormalSplitCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NormalSplitCaseRule.java index ab47adc1b..382ac6466 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NormalSplitCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/NormalSplitCaseRule.java @@ -5,20 +5,21 @@ import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.rules.CaseRule; import edu.rpi.legup.model.tree.TreeTransition; - import java.util.List; public class NormalSplitCaseRule extends CaseRule { public NormalSplitCaseRule() { - super("MASY-CASE-0002", "Normal Split", + super( + "MASY-CASE-0002", + "Normal Split", "", "edu/rpi/legup/images/masyu/CaseNormalSplit.png"); } /** - * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. This method is - * the one that should overridden in child classes. + * Checks whether the {@link TreeTransition} logically follows from the parent node using this + * rule. This method is the one that should overridden in child classes. * * @param transition transition to check * @return null if the child node logically follow from the parent node, otherwise error message @@ -29,13 +30,14 @@ public String checkRuleRaw(TreeTransition transition) { } /** - * Checks whether the child node logically follows from the parent node at the specific puzzleElement index using - * this rule. This method is the one that should overridden in child classes. + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule. This method is the one that should overridden in child + * classes. * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { @@ -43,7 +45,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem } /** - * Gets the case board that indicates where this case rule can be applied on the given {@link Board}. + * Gets the case board that indicates where this case rule can be applied on the given {@link + * Board}. * * @param board board to find locations where this case rule can be applied * @return a case board @@ -54,9 +57,10 @@ public CaseBoard getCaseBoard(Board board) { } /** - * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on this case rule. + * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on + * this case rule. * - * @param board the current board state + * @param board the current board state * @param puzzleElement equivalent puzzleElement * @return a list of elements the specified could be */ diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/OnlyOneChoiceDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/OnlyOneChoiceDirectRule.java index b0311e741..bc7353e5d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/OnlyOneChoiceDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/OnlyOneChoiceDirectRule.java @@ -1,42 +1,45 @@ -package edu.rpi.legup.puzzle.masyu.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; - -public class OnlyOneChoiceDirectRule extends DirectRule { - - public OnlyOneChoiceDirectRule() { - super("MASY-BASC-0006", "Only One Choice", - "", - "edu/rpi/legup/images/masyu/RuleOnlyOneChoice.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * This method is the one that should overridden in child classes - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - return null; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.masyu.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; + +public class OnlyOneChoiceDirectRule extends DirectRule { + + public OnlyOneChoiceDirectRule() { + super( + "MASY-BASC-0006", + "Only One Choice", + "", + "edu/rpi/legup/images/masyu/RuleOnlyOneChoice.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule This method is the one that should overridden in child + * classes + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + return null; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/OnlyTwoContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/OnlyTwoContradictionRule.java index ab587a0ec..ee71ee2bc 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/OnlyTwoContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/OnlyTwoContradictionRule.java @@ -7,18 +7,21 @@ public class OnlyTwoContradictionRule extends ContradictionRule { public OnlyTwoContradictionRule() { - super("MASY-CONT-0004", "Only Two", + super( + "MASY-CONT-0004", + "Only Two", "", "edu/rpi/legup/images/masyu/ContradictionOnly2.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteContradictionRule.java index 091c2b039..efc523b8d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteContradictionRule.java @@ -7,18 +7,17 @@ public class WhiteContradictionRule extends ContradictionRule { public WhiteContradictionRule() { - super("MASY-CONT-0005", "White", - "", - "edu/rpi/legup/images/masyu/ContradictionWhite.png"); + super("MASY-CONT-0005", "White", "", "edu/rpi/legup/images/masyu/ContradictionWhite.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteEdgeDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteEdgeDirectRule.java index bd894e1d4..4d2982d00 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteEdgeDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteEdgeDirectRule.java @@ -1,41 +1,40 @@ -package edu.rpi.legup.puzzle.masyu.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; - -public class WhiteEdgeDirectRule extends DirectRule { - public WhiteEdgeDirectRule() { - super("MASY-BASC-0007", "White Edge", - "", - "edu/rpi/legup/images/masyu/RuleWhiteEdge.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * This method is the one that should overridden in child classes - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - return null; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.masyu.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; + +public class WhiteEdgeDirectRule extends DirectRule { + public WhiteEdgeDirectRule() { + super("MASY-BASC-0007", "White Edge", "", "edu/rpi/legup/images/masyu/RuleWhiteEdge.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule This method is the one that should overridden in child + * classes + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + return null; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteSplitCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteSplitCaseRule.java index e45fde0a1..d50ddacfa 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteSplitCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/rules/WhiteSplitCaseRule.java @@ -5,20 +5,17 @@ import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.rules.CaseRule; import edu.rpi.legup.model.tree.TreeTransition; - import java.util.List; public class WhiteSplitCaseRule extends CaseRule { public WhiteSplitCaseRule() { - super("MASY-CASE-0003", "White Split", - "", - "edu/rpi/legup/images/masyu/CaseWhiteSplit.png"); + super("MASY-CASE-0003", "White Split", "", "edu/rpi/legup/images/masyu/CaseWhiteSplit.png"); } /** - * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. This method is - * the one that should overridden in child classes. + * Checks whether the {@link TreeTransition} logically follows from the parent node using this + * rule. This method is the one that should overridden in child classes. * * @param transition transition to check * @return null if the child node logically follow from the parent node, otherwise error message @@ -29,13 +26,14 @@ public String checkRuleRaw(TreeTransition transition) { } /** - * Checks whether the child node logically follows from the parent node at the specific puzzleElement index using - * this rule. This method is the one that should overridden in child classes. + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule. This method is the one that should overridden in child + * classes. * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { @@ -43,7 +41,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem } /** - * Gets the case board that indicates where this case rule can be applied on the given {@link Board}. + * Gets the case board that indicates where this case rule can be applied on the given {@link + * Board}. * * @param board board to find locations where this case rule can be applied * @return a case board @@ -54,9 +53,10 @@ public CaseBoard getCaseBoard(Board board) { } /** - * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on this case rule. + * Gets the possible cases for this {@link Board} at a specific {@link PuzzleElement} based on + * this case rule. * - * @param board the current board state + * @param board the current board state * @param puzzleElement equivalent puzzleElement * @return a list of elements the specified could be */ diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/Nurikabe.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/Nurikabe.java index 2edbcb039..8366d905f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/Nurikabe.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/Nurikabe.java @@ -17,9 +17,7 @@ public Nurikabe() { this.factory = new NurikabeCellFactory(); } - /** - * Initializes the game board. Called by the invoker of the class - */ + /** Initializes the game board. Called by the invoker of the class */ @Override public void initializeView() { boardView = new NurikabeView((NurikabeBoard) currentBoard); @@ -42,8 +40,8 @@ public Board generatePuzzle(int difficulty) { /** * Determines if the given dimensions are valid for Nurikabe * - * @param rows the number of rows - * @param columns the number of columns + * @param rows the number of rows + * @param columns the number of columns * @return true if the given dimensions are valid for Nurikabe, false otherwise */ public boolean isValidDimensions(int rows, int columns) { @@ -80,7 +78,5 @@ public boolean isBoardComplete(Board board) { * @param board the board that has changed */ @Override - public void onBoardChange(Board board) { - - } + public void onBoardChange(Board board) {} } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeBoard.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeBoard.java index d5b83d1e8..1f80611e8 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeBoard.java @@ -1,6 +1,5 @@ package edu.rpi.legup.puzzle.nurikabe; -import edu.rpi.legup.model.elements.Element; import edu.rpi.legup.model.gameboard.GridBoard; import edu.rpi.legup.model.gameboard.PuzzleElement; @@ -15,8 +14,11 @@ public NurikabeBoard(int size) { @Override public NurikabeCell getCell(int x, int y) { - if (y * dimension.width + x >= puzzleElements.size() || x >= dimension.width || - y >= dimension.height || x < 0 || y < 0) { + if (y * dimension.width + x >= puzzleElements.size() + || x >= dimension.width + || y >= dimension.height + || x < 0 + || y < 0) { return null; } return (NurikabeCell) super.getCell(x, y); diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCell.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCell.java index f84a3c9f1..c6cd2c64e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCell.java @@ -1,8 +1,7 @@ package edu.rpi.legup.puzzle.nurikabe; -import edu.rpi.legup.model.gameboard.GridCell; import edu.rpi.legup.model.elements.Element; - +import edu.rpi.legup.model.gameboard.GridCell; import java.awt.*; import java.awt.event.MouseEvent; @@ -11,7 +10,7 @@ public class NurikabeCell extends GridCell { /** * NurikabeCell Constructor - creates a NurikabeCell from the specified value and location * - * @param value value of the NurikabeCell + * @param value value of the NurikabeCell * @param location position of the NurikabeCell */ public NurikabeCell(int value, Point location) { @@ -46,7 +45,7 @@ public NurikabeType getType() { */ @Override public void setType(Element e, MouseEvent m) { - switch (e.getElementID()){ + switch (e.getElementID()) { case "NURI-PLAC-0001": this.data = -1; break; @@ -54,20 +53,18 @@ public void setType(Element e, MouseEvent m) { this.data = 0; break; case "NURI-UNPL-0001": - switch (m.getButton()){ + switch (m.getButton()) { case MouseEvent.BUTTON1: if (this.data <= 0 || this.data > 8) { this.data = 1; - } - else { + } else { this.data = this.data + 1; } break; case MouseEvent.BUTTON3: if (this.data > 1) { this.data = this.data - 1; - } - else { + } else { this.data = 9; } break; @@ -92,4 +89,4 @@ public NurikabeCell copy() { copy.setGiven(isGiven); return copy; } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCellFactory.java index b754f3e46..7241608ac 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCellFactory.java @@ -4,17 +4,16 @@ import edu.rpi.legup.model.gameboard.ElementFactory; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; -import java.awt.*; - public class NurikabeCellFactory extends ElementFactory { /** * Creates a puzzleElement based on the xml document Node and adds it to the board * - * @param node node that represents the puzzleElement + * @param node node that represents the puzzleElement * @param board board to add the newly created cell * @return newly created cell from the xml document Node * @throws InvalidFileFormatException if file is invalid @@ -23,7 +22,8 @@ public class NurikabeCellFactory extends ElementFactory { public NurikabeCell importCell(Node node, Board board) throws InvalidFileFormatException { try { if (!node.getNodeName().equalsIgnoreCase("cell")) { - throw new InvalidFileFormatException("nurikabe Factory: unknown puzzleElement puzzleElement"); + throw new InvalidFileFormatException( + "nurikabe Factory: unknown puzzleElement puzzleElement"); } NurikabeBoard nurikabeBoard = (NurikabeBoard) board; @@ -35,7 +35,8 @@ public NurikabeCell importCell(Node node, Board board) throws InvalidFileFormatE int x = Integer.valueOf(attributeList.getNamedItem("x").getNodeValue()); int y = Integer.valueOf(attributeList.getNamedItem("y").getNodeValue()); if (x >= width || y >= height) { - throw new InvalidFileFormatException("nurikabe Factory: cell location out of bounds"); + throw new InvalidFileFormatException( + "nurikabe Factory: cell location out of bounds"); } if (value < -2) { throw new InvalidFileFormatException("nurikabe Factory: cell unknown value"); @@ -44,11 +45,10 @@ public NurikabeCell importCell(Node node, Board board) throws InvalidFileFormatE NurikabeCell cell = new NurikabeCell(value, new Point(x, y)); cell.setIndex(y * height + x); return cell; - } - catch (NumberFormatException e) { - throw new InvalidFileFormatException("nurikabe Factory: unknown value where integer expected"); - } - catch (NullPointerException e) { + } catch (NumberFormatException e) { + throw new InvalidFileFormatException( + "nurikabe Factory: unknown value where integer expected"); + } catch (NullPointerException e) { throw new InvalidFileFormatException("nurikabe Factory: could not find attribute(s)"); } } @@ -56,7 +56,7 @@ public NurikabeCell importCell(Node node, Board board) throws InvalidFileFormatE /** * Creates a xml document puzzleElement from a cell for exporting * - * @param document xml document + * @param document xml document * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeController.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeController.java index c115498a8..158abe7b4 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeController.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeController.java @@ -2,7 +2,6 @@ import edu.rpi.legup.controller.ElementController; import edu.rpi.legup.model.gameboard.PuzzleElement; - import java.awt.event.MouseEvent; public class NurikabeController extends ElementController { @@ -12,32 +11,31 @@ public void changeCell(MouseEvent e, PuzzleElement data) { NurikabeCell cell = (NurikabeCell) data; if (e.getButton() == MouseEvent.BUTTON1) { if (e.isControlDown()) { - this.boardView.getSelectionPopupMenu().show(boardView, this.boardView.getCanvas().getX() + e.getX(), this.boardView.getCanvas().getY() + e.getY()); - } - else { + this.boardView + .getSelectionPopupMenu() + .show( + boardView, + this.boardView.getCanvas().getX() + e.getX(), + this.boardView.getCanvas().getY() + e.getY()); + } else { if (cell.getData() == -2) { data.setData(0); - } - else { + } else { if (cell.getData() == 0) { data.setData(-1); - } - else { + } else { data.setData(-2); } } } - } - else { + } else { if (e.getButton() == MouseEvent.BUTTON3) { if (cell.getData() == -2) { data.setData(-1); - } - else { + } else { if (cell.getData() == 0) { data.setData(-2); - } - else { + } else { data.setData(0); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeElementView.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeElementView.java index f122a7a5b..116b727d2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeElementView.java @@ -1,7 +1,6 @@ package edu.rpi.legup.puzzle.nurikabe; import edu.rpi.legup.ui.boardview.GridElementView; - import java.awt.*; public class NurikabeElementView extends GridElementView { @@ -40,24 +39,22 @@ public void drawElement(Graphics2D graphics2D) { FontMetrics metrics = graphics2D.getFontMetrics(FONT); String value = String.valueOf(puzzleElement.getData()); int xText = location.x + (size.width - metrics.stringWidth(value)) / 2; - int yText = location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent(); + int yText = + location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent(); graphics2D.drawString(String.valueOf(puzzleElement.getData()), xText, yText); - } - else { + } else { if (type == NurikabeType.BLACK) { graphics2D.setStroke(new BasicStroke(1)); graphics2D.setColor(Color.BLACK); graphics2D.fillRect(location.x, location.y, size.width, size.height); - } - else { + } else { if (type == NurikabeType.WHITE) { graphics2D.setStroke(new BasicStroke(1)); graphics2D.setColor(Color.WHITE); graphics2D.fillRect(location.x, location.y, size.width, size.height); graphics2D.setColor(Color.BLACK); graphics2D.drawRect(location.x, location.y, size.width, size.height); - } - else { + } else { if (type == NurikabeType.UNKNOWN) { graphics2D.setStroke(new BasicStroke(1)); graphics2D.setColor(Color.LIGHT_GRAY); diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeExporter.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeExporter.java index 095642a6e..23efd4724 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeExporter.java @@ -15,8 +15,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { NurikabeBoard board; if (puzzle.getTree() != null) { board = (NurikabeBoard) puzzle.getTree().getRootNode().getBoard(); - } - else { + } else { board = (NurikabeBoard) puzzle.getBoardView().getBoard(); } @@ -28,7 +27,8 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { for (PuzzleElement puzzleElement : board.getPuzzleElements()) { NurikabeCell cell = (NurikabeCell) puzzleElement; if (cell.getData() != -2) { - org.w3c.dom.Element cellElement = puzzle.getFactory().exportCell(newDocument, puzzleElement); + org.w3c.dom.Element cellElement = + puzzle.getFactory().exportCell(newDocument, puzzleElement); cellsElement.appendChild(cellElement); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeImporter.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeImporter.java index 2cbcc9ad0..ec4ed3ac1 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeImporter.java @@ -2,12 +2,11 @@ import edu.rpi.legup.model.PuzzleImporter; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import java.awt.*; - public class NurikabeImporter extends PuzzleImporter { public NurikabeImporter(Nurikabe nurikabe) { super(nurikabe); @@ -26,7 +25,7 @@ public boolean acceptsTextInput() { /** * Creates an empty board for building * - * @param rows the number of rows on the board + * @param rows the number of rows on the board * @param columns the number of columns on the board * @throws RuntimeException if board can not be created */ @@ -36,7 +35,8 @@ public void initializeBoard(int rows, int columns) { for (int y = 0; y < rows; y++) { for (int x = 0; x < columns; x++) { - NurikabeCell cell = new NurikabeCell(NurikabeType.UNKNOWN.toValue(), new Point(x, y)); + NurikabeCell cell = + new NurikabeCell(NurikabeType.UNKNOWN.toValue(), new Point(x, y)); cell.setIndex(y * columns + x); cell.setModifiable(true); nurikabeBoard.setCell(x, y, cell); @@ -55,11 +55,13 @@ public void initializeBoard(int rows, int columns) { public void initializeBoard(Node node) throws InvalidFileFormatException { try { if (!node.getNodeName().equalsIgnoreCase("board")) { - throw new InvalidFileFormatException("nurikabe Importer: cannot find board puzzleElement"); + throw new InvalidFileFormatException( + "nurikabe Importer: cannot find board puzzleElement"); } Element boardElement = (Element) node; if (boardElement.getElementsByTagName("cells").getLength() == 0) { - throw new InvalidFileFormatException("nurikabe Importer: no puzzleElement found for board"); + throw new InvalidFileFormatException( + "nurikabe Importer: no puzzleElement found for board"); } Element dataElement = (Element) boardElement.getElementsByTagName("cells").item(0); NodeList elementDataList = dataElement.getElementsByTagName("cell"); @@ -68,9 +70,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { if (!boardElement.getAttribute("size").isEmpty()) { int size = Integer.valueOf(boardElement.getAttribute("size")); nurikabeBoard = new NurikabeBoard(size); - } - else { - if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { + } else { + if (!boardElement.getAttribute("width").isEmpty() + && !boardElement.getAttribute("height").isEmpty()) { int width = Integer.valueOf(boardElement.getAttribute("width")); int height = Integer.valueOf(boardElement.getAttribute("height")); nurikabeBoard = new NurikabeBoard(width, height); @@ -85,7 +87,10 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { int height = nurikabeBoard.getHeight(); for (int i = 0; i < elementDataList.getLength(); i++) { - NurikabeCell cell = (NurikabeCell) puzzle.getFactory().importCell(elementDataList.item(i), nurikabeBoard); + NurikabeCell cell = + (NurikabeCell) + puzzle.getFactory() + .importCell(elementDataList.item(i), nurikabeBoard); Point loc = cell.getLocation(); if (cell.getData() != NurikabeType.UNKNOWN.toValue()) { cell.setModifiable(false); @@ -97,7 +102,8 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (nurikabeBoard.getCell(x, y) == null) { - NurikabeCell cell = new NurikabeCell(NurikabeType.UNKNOWN.toValue(), new Point(x, y)); + NurikabeCell cell = + new NurikabeCell(NurikabeType.UNKNOWN.toValue(), new Point(x, y)); cell.setIndex(y * height + x); cell.setModifiable(true); nurikabeBoard.setCell(x, y, cell); @@ -105,9 +111,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { } } puzzle.setCurrentBoard(nurikabeBoard); - } - catch (NumberFormatException e) { - throw new InvalidFileFormatException("nurikabe Importer: unknown value where integer expected"); + } catch (NumberFormatException e) { + throw new InvalidFileFormatException( + "nurikabe Importer: unknown value where integer expected"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeType.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeType.java index 1dbab645d..8acf9fc02 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeType.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeType.java @@ -1,7 +1,10 @@ package edu.rpi.legup.puzzle.nurikabe; public enum NurikabeType { - UNKNOWN, BLACK, WHITE, NUMBER; + UNKNOWN, + BLACK, + WHITE, + NUMBER; public int toValue() { return this.ordinal() - 2; diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeUtilities.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeUtilities.java index 024cf6bb2..71ffa08e5 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeUtilities.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeUtilities.java @@ -2,7 +2,6 @@ import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.utility.DisjointSets; - import java.awt.*; import java.util.HashMap; import java.util.HashSet; @@ -50,18 +49,18 @@ public static DisjointSets getNurikabeRegions(NurikabeBoard board) NurikabeCell rightCell = board.getCell(x + 1, y); NurikabeCell downCell = board.getCell(x, y + 1); - if (cell.getType() == NurikabeType.NUMBER || - cell.getType() == NurikabeType.WHITE) { - if (rightCell != null && (rightCell.getType() == NurikabeType.NUMBER || - rightCell.getType() == NurikabeType.WHITE)) { + if (cell.getType() == NurikabeType.NUMBER || cell.getType() == NurikabeType.WHITE) { + if (rightCell != null + && (rightCell.getType() == NurikabeType.NUMBER + || rightCell.getType() == NurikabeType.WHITE)) { regions.union(cell, rightCell); } - if (downCell != null && (downCell.getType() == NurikabeType.NUMBER || - downCell.getType() == NurikabeType.WHITE)) { + if (downCell != null + && (downCell.getType() == NurikabeType.NUMBER + || downCell.getType() == NurikabeType.WHITE)) { regions.union(cell, downCell); } - } - else { + } else { if (cell.getType() == NurikabeType.BLACK) { if (rightCell != null && rightCell.getType() == NurikabeType.BLACK) { regions.union(cell, rightCell); @@ -69,8 +68,7 @@ public static DisjointSets getNurikabeRegions(NurikabeBoard board) if (downCell != null && downCell.getType() == NurikabeType.BLACK) { regions.union(cell, downCell); } - } - else { + } else { if (cell.getType() == NurikabeType.UNKNOWN) { if (rightCell != null && rightCell.getType() == NurikabeType.UNKNOWN) { regions.union(cell, rightCell); @@ -110,13 +108,16 @@ public static DisjointSets getPossibleBlackRegions(NurikabeBoard b NurikabeCell cell = board.getCell(x, y); NurikabeCell rightCell = board.getCell(x + 1, y); NurikabeCell downCell = board.getCell(x, y + 1); - if (cell.getType() == NurikabeType.BLACK || cell.getType() == NurikabeType.UNKNOWN) { - if (rightCell != null && (rightCell.getType() == NurikabeType.BLACK || - rightCell.getType() == NurikabeType.UNKNOWN)) { + if (cell.getType() == NurikabeType.BLACK + || cell.getType() == NurikabeType.UNKNOWN) { + if (rightCell != null + && (rightCell.getType() == NurikabeType.BLACK + || rightCell.getType() == NurikabeType.UNKNOWN)) { blackRegions.union(cell, rightCell); } - if (downCell != null && (downCell.getType() == NurikabeType.BLACK || - downCell.getType() == NurikabeType.UNKNOWN)) { + if (downCell != null + && (downCell.getType() == NurikabeType.BLACK + || downCell.getType() == NurikabeType.UNKNOWN)) { blackRegions.union(cell, downCell); } } @@ -139,7 +140,9 @@ public static DisjointSets getPossibleWhiteRegions(NurikabeBoard b DisjointSets whiteRegions = new DisjointSets<>(); for (PuzzleElement data : board.getPuzzleElements()) { NurikabeCell cell = (NurikabeCell) data; - if (cell.getType() == NurikabeType.WHITE || cell.getType() == NurikabeType.NUMBER || cell.getType() == NurikabeType.UNKNOWN) { + if (cell.getType() == NurikabeType.WHITE + || cell.getType() == NurikabeType.NUMBER + || cell.getType() == NurikabeType.UNKNOWN) { whiteRegions.createSet(cell); } } @@ -149,14 +152,19 @@ public static DisjointSets getPossibleWhiteRegions(NurikabeBoard b NurikabeCell cell = board.getCell(x, y); NurikabeCell rightCell = board.getCell(x + 1, y); NurikabeCell downCell = board.getCell(x, y + 1); - if (cell.getType() == NurikabeType.WHITE || cell.getType() == NurikabeType.NUMBER || - cell.getType() == NurikabeType.UNKNOWN) { - if (rightCell != null && (rightCell.getType() == NurikabeType.WHITE || - rightCell.getType() == NurikabeType.NUMBER || rightCell.getType() == NurikabeType.UNKNOWN)) { + if (cell.getType() == NurikabeType.WHITE + || cell.getType() == NurikabeType.NUMBER + || cell.getType() == NurikabeType.UNKNOWN) { + if (rightCell != null + && (rightCell.getType() == NurikabeType.WHITE + || rightCell.getType() == NurikabeType.NUMBER + || rightCell.getType() == NurikabeType.UNKNOWN)) { whiteRegions.union(cell, rightCell); } - if (downCell != null && (downCell.getType() == NurikabeType.WHITE || - downCell.getType() == NurikabeType.NUMBER || downCell.getType() == NurikabeType.UNKNOWN)) { + if (downCell != null + && (downCell.getType() == NurikabeType.WHITE + || downCell.getType() == NurikabeType.NUMBER + || downCell.getType() == NurikabeType.UNKNOWN)) { whiteRegions.union(cell, downCell); } } @@ -166,9 +174,8 @@ public static DisjointSets getPossibleWhiteRegions(NurikabeBoard b } /** - * Makes a map where the keys are white/numbered cells - * and the values are the amount of cells that need - * to be added to the region + * Makes a map where the keys are white/numbered cells and the values are the amount of cells + * that need to be added to the region * * @param board nurikabe board * @return a map of cell keys to integer values @@ -181,7 +188,7 @@ public static HashMap getWhiteRegionMap(NurikabeBoard boa // Final mapping of cell to size HashMap whiteRegionMap = new HashMap<>(); for (NurikabeCell center : numberedCells) { - //BFS for each center to find the size of the region + // BFS for each center to find the size of the region int size = 1; // Mark all the vertices as not visited(By default // set as false) @@ -224,8 +231,7 @@ public static HashMap getWhiteRegionMap(NurikabeBoard boa // If a adjacent has not been visited, then mark it // visited and enqueue it for (NurikabeCell n : adj) { - if (!visited.getOrDefault(n, false) - && n.getType() == NurikabeType.WHITE) { + if (!visited.getOrDefault(n, false) && n.getType() == NurikabeType.WHITE) { connected.add(n); visited.put(n, true); queue.add(n); @@ -249,7 +255,8 @@ public static HashMap getWhiteRegionMap(NurikabeBoard boa * @param center nurikabe cell * @return a set of all white/numbered cells in the region */ - public static Set getSurroundedRegionOf(NurikabeBoard board, NurikabeCell center) { + public static Set getSurroundedRegionOf( + NurikabeBoard board, NurikabeCell center) { int width = board.getWidth(); int height = board.getHeight(); diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeView.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeView.java index cef287b92..0bac7e3e5 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeView.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeView.java @@ -3,7 +3,6 @@ import edu.rpi.legup.controller.BoardController; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.ui.boardview.GridBoardView; - import java.awt.*; public class NurikabeView extends GridBoardView { @@ -17,7 +16,8 @@ public NurikabeView(NurikabeBoard board) { NurikabeElementView elementView = new NurikabeElementView(cell); elementView.setIndex(cell.getIndex()); elementView.setSize(elementSize); - elementView.setLocation(new Point(loc.x * elementSize.width, loc.y * elementSize.height)); + elementView.setLocation( + new Point(loc.x * elementSize.width, loc.y * elementSize.height)); elementViews.add(elementView); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/BlackTile.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/BlackTile.java index 1609fbf99..459a809e0 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/BlackTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/BlackTile.java @@ -4,6 +4,10 @@ public class BlackTile extends PlaceableElement { public BlackTile() { - super("NURI-PLAC-0001", "Black Tile", "The black tile", "edu/rpi/legup/images/nurikabe/tiles/BlackTile.png"); + super( + "NURI-PLAC-0001", + "Black Tile", + "The black tile", + "edu/rpi/legup/images/nurikabe/tiles/BlackTile.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/NumberTile.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/NumberTile.java index 0b1ee9656..475b278da 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/NumberTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/NumberTile.java @@ -6,7 +6,11 @@ public class NumberTile extends NonPlaceableElement { private int object_num; public NumberTile() { - super("NURI-UNPL-0001", "Number Tile", "A numbered tile", "edu/rpi/legup/images/nurikabe/tiles/NumberTile.png"); + super( + "NURI-UNPL-0001", + "Number Tile", + "A numbered tile", + "edu/rpi/legup/images/nurikabe/tiles/NumberTile.png"); object_num = 0; } @@ -23,5 +27,4 @@ public int getTileNumber() { public void setTileNumber(int num) { object_num = num; } - } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/UnknownTile.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/UnknownTile.java index 259e17e74..85d47e208 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/UnknownTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/UnknownTile.java @@ -4,6 +4,10 @@ public class UnknownTile extends NonPlaceableElement { public UnknownTile() { - super("NURI-UNPL-0002", "Unknown Tile", "A blank tile", "edu/rpi/legup/images/nurikabe/tiles/UnknownTile.png"); + super( + "NURI-UNPL-0002", + "Unknown Tile", + "A blank tile", + "edu/rpi/legup/images/nurikabe/tiles/UnknownTile.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/WhiteTile.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/WhiteTile.java index 434e0663e..35eb63b81 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/WhiteTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/elements/WhiteTile.java @@ -4,6 +4,10 @@ public class WhiteTile extends PlaceableElement { public WhiteTile() { - super("NURI-PLAC-0002", "White Tile", "The white tile", "edu/rpi/legup/images/nurikabe/tiles/WhiteTile.png"); + super( + "NURI-PLAC-0002", + "White Tile", + "The white tile", + "edu/rpi/legup/images/nurikabe/tiles/WhiteTile.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBetweenRegionsDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBetweenRegionsDirectRule.java index bb527e4e2..7428ac204 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBetweenRegionsDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBetweenRegionsDirectRule.java @@ -1,112 +1,122 @@ -package edu.rpi.legup.puzzle.nurikabe.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.rules.ContradictionRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; -import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; -import edu.rpi.legup.puzzle.nurikabe.NurikabeType; -import edu.rpi.legup.puzzle.nurikabe.NurikabeUtilities; -import edu.rpi.legup.utility.DisjointSets; - -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.Set; - -public class BlackBetweenRegionsDirectRule extends DirectRule { - - public BlackBetweenRegionsDirectRule() { - super("NURI-BASC-0001", - "Black Between Regions", - "Any unknowns between two regions must be black.", - "edu/rpi/legup/images/nurikabe/rules/BetweenRegions.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - Set contras = new LinkedHashSet<>(); - contras.add(new MultipleNumbersContradictionRule()); - contras.add(new TooManySpacesContradictionRule()); - - NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard(); - NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard(); - - NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement); - - if (cell.getType() != NurikabeType.BLACK) { - return super.getInvalidUseOfRuleMessage() + ": Only black cells are allowed for this rule!"; - } - - int x = cell.getLocation().x; - int y = cell.getLocation().y; - - DisjointSets regions = NurikabeUtilities.getNurikabeRegions(destBoardState); - Set adjacentWhiteRegions = new HashSet<>(); - NurikabeCell upCell = destBoardState.getCell(x, y - 1); - NurikabeCell rightCell = destBoardState.getCell(x + 1, y); - NurikabeCell downCell = destBoardState.getCell(x, y + 1); - NurikabeCell leftCell = destBoardState.getCell(x - 1, y); - - if (upCell != null && (upCell.getType() == NurikabeType.WHITE || upCell.getType() == NurikabeType.NUMBER)) { - NurikabeCell repCell = regions.find(upCell); - if (!adjacentWhiteRegions.contains(repCell)) { - adjacentWhiteRegions.add(repCell); - } - } - if (rightCell != null && (rightCell.getType() == NurikabeType.WHITE || rightCell.getType() == NurikabeType.NUMBER)) { - NurikabeCell repCell = regions.find(rightCell); - if (!adjacentWhiteRegions.contains(repCell)) { - adjacentWhiteRegions.add(repCell); - } - } - if (downCell != null && (downCell.getType() == NurikabeType.WHITE || downCell.getType() == NurikabeType.NUMBER)) { - NurikabeCell repCell = regions.find(downCell); - if (!adjacentWhiteRegions.contains(repCell)) { - adjacentWhiteRegions.add(repCell); - } - } - if (leftCell != null && (leftCell.getType() == NurikabeType.WHITE || leftCell.getType() == NurikabeType.NUMBER)) { - NurikabeCell repCell = regions.find(leftCell); - if (!adjacentWhiteRegions.contains(repCell)) { - adjacentWhiteRegions.add(repCell); - } - } - - if (adjacentWhiteRegions.size() < 2) { - return "The new black cell must separate two white regions for this rule!"; - } - - NurikabeBoard modified = origBoardState.copy(); - modified.getCell(x, y).setData(NurikabeType.WHITE.toValue()); - - for (ContradictionRule c : contras) { - if (c.checkContradiction(modified) == null) { - return null; - } - } - return "Does not follow from the rule"; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.nurikabe.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.ContradictionRule; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; +import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; +import edu.rpi.legup.puzzle.nurikabe.NurikabeType; +import edu.rpi.legup.puzzle.nurikabe.NurikabeUtilities; +import edu.rpi.legup.utility.DisjointSets; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.Set; + +public class BlackBetweenRegionsDirectRule extends DirectRule { + + public BlackBetweenRegionsDirectRule() { + super( + "NURI-BASC-0001", + "Black Between Regions", + "Any unknowns between two regions must be black.", + "edu/rpi/legup/images/nurikabe/rules/BetweenRegions.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + Set contras = new LinkedHashSet<>(); + contras.add(new MultipleNumbersContradictionRule()); + contras.add(new TooManySpacesContradictionRule()); + + NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard(); + NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard(); + + NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement); + + if (cell.getType() != NurikabeType.BLACK) { + return super.getInvalidUseOfRuleMessage() + + ": Only black cells are allowed for this rule!"; + } + + int x = cell.getLocation().x; + int y = cell.getLocation().y; + + DisjointSets regions = NurikabeUtilities.getNurikabeRegions(destBoardState); + Set adjacentWhiteRegions = new HashSet<>(); + NurikabeCell upCell = destBoardState.getCell(x, y - 1); + NurikabeCell rightCell = destBoardState.getCell(x + 1, y); + NurikabeCell downCell = destBoardState.getCell(x, y + 1); + NurikabeCell leftCell = destBoardState.getCell(x - 1, y); + + if (upCell != null + && (upCell.getType() == NurikabeType.WHITE + || upCell.getType() == NurikabeType.NUMBER)) { + NurikabeCell repCell = regions.find(upCell); + if (!adjacentWhiteRegions.contains(repCell)) { + adjacentWhiteRegions.add(repCell); + } + } + if (rightCell != null + && (rightCell.getType() == NurikabeType.WHITE + || rightCell.getType() == NurikabeType.NUMBER)) { + NurikabeCell repCell = regions.find(rightCell); + if (!adjacentWhiteRegions.contains(repCell)) { + adjacentWhiteRegions.add(repCell); + } + } + if (downCell != null + && (downCell.getType() == NurikabeType.WHITE + || downCell.getType() == NurikabeType.NUMBER)) { + NurikabeCell repCell = regions.find(downCell); + if (!adjacentWhiteRegions.contains(repCell)) { + adjacentWhiteRegions.add(repCell); + } + } + if (leftCell != null + && (leftCell.getType() == NurikabeType.WHITE + || leftCell.getType() == NurikabeType.NUMBER)) { + NurikabeCell repCell = regions.find(leftCell); + if (!adjacentWhiteRegions.contains(repCell)) { + adjacentWhiteRegions.add(repCell); + } + } + + if (adjacentWhiteRegions.size() < 2) { + return "The new black cell must separate two white regions for this rule!"; + } + + NurikabeBoard modified = origBoardState.copy(); + modified.getCell(x, y).setData(NurikabeType.WHITE.toValue()); + + for (ContradictionRule c : contras) { + if (c.checkContradiction(modified) == null) { + return null; + } + } + return "Does not follow from the rule"; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBottleNeckDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBottleNeckDirectRule.java index c4cf0d3fd..a8a94178b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBottleNeckDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/BlackBottleNeckDirectRule.java @@ -1,65 +1,69 @@ -package edu.rpi.legup.puzzle.nurikabe.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.rules.ContradictionRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; -import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; -import edu.rpi.legup.puzzle.nurikabe.NurikabeType; - -public class BlackBottleNeckDirectRule extends DirectRule { - - public BlackBottleNeckDirectRule() { - super("NURI-BASC-0002", - "Black Bottle Neck", - "If there is only one path for a black to escape, then those unknowns must be black.", - "edu/rpi/legup/images/nurikabe/rules/OneUnknownBlack.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - ContradictionRule contraRule = new IsolateBlackContradictionRule(); - - NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard(); - NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard(); - - NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement); - - if (cell.getType() != NurikabeType.BLACK) { - return super.getInvalidUseOfRuleMessage() + ": Only black cells are allowed for this rule!"; - } - NurikabeBoard modified = origBoardState.copy(); - NurikabeCell modCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement); - modCell.setData(NurikabeType.WHITE.toValue()); - - if (contraRule.checkContradiction(modified) == null) { - return null; - } - else { - return super.getInvalidUseOfRuleMessage() + ": This is not the only way for black to escape!"; - } - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.nurikabe.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.ContradictionRule; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; +import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; +import edu.rpi.legup.puzzle.nurikabe.NurikabeType; + +public class BlackBottleNeckDirectRule extends DirectRule { + + public BlackBottleNeckDirectRule() { + super( + "NURI-BASC-0002", + "Black Bottle Neck", + "If there is only one path for a black to escape, then those unknowns must be" + + " black.", + "edu/rpi/legup/images/nurikabe/rules/OneUnknownBlack.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + ContradictionRule contraRule = new IsolateBlackContradictionRule(); + + NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard(); + NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard(); + + NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement); + + if (cell.getType() != NurikabeType.BLACK) { + return super.getInvalidUseOfRuleMessage() + + ": Only black cells are allowed for this rule!"; + } + NurikabeBoard modified = origBoardState.copy(); + NurikabeCell modCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement); + modCell.setData(NurikabeType.WHITE.toValue()); + + if (contraRule.checkContradiction(modified) == null) { + return null; + } else { + return super.getInvalidUseOfRuleMessage() + + ": This is not the only way for black to escape!"; + } + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} 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 641b76322..fe1ffcf91 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 @@ -8,22 +8,22 @@ import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; import edu.rpi.legup.puzzle.nurikabe.NurikabeType; - import java.util.ArrayList; import java.util.List; public class BlackOrWhiteCaseRule extends CaseRule { public BlackOrWhiteCaseRule() { - super("NURI-CASE-0001", + super( + "NURI-CASE-0001", "Black or White", "Each blank cell is either black or white.", "edu/rpi/legup/images/nurikabe/cases/BlackOrWhite.png"); } /** - * Checks whether the {@link TreeTransition} logically follows from the parent node using this rule. This method is - * the one that should overridden in child classes. + * Checks whether the {@link TreeTransition} logically follows from the parent node using this + * rule. This method is the one that should overridden in child classes. * * @param transition transition to check * @return null if the child node logically follow from the parent node, otherwise error message @@ -37,20 +37,24 @@ public String checkRuleRaw(TreeTransition transition) { TreeTransition case1 = childTransitions.get(0); TreeTransition case2 = childTransitions.get(1); - if (case1.getBoard().getModifiedData().size() != 1 || - case2.getBoard().getModifiedData().size() != 1) { - return super.getInvalidUseOfRuleMessage() + ": This case rule must have 1 modified cell for each case."; + if (case1.getBoard().getModifiedData().size() != 1 + || case2.getBoard().getModifiedData().size() != 1) { + 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 super.getInvalidUseOfRuleMessage() + ": 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 super.getInvalidUseOfRuleMessage() + ": This case rule must an empty white and black cell."; + if (!((mod1.getType() == NurikabeType.WHITE && mod2.getType() == NurikabeType.BLACK) + || (mod2.getType() == NurikabeType.WHITE + && mod1.getType() == NurikabeType.BLACK))) { + return super.getInvalidUseOfRuleMessage() + + ": This case rule must an empty white and black cell."; } return null; @@ -72,7 +76,7 @@ public CaseBoard getCaseBoard(Board board) { /** * Gets the possible cases at a specific location based on this case rule * - * @param board the current board state + * @param board the current board state * @param puzzleElement equivalent puzzleElement * @return a list of elements the specified could be */ @@ -95,13 +99,13 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { } /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { 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 2dfb817e2..751c88881 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 @@ -13,20 +13,21 @@ public class BlackSquareContradictionRule extends ContradictionRule { private final String INVALID_USE_MESSAGE = "Does not contain a contradiction at this index"; public BlackSquareContradictionRule() { - super("NURI-CONT-0001", + super( + "NURI-CONT-0001", "Black Square", "There cannot be a 2x2 square of black.", "edu/rpi/legup/images/nurikabe/contradictions/BlackSquare.png"); } - /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { @@ -39,12 +40,16 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { 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++) { - for (int y = cell.getLocation().y - 1; y >= 0 && y < cell.getLocation().y + 1 && y < height - 1; y++) { - if (nurikabeBoard.getCell(x, y).getType() == NurikabeType.BLACK && - nurikabeBoard.getCell(x + 1, y).getType() == NurikabeType.BLACK && - nurikabeBoard.getCell(x, y + 1).getType() == NurikabeType.BLACK && - nurikabeBoard.getCell(x + 1, y + 1).getType() == NurikabeType.BLACK) { + for (int x = cell.getLocation().x - 1; + x >= 0 && x < cell.getLocation().x + 1 && x < width - 1; + x++) { + for (int y = cell.getLocation().y - 1; + y >= 0 && y < cell.getLocation().y + 1 && y < height - 1; + y++) { + if (nurikabeBoard.getCell(x, y).getType() == NurikabeType.BLACK + && nurikabeBoard.getCell(x + 1, y).getType() == NurikabeType.BLACK + && nurikabeBoard.getCell(x, y + 1).getType() == NurikabeType.BLACK + && nurikabeBoard.getCell(x + 1, y + 1).getType() == NurikabeType.BLACK) { return null; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CannotReachCellDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CannotReachCellDirectRule.java index e86724ed9..f3d3ee8f2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CannotReachCellDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CannotReachCellDirectRule.java @@ -1,61 +1,64 @@ -package edu.rpi.legup.puzzle.nurikabe.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.rules.ContradictionRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; -import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; -import edu.rpi.legup.puzzle.nurikabe.NurikabeType; - -public class CannotReachCellDirectRule extends DirectRule { - public CannotReachCellDirectRule() { - super("NURI-BASC-0008", - "Can't Reach Cell", - "A cell must be black if it cannot be reached by any white region", - "edu/rpi/legup/images/nurikabe/rules/Unreachable.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - ContradictionRule contraRule = new UnreachableWhiteCellContradictionRule(); - - NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard(); - NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement); - if (cell.getType() != NurikabeType.BLACK) { - return super.getInvalidUseOfRuleMessage() + ": Only black cells are allowed for this rule!"; - } - - NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard(); - NurikabeBoard modified = origBoardState.copy(); - - NurikabeCell modifiedCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement); - modifiedCell.setData(NurikabeType.WHITE.toValue()); - if (contraRule.checkContradictionAt(modified, modifiedCell) == null) { - return null; - } - return super.getInvalidUseOfRuleMessage() + ": Cell at this index can be reached"; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.nurikabe.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.ContradictionRule; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; +import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; +import edu.rpi.legup.puzzle.nurikabe.NurikabeType; + +public class CannotReachCellDirectRule extends DirectRule { + public CannotReachCellDirectRule() { + super( + "NURI-BASC-0008", + "Can't Reach Cell", + "A cell must be black if it cannot be reached by any white region", + "edu/rpi/legup/images/nurikabe/rules/Unreachable.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + protected String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + ContradictionRule contraRule = new UnreachableWhiteCellContradictionRule(); + + NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard(); + NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement); + if (cell.getType() != NurikabeType.BLACK) { + return super.getInvalidUseOfRuleMessage() + + ": Only black cells are allowed for this rule!"; + } + + NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard(); + NurikabeBoard modified = origBoardState.copy(); + + NurikabeCell modifiedCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement); + modifiedCell.setData(NurikabeType.WHITE.toValue()); + if (contraRule.checkContradictionAt(modified, modifiedCell) == null) { + return null; + } + return super.getInvalidUseOfRuleMessage() + ": Cell at this index can be reached"; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CornerBlackDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CornerBlackDirectRule.java index 55316fcbb..84ec45e99 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CornerBlackDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/CornerBlackDirectRule.java @@ -1,108 +1,133 @@ -package edu.rpi.legup.puzzle.nurikabe.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.rules.ContradictionRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; -import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; -import edu.rpi.legup.puzzle.nurikabe.NurikabeType; -import edu.rpi.legup.utility.ConnectedRegions; - -import java.awt.*; -import java.util.Set; - -public class CornerBlackDirectRule extends DirectRule { - - public CornerBlackDirectRule() { - super("NURI-BASC-0003", - "Corners Black", - "If there is only one white square connected to unknowns and one more white is needed then the angles of that white square are black", - "edu/rpi/legup/images/nurikabe/rules/CornerBlack.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - NurikabeBoard board = (NurikabeBoard) transition.getBoard(); - NurikabeCell cell = (NurikabeCell) board.getPuzzleElement(puzzleElement); - if (cell.getType() != NurikabeType.BLACK) { - return "Only black cells are allowed for this rule!"; - } - - ContradictionRule tooFewContra = new TooFewSpacesContradictionRule(); - Point cellLocation = cell.getLocation(); - // 1. Find the coordinates of the white space (should be a corner of cell) - for (int i = -1; i < 2; i += 2) { - for (int j = -1; j < 2; j += 2) { - // If the corner does not exist, skip the corner - if (!(cellLocation.x + i >= 0 && cellLocation.x + i < board.getWidth() && cellLocation.y + j >= 0 && cellLocation.y + j < board.getHeight())) { - continue; - } - - NurikabeCell corner = board.getCell(cellLocation.x + i, cellLocation.y + j); - NurikabeType cornerType = corner.getType(); - if (cornerType == NurikabeType.WHITE || cornerType == NurikabeType.NUMBER) { - Point cornerLocation = corner.getLocation(); - // 2. Check if the intersecting adjacent spaces of the white space and the black corner are empty - if (board.getCell(cornerLocation.x, cellLocation.y).getType() == NurikabeType.UNKNOWN && board.getCell(cellLocation.x, cornerLocation.y).getType() == NurikabeType.UNKNOWN) { - // System.out.println("Went inside if statement"); - NurikabeBoard modified = board.copy(); - modified.getCell(cornerLocation.x, cellLocation.y).setData(NurikabeType.BLACK.toValue()); - modified.getCell(cellLocation.x, cornerLocation.y).setData(NurikabeType.BLACK.toValue()); - boolean containsContradiction = tooFewContra.checkContradiction(modified) == null; - if (containsContradiction) { - // 3. Check if the connected region is 1 under what is needed - Set region = ConnectedRegions.getRegionAroundPoint(cornerLocation, NurikabeType.BLACK.toValue(), modified.getIntArray(), modified.getWidth(), modified.getHeight()); - int regionNumber = 0; - // System.out.println("Region set size: " + region.size()); - for (Point p : region) { - NurikabeCell pCell = modified.getCell(p.x, p.y); - if (pCell.getType() == NurikabeType.NUMBER) { - if (regionNumber == 0) { - regionNumber = pCell.getData(); - } - else { - return "There is a MultipleNumbers Contradiction on the board."; - } - } - } - // If the region size is 0, there is a possibility that there was only 1 cell in the white - // region, and that white cell was a NurikabeType.NUMBER cell - if (regionNumber == 0 && corner.getType() == NurikabeType.NUMBER && corner.getData() == 2) { - return null; - } - // If the region size is not 0, make sure the regionNumber and the region size match (need - // to add 1 to account for the cell that was surrounded - if (regionNumber != 0 && region.size() + 1 == regionNumber) { - return null; - } - } - } - } - } - } - return "This is not a valid use of the corner black rule!"; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.nurikabe.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.ContradictionRule; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; +import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; +import edu.rpi.legup.puzzle.nurikabe.NurikabeType; +import edu.rpi.legup.utility.ConnectedRegions; +import java.awt.*; +import java.util.Set; + +public class CornerBlackDirectRule extends DirectRule { + + public CornerBlackDirectRule() { + super( + "NURI-BASC-0003", + "Corners Black", + "If there is only one white square connected to unknowns and one more white is" + + " needed then the angles of that white square are black", + "edu/rpi/legup/images/nurikabe/rules/CornerBlack.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + NurikabeBoard board = (NurikabeBoard) transition.getBoard(); + NurikabeCell cell = (NurikabeCell) board.getPuzzleElement(puzzleElement); + if (cell.getType() != NurikabeType.BLACK) { + return "Only black cells are allowed for this rule!"; + } + + ContradictionRule tooFewContra = new TooFewSpacesContradictionRule(); + Point cellLocation = cell.getLocation(); + // 1. Find the coordinates of the white space (should be a corner of cell) + for (int i = -1; i < 2; i += 2) { + for (int j = -1; j < 2; j += 2) { + // If the corner does not exist, skip the corner + if (!(cellLocation.x + i >= 0 + && cellLocation.x + i < board.getWidth() + && cellLocation.y + j >= 0 + && cellLocation.y + j < board.getHeight())) { + continue; + } + + NurikabeCell corner = board.getCell(cellLocation.x + i, cellLocation.y + j); + NurikabeType cornerType = corner.getType(); + if (cornerType == NurikabeType.WHITE || cornerType == NurikabeType.NUMBER) { + Point cornerLocation = corner.getLocation(); + // 2. Check if the intersecting adjacent spaces of the white space and the black + // corner + // are empty + if (board.getCell(cornerLocation.x, cellLocation.y).getType() + == NurikabeType.UNKNOWN + && board.getCell(cellLocation.x, cornerLocation.y).getType() + == NurikabeType.UNKNOWN) { + // System.out.println("Went inside if statement"); + NurikabeBoard modified = board.copy(); + modified.getCell(cornerLocation.x, cellLocation.y) + .setData(NurikabeType.BLACK.toValue()); + modified.getCell(cellLocation.x, cornerLocation.y) + .setData(NurikabeType.BLACK.toValue()); + boolean containsContradiction = + tooFewContra.checkContradiction(modified) == null; + if (containsContradiction) { + // 3. Check if the connected region is 1 under what is needed + Set region = + ConnectedRegions.getRegionAroundPoint( + cornerLocation, + NurikabeType.BLACK.toValue(), + modified.getIntArray(), + modified.getWidth(), + modified.getHeight()); + int regionNumber = 0; + // System.out.println("Region set size: " + region.size()); + for (Point p : region) { + NurikabeCell pCell = modified.getCell(p.x, p.y); + if (pCell.getType() == NurikabeType.NUMBER) { + if (regionNumber == 0) { + regionNumber = pCell.getData(); + } else { + return "There is a MultipleNumbers Contradiction on the" + + " board."; + } + } + } + // If the region size is 0, there is a possibility that there was only 1 + // cell in the + // white + // region, and that white cell was a NurikabeType.NUMBER cell + if (regionNumber == 0 + && corner.getType() == NurikabeType.NUMBER + && corner.getData() == 2) { + return null; + } + // If the region size is not 0, make sure the regionNumber and the + // region size match + // (need + // to add 1 to account for the cell that was surrounded + if (regionNumber != 0 && region.size() + 1 == regionNumber) { + return null; + } + } + } + } + } + } + return "This is not a valid use of the corner black rule!"; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/FillinBlackDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/FillinBlackDirectRule.java index aab389e4a..7c4629f65 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/FillinBlackDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/FillinBlackDirectRule.java @@ -1,60 +1,62 @@ -package edu.rpi.legup.puzzle.nurikabe.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.rules.ContradictionRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; -import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; -import edu.rpi.legup.puzzle.nurikabe.NurikabeType; - -public class FillinBlackDirectRule extends DirectRule { - - public FillinBlackDirectRule() { - super("NURI-BASC-0004", - "Fill In Black", - "If there an unknown region surrounded by black, it must be black.", - "edu/rpi/legup/images/nurikabe/rules/FillInBlack.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - NurikabeBoard board = (NurikabeBoard) transition.getBoard(); - NurikabeBoard origBoard = (NurikabeBoard) transition.getParents().get(0).getBoard(); - ContradictionRule contraRule = new NoNumberContradictionRule(); - - NurikabeCell cell = (NurikabeCell) board.getPuzzleElement(puzzleElement); - - if (cell.getType() != NurikabeType.BLACK) { - return "Only black cells are allowed for this rule!"; - } - NurikabeBoard modified = origBoard.copy(); - modified.getPuzzleElement(puzzleElement).setData(NurikabeType.WHITE.toValue()); - if (contraRule.checkContradictionAt(modified, puzzleElement) != null) { - return "Black cells must be placed in a region of black cells!"; - } - return null; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.nurikabe.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.ContradictionRule; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; +import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; +import edu.rpi.legup.puzzle.nurikabe.NurikabeType; + +public class FillinBlackDirectRule extends DirectRule { + + public FillinBlackDirectRule() { + super( + "NURI-BASC-0004", + "Fill In Black", + "If there an unknown region surrounded by black, it must be black.", + "edu/rpi/legup/images/nurikabe/rules/FillInBlack.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + NurikabeBoard board = (NurikabeBoard) transition.getBoard(); + NurikabeBoard origBoard = (NurikabeBoard) transition.getParents().get(0).getBoard(); + ContradictionRule contraRule = new NoNumberContradictionRule(); + + NurikabeCell cell = (NurikabeCell) board.getPuzzleElement(puzzleElement); + + if (cell.getType() != NurikabeType.BLACK) { + return "Only black cells are allowed for this rule!"; + } + NurikabeBoard modified = origBoard.copy(); + modified.getPuzzleElement(puzzleElement).setData(NurikabeType.WHITE.toValue()); + if (contraRule.checkContradictionAt(modified, puzzleElement) != null) { + return "Black cells must be placed in a region of black cells!"; + } + return null; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/FillinWhiteDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/FillinWhiteDirectRule.java index 4f57602d5..05bb2f046 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/FillinWhiteDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/FillinWhiteDirectRule.java @@ -1,60 +1,62 @@ -package edu.rpi.legup.puzzle.nurikabe.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.rules.ContradictionRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; -import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; -import edu.rpi.legup.puzzle.nurikabe.NurikabeType; - -public class FillinWhiteDirectRule extends DirectRule { - - public FillinWhiteDirectRule() { - super("NURI-BASC-0005", - "Fill In White", - "If there an unknown region surrounded by white, it must be white.", - "edu/rpi/legup/images/nurikabe/rules/FillInWhite.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - NurikabeBoard board = (NurikabeBoard) transition.getBoard(); - NurikabeBoard origBoard = (NurikabeBoard) transition.getParents().get(0).getBoard(); - ContradictionRule contraRule = new IsolateBlackContradictionRule(); - - NurikabeCell cell = (NurikabeCell) board.getPuzzleElement(puzzleElement); - - if (cell.getType() != NurikabeType.WHITE) { - return "Only white cells are allowed for this rule!"; - } - NurikabeBoard modified = origBoard.copy(); - modified.getPuzzleElement(puzzleElement).setData(NurikabeType.BLACK.toValue()); - if (contraRule.checkContradictionAt(modified, puzzleElement) != null) { - return "white cells must be placed in a region of white cells!"; - } - return null; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.nurikabe.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.ContradictionRule; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; +import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; +import edu.rpi.legup.puzzle.nurikabe.NurikabeType; + +public class FillinWhiteDirectRule extends DirectRule { + + public FillinWhiteDirectRule() { + super( + "NURI-BASC-0005", + "Fill In White", + "If there an unknown region surrounded by white, it must be white.", + "edu/rpi/legup/images/nurikabe/rules/FillInWhite.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + NurikabeBoard board = (NurikabeBoard) transition.getBoard(); + NurikabeBoard origBoard = (NurikabeBoard) transition.getParents().get(0).getBoard(); + ContradictionRule contraRule = new IsolateBlackContradictionRule(); + + NurikabeCell cell = (NurikabeCell) board.getPuzzleElement(puzzleElement); + + if (cell.getType() != NurikabeType.WHITE) { + return "Only white cells are allowed for this rule!"; + } + NurikabeBoard modified = origBoard.copy(); + modified.getPuzzleElement(puzzleElement).setData(NurikabeType.BLACK.toValue()); + if (contraRule.checkContradictionAt(modified, puzzleElement) != null) { + return "white cells must be placed in a region of white cells!"; + } + return null; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} 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 c7331330b..f26f0c3fe 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 @@ -8,30 +8,30 @@ import edu.rpi.legup.puzzle.nurikabe.NurikabeType; import edu.rpi.legup.puzzle.nurikabe.NurikabeUtilities; import edu.rpi.legup.utility.DisjointSets; - import java.util.Set; public class IsolateBlackContradictionRule extends ContradictionRule { - private final String NO_CONTRADICTION_MESSAGE = "Contradiction applied incorrectly. No isolated Blacks."; + 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("NURI-CONT-0003", + super( + "NURI-CONT-0003", "Isolated Black", "There must still be a possibility to connect every Black cell", "edu/rpi/legup/images/nurikabe/contradictions/BlackArea.png"); } /** - * Checks whether the transition has a contradiction at the specific - * {@link PuzzleElement} index using this rule. + * Checks whether the transition has a contradiction at the specific {@link PuzzleElement} index + * using this rule. * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement - * @return null if the transition contains a - * contradiction at the specified {@link PuzzleElement}, - * otherwise return a no contradiction message. + * @return null if the transition contains a contradiction at the specified {@link + * PuzzleElement}, otherwise return a no contradiction message. */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { @@ -41,15 +41,15 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { return super.getInvalidUseOfRuleMessage() + ": " + this.INVALID_USE_MESSAGE; } - DisjointSets blackRegions = NurikabeUtilities.getPossibleBlackRegions(nurikabeBoard); + DisjointSets blackRegions = + NurikabeUtilities.getPossibleBlackRegions(nurikabeBoard); boolean oneRegion = false; for (Set region : blackRegions.getAllSets()) { for (NurikabeCell c : region) { if (c.getType() == NurikabeType.BLACK) { if (oneRegion) { return null; - } - else { + } else { oneRegion = true; break; } 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 e83204b99..1925a68ec 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 @@ -8,28 +8,30 @@ import edu.rpi.legup.puzzle.nurikabe.NurikabeType; import edu.rpi.legup.puzzle.nurikabe.NurikabeUtilities; import edu.rpi.legup.utility.DisjointSets; - import java.util.Set; public class MultipleNumbersContradictionRule extends ContradictionRule { - private final String NO_CONTRADICTION_MESSAGE = "Does not contain a contradiction at this index"; + 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("NURI-CONT-0004", + super( + "NURI-CONT-0004", "Multiple Numbers", "All white regions cannot have more than one number.", "edu/rpi/legup/images/nurikabe/contradictions/MultipleNumbers.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { 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 c2752da7a..6c69136b2 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 @@ -7,31 +7,31 @@ import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; import edu.rpi.legup.puzzle.nurikabe.NurikabeType; import edu.rpi.legup.puzzle.nurikabe.NurikabeUtilities; -import edu.rpi.legup.utility.DisjointSets; - import java.util.Set; -import java.util.List; public class NoNumberContradictionRule extends ContradictionRule { - private final String NO_CONTRADICTION_MESSAGE = "Does not contain a contradiction at this index"; + 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("NURI-CONT-0005", + super( + "NURI-CONT-0005", "No Number", "All enclosed white regions must have a number.", "edu/rpi/legup/images/nurikabe/contradictions/NoNumber.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/PreventBlackSquareDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/PreventBlackSquareDirectRule.java index 2502ee62f..106c22f7a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/PreventBlackSquareDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/PreventBlackSquareDirectRule.java @@ -1,66 +1,67 @@ -package edu.rpi.legup.puzzle.nurikabe.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.rules.ContradictionRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; -import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; -import edu.rpi.legup.puzzle.nurikabe.NurikabeType; - -public class PreventBlackSquareDirectRule extends DirectRule { - - public PreventBlackSquareDirectRule() { - super("NURI-BASC-0006", - "Prevent Black Square", - "There cannot be a 2x2 square of black. (3 blacks = fill in last corner white)", - "edu/rpi/legup/images/nurikabe/rules/NoBlackSquare.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - ContradictionRule contraRule = new BlackSquareContradictionRule(); - - NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard(); - NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard(); - - NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement); - - if (cell.getType() != NurikabeType.WHITE) { - return "Only white cells are allowed for this rule!"; - } - - NurikabeBoard modified = origBoardState.copy(); - NurikabeCell modCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement); - modCell.setData(NurikabeType.BLACK.toValue()); - - if (contraRule.checkContradiction(modified) == null) { - return null; - } - else { - return "Does not contain a contradiction at this index"; - } - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.nurikabe.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.ContradictionRule; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; +import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; +import edu.rpi.legup.puzzle.nurikabe.NurikabeType; + +public class PreventBlackSquareDirectRule extends DirectRule { + + public PreventBlackSquareDirectRule() { + super( + "NURI-BASC-0006", + "Prevent Black Square", + "There cannot be a 2x2 square of black. (3 blacks = fill in last corner white)", + "edu/rpi/legup/images/nurikabe/rules/NoBlackSquare.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + ContradictionRule contraRule = new BlackSquareContradictionRule(); + + NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard(); + NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard(); + + NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement); + + if (cell.getType() != NurikabeType.WHITE) { + return "Only white cells are allowed for this rule!"; + } + + NurikabeBoard modified = origBoardState.copy(); + NurikabeCell modCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement); + modCell.setData(NurikabeType.BLACK.toValue()); + + if (contraRule.checkContradiction(modified) == null) { + return null; + } else { + return "Does not contain a contradiction at this index"; + } + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/SurroundRegionDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/SurroundRegionDirectRule.java index d992fd22c..8e260cf42 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/SurroundRegionDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/SurroundRegionDirectRule.java @@ -1,95 +1,103 @@ -package edu.rpi.legup.puzzle.nurikabe.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; -import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; -import edu.rpi.legup.puzzle.nurikabe.NurikabeType; -import edu.rpi.legup.puzzle.nurikabe.NurikabeUtilities; -import edu.rpi.legup.utility.DisjointSets; - -import java.util.Arrays; -import java.util.ArrayList; -import java.util.List; -import java.util.HashSet; -import java.util.Set; -import java.awt.*; - -public class SurroundRegionDirectRule extends DirectRule { - - public SurroundRegionDirectRule() { - super("NURI-BASC-0007", "Surround Region", - "Surround Region", - "edu/rpi/legup/images/nurikabe/rules/SurroundBlack.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - - NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard(); - NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard(); - - NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement); - - if (cell.getType() != NurikabeType.BLACK) { - return "Only black cells are allowed for this rule!"; - } - - NurikabeBoard modified = origBoardState.copy(); - NurikabeCell modCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement); - modCell.setData(NurikabeType.WHITE.toValue()); - - if(cell.getType() == NurikabeType.BLACK) { - DisjointSets regions = NurikabeUtilities.getNurikabeRegions(destBoardState); - Set adj = new HashSet<>(); //set to hold adjacent cells - Point loc = cell.getLocation(); //position of placed cell - List directions = Arrays.asList(new Point(-1, 0), new Point(1, 0), new Point(0, -1), new Point(0, 1)); - for(Point direction : directions) { - NurikabeCell curr = destBoardState.getCell(loc.x + direction.x, loc.y + direction.y); - if(curr != null) { - if(curr.getType() == NurikabeType.WHITE || curr.getType() == NurikabeType.NUMBER) { - adj.add(curr); //adds cells to adj only if they are white or number blocks - } - } - } - List numberedCells = new ArrayList<>(); //number value of number cells - for (NurikabeCell c : adj) { //loops through adjacent cells - Set disRow = regions.getSet(c); //set of white spaces - for (NurikabeCell d : disRow) { //loops through white spaces - if (d.getType() == NurikabeType.NUMBER) { //if the white space is a number - numberedCells.add(d); //add that number to numberedCells - } - } - } - for (NurikabeCell number : numberedCells) { //loops through numberedCells - if (regions.getSet(number).size() == number.getData()) { //if that cells white area is the exact - return null; //size of the number of one of the number cells within that set - } - } - } - return "Does not follow from this rule at this index"; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.nurikabe.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; +import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; +import edu.rpi.legup.puzzle.nurikabe.NurikabeType; +import edu.rpi.legup.puzzle.nurikabe.NurikabeUtilities; +import edu.rpi.legup.utility.DisjointSets; +import java.awt.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class SurroundRegionDirectRule extends DirectRule { + + public SurroundRegionDirectRule() { + super( + "NURI-BASC-0007", + "Surround Region", + "Surround Region", + "edu/rpi/legup/images/nurikabe/rules/SurroundBlack.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + + NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard(); + NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard(); + + NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement); + + if (cell.getType() != NurikabeType.BLACK) { + return "Only black cells are allowed for this rule!"; + } + + NurikabeBoard modified = origBoardState.copy(); + NurikabeCell modCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement); + modCell.setData(NurikabeType.WHITE.toValue()); + + if (cell.getType() == NurikabeType.BLACK) { + DisjointSets regions = + NurikabeUtilities.getNurikabeRegions(destBoardState); + Set adj = new HashSet<>(); // set to hold adjacent cells + Point loc = cell.getLocation(); // position of placed cell + List directions = + Arrays.asList( + new Point(-1, 0), new Point(1, 0), new Point(0, -1), new Point(0, 1)); + for (Point direction : directions) { + NurikabeCell curr = + destBoardState.getCell(loc.x + direction.x, loc.y + direction.y); + if (curr != null) { + if (curr.getType() == NurikabeType.WHITE + || curr.getType() == NurikabeType.NUMBER) { + adj.add(curr); // adds cells to adj only if they are white or number blocks + } + } + } + List numberedCells = new ArrayList<>(); // number value of number cells + for (NurikabeCell c : adj) { // loops through adjacent cells + Set disRow = regions.getSet(c); // set of white spaces + for (NurikabeCell d : disRow) { // loops through white spaces + if (d.getType() == NurikabeType.NUMBER) { // if the white space is a number + numberedCells.add(d); // add that number to numberedCells + } + } + } + for (NurikabeCell number : numberedCells) { // loops through numberedCells + if (regions.getSet(number).size() + == number.getData()) { // if that cells white area is the exact + return null; // size of the number of one of the number cells within that set + } + } + } + return "Does not follow from this rule at this index"; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + 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 d01dd806c..e7995165b 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 @@ -8,28 +8,30 @@ import edu.rpi.legup.puzzle.nurikabe.NurikabeType; import edu.rpi.legup.puzzle.nurikabe.NurikabeUtilities; import edu.rpi.legup.utility.DisjointSets; - import java.util.Set; public class TooFewSpacesContradictionRule extends ContradictionRule { - private final String NO_CONTRADICTION_MESSAGE = "Does not contain a contradiction at this index"; + 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("NURI-CONT-0006", + super( + "NURI-CONT-0006", "Too Few Spaces", "A region cannot contain less spaces than its number.", "edu/rpi/legup/images/nurikabe/contradictions/TooFewSpaces.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { @@ -40,7 +42,8 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { return super.getInvalidUseOfRuleMessage() + ": " + this.INVALID_USE_MESSAGE; } - DisjointSets regions = NurikabeUtilities.getPossibleWhiteRegions(nurikabeBoard); + DisjointSets regions = + NurikabeUtilities.getPossibleWhiteRegions(nurikabeBoard); Set whiteRegion = regions.getSet(cell); NurikabeCell numberedCell = null; for (NurikabeCell c : whiteRegion) { @@ -51,7 +54,9 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { } if (numberedCell != null && whiteRegion.size() < numberedCell.getData()) { - // System.err.println("Cell Value: " + numberedCell.getData() + ", Loc: " + cell.getLocation() + ", region: " + whiteRegion.size()); + // System.err.println("Cell Value: " + numberedCell.getData() + ", Loc: " + + // cell.getLocation() + // + ", region: " + whiteRegion.size()); return null; } 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 e5aa9f18b..7bd0883ef 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 @@ -8,29 +8,31 @@ import edu.rpi.legup.puzzle.nurikabe.NurikabeType; import edu.rpi.legup.puzzle.nurikabe.NurikabeUtilities; import edu.rpi.legup.utility.DisjointSets; - import java.util.ArrayList; import java.util.Set; public class TooManySpacesContradictionRule extends ContradictionRule { - private final String NO_CONTRADICTION_MESSAGE = "Does not contain a contradiction at this index"; + 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("NURI-CONT-0007", + super( + "NURI-CONT-0007", "Too Many Spaces", "A region cannot contain more spaces than its number.", "edu/rpi/legup/images/nurikabe/contradictions/TooManySpaces.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/UnreachableWhiteCellContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/UnreachableWhiteCellContradictionRule.java index ec16475f1..c578d317f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/UnreachableWhiteCellContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/UnreachableWhiteCellContradictionRule.java @@ -7,7 +7,6 @@ import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; import edu.rpi.legup.puzzle.nurikabe.NurikabeType; import edu.rpi.legup.puzzle.nurikabe.NurikabeUtilities; - import java.awt.*; import java.util.*; @@ -17,19 +16,21 @@ public class UnreachableWhiteCellContradictionRule extends ContradictionRule { private final String INVALID_USE_MESSAGE = "Does not contain a contradiction at this index"; public UnreachableWhiteCellContradictionRule() { - super("NURI-CONT-0002", + super( + "NURI-CONT-0002", "Unreachable White Cell", "A white cell must be able to reach a white region", "edu/rpi/legup/images/nurikabe/contradictions/CantReach.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { @@ -44,7 +45,8 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { int width = nurikabeBoard.getWidth(); // Get regions - HashMap whiteRegionMap = NurikabeUtilities.getWhiteRegionMap(nurikabeBoard); + HashMap whiteRegionMap = + NurikabeUtilities.getWhiteRegionMap(nurikabeBoard); if (whiteRegionMap.containsKey(cell)) { return super.getNoContradictionMessage() + ": " + this.NO_CONTRADICTION_MESSAGE; } @@ -83,15 +85,17 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { for (NurikabeCell n : adj) { int regionNeed = whiteRegionMap.getOrDefault(n, -1); if (pathLength <= regionNeed) { - return super.getNoContradictionMessage() + ": " + this.NO_CONTRADICTION_MESSAGE; + return super.getNoContradictionMessage() + + ": " + + this.NO_CONTRADICTION_MESSAGE; } } } for (NurikabeCell n : adj) { if (!visited.getOrDefault(n, false) - && (n.getType() == NurikabeType.UNKNOWN || - n.getType() == NurikabeType.WHITE)) { + && (n.getType() == NurikabeType.UNKNOWN + || n.getType() == NurikabeType.WHITE)) { visited.put(n, true); queue.add(n); } diff --git a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/WhiteBottleNeckDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/WhiteBottleNeckDirectRule.java index dd337858c..434e7ccde 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/WhiteBottleNeckDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/rules/WhiteBottleNeckDirectRule.java @@ -1,69 +1,72 @@ -package edu.rpi.legup.puzzle.nurikabe.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.rules.ContradictionRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; -import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; -import edu.rpi.legup.puzzle.nurikabe.NurikabeType; - -import java.util.LinkedHashSet; -import java.util.Set; - -public class WhiteBottleNeckDirectRule extends DirectRule { - - public WhiteBottleNeckDirectRule() { - super("NURI-BASC-0009", - "White Bottle Neck", - "If a region needs more whites and there is only one path for the region to expand, then those unknowns must be white.", "edu/rpi/legup/images/nurikabe/rules/OneUnknownWhite.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - Set contras = new LinkedHashSet<>(); - contras.add(new NoNumberContradictionRule()); - contras.add(new TooFewSpacesContradictionRule()); - - NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard(); - NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard(); - - NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement); - - if (cell.getType() != NurikabeType.WHITE) { - return "Only white cells are allowed for this rule!"; - } - NurikabeBoard modified = origBoardState.copy(); - NurikabeCell modCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement); - modCell.setData(NurikabeType.BLACK.toValue()); - - for (ContradictionRule contraRule : contras) { - if (contraRule.checkContradiction(modified) == null) { - return null; - } - } - return "This is not the only way for white to escape!"; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.nurikabe.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.ContradictionRule; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; +import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; +import edu.rpi.legup.puzzle.nurikabe.NurikabeType; +import java.util.LinkedHashSet; +import java.util.Set; + +public class WhiteBottleNeckDirectRule extends DirectRule { + + public WhiteBottleNeckDirectRule() { + super( + "NURI-BASC-0009", + "White Bottle Neck", + "If a region needs more whites and there is only one path for the region to expand," + + " then those unknowns must be white.", + "edu/rpi/legup/images/nurikabe/rules/OneUnknownWhite.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + Set contras = new LinkedHashSet<>(); + contras.add(new NoNumberContradictionRule()); + contras.add(new TooFewSpacesContradictionRule()); + + NurikabeBoard destBoardState = (NurikabeBoard) transition.getBoard(); + NurikabeBoard origBoardState = (NurikabeBoard) transition.getParents().get(0).getBoard(); + + NurikabeCell cell = (NurikabeCell) destBoardState.getPuzzleElement(puzzleElement); + + if (cell.getType() != NurikabeType.WHITE) { + return "Only white cells are allowed for this rule!"; + } + NurikabeBoard modified = origBoardState.copy(); + NurikabeCell modCell = (NurikabeCell) modified.getPuzzleElement(puzzleElement); + modCell.setData(NurikabeType.BLACK.toValue()); + + for (ContradictionRule contraRule : contras) { + if (contraRule.checkContradiction(modified) == null) { + return null; + } + } + return "This is not the only way for white to escape!"; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTable.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTable.java index e8f9ffc0d..8b0b8e6d5 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTable.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTable.java @@ -18,9 +18,7 @@ public ShortTruthTable() { this.factory = new ShortTruthTableCellFactory(); } - /** - * Initializes the game board. Called by the invoker of the class - */ + /** Initializes the game board. Called by the invoker of the class */ @Override public void initializeView() { ShortTruthTableBoard sttBoard = (ShortTruthTableBoard) currentBoard; @@ -44,8 +42,8 @@ public Board generatePuzzle(int difficulty) { /** * Determines if the given dimensions are valid for Short Truth Table * - * @param rows the number of rows - * @param columns the number of columns + * @param rows the number of rows + * @param columns the number of columns * @return true if the given dimensions are valid for Short Truth Table, false otherwise */ public boolean isValidDimensions(int rows, int columns) { @@ -100,7 +98,6 @@ public boolean isBoardComplete(Board board) { } } return true; - } /** @@ -109,7 +106,5 @@ public boolean isBoardComplete(Board board) { * @param board the board that has changed */ @Override - public void onBoardChange(Board board) { - - } -} \ No newline at end of file + public void onBoardChange(Board board) {} +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableBoard.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableBoard.java index e5011182a..519a61974 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableBoard.java @@ -1,17 +1,12 @@ package edu.rpi.legup.puzzle.shorttruthtable; -import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.GridBoard; import edu.rpi.legup.model.gameboard.PuzzleElement; - -import edu.rpi.legup.puzzle.lightup.LightUpCell; -import edu.rpi.legup.puzzle.shorttruthtable.*; - import java.awt.*; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.HashSet; public class ShortTruthTableBoard extends GridBoard { @@ -22,10 +17,8 @@ public ShortTruthTableBoard(int width, int height, ShortTruthTableStatement[] st super(width, height); this.statements = statements; - } - public Set getCellsWithSymbol(char symbol) { Set cells = new HashSet(); for (int x = 0; x < this.dimension.width; x++) { @@ -48,23 +41,23 @@ public ShortTruthTableCell getCell(int x, int y) { return (ShortTruthTableCell) super.getCell(x, y); } - @Override public ShortTruthTableBoard copy() { - //Copy the statements - ShortTruthTableStatement[] statementsCopy = new ShortTruthTableStatement[this.statements.length]; + // Copy the statements + ShortTruthTableStatement[] statementsCopy = + new ShortTruthTableStatement[this.statements.length]; for (int i = 0; i < statements.length; i++) { statementsCopy[i] = this.statements[i].copy(); } - //copy the board and set the cells - ShortTruthTableBoard boardCopy = new ShortTruthTableBoard(getWidth(), getHeight(), statementsCopy); + // copy the board and set the cells + ShortTruthTableBoard boardCopy = + new ShortTruthTableBoard(getWidth(), getHeight(), statementsCopy); for (int r = 0; r < this.dimension.height; r++) { for (int c = 0; c < this.dimension.width; c++) { if (r % 2 == 0 && c < statementsCopy[r / 2].getLength()) { boardCopy.setCell(c, r, statementsCopy[r / 2].getCell(c)); - } - else { + } else { boardCopy.setCell(c, r, getCell(c, r).copy()); } } @@ -76,14 +69,14 @@ public ShortTruthTableBoard copy() { System.out.println("original:\n" + this); System.out.println("copy:\n" + boardCopy); return boardCopy; - } public ShortTruthTableStatement[] getStatements() { return statements; } - public static List copyStatementList(List statements) { + public static List copyStatementList( + List statements) { List copy = new ArrayList(); for (int i = 0; i < statements.size(); i++) { copy.add(statements.get(i).copy()); @@ -91,13 +84,12 @@ public static List copyStatementList(List { - //The symbol on the cell + // The symbol on the cell private char symbol; - //This is a reference to the statement that contains this cell + // This is a reference to the statement that contains this cell private ShortTruthTableStatement statement; - //Constructors + // Constructors public ShortTruthTableCell(char symbol, ShortTruthTableCellType cellType, Point location) { super(cellType, location); this.symbol = symbol; } - /** * Constructs a new NOT_IN_PLAY Cell * @@ -33,8 +29,7 @@ public ShortTruthTableCell(Point location) { this(' ', ShortTruthTableCellType.NOT_IN_PLAY, location); } - - //Getters + // Getters public ShortTruthTableStatement getStatementReference() { return statement; @@ -65,12 +60,12 @@ public int getY() { return (int) location.getY(); } - public boolean isAssigned() { - return getType() == ShortTruthTableCellType.TRUE || getType() == ShortTruthTableCellType.FALSE; + return getType() == ShortTruthTableCellType.TRUE + || getType() == ShortTruthTableCellType.FALSE; } - //Setters + // Setters void setStatementReference(ShortTruthTableStatement statement) { this.statement = statement; @@ -86,7 +81,7 @@ public void setGiven(ShortTruthTableCellType type) { setGiven(true); } - //Modifiers + // Modifiers public void cycleTypeForward() { switch (data) { @@ -109,16 +104,14 @@ public void cycleTypeBackward() { cycleTypeForward(); } - - //TO STRING + // TO STRING @Override public String toString() { return String.format("STTCell: %c %2d %-11s %s", symbol, index, data, location.toString()); } - - //Copy function + // Copy function @Override public ShortTruthTableCell copy() { @@ -168,8 +161,7 @@ public void setType(Element e, MouseEvent m) { if (this.symbol > 'Z') { this.symbol = 'A'; } - } - else { + } else { if (m.getButton() == MouseEvent.BUTTON3) { this.symbol -= 1; if (this.symbol < 'A') { @@ -184,37 +176,30 @@ public void setType(Element e, MouseEvent m) { if (m.getButton() == MouseEvent.BUTTON1) { if (this.symbol == '^') { this.symbol = '|'; - } - else { + } else { if (this.symbol == '|') { this.symbol = '>'; - } - else { + } else { if (this.symbol == '>') { this.symbol = '-'; - } - else { + } else { if (this.symbol == '-') { this.symbol = '^'; } } } } - } - else { + } else { if (m.getButton() == MouseEvent.BUTTON3) { if (this.symbol == '^') { this.symbol = '-'; - } - else { + } else { if (this.symbol == '|') { this.symbol = '^'; - } - else { + } else { if (this.symbol == '>') { this.symbol = '|'; - } - else { + } else { if (this.symbol == '-') { this.symbol = '>'; } @@ -229,4 +214,4 @@ public void setType(Element e, MouseEvent m) { } } } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellFactory.java index 99d626447..df74afdc9 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellFactory.java @@ -4,57 +4,58 @@ import edu.rpi.legup.model.gameboard.ElementFactory; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; -import java.awt.*; - public class ShortTruthTableCellFactory extends ElementFactory { /** * Creates a puzzleElement based on the xml document Node and adds it to the board * - * @param node node that represents the puzzleElement + * @param node node that represents the puzzleElement * @param board board to add the newly created cell * @return newly created cell from the xml document Node * @throws InvalidFileFormatException if file is invalid */ @Override - public ShortTruthTableCell importCell(Node node, Board board) throws InvalidFileFormatException { + public ShortTruthTableCell importCell(Node node, Board board) + throws InvalidFileFormatException { try { if (!node.getNodeName().equalsIgnoreCase("cell")) { - throw new InvalidFileFormatException("ShortTruthTable Factory: unknown puzzleElement puzzleElement"); + throw new InvalidFileFormatException( + "ShortTruthTable Factory: unknown puzzleElement puzzleElement"); } ShortTruthTableBoard sttBoard = (ShortTruthTableBoard) board; - //get the attributes for the cell + // get the attributes for the cell NamedNodeMap attributeList = node.getAttributes(); int rowIndex = Integer.valueOf(attributeList.getNamedItem("row_index").getNodeValue()); - int charIndex = Integer.valueOf(attributeList.getNamedItem("char_index").getNodeValue()); + int charIndex = + Integer.valueOf(attributeList.getNamedItem("char_index").getNodeValue()); String cellType = attributeList.getNamedItem("type").getNodeValue(); - //modify the appropriate cell - ShortTruthTableCell cell = (ShortTruthTableCell) sttBoard.getCell(charIndex, rowIndex * 2); + // modify the appropriate cell + ShortTruthTableCell cell = + (ShortTruthTableCell) sttBoard.getCell(charIndex, rowIndex * 2); cell.setData(ShortTruthTableCellType.valueOf(cellType)); return cell; - } - catch (NumberFormatException e) { - throw new InvalidFileFormatException("nurikabe Factory: unknown value where integer expected"); - } - catch (NullPointerException e) { + } catch (NumberFormatException e) { + throw new InvalidFileFormatException( + "nurikabe Factory: unknown value where integer expected"); + } catch (NullPointerException e) { throw new InvalidFileFormatException("nurikabe Factory: could not find attribute(s)"); } - } /** * Creates a xml document puzzleElement from a cell for exporting * - * @param document xml document + * @param document xml document * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellType.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellType.java index c997faf5f..d5a8292a2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellType.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellType.java @@ -1,11 +1,14 @@ package edu.rpi.legup.puzzle.shorttruthtable; -import java.util.Map; import java.util.HashMap; +import java.util.Map; public enum ShortTruthTableCellType { - - FALSE(0), TRUE(1), UNKNOWN(-1), NOT_IN_PLAY(-2), PARENTHESIS(-3); + FALSE(0), + TRUE(1), + UNKNOWN(-1), + NOT_IN_PLAY(-2), + PARENTHESIS(-3); public int value; private static Map map = new HashMap<>(); @@ -37,7 +40,6 @@ public static char toChar(ShortTruthTableCellType type) { return ' '; } - /** * Returns true if this cell holds the value either TRUE or FALSE * @@ -47,7 +49,6 @@ public boolean isTrueOrFalse() { return value == 0 || value == 1; } - public ShortTruthTableCellType getNegation() { switch (value) { case 1: @@ -63,5 +64,4 @@ public static ShortTruthTableCellType getDefaultType(char c) { if (c == '(' || c == ')') return PARENTHESIS; return UNKNOWN; } - -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableController.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableController.java index bddde44a5..172867f5a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableController.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableController.java @@ -2,7 +2,6 @@ import edu.rpi.legup.controller.ElementController; import edu.rpi.legup.model.gameboard.PuzzleElement; - import java.awt.event.MouseEvent; public class ShortTruthTableController extends ElementController { @@ -17,13 +16,16 @@ public void changeCell(MouseEvent e, PuzzleElement data) { if (e.getButton() == MouseEvent.BUTTON1) { if (e.isControlDown()) { - this.boardView.getSelectionPopupMenu().show(boardView, this.boardView.getCanvas().getX() + e.getX(), this.boardView.getCanvas().getY() + e.getY()); - } - else { + this.boardView + .getSelectionPopupMenu() + .show( + boardView, + this.boardView.getCanvas().getX() + e.getX(), + this.boardView.getCanvas().getY() + e.getY()); + } else { cell.cycleTypeForward(); } - } - else { + } else { if (e.getButton() == MouseEvent.BUTTON3) { cell.cycleTypeBackward(); } diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableElementView.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableElementView.java index b787921ad..43e1d2299 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableElementView.java @@ -1,20 +1,19 @@ package edu.rpi.legup.puzzle.shorttruthtable; -import edu.rpi.legup.ui.boardview.GridElementView; import edu.rpi.legup.app.LegupPreferences; - +import edu.rpi.legup.ui.boardview.GridElementView; import java.awt.*; public class ShortTruthTableElementView extends GridElementView { - //Font + // Font private static final Font FONT = new Font("TimesRoman", Font.BOLD, 16); private static final Color FONT_COLOR = Color.BLACK; - //Square Colors - private static final Color TRUE_COLOR = new Color(0, 130, 0);//green + // Square Colors + private static final Color TRUE_COLOR = new Color(0, 130, 0); // green private static final Color TRUE_COLOR_COLORBLIND = new Color(0, 0, 255); - private static final Color FALSE_COLOR = new Color(200, 0, 0);//red + private static final Color FALSE_COLOR = new Color(200, 0, 0); // red private static final Color FALSE_COLOR_COLORBLIND = new Color(255, 0, 0); private static final Color UNKNOWN_COLOR = Color.WHITE; @@ -23,7 +22,6 @@ public ShortTruthTableElementView(ShortTruthTableCell cell) { super(cell); } - /** * Gets the PuzzleElement associated with this view * @@ -37,14 +35,14 @@ public ShortTruthTableCell getPuzzleElement() { @Override public void drawElement(Graphics2D graphics2D) { - //get information about the cell + // get information about the cell ShortTruthTableCell cell = (ShortTruthTableCell) puzzleElement; ShortTruthTableCellType type = cell.getData(); - //do not draw the cell if it is not in play + // do not draw the cell if it is not in play if (type == ShortTruthTableCellType.NOT_IN_PLAY) return; - //fill in background color of the cell + // fill in background color of the cell graphics2D.setStroke(new BasicStroke(1)); LegupPreferences prefs = LegupPreferences.getInstance(); switch (type) { @@ -68,15 +66,14 @@ public void drawElement(Graphics2D graphics2D) { } graphics2D.fillRect(location.x, location.y, size.width, size.height); - //Draw the symbol on the cell + // Draw the symbol on the cell graphics2D.setColor(FONT_COLOR); graphics2D.setFont(FONT); FontMetrics metrics = graphics2D.getFontMetrics(FONT); String value = String.valueOf(cell.getSymbol()); int xText = location.x + (size.width - metrics.stringWidth(value)) / 2; int yText = location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent(); - graphics2D.drawString(ShortTruthTableOperation.getLogicSymbol(cell.getSymbol()), xText, yText); - - + graphics2D.drawString( + ShortTruthTableOperation.getLogicSymbol(cell.getSymbol()), xText, yText); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableExporter.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableExporter.java index 9d6553c7c..0914c159a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableExporter.java @@ -2,7 +2,6 @@ import edu.rpi.legup.model.PuzzleExporter; import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; import org.w3c.dom.Document; public class ShortTruthTableExporter extends PuzzleExporter { @@ -16,8 +15,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { ShortTruthTableBoard board; if (puzzle.getTree() != null) { board = (ShortTruthTableBoard) puzzle.getTree().getRootNode().getBoard(); - } - else { + } else { board = (ShortTruthTableBoard) puzzle.getBoardView().getBoard(); } @@ -33,12 +31,12 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { dataElement.appendChild(statementElement); } - for (PuzzleElement puzzleElement : board.getPuzzleElements()) { ShortTruthTableCell cell = board.getCellFromElement(puzzleElement); if (!cell.getType().isTrueOrFalse()) continue; - org.w3c.dom.Element cellElement = puzzle.getFactory().exportCell(newDocument, puzzleElement); + org.w3c.dom.Element cellElement = + puzzle.getFactory().exportCell(newDocument, puzzleElement); dataElement.appendChild(cellElement); } diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableImporter.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableImporter.java index 84d04fb45..396668380 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableImporter.java @@ -2,16 +2,15 @@ import edu.rpi.legup.model.PuzzleImporter; import edu.rpi.legup.save.InvalidFileFormatException; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import javax.swing.*; import java.awt.*; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import javax.swing.*; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; class ShortTruthTableImporter extends PuzzleImporter { @@ -19,9 +18,9 @@ public ShortTruthTableImporter(ShortTruthTable stt) { super(stt); } - /** - * Parse a string into all the cells, the y position of the statement is passed so the y position can be set + * Parse a string into all the cells, the y position of the statement is passed so the y + * position can be set * * @param statement * @param y @@ -29,83 +28,90 @@ public ShortTruthTableImporter(ShortTruthTable stt) { */ private List getCells(String statement, int y) { List cells = new ArrayList(); - //go through each char in the statement and make a cell for it + // go through each char in the statement and make a cell for it for (int i = 0; i < statement.length(); i++) { char c = statement.charAt(i); - ShortTruthTableCell cell = new ShortTruthTableCell(c, ShortTruthTableCellType.getDefaultType(c), new Point(i, y)); - //it is modifiable if the type is unknown + ShortTruthTableCell cell = + new ShortTruthTableCell( + c, ShortTruthTableCellType.getDefaultType(c), new Point(i, y)); + // it is modifiable if the type is unknown cell.setModifiable(cell.getType() == ShortTruthTableCellType.UNKNOWN); cells.add(cell); } return cells; } - /** - * Parses the statementData into all the cells (with symbols) and statements for the - * puzzle. All cells are set to UNKNWON, it their value is given, it will be set later - * in the import process. - *

- * Both allCells and statements act as returns, They should be passed as empty arrays + * Parses the statementData into all the cells (with symbols) and statements for the puzzle. All + * cells are set to UNKNWON, it their value is given, it will be set later in the import + * process. + * + *

Both allCells and statements act as returns, They should be passed as empty arrays * * @param statementData The data to be imported - * @param allCells returns all the cells as a jagged 2d array - * @param statements returns all the statements + * @param allCells returns all the cells as a jagged 2d array + * @param statements returns all the statements * @return the length, in chars, of the longest statement */ - private int parseAllStatementsAndCells(final NodeList statementData, - List> allCells, - List statements) throws InvalidFileFormatException { + private int parseAllStatementsAndCells( + final NodeList statementData, + List> allCells, + List statements) + throws InvalidFileFormatException { int maxStatementLength = 0; - //get a 2D arraylist of all the cells + // get a 2D arraylist of all the cells for (int i = 0; i < statementData.getLength(); i++) { - //Get the atributes from the statement i in the file + // Get the atributes from the statement i in the file NamedNodeMap attributeList = statementData.item(i).getAttributes(); String statementRep = attributeList.getNamedItem("representation").getNodeValue(); System.out.println("STATEMENT REP: " + statementRep); - System.out.println("ROW INDEX: " + attributeList.getNamedItem("row_index").getNodeValue()); - //parser time (on statementRep) - //if (!validGrammar(statementRep)) throw some error + System.out.println( + "ROW INDEX: " + attributeList.getNamedItem("row_index").getNodeValue()); + // parser time (on statementRep) + // if (!validGrammar(statementRep)) throw some error if (!validGrammar(statementRep)) { JOptionPane.showMessageDialog(null, "ERROR: Invalid file syntax"); - throw new InvalidFileFormatException("shorttruthtable importer: invalid sentence syntax"); + throw new InvalidFileFormatException( + "shorttruthtable importer: invalid sentence syntax"); } int rowIndex = Integer.valueOf(attributeList.getNamedItem("row_index").getNodeValue()); - //get the cells for the statement + // get the cells for the statement List rowOfCells = getCells(statementRep, rowIndex * 2); allCells.add(rowOfCells); statements.add(new ShortTruthTableStatement(statementRep, rowOfCells)); - //keep track of the length of the longest statement + // keep track of the length of the longest statement maxStatementLength = Math.max(maxStatementLength, statementRep.length()); - } return maxStatementLength; } - private int parseAllStatementsAndCells(String[] statementData, - List> allCells, - List statements) throws IllegalArgumentException { + private int parseAllStatementsAndCells( + String[] statementData, + List> allCells, + List statements) + throws IllegalArgumentException { int maxStatementLength = 0; for (int i = 0; i < statementData.length; i++) { if (!validGrammar(statementData[i])) { JOptionPane.showMessageDialog(null, "ERROR: Invalid file syntax"); - throw new IllegalArgumentException("shorttruthtable importer: invalid sentence syntax"); + throw new IllegalArgumentException( + "shorttruthtable importer: invalid sentence syntax"); } - //get the cells for the statement + // get the cells for the statement List rowOfCells = getCells(statementData[i], i * 2); allCells.add(rowOfCells); statements.add(new ShortTruthTableStatement(statementData[i], rowOfCells)); - //keep track of the length of the longest statement + // keep track of the length of the longest statement maxStatementLength = Math.max(maxStatementLength, statementData[i].length()); } @@ -115,7 +121,7 @@ private int parseAllStatementsAndCells(String[] statementData, protected boolean validGrammar(String sentence) { int open = 0; int close = 0; - char[] valid_characters = new char[]{'^', 'v', '!', '>', '-', '&', '|', '~', '$', '%'}; + char[] valid_characters = new char[] {'^', 'v', '!', '>', '-', '&', '|', '~', '$', '%'}; for (int i = 0; i < sentence.length(); i++) { char s = sentence.charAt(i); if (s == '(' || s == ')') { @@ -155,8 +161,7 @@ protected boolean validGrammar(String sentence) { } } } - } - else { + } else { if (i != sentence.length() - 1) { if (Character.isLetter(sentence.charAt(i + 1))) { System.out.println("Invalid next character"); @@ -170,75 +175,81 @@ protected boolean validGrammar(String sentence) { return open == close; } - private ShortTruthTableBoard generateBoard(List> allCells, - List statements, - int width) { + private ShortTruthTableBoard generateBoard( + List> allCells, + List statements, + int width) { - //calculate the height for the board + // calculate the height for the board int height = statements.size() * 2 - 1; - //instantiate the board with the correct width and height - ShortTruthTableBoard sttBoard = new ShortTruthTableBoard(width, height, - statements.toArray(new ShortTruthTableStatement[statements.size()])); + // instantiate the board with the correct width and height + ShortTruthTableBoard sttBoard = + new ShortTruthTableBoard( + width, + height, + statements.toArray(new ShortTruthTableStatement[statements.size()])); - //set the cells in the board. create not_in_play cells where needed + // set the cells in the board. create not_in_play cells where needed for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { - //get the statement index for this row of the table + // get the statement index for this row of the table int statementIndex = y / 2; - //get the cell at this location; or create a not_in_play one if necessary + // get the cell at this location; or create a not_in_play one if necessary ShortTruthTableCell cell = null; - //for a cell to exist at (x, y), it must be a valid row and within the statement length + // for a cell to exist at (x, y), it must be a valid row and within the statement + // length if (y % 2 == 0 && x < statements.get(statementIndex).getLength()) { cell = allCells.get(statementIndex).get(x); - System.out.println("Importer: check cell statement ref: " + cell.getStatementReference()); - } - else { - //if it is not a valid cell space, add a NOT_IN_PLAY cell - cell = new ShortTruthTableCell(' ', ShortTruthTableCellType.NOT_IN_PLAY, new Point(x, y)); + System.out.println( + "Importer: check cell statement ref: " + cell.getStatementReference()); + } else { + // if it is not a valid cell space, add a NOT_IN_PLAY cell + cell = + new ShortTruthTableCell( + ' ', ShortTruthTableCellType.NOT_IN_PLAY, new Point(x, y)); cell.setModifiable(false); } - //add the cell to the table + // add the cell to the table cell.setIndex(y * width + x); sttBoard.setCell(x, y, cell); } } return sttBoard; - } + private void setGivenCells( + ShortTruthTableBoard sttBoard, + Element dataElement, + NodeList cellData, + List statements) + throws InvalidFileFormatException { - private void setGivenCells(ShortTruthTableBoard sttBoard, - Element dataElement, - NodeList cellData, - List statements) throws InvalidFileFormatException { - - - //if it is normal, set all predicates to true and the conclusion to false + // if it is normal, set all predicates to true and the conclusion to false if (dataElement.getAttribute("normal").equalsIgnoreCase("true")) { - //set all predicates to true (all but the last one) + // set all predicates to true (all but the last one) for (int i = 0; i < statements.size() - 1; i++) { statements.get(i).getCell().setGiven(ShortTruthTableCellType.TRUE); } - //set the conclusion to false (the last one) + // set the conclusion to false (the last one) statements.get(statements.size() - 1).getCell().setGiven(ShortTruthTableCellType.FALSE); } - //set the given cell values + // set the given cell values for (int i = 0; i < cellData.getLength(); i++) { - //set the value with the factory importer - ShortTruthTableCell cell = (ShortTruthTableCell) puzzle.getFactory().importCell(cellData.item(i), sttBoard); - //set the modifiable and given flags + // set the value with the factory importer + ShortTruthTableCell cell = + (ShortTruthTableCell) + puzzle.getFactory().importCell(cellData.item(i), sttBoard); + // set the modifiable and given flags cell.setModifiable(false); cell.setGiven(true); } - - } @Override @@ -254,16 +265,14 @@ public boolean acceptsTextInput() { /** * Creates an empty board for building * - * @param rows the number of rows on the board + * @param rows the number of rows on the board * @param columns the number of columns on the board * @throws RuntimeException */ @Override - public void initializeBoard(int rows, int columns) { - - } + public void initializeBoard(int rows, int columns) {} - //STATEMENT IMPORTER + // STATEMENT IMPORTER /** * Creates the board for building @@ -276,41 +285,42 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { try { - //Check File formatting + // Check File formatting if (!node.getNodeName().equalsIgnoreCase("board")) { - throw new InvalidFileFormatException("short truth table Importer: cannot find board puzzleElement"); + throw new InvalidFileFormatException( + "short truth table Importer: cannot find board puzzleElement"); } Element boardElement = (Element) node; if (boardElement.getElementsByTagName("data").getLength() == 0) { - throw new InvalidFileFormatException("short truth table Importer: no statements found for board"); + throw new InvalidFileFormatException( + "short truth table Importer: no statements found for board"); } - - //get all the cells in a 2D arraylist + // get all the cells in a 2D arraylist List> allCells = new ArrayList>(); - //store the statement data structors + // store the statement data structors List statements = new ArrayList(); - //get the elements from the file + // get the elements from the file Element dataElement = (Element) boardElement.getElementsByTagName("data").item(0); NodeList statementData = dataElement.getElementsByTagName("statement"); NodeList cellData = dataElement.getElementsByTagName("cell"); + // Parse the data + int maxStatementLength = + parseAllStatementsAndCells(statementData, allCells, statements); - //Parse the data - int maxStatementLength = parseAllStatementsAndCells(statementData, allCells, statements); - - //generate the board + // generate the board ShortTruthTableBoard sttBoard = generateBoard(allCells, statements, maxStatementLength); - //set the given cell values + // set the given cell values setGivenCells(sttBoard, dataElement, cellData, statements); puzzle.setCurrentBoard(sttBoard); - } - catch (NumberFormatException e) { - throw new InvalidFileFormatException("short truth table Importer: unknown value where integer expected"); + } catch (NumberFormatException e) { + throw new InvalidFileFormatException( + "short truth table Importer: unknown value where integer expected"); } } @@ -321,7 +331,8 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { * @throws UnsupportedOperationException * @throws IllegalArgumentException */ - public void initializeBoard(String[] statementInput) throws UnsupportedOperationException, IllegalArgumentException { + public void initializeBoard(String[] statementInput) + throws UnsupportedOperationException, IllegalArgumentException { List statementsList = new LinkedList<>(); for (String s : statementInput) { if (s.strip().length() > 0) { @@ -331,7 +342,8 @@ public void initializeBoard(String[] statementInput) throws UnsupportedOperation String[] statementData = statementsList.toArray(new String[statementsList.size()]); if (statementData.length == 0) { - throw new IllegalArgumentException("short truth table Importer: no statements found for board"); + throw new IllegalArgumentException( + "short truth table Importer: no statements found for board"); } // Store all cells and statements diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableOperation.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableOperation.java index bc713d407..8284474da 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableOperation.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableOperation.java @@ -1,57 +1,48 @@ -package edu.rpi.legup.puzzle.shorttruthtable; - -import java.util.Collections; -import java.util.Map; -import java.util.TreeMap; - -public class ShortTruthTableOperation { - - public static final char AND = '^'; - public static final char OR = '|'; - public static final char NOT = '~'; - public static final char CONDITIONAL = '>'; - public static final char BICONDITIONAL = '-'; - - private ShortTruthTableOperation() { - } - - public static String getLogicSymbol(char c) { - switch (c) { - case AND: - return "\u2227"; - case OR: - return "\u2228"; - case NOT: - return "\u00AC"; - case CONDITIONAL: - return "\u2192"; - case BICONDITIONAL: - return "\u2194"; - } - return "" + c; - } - - public static String getRuleName(char operation) { - switch (operation) { - case AND: - return "And"; - case OR: - return "Or"; - case NOT: - return "Not"; - case CONDITIONAL: - return "Conditional"; - case BICONDITIONAL: - return "Biconditional"; - } - return null; - } - - public static boolean isOperation(char c) { - return c == AND || - c == OR || - c == NOT || - c == CONDITIONAL || - c == BICONDITIONAL; - } -} +package edu.rpi.legup.puzzle.shorttruthtable; + +public class ShortTruthTableOperation { + + public static final char AND = '^'; + public static final char OR = '|'; + public static final char NOT = '~'; + public static final char CONDITIONAL = '>'; + public static final char BICONDITIONAL = '-'; + + private ShortTruthTableOperation() {} + + public static String getLogicSymbol(char c) { + switch (c) { + case AND: + return "\u2227"; + case OR: + return "\u2228"; + case NOT: + return "\u00AC"; + case CONDITIONAL: + return "\u2192"; + case BICONDITIONAL: + return "\u2194"; + } + return "" + c; + } + + public static String getRuleName(char operation) { + switch (operation) { + case AND: + return "And"; + case OR: + return "Or"; + case NOT: + return "Not"; + case CONDITIONAL: + return "Conditional"; + case BICONDITIONAL: + return "Biconditional"; + } + return null; + } + + public static boolean isOperation(char c) { + return c == AND || c == OR || c == NOT || c == CONDITIONAL || c == BICONDITIONAL; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableStatement.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableStatement.java index e40a10cf0..2059e3ca5 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableStatement.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableStatement.java @@ -1,149 +1,143 @@ package edu.rpi.legup.puzzle.shorttruthtable; - import edu.rpi.legup.model.gameboard.PuzzleElement; - -import java.util.Set; -import java.util.HashSet; import java.awt.Point; -import java.util.List; import java.util.ArrayList; - +import java.util.HashSet; +import java.util.List; +import java.util.Set; public class ShortTruthTableStatement extends PuzzleElement { - //the cell that this statement holds + // the cell that this statement holds private final ShortTruthTableCell cell; - //child nodes of the tree + // child nodes of the tree private final ShortTruthTableStatement parentStatement; private final ShortTruthTableStatement leftStatement; private final ShortTruthTableStatement rightStatement; - //the representation string for this statement + // the representation string for this statement private final String stringRep; private final List cells; - - //constructor for root statement, sets parent to null + // constructor for root statement, sets parent to null public ShortTruthTableStatement(String statement, List cells) { this(statement, null, cells); } - //recursive constructor; constructs child statement nodes if necessary - private ShortTruthTableStatement(String statement, ShortTruthTableStatement parent, List cells) { + // recursive constructor; constructs child statement nodes if necessary + private ShortTruthTableStatement( + String statement, ShortTruthTableStatement parent, List cells) { this.parentStatement = parent; - //set the string rep to the statement (include parens in case this is a sub statement) + // set the string rep to the statement (include parens in case this is a sub statement) this.stringRep = statement; this.cells = new ArrayList(cells); - //remove the parens for parsing the statement + // remove the parens for parsing the statement statement = removeParens(statement); removeParens(cells); - //get the index of the char that this statement represents + // get the index of the char that this statement represents int index = parse(statement); - //construct the cell for this node in the tree + // construct the cell for this node in the tree cell = cells.get(index); - //give the cell a reference back to this statement + // give the cell a reference back to this statement cell.setStatementReference(this); - //get the strings on either side of this char in the string rep + // get the strings on either side of this char in the string rep String left = statement.substring(0, index); String right = statement.substring(index + 1); - List leftCells = new ArrayList(cells.subList(0, index)); - List rightCells = new ArrayList(cells.subList(index + 1, cells.size())); + List leftCells = + new ArrayList(cells.subList(0, index)); + List rightCells = + new ArrayList(cells.subList(index + 1, cells.size())); - //construct sub-statements if necessary + // construct sub-statements if necessary if (left.length() > 0) { leftStatement = new ShortTruthTableStatement(left, this, leftCells); - } - else { + } else { leftStatement = null; } if (right.length() > 0) { rightStatement = new ShortTruthTableStatement(right, this, rightCells); - } - else { + } else { rightStatement = null; } - } - - //parsing for the constructor + // parsing for the constructor static String removeParens(String statement) { if (statement.charAt(0) != '(') { return statement; } - //if the statement does start with a paren, check that it matches with the last paren + // if the statement does start with a paren, check that it matches with the last paren int openParenCount = 1; int i = 1; while (i < statement.length() - 1) { char c = statement.charAt(i); if (c == '(') { openParenCount++; - } - else { + } else { if (c == ')') openParenCount--; } - //if the first paren has been closed, and it is not the end of the string, - //then there is no whole statement parens to remove + // if the first paren has been closed, and it is not the end of the string, + // then there is no whole statement parens to remove if (openParenCount == 0 && i != statement.length() - 1) { return statement; } i++; } - //if the while loop made it through the entire statement, there are parens around the whole thing + // if the while loop made it through the entire statement, there are parens around the whole + // thing return statement.substring(1, statement.length() - 1); - } int parse(String statement) { - - //Split by and, or, CONDITIONAL, or biconditional - //keep track of the parens, it must be equal to zero to split + // Split by and, or, CONDITIONAL, or biconditional + // keep track of the parens, it must be equal to zero to split int openParenCount = 0; - //index for stepping through the string + // index for stepping through the string int i = 0; - //step through each char in the statement + // step through each char in the statement while (i < statement.length()) { - //get the char + // get the char char c = statement.charAt(i); - //keep track of the open parens + // keep track of the open parens if (c == '(') { openParenCount++; - } - else { + } else { if (c == ')') { openParenCount--; } - //if the char is an operator, and there are no open parens, split the statement here + // if the char is an operator, and there are no open parens, split the statement + // here else { - if (openParenCount == 0 && ShortTruthTableOperation.isOperation(c) && c != ShortTruthTableOperation.NOT) { + if (openParenCount == 0 + && ShortTruthTableOperation.isOperation(c) + && c != ShortTruthTableOperation.NOT) { return i; } } } - //increment the index + // increment the index i++; } - //if it made it through the while loop: - //this is an atomic statement or a negation - //either way, the important char is the first character in the string + // if it made it through the while loop: + // this is an atomic statement or a negation + // either way, the important char is the first character in the string return 0; - } static void removeParens(List cells) { @@ -152,20 +146,19 @@ static void removeParens(List cells) { return; } - //if the statement does start with a paren, check that it matches with the last paren + // if the statement does start with a paren, check that it matches with the last paren int openParenCount = 1; int i = 1; while (i < cells.size() - 1) { char c = cells.get(i).getSymbol(); if (c == '(') { openParenCount++; - } - else { + } else { if (c == ')') openParenCount--; } - //if the first paren has been closed, and it is not the end of the string, - //then there is no whole statement parens to remove + // if the first paren has been closed, and it is not the end of the string, + // then there is no whole statement parens to remove if (openParenCount == 0 && i != cells.size() - 1) { return; } @@ -173,15 +166,13 @@ static void removeParens(List cells) { i++; } - //if the while loop made it through the entire statement, there are parens around the whole thing + // if the while loop made it through the entire statement, there are parens around the whole + // thing cells.remove(cells.size() - 1); cells.remove(0); - } - - //Getters - + // Getters public ShortTruthTableCell getCell() { return cell; @@ -220,15 +211,15 @@ public int getLength() { return stringRep.length(); } - public ShortTruthTableCell getCell(int i) { return cells.get(i); } + // Getters (recursive) - //Getters (recursive) - - //returns all cells in this statement with the symbol 'symbol'; runs recursively on both sides of the tree + // returns all cells in this statement with the symbol 'symbol'; runs recursively on both sides + // of + // the tree public Set getCellsWithSymbol(char symbol) { Set set = new HashSet(getLength()); if (cell.getSymbol() == symbol) set.add(cell); @@ -238,38 +229,37 @@ public Set getCellsWithSymbol(char symbol) { } /** - * Returns an array of three elements where [0] is the left - * statement type, [1] is this statement type, and [2] is the - * right statement type. null means either the statement doesn't + * Returns an array of three elements where [0] is the left statement type, [1] is this + * statement type, and [2] is the right statement type. null means either the statement doesn't * exist or is an unknown value. * * @return the assigned values to this statement and its sub-statements */ public ShortTruthTableCellType[] getCellTypePattern() { - //get this type and the right type, they will always be used + // get this type and the right type, they will always be used ShortTruthTableCellType type = this.cell.getType(); System.out.println("Right statement: " + rightStatement.getCell()); ShortTruthTableCellType rightType = this.rightStatement.getCell().getType(); System.out.println("Right type: " + rightType); - //if this is a not statement, there is no left side + // if this is a not statement, there is no left side if (cell.getSymbol() == ShortTruthTableOperation.NOT) { - return new ShortTruthTableCellType[]{null, type, rightType}; + return new ShortTruthTableCellType[] {null, type, rightType}; } - //if it is any other operation, get the left side too and return it + // if it is any other operation, get the left side too and return it ShortTruthTableCellType leftType = this.leftStatement.getCell().getType(); - return new ShortTruthTableCellType[]{leftType, type, rightType}; + return new ShortTruthTableCellType[] {leftType, type, rightType}; } - //Setters + // Setters private void setCellLocations(int rowIndex, int offset) { - //set the location of this cell + // set the location of this cell int xLoc = offset; if (leftStatement != null) { xLoc += leftStatement.getLength(); } cell.setLocation(new Point(xLoc, rowIndex)); - //recurse on both sides of the tree + // recurse on both sides of the tree if (leftStatement != null) { leftStatement.setCellLocations(rowIndex, offset); } @@ -282,32 +272,29 @@ public void setCellLocations(int rowIndex) { setCellLocations(rowIndex, 0); } - public ShortTruthTableStatement copy() { - //copy all the cells + // copy all the cells List cellsCopy = new ArrayList<>(); for (ShortTruthTableCell c : cells) { cellsCopy.add(c.copy()); } - //make a copy of the statement with all the copied cells - //return the new statement + // make a copy of the statement with all the copied cells + // return the new statement return new ShortTruthTableStatement(stringRep, cellsCopy); } public ShortTruthTableStatement replace(int column, ShortTruthTableCell cell) { - //copy all the cells (replacing one) + // copy all the cells (replacing one) List cellsCopy = new ArrayList<>(); for (ShortTruthTableCell c : cells) { if (c.getX() == column) { cellsCopy.add(cell); - } - else { + } else { cellsCopy.add(c); } } - //make a copy of the statement with all the copied cells - //return the new statement + // make a copy of the statement with all the copied cells + // return the new statement return new ShortTruthTableStatement(stringRep, cellsCopy); } - -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableView.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableView.java index 64e9fda75..15becf443 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableView.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableView.java @@ -3,7 +3,6 @@ import edu.rpi.legup.controller.BoardController; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.ui.boardview.GridBoardView; - import java.awt.*; public class ShortTruthTableView extends GridBoardView { @@ -13,12 +12,13 @@ public ShortTruthTableView(ShortTruthTableBoard board) { for (PuzzleElement puzzleElement : board.getPuzzleElements()) { ShortTruthTableCell cell = (ShortTruthTableCell) puzzleElement; -// System.out.println("STTView :"+cell); + // System.out.println("STTView :"+cell); Point loc = cell.getLocation(); ShortTruthTableElementView elementView = new ShortTruthTableElementView(cell); elementView.setIndex(cell.getIndex()); elementView.setSize(elementSize); - elementView.setLocation(new Point(loc.x * elementSize.width, loc.y * elementSize.height)); + elementView.setLocation( + new Point(loc.x * elementSize.width, loc.y * elementSize.height)); elementViews.add(elementView); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/ArgumentElement.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/ArgumentElement.java index 9f238a9bf..9294fba4e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/ArgumentElement.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/ArgumentElement.java @@ -4,6 +4,10 @@ public class ArgumentElement extends NonPlaceableElement { public ArgumentElement() { - super("STTT-UNPL-0001", "Argument Element", "Argument of logic statement element", "edu/rpi/legup/images/shorttruthtable/tiles/LetterTile.png"); + super( + "STTT-UNPL-0001", + "Argument Element", + "Argument of logic statement element", + "edu/rpi/legup/images/shorttruthtable/tiles/LetterTile.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/GreenElement.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/GreenElement.java index 605f6a207..783186baa 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/GreenElement.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/GreenElement.java @@ -4,6 +4,10 @@ public class GreenElement extends PlaceableElement { public GreenElement() { - super("STTT-PLAC-0001", "Green Element", "A green tile to set certain tiles to true", "edu/rpi/legup/images/shorttruthtable/tiles/GreenTile.png"); + super( + "STTT-PLAC-0001", + "Green Element", + "A green tile to set certain tiles to true", + "edu/rpi/legup/images/shorttruthtable/tiles/GreenTile.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/LogicSymbolElement.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/LogicSymbolElement.java index b2adfddef..5fed4b1df 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/LogicSymbolElement.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/LogicSymbolElement.java @@ -4,6 +4,10 @@ public class LogicSymbolElement extends NonPlaceableElement { public LogicSymbolElement() { - super("STTT-UNPL-0002", "Logic Symbol Element", "Logic symbol element", "edu/rpi/legup/images/shorttruthtable/tiles/ConditionalBiconditionalTile.png"); + super( + "STTT-UNPL-0002", + "Logic Symbol Element", + "Logic symbol element", + "edu/rpi/legup/images/shorttruthtable/tiles/ConditionalBiconditionalTile.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/RedElement.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/RedElement.java index ecc7d5a02..e2a589b65 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/RedElement.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/RedElement.java @@ -4,6 +4,10 @@ public class RedElement extends PlaceableElement { public RedElement() { - super("STTT-PLAC-0002", "Red Element", "A red tile to set certain tiles to false", "edu/rpi/legup/images/shorttruthtable/tiles/RedTile.png"); + super( + "STTT-PLAC-0002", + "Red Element", + "A red tile to set certain tiles to false", + "edu/rpi/legup/images/shorttruthtable/tiles/RedTile.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/UnknownElement.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/UnknownElement.java index 9a9ab8b84..d475bc05d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/UnknownElement.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/UnknownElement.java @@ -4,6 +4,10 @@ public class UnknownElement extends PlaceableElement { public UnknownElement() { - super("STTT-PLAC-0003", "Unknown Element", "A blank tile", "edu/rpi/legup/images/shorttruthtable/tiles/UnknownTile.png"); + super( + "STTT-PLAC-0003", + "Unknown Element", + "A blank tile", + "edu/rpi/legup/images/shorttruthtable/tiles/UnknownTile.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/DirectRuleAtomic.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/DirectRuleAtomic.java index 4b40c833d..38048b5b0 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/DirectRuleAtomic.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/DirectRuleAtomic.java @@ -5,12 +5,12 @@ public class DirectRuleAtomic extends DirectRule_Generic { public DirectRuleAtomic() { - super("STTT-BASC-0001", "Atomic Rule", + super( + "STTT-BASC-0001", + "Atomic Rule", "All identical atoms have the same T/F value", "Atomic", new ContradictionRuleAtomic(), - false - ); + false); } - -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/DirectRule_Generic.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/DirectRule_Generic.java index e1ac78b8c..470ba7c29 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/DirectRule_Generic.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/DirectRule_Generic.java @@ -2,21 +2,30 @@ import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.ContradictionRule; import edu.rpi.legup.model.rules.DirectRule; import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; - import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCell; -import edu.rpi.legup.model.rules.ContradictionRule; public abstract class DirectRule_Generic extends DirectRule { final ContradictionRule CORRESPONDING_CONTRADICTION_RULE; final boolean ELIMINATION_RULE; - public DirectRule_Generic(String ruleID, String ruleName, String description, String imageName, ContradictionRule contraRule, boolean eliminationRule) { - super(ruleID, ruleName, description, "edu/rpi/legup/images/shorttruthtable/ruleimages/basic/" + imageName + ".png"); + public DirectRule_Generic( + String ruleID, + String ruleName, + String description, + String imageName, + ContradictionRule contraRule, + boolean eliminationRule) { + super( + ruleID, + ruleName, + description, + "edu/rpi/legup/images/shorttruthtable/ruleimages/basic/" + imageName + ".png"); this.CORRESPONDING_CONTRADICTION_RULE = contraRule; this.ELIMINATION_RULE = eliminationRule; } @@ -26,17 +35,23 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement element) { if (element == null) return super.getInvalidUseOfRuleMessage() + ": Must have painted cell"; // Check that the puzzle element is not unknown - ShortTruthTableBoard parentBoard = (ShortTruthTableBoard) transition.getParents().get(0).getBoard(); + ShortTruthTableBoard parentBoard = + (ShortTruthTableBoard) transition.getParents().get(0).getBoard(); ShortTruthTableBoard finalBoard = (ShortTruthTableBoard) transition.getBoard(); - ShortTruthTableCell parentCell = (ShortTruthTableCell) parentBoard.getPuzzleElement(element); + ShortTruthTableCell parentCell = + (ShortTruthTableCell) parentBoard.getPuzzleElement(element); ShortTruthTableCell finalCell = (ShortTruthTableCell) finalBoard.getPuzzleElement(element); if (!finalCell.isAssigned()) { - return super.getInvalidUseOfRuleMessage() + ": Only assigned cells are allowed for basic rules"; + return super.getInvalidUseOfRuleMessage() + + ": Only assigned cells are allowed for basic rules"; } - // 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. + // 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 = parentBoard.copy(); @@ -47,13 +62,16 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement element) { ShortTruthTableCell checkCell = this.ELIMINATION_RULE - ? (ShortTruthTableCell) modifiedBoard.getCell(parentCell.getX(), parentCell.getY()) + ? (ShortTruthTableCell) + modifiedBoard.getCell(parentCell.getX(), parentCell.getY()) : (ShortTruthTableCell) modifiedBoard.getPuzzleElement(element); checkCell.setType(finalCell.getType().getNegation()); - String contradictionMessage = CORRESPONDING_CONTRADICTION_RULE.checkContradictionAt(modifiedBoard, checkElement); - if (contradictionMessage == null) { // A contradiction exists in the modified statement; this is good! + String contradictionMessage = + CORRESPONDING_CONTRADICTION_RULE.checkContradictionAt(modifiedBoard, checkElement); + if (contradictionMessage + == null) { // A contradiction exists in the modified statement; this is good! return null; } @@ -61,7 +79,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement element) { } /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. * * @param node short truth table board used to create default transition board * @return default board or null if this rule cannot be applied to this tree node diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRuleAndElimination.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRuleAndElimination.java index 63e3c8dd9..6f48784a3 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRuleAndElimination.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRuleAndElimination.java @@ -1,11 +1,10 @@ -package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.elimination; - -import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleAnd; - -public class DirectRuleAndElimination extends DirectRule_GenericElimination { - - public DirectRuleAndElimination() { - super("STTT-BASC-0002", "And", new ContradictionRuleAnd()); - } - -} \ No newline at end of file +package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.elimination; + +import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleAnd; + +public class DirectRuleAndElimination extends DirectRule_GenericElimination { + + public DirectRuleAndElimination() { + super("STTT-BASC-0002", "And", new ContradictionRuleAnd()); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRuleBiconditionalElimination.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRuleBiconditionalElimination.java index 7f7336a4c..168877ca6 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRuleBiconditionalElimination.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRuleBiconditionalElimination.java @@ -1,11 +1,10 @@ -package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.elimination; - -import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleBiconditional; - -public class DirectRuleBiconditionalElimination extends DirectRule_GenericElimination { - - public DirectRuleBiconditionalElimination() { - super("STTT-BASC-0003", "Biconditional", new ContradictionRuleBiconditional()); - } - -} \ No newline at end of file +package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.elimination; + +import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleBiconditional; + +public class DirectRuleBiconditionalElimination extends DirectRule_GenericElimination { + + public DirectRuleBiconditionalElimination() { + super("STTT-BASC-0003", "Biconditional", new ContradictionRuleBiconditional()); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRuleConditionalElimination.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRuleConditionalElimination.java index 8f15be021..4a287b195 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRuleConditionalElimination.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRuleConditionalElimination.java @@ -1,11 +1,10 @@ -package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.elimination; - -import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleConditional; - -public class DirectRuleConditionalElimination extends DirectRule_GenericElimination { - - public DirectRuleConditionalElimination() { - super("STTT-BASC-0004", "Conditional", new ContradictionRuleConditional()); - } - -} \ No newline at end of file +package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.elimination; + +import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleConditional; + +public class DirectRuleConditionalElimination extends DirectRule_GenericElimination { + + public DirectRuleConditionalElimination() { + super("STTT-BASC-0004", "Conditional", new ContradictionRuleConditional()); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRuleNotElimination.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRuleNotElimination.java index a2f08635c..5acff5837 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRuleNotElimination.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRuleNotElimination.java @@ -1,11 +1,10 @@ -package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.elimination; - -import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleNot; - -public class DirectRuleNotElimination extends DirectRule_GenericElimination { - - public DirectRuleNotElimination() { - super("STTT-BASC-0005", "Not", new ContradictionRuleNot()); - } - -} \ No newline at end of file +package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.elimination; + +import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleNot; + +public class DirectRuleNotElimination extends DirectRule_GenericElimination { + + public DirectRuleNotElimination() { + super("STTT-BASC-0005", "Not", new ContradictionRuleNot()); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRuleOrElimination.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRuleOrElimination.java index eca1848bd..fba43762a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRuleOrElimination.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRuleOrElimination.java @@ -1,11 +1,10 @@ -package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.elimination; - -import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleOr; - -public class DirectRuleOrElimination extends DirectRule_GenericElimination { - - public DirectRuleOrElimination() { - super("STTT-BASC-0006", "Or", new ContradictionRuleOr()); - } - -} \ No newline at end of file +package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.elimination; + +import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleOr; + +public class DirectRuleOrElimination extends DirectRule_GenericElimination { + + public DirectRuleOrElimination() { + super("STTT-BASC-0006", "Or", new ContradictionRuleOr()); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRule_GenericElimination.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRule_GenericElimination.java index 49dc43510..1f85e5b79 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRule_GenericElimination.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/elimination/DirectRule_GenericElimination.java @@ -1,18 +1,19 @@ -package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.elimination; - -import edu.rpi.legup.puzzle.shorttruthtable.rules.basic.DirectRule_Generic; -import edu.rpi.legup.model.rules.ContradictionRule; - -public abstract class DirectRule_GenericElimination extends DirectRule_Generic { - - public DirectRule_GenericElimination(String ruleID, String ruleName, ContradictionRule contradictionRule) { - - super(ruleID, ruleName + " Elimination", - ruleName + " statements must have a valid pattern", - "elimination/" + ruleName, - contradictionRule, - true - ); - } - -} \ No newline at end of file +package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.elimination; + +import edu.rpi.legup.model.rules.ContradictionRule; +import edu.rpi.legup.puzzle.shorttruthtable.rules.basic.DirectRule_Generic; + +public abstract class DirectRule_GenericElimination extends DirectRule_Generic { + + public DirectRule_GenericElimination( + String ruleID, String ruleName, ContradictionRule contradictionRule) { + + super( + ruleID, + ruleName + " Elimination", + ruleName + " statements must have a valid pattern", + "elimination/" + ruleName, + contradictionRule, + true); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRuleAndIntroduction.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRuleAndIntroduction.java index 0ca2a7dcf..667b97a0f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRuleAndIntroduction.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRuleAndIntroduction.java @@ -1,11 +1,10 @@ -package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.introduction; - -import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleAnd; - -public class DirectRuleAndIntroduction extends DirectRule_GenericIntroduction { - - public DirectRuleAndIntroduction() { - super("STTT-BASC-0007", "And", new ContradictionRuleAnd()); - } - -} \ No newline at end of file +package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.introduction; + +import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleAnd; + +public class DirectRuleAndIntroduction extends DirectRule_GenericIntroduction { + + public DirectRuleAndIntroduction() { + super("STTT-BASC-0007", "And", new ContradictionRuleAnd()); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRuleBiconditionalIntroduction.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRuleBiconditionalIntroduction.java index b72d5299c..c2dfeebba 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRuleBiconditionalIntroduction.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRuleBiconditionalIntroduction.java @@ -1,11 +1,10 @@ -package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.introduction; - -import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleBiconditional; - -public class DirectRuleBiconditionalIntroduction extends DirectRule_GenericIntroduction { - - public DirectRuleBiconditionalIntroduction() { - super("STTT-BASC-0008", "Biconditional", new ContradictionRuleBiconditional()); - } - -} \ No newline at end of file +package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.introduction; + +import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleBiconditional; + +public class DirectRuleBiconditionalIntroduction extends DirectRule_GenericIntroduction { + + public DirectRuleBiconditionalIntroduction() { + super("STTT-BASC-0008", "Biconditional", new ContradictionRuleBiconditional()); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRuleConditionalIntroduction.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRuleConditionalIntroduction.java index 0e27d267c..728d7f244 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRuleConditionalIntroduction.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRuleConditionalIntroduction.java @@ -1,11 +1,10 @@ -package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.introduction; - -import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleConditional; - -public class DirectRuleConditionalIntroduction extends DirectRule_GenericIntroduction { - - public DirectRuleConditionalIntroduction() { - super("STTT-BASC-0009", "Conditional", new ContradictionRuleConditional()); - } - -} \ No newline at end of file +package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.introduction; + +import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleConditional; + +public class DirectRuleConditionalIntroduction extends DirectRule_GenericIntroduction { + + public DirectRuleConditionalIntroduction() { + super("STTT-BASC-0009", "Conditional", new ContradictionRuleConditional()); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRuleNotIntroduction.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRuleNotIntroduction.java index 980a132fe..80b963a56 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRuleNotIntroduction.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRuleNotIntroduction.java @@ -1,11 +1,10 @@ -package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.introduction; - -import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleNot; - -public class DirectRuleNotIntroduction extends DirectRule_GenericIntroduction { - - public DirectRuleNotIntroduction() { - super("STTT-BASC-0010", "Not", new ContradictionRuleNot()); - } - -} \ No newline at end of file +package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.introduction; + +import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleNot; + +public class DirectRuleNotIntroduction extends DirectRule_GenericIntroduction { + + public DirectRuleNotIntroduction() { + super("STTT-BASC-0010", "Not", new ContradictionRuleNot()); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRuleOrIntroduction.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRuleOrIntroduction.java index 0fd7108bd..66a569655 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRuleOrIntroduction.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRuleOrIntroduction.java @@ -1,11 +1,10 @@ -package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.introduction; - -import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleOr; - -public class DirectRuleOrIntroduction extends DirectRule_GenericIntroduction { - - public DirectRuleOrIntroduction() { - super("STTT-BASC-0011", "Or", new ContradictionRuleOr()); - } - -} \ No newline at end of file +package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.introduction; + +import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleOr; + +public class DirectRuleOrIntroduction extends DirectRule_GenericIntroduction { + + public DirectRuleOrIntroduction() { + super("STTT-BASC-0011", "Or", new ContradictionRuleOr()); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRule_GenericIntroduction.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRule_GenericIntroduction.java index 123165d7a..8469ff0b9 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRule_GenericIntroduction.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/basic/introduction/DirectRule_GenericIntroduction.java @@ -1,18 +1,19 @@ -package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.introduction; - -import edu.rpi.legup.puzzle.shorttruthtable.rules.basic.DirectRule_Generic; -import edu.rpi.legup.model.rules.ContradictionRule; - -public abstract class DirectRule_GenericIntroduction extends DirectRule_Generic { - - protected DirectRule_GenericIntroduction(String ruleID, String ruleName, ContradictionRule contradictionRule) { - - super(ruleID, ruleName + " Introduction", - ruleName + " statements must have a valid pattern", - "introduction/" + ruleName, - contradictionRule, - false - ); - } - -} \ No newline at end of file +package edu.rpi.legup.puzzle.shorttruthtable.rules.basic.introduction; + +import edu.rpi.legup.model.rules.ContradictionRule; +import edu.rpi.legup.puzzle.shorttruthtable.rules.basic.DirectRule_Generic; + +public abstract class DirectRule_GenericIntroduction extends DirectRule_Generic { + + protected DirectRule_GenericIntroduction( + String ruleID, String ruleName, ContradictionRule contradictionRule) { + + super( + ruleID, + ruleName + " Introduction", + ruleName + " statements must have a valid pattern", + "introduction/" + ruleName, + contradictionRule, + false); + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleAnd.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleAnd.java index 12fac9c4c..9b589f14e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleAnd.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleAnd.java @@ -1,23 +1,17 @@ -package edu.rpi.legup.puzzle.shorttruthtable.rules.caserule; - -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; - -public class CaseRuleAnd extends CaseRule_GenericStatement { - - public CaseRuleAnd() { - super("STTT-CASE-0001", ShortTruthTableOperation.AND, - "And", - trueCases, - falseCases); - } - - private static final ShortTruthTableCellType[][] trueCases = { - {T, T} - }; - private static final ShortTruthTableCellType[][] falseCases = { - {F, U}, - {U, F} - }; - -} +package edu.rpi.legup.puzzle.shorttruthtable.rules.caserule; + +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; + +public class CaseRuleAnd extends CaseRule_GenericStatement { + + public CaseRuleAnd() { + super("STTT-CASE-0001", ShortTruthTableOperation.AND, "And", trueCases, falseCases); + } + + private static final ShortTruthTableCellType[][] trueCases = {{T, T}}; + private static final ShortTruthTableCellType[][] falseCases = { + {F, U}, + {U, F} + }; +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleAtomic.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleAtomic.java index f168499cc..58d2068b2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleAtomic.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleAtomic.java @@ -3,21 +3,18 @@ import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.CaseBoard; import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.CaseRule; import edu.rpi.legup.model.tree.TreeTransition; - import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCell; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; - - import java.util.ArrayList; -import java.util.List; public class CaseRuleAtomic extends CaseRule_Generic { public CaseRuleAtomic() { - super("STTT-CASE-0002", "Atomic", + super( + "STTT-CASE-0002", + "Atomic", "True or False", "Each unknown cell must either be true or false"); } @@ -39,7 +36,7 @@ public CaseBoard getCaseBoard(Board board) { /** * Gets the possible cases at a specific location based on this case rule * - * @param board the current board state + * @param board the current board state * @param puzzleElement equivalent puzzleElement * @return a list of elements the specified could be */ diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleBiconditional.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleBiconditional.java index 85c6f5447..1bb5f0332 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleBiconditional.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleBiconditional.java @@ -1,24 +1,25 @@ package edu.rpi.legup.puzzle.shorttruthtable.rules.caserule; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; public class CaseRuleBiconditional extends CaseRule_GenericStatement { public CaseRuleBiconditional() { - super("STTT-CASE-0003", ShortTruthTableOperation.BICONDITIONAL, + super( + "STTT-CASE-0003", + ShortTruthTableOperation.BICONDITIONAL, "Biconditional", trueCases, falseCases); } private static final ShortTruthTableCellType[][] trueCases = { - {T, T}, - {F, F} + {T, T}, + {F, F} }; private static final ShortTruthTableCellType[][] falseCases = { - {T, F}, - {F, T} + {T, F}, + {F, T} }; - } diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleConditional.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleConditional.java index a9fee2b4e..397341f0e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleConditional.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleConditional.java @@ -1,23 +1,24 @@ -package edu.rpi.legup.puzzle.shorttruthtable.rules.caserule; - -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; - -public class CaseRuleConditional extends CaseRule_GenericStatement { - - public CaseRuleConditional() { - super("STTT-CASE-0004", ShortTruthTableOperation.CONDITIONAL, - "Conditional", - trueCases, - falseCases); - } - - private static final ShortTruthTableCellType[][] trueCases = { - {U, T}, - {F, U} - }; - private static final ShortTruthTableCellType[][] falseCases = { - {T, F}, - }; - -} +package edu.rpi.legup.puzzle.shorttruthtable.rules.caserule; + +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; + +public class CaseRuleConditional extends CaseRule_GenericStatement { + + public CaseRuleConditional() { + super( + "STTT-CASE-0004", + ShortTruthTableOperation.CONDITIONAL, + "Conditional", + trueCases, + falseCases); + } + + private static final ShortTruthTableCellType[][] trueCases = { + {U, T}, + {F, U} + }; + private static final ShortTruthTableCellType[][] falseCases = { + {T, F}, + }; +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleOr.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleOr.java index 82f814cc8..36f4e6f87 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleOr.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/caserule/CaseRuleOr.java @@ -1,23 +1,19 @@ -package edu.rpi.legup.puzzle.shorttruthtable.rules.caserule; - -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; - -public class CaseRuleOr extends CaseRule_GenericStatement { - - public CaseRuleOr() { - super("STTT-CASE-0005", ShortTruthTableOperation.OR, - "Or", - trueCases, - falseCases); - } - - private static final ShortTruthTableCellType[][] trueCases = { - {T, U}, - {U, T} - }; - private static final ShortTruthTableCellType[][] falseCases = { - {F, F}, - }; - -} +package edu.rpi.legup.puzzle.shorttruthtable.rules.caserule; + +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; + +public class CaseRuleOr extends CaseRule_GenericStatement { + + public CaseRuleOr() { + super("STTT-CASE-0005", ShortTruthTableOperation.OR, "Or", trueCases, falseCases); + } + + private static final ShortTruthTableCellType[][] trueCases = { + {T, U}, + {U, T} + }; + private static final ShortTruthTableCellType[][] falseCases = { + {F, F}, + }; +} 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 46163c2a3..5885f98f8 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 @@ -1,71 +1,63 @@ -package edu.rpi.legup.puzzle.shorttruthtable.rules.caserule; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.CaseBoard; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.CaseRule; -import edu.rpi.legup.model.tree.TreeTransition; - -import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; -import edu.rpi.legup.puzzle.nurikabe.NurikabeType; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCell; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; - - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import javax.swing.JOptionPane; - -import com.google.firebase.database.core.utilities.Tree; - -public abstract class CaseRule_Generic extends CaseRule { - - public CaseRule_Generic(String ruleID, String ruleName, String title, String description) { - super(ruleID, title, description, "edu/rpi/legup/images/shorttruthtable/ruleimages/case/" + ruleName + ".png"); - } - - - /** - * Checks whether the transition logically follows from the parent node using this rule - * - * @param transition transition to check - * @return null if the child node logically follow from the parent node, otherwise error message - */ - @Override - public String checkRuleRaw(TreeTransition transition) { - // Validate that two children are generated - List childTransitions = transition.getParents().get(0).getChildren(); - if (childTransitions.size() == 0) { - return "ERROR: This case rule must spawn at least 1 child."; - } - - // // Validate that the modified cells are of type UNKNOWN, TRUE, or FALSE - // List cases = Arrays.asList(childTransitions.get(0), childTransitions.get(1)); - // for (TreeTransition c : cases) { - // ShortTruthTableCell mod1 = (ShortTruthTableCell)c.getBoard().getModifiedData().iterator().next(); - // ShortTruthTableCell mod2 = (ShortTruthTableCell)c.getBoard().getModifiedData().iterator().next(); - // if (!(mod1.getType() == ShortTruthTableCellType.TRUE || mod1.getType() == ShortTruthTableCellType.FALSE || mod1.getType() == ShortTruthTableCellType.UNKNOWN) && - // (mod2.getType() == ShortTruthTableCellType.TRUE || mod2.getType() == ShortTruthTableCellType.FALSE || mod2.getType() == ShortTruthTableCellType.UNKNOWN)) { - // return "ERROR: This case rule must be an unknown, true, or false cell."; - // } - // } - return null; - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - return checkRuleRaw(transition); - } -} +package edu.rpi.legup.puzzle.shorttruthtable.rules.caserule; + +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.CaseRule; +import edu.rpi.legup.model.tree.TreeTransition; +import java.util.List; + +public abstract class CaseRule_Generic extends CaseRule { + + public CaseRule_Generic(String ruleID, String ruleName, String title, String description) { + super( + ruleID, + title, + description, + "edu/rpi/legup/images/shorttruthtable/ruleimages/case/" + ruleName + ".png"); + } + + /** + * Checks whether the transition logically follows from the parent node using this rule + * + * @param transition transition to check + * @return null if the child node logically follow from the parent node, otherwise error message + */ + @Override + public String checkRuleRaw(TreeTransition transition) { + // Validate that two children are generated + List childTransitions = transition.getParents().get(0).getChildren(); + if (childTransitions.size() == 0) { + return "ERROR: This case rule must spawn at least 1 child."; + } + + // // Validate that the modified cells are of type UNKNOWN, TRUE, or FALSE + // List cases = Arrays.asList(childTransitions.get(0), + // childTransitions.get(1)); + // for (TreeTransition c : cases) { + // ShortTruthTableCell mod1 = + // (ShortTruthTableCell)c.getBoard().getModifiedData().iterator().next(); + // ShortTruthTableCell mod2 = + // (ShortTruthTableCell)c.getBoard().getModifiedData().iterator().next(); + // if (!(mod1.getType() == ShortTruthTableCellType.TRUE || mod1.getType() == + // ShortTruthTableCellType.FALSE || mod1.getType() == ShortTruthTableCellType.UNKNOWN) && + // (mod2.getType() == ShortTruthTableCellType.TRUE || mod2.getType() == + // ShortTruthTableCellType.FALSE || mod2.getType() == ShortTruthTableCellType.UNKNOWN)) { + // return "ERROR: This case rule must be an unknown, true, or false cell."; + // } + // } + return null; + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + return checkRuleRaw(transition); + } +} 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 0e25586a8..99f771246 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 @@ -3,22 +3,25 @@ import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.CaseBoard; import edu.rpi.legup.model.gameboard.PuzzleElement; - import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCell; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableStatement; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; - -import java.util.List; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableStatement; import java.util.ArrayList; +import java.util.List; public abstract class CaseRule_GenericStatement extends CaseRule_Generic { - public CaseRule_GenericStatement(String ruleID, char operation, String title, - ShortTruthTableCellType[][] trueCases, - ShortTruthTableCellType[][] falseCases) { - super(ruleID, ShortTruthTableOperation.getRuleName(operation), + public CaseRule_GenericStatement( + String ruleID, + char operation, + String title, + ShortTruthTableCellType[][] trueCases, + ShortTruthTableCellType[][] falseCases) { + super( + ruleID, + ShortTruthTableOperation.getRuleName(operation), title + " case", "A known " + title.toUpperCase() + " statement can have multiple forms"); @@ -40,25 +43,33 @@ public CaseRule_GenericStatement(String ruleID, char operation, String title, // Adds all elements that can be selected for this caserule @Override public CaseBoard getCaseBoard(Board board) { - //copy the board and add all elements that can be selected + // copy the board and add all elements that can be selected ShortTruthTableBoard sttBoard = (ShortTruthTableBoard) board.copy(); sttBoard.setModifiable(false); CaseBoard caseBoard = new CaseBoard(sttBoard, this); - //add all elements that can be selected for the case rule statement + // add all elements that can be selected for the case rule statement for (PuzzleElement element : sttBoard.getPuzzleElements()) { - //get the cell object + // get the cell object ShortTruthTableCell cell = sttBoard.getCellFromElement(element); - //the cell must match the symbol + // the cell must match the symbol if (cell.getSymbol() != this.operation) continue; - //the statement must be assigned with unassigned sub-statements + // the statement must be assigned with unassigned sub-statements if (!cell.getType().isTrueOrFalse()) continue; - if (cell.getStatementReference().getRightStatement().getCell().getType().isTrueOrFalse()) continue; - if (this.operation != ShortTruthTableOperation.NOT && - cell.getStatementReference().getRightStatement().getCell().getType().isTrueOrFalse()) { + if (cell.getStatementReference() + .getRightStatement() + .getCell() + .getType() + .isTrueOrFalse()) continue; + if (this.operation != ShortTruthTableOperation.NOT + && cell.getStatementReference() + .getRightStatement() + .getCell() + .getType() + .isTrueOrFalse()) { continue; } - //if the element has passed all the checks, it can be selected + // if the element has passed all the checks, it can be selected caseBoard.addPickableElement(element); } return caseBoard; @@ -67,7 +78,7 @@ public CaseBoard getCaseBoard(Board board) { /** * Gets the possible cases at a specific location based on this case rule * - * @param board the current board state + * @param board the current board state * @param puzzleElement equivalent puzzleElement * @return a list of elements the specified could be */ @@ -86,12 +97,16 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { /** * Collects a list of boards for each possible outcome of case-rule application + * * @param board current board state * @param puzzleElement case rule operator * @param possibilities list of possibilities for operator state * @return ArrayList of Boards */ - private ArrayList getCasesFromCell(ShortTruthTableBoard board, PuzzleElement puzzleElement, ShortTruthTableCellType[][] possibilities) { + private ArrayList getCasesFromCell( + ShortTruthTableBoard board, + PuzzleElement puzzleElement, + ShortTruthTableCellType[][] possibilities) { // Create branch case for each possibility ArrayList cases = new ArrayList<>(); for (int i = 0; i < possibilities.length; i++) { @@ -116,19 +131,19 @@ private ArrayList getCasesFromCell(ShortTruthTableBoard board, PuzzleElem } return cases; } - - /** - * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid - * Overridden by case rules dependent on more than just the modified data + + /** + * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be + * valid Overridden by case rules dependent on more than just the modified data * - * @param board board state at application + * @param board board state at application * @param puzzleElement selected puzzleElement - * @return List of puzzle elements (typically cells) this application of the case rule depends upon. - * Defaults to any element modified by any case + * @return List of puzzle elements (typically cells) this application of the case rule depends + * upon. Defaults to any element modified by any case */ @Override public List dependentElements(Board board, PuzzleElement puzzleElement) { - List elements = super.dependentElements(board,puzzleElement); + List elements = super.dependentElements(board, puzzleElement); elements.add(board.getPuzzleElement(puzzleElement)); diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleAnd.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleAnd.java index aa0da52c3..595dd0cb2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleAnd.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleAnd.java @@ -1,22 +1,22 @@ package edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; public class ContradictionRuleAnd extends ContradictionRule_GenericStatement { public ContradictionRuleAnd() { - super("STTT-CONT-0001", "Contradicting And", + super( + "STTT-CONT-0001", + "Contradicting And", "An AND statement must have a contradicting pattern", "edu/rpi/legup/images/shorttruthtable/ruleimages/contradiction/And.png", ShortTruthTableOperation.AND, - new ShortTruthTableCellType[][]{ - {n, T, F}, - {F, T, n}, - // {F, T, F}, - {T, F, T}, - } - ); + new ShortTruthTableCellType[][] { + {n, T, F}, + {F, T, n}, + // {F, T, F}, + {T, F, T}, + }); } - -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleAtomic.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleAtomic.java index 2d1efb945..879b7c9a5 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleAtomic.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleAtomic.java @@ -1,36 +1,31 @@ package edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction; - import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.rules.ContradictionRule; - import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCell; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableStatement; - -import java.util.Set; import java.util.Iterator; - +import java.util.Set; public class ContradictionRuleAtomic extends ContradictionRule { - public ContradictionRuleAtomic() { - super("STTT-CONT-0002", "Contradicting Variable", + super( + "STTT-CONT-0002", + "Contradicting Variable", "A single variable can not be both True and False", "edu/rpi/legup/images/shorttruthtable/ruleimages/contradiction/Atomic.png"); } - @Override public String checkContradictionAt(Board puzzleBoard, PuzzleElement puzzleElement) { - //cast the board toa shortTruthTableBoard + // cast the board toa shortTruthTableBoard ShortTruthTableBoard board = (ShortTruthTableBoard) puzzleBoard; - //get the cell that contradicts another cell in the board + // get the cell that contradicts another cell in the board ShortTruthTableCell cell = (ShortTruthTableCell) board.getPuzzleElement(puzzleElement); if (!cell.isVariable()) { @@ -40,26 +35,25 @@ public String checkContradictionAt(Board puzzleBoard, PuzzleElement puzzleElemen ShortTruthTableCellType cellType = cell.getType(); if (!cellType.isTrueOrFalse()) { - return "Can only check for a contradiction against a cell that is assigned a value of True or False"; + return "Can only check for a contradiction against a cell that is assigned a value of" + + " True or False"; } - //get all the cells with the same value + // get all the cells with the same value Set varCells = board.getCellsWithSymbol(cell.getSymbol()); - //check if there are any contradictions + // check if there are any contradictions Iterator itr = varCells.iterator(); while (itr.hasNext()) { ShortTruthTableCell checkCell = itr.next(); ShortTruthTableCellType checkCellType = checkCell.getType(); - //if there is an assigned contradiction, return null + // if there is an assigned contradiction, return null if (checkCellType.isTrueOrFalse() && checkCellType != cellType) { return null; } } - //if it made it through the while loop, thene there is no contradiction + // if it made it through the while loop, thene there is no contradiction return "There is no contradiction for the variable " + cell.getSymbol(); - } - -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleBiconditional.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleBiconditional.java index bf215358a..bae07acce 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleBiconditional.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleBiconditional.java @@ -1,22 +1,22 @@ package edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; public class ContradictionRuleBiconditional extends ContradictionRule_GenericStatement { public ContradictionRuleBiconditional() { - super("STTT-CONT-0003", "Contradicting Biconditional", + super( + "STTT-CONT-0003", + "Contradicting Biconditional", "A Biconditional statement must have a contradicting pattern", "edu/rpi/legup/images/shorttruthtable/ruleimages/contradiction/Biconditional.png", ShortTruthTableOperation.BICONDITIONAL, - new ShortTruthTableCellType[][]{ - {T, T, F}, - {F, T, T}, - {T, F, T}, - {F, F, F} - } - ); + new ShortTruthTableCellType[][] { + {T, T, F}, + {F, T, T}, + {T, F, T}, + {F, F, F} + }); } - -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleConditional.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleConditional.java index caa65afa4..e3a51a00e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleConditional.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleConditional.java @@ -1,21 +1,21 @@ package edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; public class ContradictionRuleConditional extends ContradictionRule_GenericStatement { public ContradictionRuleConditional() { - super("STTT-CONT-0004", "Contradicting Conditional", + super( + "STTT-CONT-0004", + "Contradicting Conditional", "A Conditional statement must have a contradicting pattern", "edu/rpi/legup/images/shorttruthtable/ruleimages/contradiction/Conditional.png", ShortTruthTableOperation.CONDITIONAL, - new ShortTruthTableCellType[][]{ - {n, F, T}, - {F, F, n}, - {T, T, F} - } - ); + new ShortTruthTableCellType[][] { + {n, F, T}, + {F, F, n}, + {T, T, F} + }); } - -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleNot.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleNot.java index 4be059a06..4e20485bc 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleNot.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleNot.java @@ -1,20 +1,20 @@ package edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; public class ContradictionRuleNot extends ContradictionRule_GenericStatement { public ContradictionRuleNot() { - super("STTT-CONT-0005", "Contradicting Negation", + super( + "STTT-CONT-0005", + "Contradicting Negation", "A negation and its following statement can not have the same truth value", "edu/rpi/legup/images/shorttruthtable/ruleimages/contradiction/Not.png", ShortTruthTableOperation.NOT, - new ShortTruthTableCellType[][]{ - {n, T, T}, - {n, F, F} - } - ); + new ShortTruthTableCellType[][] { + {n, T, T}, + {n, F, F} + }); } - -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleOr.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleOr.java index 46fee2a44..2ab197dad 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleOr.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/contradiction/ContradictionRuleOr.java @@ -1,21 +1,21 @@ package edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction; -import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; +import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableOperation; public class ContradictionRuleOr extends ContradictionRule_GenericStatement { public ContradictionRuleOr() { - super("STTT-CONT-0006", "Contradicting Or", + super( + "STTT-CONT-0006", + "Contradicting Or", "An OR statement must have a contradicting pattern", "edu/rpi/legup/images/shorttruthtable/ruleimages/contradiction/Or.png", ShortTruthTableOperation.OR, - new ShortTruthTableCellType[][]{ - {n, F, T}, - {T, F, n}, - {F, T, F} - } - ); + new ShortTruthTableCellType[][] { + {n, F, T}, + {T, F, n}, + {F, T, F} + }); } - -} \ No newline at end of file +} 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 4554e5100..87b1ba628 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 @@ -1,31 +1,36 @@ package edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction; - import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.rules.ContradictionRule; - import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCell; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableStatement; - public abstract class ContradictionRule_GenericStatement extends ContradictionRule { private final char operationSymbol; 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"; - - public ContradictionRule_GenericStatement(String ruleID, String ruleName, String description, String imageName, - char operationSymbol, ShortTruthTableCellType[][] contradictionPatterns) { + static final ShortTruthTableCellType T = ShortTruthTableCellType.TRUE; + static final ShortTruthTableCellType F = ShortTruthTableCellType.FALSE; + static final 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"; + + public ContradictionRule_GenericStatement( + String ruleID, + String ruleName, + String description, + String imageName, + char operationSymbol, + ShortTruthTableCellType[][] contradictionPatterns) { super(ruleID, ruleName, description, imageName); this.operationSymbol = operationSymbol; this.contradictionPatterns = contradictionPatterns; @@ -42,7 +47,9 @@ public String checkContradictionAt(Board puzzleBoard, PuzzleElement operatorPuzz ShortTruthTableStatement statement = cell.getStatementReference(); if (cell.getSymbol() != this.operationSymbol) { - return super.getInvalidUseOfRuleMessage() + ": " + this.NOT_RIGHT_OPERATOR_ERROR_MESSAGE; + return super.getInvalidUseOfRuleMessage() + + ": " + + this.NOT_RIGHT_OPERATOR_ERROR_MESSAGE; } // check that the initial statement is assigned @@ -63,13 +70,14 @@ public String checkContradictionAt(Board puzzleBoard, PuzzleElement operatorPuzz if (pattern[i] == null) { continue; } - //if it is not null, it must match the test pattern + // if it is not null, it must match the test pattern if (pattern[i] != testPattern[i]) { matches = false; break; } } - // if testPattern matches one of the valid contradiction patterns, the contradiction is correct + // if testPattern matches one of the valid contradiction patterns, the contradiction is + // correct if (matches) { return null; } @@ -77,4 +85,4 @@ public String checkContradictionAt(Board puzzleBoard, PuzzleElement operatorPuzz return super.getNoContradictionMessage(); } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/Skyscrapers.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/Skyscrapers.java index f87462978..df5ba78a3 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/Skyscrapers.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/Skyscrapers.java @@ -18,9 +18,7 @@ public Skyscrapers() { this.factory = new SkyscrapersCellFactory(); } - /** - * Initializes the game board. Called by the invoker of the class - */ + /** Initializes the game board. Called by the invoker of the class */ @Override public void initializeView() { boardView = new SkyscrapersView((SkyscrapersBoard) currentBoard); @@ -43,8 +41,8 @@ public Board generatePuzzle(int difficulty) { /** * Determines if the given dimensions are valid for Skyscrapers * - * @param rows the number of rows - * @param columns the number of columns + * @param rows the number of rows + * @param columns the number of columns * @return true if the given dimensions are valid for Skyscrapers, false otherwise */ public boolean isValidDimensions(int rows, int columns) { @@ -82,7 +80,5 @@ public boolean isBoardComplete(Board board) { * @param board the board that has changed */ @Override - public void onBoardChange(Board board) { - - } + public void onBoardChange(Board board) {} } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java index 65f5eb561..4cd09b254 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java @@ -3,7 +3,6 @@ import edu.rpi.legup.model.elements.Element; import edu.rpi.legup.model.gameboard.GridBoard; import edu.rpi.legup.model.gameboard.PuzzleElement; - import java.awt.*; import java.awt.event.MouseEvent; import java.util.ArrayList; @@ -11,15 +10,14 @@ public class SkyscrapersBoard extends GridBoard { - private ArrayList eastClues; - //EAST clues + // EAST clues private ArrayList southClues; - //SOUTH clues + // SOUTH clues private ArrayList westClues; - //WEST clues + // WEST clues private ArrayList northClues; - //NORTH clues + // NORTH clues private boolean viewFlag = false; private boolean dupeFlag = false; @@ -40,10 +38,9 @@ public SkyscrapersBoard(int size) { } } - /** - * @return eastClues a list of the eastern clues ordered from loc.y = 0 to max - */ + * @return eastClues a list of the eastern clues ordered from loc.y = 0 to max + */ public ArrayList getEastClues() { return eastClues; } @@ -103,7 +100,6 @@ public PuzzleElement getPuzzleElement(PuzzleElement element) { return super.getPuzzleElement(element); } - /** * Gets the cells of a certain type directly adjacent to a given cell * @@ -176,8 +172,7 @@ public List getRowCol(int index, SkyscrapersType type, boolean SkyscrapersCell cell; if (isRow) { cell = getCell(i, index); - } - else { + } else { cell = getCell(index, i); } @@ -188,16 +183,13 @@ public List getRowCol(int index, SkyscrapersType type, boolean return list; } - /** - * Prints a semblance of the board to console (helps in debugging) - */ + /** Prints a semblance of the board to console (helps in debugging) */ public void printBoard() { for (int i = 0; i < this.dimension.height; i++) { for (SkyscrapersCell cell : this.getRowCol(i, SkyscrapersType.ANY, true)) { if (cell.getType() == SkyscrapersType.Number) { System.out.print(cell.getData() + " "); - } - else { + } else { System.out.print(0 + " "); } } @@ -206,13 +198,11 @@ public void printBoard() { } /** - * * @param x position of cell * @param y position of cell * @param e Element to be placed (null if nothing selected) - * @param m MouseEvent - * Increases clue values if in editor mode. Currently allows for - * presetting tile values, though they will not be saved. + * @param m MouseEvent Increases clue values if in editor mode. Currently allows for presetting + * tile values, though they will not be saved. */ @Override public void setCell(int x, int y, Element e, MouseEvent m) { @@ -226,27 +216,22 @@ public void setCell(int x, int y, Element e, MouseEvent m) { if (m.getButton() == MouseEvent.BUTTON1) { if (clue.getData() < dimension.height) { clue.setData(clue.getData() + 1); - } - else { + } else { clue.setData(0); } - } - else { + } else { if (clue.getData() > 0) { clue.setData(clue.getData() - 1); - } - else { + } else { clue.setData(dimension.height); } } - } - else { + } else { super.setCell(x - 1, y - 1, e, m); } } /** - * * @param x position of element on boardView * @param y position of element on boardView * @return The clue at the given position @@ -254,16 +239,13 @@ public void setCell(int x, int y, Element e, MouseEvent m) { public SkyscrapersClue getClue(int x, int y) { int viewIndex = getSize() + 1; if (x == 0 && y > 0 && y < viewIndex) { - return westClues.get(y-1); - } - else if (x == viewIndex && y > 0 && y < viewIndex) { - return eastClues.get(y-1); - } - else if (y == 0 && x > 0 && x < viewIndex) { - return northClues.get(x-1); - } - else if (y == viewIndex && x > 0 && x < viewIndex) { - return southClues.get(x-1); + return westClues.get(y - 1); + } else if (x == viewIndex && y > 0 && y < viewIndex) { + return eastClues.get(y - 1); + } else if (y == 0 && x > 0 && x < viewIndex) { + return northClues.get(x - 1); + } else if (y == viewIndex && x > 0 && x < viewIndex) { + return southClues.get(x - 1); } return null; } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCell.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCell.java index 409555b83..1cf9a357b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCell.java @@ -1,13 +1,12 @@ package edu.rpi.legup.puzzle.skyscrapers; +import static edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType.convertToSkyType; + import edu.rpi.legup.model.elements.Element; import edu.rpi.legup.model.gameboard.GridCell; - import java.awt.*; import java.awt.event.MouseEvent; -import static edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType.convertToSkyType; - public class SkyscrapersCell extends GridCell { private int max; @@ -17,7 +16,7 @@ public SkyscrapersCell(Integer value, Point location, int size) { } public SkyscrapersType getType() { - switch (convertToSkyType(data)){ + switch (convertToSkyType(data)) { case UNKNOWN: return SkyscrapersType.UNKNOWN; default: @@ -27,25 +26,23 @@ public SkyscrapersType getType() { @Override public void setType(Element e, MouseEvent m) { - switch (e.getElementID()){ + switch (e.getElementID()) { case "SKYS-UNPL-0001": this.data = 0; break; case "SKYS-UNPL-0002": - switch (m.getButton()){ + switch (m.getButton()) { case MouseEvent.BUTTON1: if (this.data <= 0 || this.data >= this.max) { this.data = 1; - } - else { + } else { this.data = this.data + 1; } break; case MouseEvent.BUTTON3: if (this.data > 1) { this.data = this.data - 1; - } - else { + } else { this.data = this.max; } break; @@ -54,7 +51,6 @@ public void setType(Element e, MouseEvent m) { } } - public int getMax() { return max; } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCellFactory.java index 5f6de7369..03572b816 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCellFactory.java @@ -4,17 +4,16 @@ import edu.rpi.legup.model.gameboard.ElementFactory; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; -import java.awt.*; - public class SkyscrapersCellFactory extends ElementFactory { /** * Creates a puzzleElement based on the xml document Node and adds it to the board * - * @param node node that represents the puzzleElement + * @param node node that represents the puzzleElement * @param board board to add the newly created cell * @return newly created cell from the xml document Node * @throws InvalidFileFormatException if input is invalid @@ -23,7 +22,8 @@ public class SkyscrapersCellFactory extends ElementFactory { public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormatException { try { if (!node.getNodeName().equalsIgnoreCase("cell")) { - throw new InvalidFileFormatException("Skyscrapers Factory: unknown puzzleElement puzzleElement"); + throw new InvalidFileFormatException( + "Skyscrapers Factory: unknown puzzleElement puzzleElement"); } SkyscrapersBoard skyscrapersBoard = (SkyscrapersBoard) board; @@ -34,7 +34,8 @@ public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormat int x = Integer.valueOf(attributeList.getNamedItem("x").getNodeValue()); int y = Integer.valueOf(attributeList.getNamedItem("y").getNodeValue()); if (x >= size || y >= size) { - throw new InvalidFileFormatException("Skyscrapers Factory: cell location out of bounds"); + throw new InvalidFileFormatException( + "Skyscrapers Factory: cell location out of bounds"); } if (value < 0 || value > size) { throw new InvalidFileFormatException("Skyscrapers Factory: cell unknown value"); @@ -44,19 +45,19 @@ public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormat cell.setIndex(y * size + x); return cell; - } - catch (NumberFormatException e) { - throw new InvalidFileFormatException("Skyscrapers Factory: unknown value where integer expected"); - } - catch (NullPointerException e) { - throw new InvalidFileFormatException("Skyscrapers Factory: could not find attribute(s)"); + } catch (NumberFormatException e) { + throw new InvalidFileFormatException( + "Skyscrapers Factory: unknown value where integer expected"); + } catch (NullPointerException e) { + throw new InvalidFileFormatException( + "Skyscrapers Factory: could not find attribute(s)"); } } /** * Creates a xml document puzzleElement from a cell for exporting * - * @param document xml document + * @param document xml document * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClue.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClue.java index 1e7b1b45e..7b8bf635b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClue.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClue.java @@ -9,7 +9,7 @@ public class SkyscrapersClue extends PuzzleElement { public SkyscrapersClue(int value, int clueIndex, SkyscrapersType type) { super(value); this.index = -2; - this.clueIndex = clueIndex;//index in list + this.clueIndex = clueIndex; // index in list this.type = type; this.setModifiable(false); } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClueView.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClueView.java index 649f85f4e..5a49a1476 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClueView.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersClueView.java @@ -1,7 +1,6 @@ package edu.rpi.legup.puzzle.skyscrapers; import edu.rpi.legup.ui.boardview.ElementView; - import java.awt.*; public class SkyscrapersClueView extends ElementView { diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersController.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersController.java index 8e338a351..f78774e35 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersController.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersController.java @@ -2,7 +2,6 @@ import edu.rpi.legup.controller.ElementController; import edu.rpi.legup.model.gameboard.PuzzleElement; - import java.awt.event.MouseEvent; public class SkyscrapersController extends ElementController { @@ -18,18 +17,15 @@ public void changeCell(MouseEvent e, PuzzleElement element) { if (cell.getData() < cell.getMax()) { int num = cell.getData() + 1; cell.setData(num); - } - else { + } else { cell.setData(SkyscrapersType.UNKNOWN.toValue()); } - } - else { + } else { if (e.getButton() == MouseEvent.BUTTON3) { if (cell.getData() > 0) { int num = cell.getData() - 1; cell.setData(num); - } - else { + } else { cell.setData(cell.getMax()); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersElementView.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersElementView.java index 9884b4a3c..2f33017c3 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersElementView.java @@ -1,7 +1,6 @@ package edu.rpi.legup.puzzle.skyscrapers; import edu.rpi.legup.ui.boardview.GridElementView; - import java.awt.*; public class SkyscrapersElementView extends GridElementView { @@ -30,7 +29,8 @@ public void drawElement(Graphics2D graphics2D) { FontMetrics metrics = graphics2D.getFontMetrics(FONT); String value = String.valueOf(val); int xText = location.x + (size.width - metrics.stringWidth(value)) / 2; - int yText = location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent(); + int yText = + location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent(); graphics2D.drawString(value, xText, yText); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java index f784fb2d9..75d2bd04f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java @@ -15,8 +15,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { SkyscrapersBoard board; if (puzzle.getTree() != null) { board = (SkyscrapersBoard) puzzle.getTree().getRootNode().getBoard(); - } - else { + } else { board = (SkyscrapersBoard) puzzle.getBoardView().getBoard(); } @@ -27,7 +26,8 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { for (PuzzleElement puzzleElement : board.getPuzzleElements()) { SkyscrapersCell cell = (SkyscrapersCell) puzzleElement; if (cell.getData() != 0) { - org.w3c.dom.Element cellElement = puzzle.getFactory().exportCell(newDocument, puzzleElement); + org.w3c.dom.Element cellElement = + puzzle.getFactory().exportCell(newDocument, puzzleElement); cellsElement.appendChild(cellElement); } } @@ -35,29 +35,33 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { org.w3c.dom.Element axisEast = newDocument.createElement("axis"); axisEast.setAttribute("side", "east"); - for (int i=0; i northClues; private ArrayList eastClues; @@ -34,7 +33,8 @@ public SkyscrapersView(SkyscrapersBoard board) { SkyscrapersElementView elementView = new SkyscrapersElementView(cell); elementView.setIndex(cell.getIndex()); elementView.setSize(elementSize); - elementView.setLocation(new Point((loc.x + 1) * elementSize.width, (loc.y + 1) * elementSize.height)); + elementView.setLocation( + new Point((loc.x + 1) * elementSize.width, (loc.y + 1) * elementSize.height)); elementViews.add(elementView); } @@ -44,7 +44,10 @@ public SkyscrapersView(SkyscrapersBoard board) { row.setSize(elementSize); SkyscrapersClueView clue = new SkyscrapersClueView(board.getEastClues().get(i)); - clue.setLocation(new Point((gridSize.height + 1) * elementSize.height, (i + 1) * elementSize.height)); + clue.setLocation( + new Point( + (gridSize.height + 1) * elementSize.height, + (i + 1) * elementSize.height)); clue.setSize(elementSize); westClues.add(row); @@ -57,7 +60,9 @@ public SkyscrapersView(SkyscrapersBoard board) { col.setSize(elementSize); SkyscrapersClueView clue = new SkyscrapersClueView(board.getSouthClues().get(i)); - clue.setLocation(new Point((i + 1) * elementSize.width, (gridSize.width + 1) * elementSize.width)); + clue.setLocation( + new Point( + (i + 1) * elementSize.width, (gridSize.width + 1) * elementSize.width)); clue.setSize(elementSize); northClues.add(col); @@ -66,15 +71,18 @@ public SkyscrapersView(SkyscrapersBoard board) { } /** - * Gets the ElementView from the location specified or - * null if one does not exists at that location + * Gets the ElementView from the location specified or null if one does not exists at that + * location * * @param point location on the viewport * @return ElementView at the specified location */ @Override public ElementView getElement(Point point) { - Point scaledPoint = new Point((int) Math.round(point.x / getScale()), (int) Math.round(point.y / getScale())); + Point scaledPoint = + new Point( + (int) Math.round(point.x / getScale()), + (int) Math.round(point.y / getScale())); for (ElementView element : elementViews) { if (element.isWithinBounds(scaledPoint)) { return element; @@ -131,10 +139,10 @@ public void setBoard(Board board) { if (board instanceof CaseBoard) { setCasePickable(); - } - else { + } else { for (ElementView elementView : elementViews) { - elementView.setPuzzleElement(board.getPuzzleElement(elementView.getPuzzleElement())); + elementView.setPuzzleElement( + board.getPuzzleElement(elementView.getPuzzleElement())); elementView.setShowCasePicker(false); } for (SkyscrapersClueView clueView : northClues) { @@ -155,7 +163,8 @@ protected void setCasePickable() { Board baseBoard = caseBoard.getBaseBoard(); for (ElementView elementView : elementViews) { - PuzzleElement puzzleElement = baseBoard.getPuzzleElement(elementView.getPuzzleElement()); + PuzzleElement puzzleElement = + baseBoard.getPuzzleElement(elementView.getPuzzleElement()); elementView.setPuzzleElement(puzzleElement); elementView.setShowCasePicker(true); elementView.setCaseRulePickable(caseBoard.isPickable(puzzleElement, null)); diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/ClueTile.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/ClueTile.java index 8505de523..64c9033e6 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/ClueTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/ClueTile.java @@ -5,6 +5,10 @@ public class ClueTile extends NonPlaceableElement { public ClueTile() { - super("SKYS-UNPL-0003", "Clue Tile", "Clue Updater", "edu/rpi/legup/images/skyscrapers/tiles/ClueTile.png"); + super( + "SKYS-UNPL-0003", + "Clue Tile", + "Clue Updater", + "edu/rpi/legup/images/skyscrapers/tiles/ClueTile.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/NumberTile.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/NumberTile.java index 8f78fb1cf..4d6b37c9a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/NumberTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/NumberTile.java @@ -4,6 +4,10 @@ public class NumberTile extends NonPlaceableElement { public NumberTile() { - super("SKYS-UNPL-0002", "Number Tile", "A numbered tile", "edu/rpi/legup/images/skyscrapers/tiles/ClueTile.png"); + super( + "SKYS-UNPL-0002", + "Number Tile", + "A numbered tile", + "edu/rpi/legup/images/skyscrapers/tiles/ClueTile.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/UnknownTile.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/UnknownTile.java index 3559dc332..2fb21193a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/UnknownTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/elements/UnknownTile.java @@ -4,6 +4,10 @@ public class UnknownTile extends NonPlaceableElement { public UnknownTile() { - super("SKYS-UNPL-0001", "Unknown", "A blank tile", "edu/rpi/legup/images/skyscrapers/tiles/UnknownTile.png"); + super( + "SKYS-UNPL-0001", + "Unknown", + "A blank tile", + "edu/rpi/legup/images/skyscrapers/tiles/UnknownTile.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/CellForNumberCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/CellForNumberCaseRule.java index 01527294a..45bdadea3 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/CellForNumberCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/CellForNumberCaseRule.java @@ -6,18 +6,16 @@ import edu.rpi.legup.model.rules.CaseRule; import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.skyscrapers.*; -import org.apache.commons.lang3.ObjectUtils; - -import javax.swing.*; import java.awt.*; import java.util.ArrayList; import java.util.List; -import java.util.Set; -import java.util.TreeSet; +import javax.swing.*; public class CellForNumberCaseRule extends CaseRule { public CellForNumberCaseRule() { - super("SKYS-CASE-0002", "Cell For Number", + super( + "SKYS-CASE-0002", + "Cell For Number", "A number (1-n) must appear in any given row/column", "edu/rpi/legup/images/skyscrapers/cases/CellForNumber.png"); } @@ -30,15 +28,15 @@ public CaseBoard getCaseBoard(Board board) { currentBoard.setModifiable(false); CaseBoard caseBoard = new CaseBoard(currentBoard, this); for (SkyscrapersClue data : currentBoard.getWestClues()) { - //System.out.println(data.getType()); + // System.out.println(data.getType()); caseBoard.addPickableElement(data); } for (SkyscrapersClue data : currentBoard.getNorthClues()) { - //System.out.println(data.getType()); + // System.out.println(data.getType()); caseBoard.addPickableElement(data); } - //selects integer before checking Command.canExecute for use in Command.getErrorString + // selects integer before checking Command.canExecute for use in Command.getErrorString int size = ((SkyscrapersBoard) board).getWidth(); Object[] possibleValues = new Object[size]; for (int i = 0; i < size; i++) { @@ -46,12 +44,16 @@ public CaseBoard getCaseBoard(Board board) { } Object selectedValue; do { - selectedValue = JOptionPane.showInputDialog(null, - "Pick the number to be added", "Cell For Number", - JOptionPane.INFORMATION_MESSAGE, null, - possibleValues, possibleValues[0]); - } - while (selectedValue == null); + selectedValue = + JOptionPane.showInputDialog( + null, + "Pick the number to be added", + "Cell For Number", + JOptionPane.INFORMATION_MESSAGE, + null, + possibleValues, + possibleValues[0]); + } while (selectedValue == null); selectedNumber = (Integer) selectedValue; return caseBoard; @@ -63,28 +65,31 @@ public ArrayList getCasesFor(Board board, PuzzleElement puzzleElement, In SkyscrapersClue clue = (SkyscrapersClue) puzzleElement; SkyscrapersBoard skyscrapersboard = (SkyscrapersBoard) board; - List openCells = skyscrapersboard.getRowCol(clue.getClueIndex(), SkyscrapersType.UNKNOWN, clue.getType() == SkyscrapersType.CLUE_WEST); + List openCells = + skyscrapersboard.getRowCol( + clue.getClueIndex(), + SkyscrapersType.UNKNOWN, + clue.getType() == SkyscrapersType.CLUE_WEST); for (SkyscrapersCell cell : openCells) { SkyscrapersBoard newCase = skyscrapersboard.copy(); PuzzleElement newCell = newCase.getPuzzleElement(cell); newCell.setData(number); newCase.addModifiedData(newCell); - //if flags + // if flags boolean passed = true; if (skyscrapersboard.getDupeFlag()) { DuplicateNumberContradictionRule DupeRule = new DuplicateNumberContradictionRule(); passed = passed && DupeRule.checkContradictionAt(newCase, newCell) != null; } if (skyscrapersboard.getViewFlag()) { - PreemptiveVisibilityContradictionRule ViewRule = new PreemptiveVisibilityContradictionRule(); + PreemptiveVisibilityContradictionRule ViewRule = + new PreemptiveVisibilityContradictionRule(); passed = passed && ViewRule.checkContradictionAt(newCase, newCell) != null; } if (passed) { cases.add(newCase); } - - } return cases; } @@ -102,20 +107,33 @@ public String checkRuleRaw(TreeTransition transition) { return "This case rule must have at least one child."; } - if (childTransitions.size() != getCasesFor(oldBoard, oldBoard.getPuzzleElement(transition.getSelection()), (Integer) childTransitions.get(0).getBoard().getModifiedData().iterator().next().getData()).size()) { - //System.out.println("Wrong number of cases."); + if (childTransitions.size() + != getCasesFor( + oldBoard, + oldBoard.getPuzzleElement(transition.getSelection()), + (Integer) + childTransitions + .get(0) + .getBoard() + .getModifiedData() + .iterator() + .next() + .getData()) + .size()) { + // System.out.println("Wrong number of cases."); return "Wrong number of cases."; } for (TreeTransition newTree : childTransitions) { SkyscrapersBoard newBoard = (SkyscrapersBoard) newTree.getBoard(); if (newBoard.getModifiedData().size() != 1) { - //System.out.println("Only one cell should be modified."); + // System.out.println("Only one cell should be modified."); return "Only one cell should be modified."; } - SkyscrapersCell newCell = (SkyscrapersCell) newBoard.getModifiedData().iterator().next(); + SkyscrapersCell newCell = + (SkyscrapersCell) newBoard.getModifiedData().iterator().next(); if (newCell.getType() != SkyscrapersType.Number) { - //System.out.println("Changed value should be a number."); + // System.out.println("Changed value should be a number."); return "Changed value should be a number."; } } @@ -128,37 +146,45 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem } /** - * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid - * Overridden by case rules dependent on more than just the modified data + * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be + * valid Overridden by case rules dependent on more than just the modified data * - * @param board board state at application + * @param board board state at application * @param puzzleElement selected puzzleElement - * @return List of puzzle elements (typically cells) this application of the case rule depends upon. - * Defaults to any element modified by any case + * @return List of puzzle elements (typically cells) this application of the case rule depends + * upon. Defaults to any element modified by any case */ @Override public List dependentElements(Board board, PuzzleElement puzzleElement) { List elements = new ArrayList<>(); SkyscrapersBoard puzzleBoard = (SkyscrapersBoard) board; - SkyscrapersClue clue = (SkyscrapersClue)puzzleBoard.getPuzzleElement(puzzleElement); + SkyscrapersClue clue = (SkyscrapersClue) puzzleBoard.getPuzzleElement(puzzleElement); // check each point in modified row/col - List data = puzzleBoard.getRowCol(clue.getClueIndex(),SkyscrapersType.ANY,clue.getType() == SkyscrapersType.CLUE_WEST); + List data = + puzzleBoard.getRowCol( + clue.getClueIndex(), + SkyscrapersType.ANY, + clue.getType() == SkyscrapersType.CLUE_WEST); for (SkyscrapersCell point : data) { List cells = new ArrayList<>(List.of(point)); // if dependent on row/col - if ((puzzleBoard.getDupeFlag() || puzzleBoard.getViewFlag()) && point.getType() == SkyscrapersType.UNKNOWN) { + if ((puzzleBoard.getDupeFlag() || puzzleBoard.getViewFlag()) + && point.getType() == SkyscrapersType.UNKNOWN) { // get perpendicular row/col intersecting this point int index; if (clue.getType() == SkyscrapersType.CLUE_WEST) { index = point.getLocation().x; - } - else { + } else { index = point.getLocation().y; } - cells.addAll(puzzleBoard.getRowCol(index,SkyscrapersType.ANY,clue.getType() != SkyscrapersType.CLUE_WEST)); + cells.addAll( + puzzleBoard.getRowCol( + index, + SkyscrapersType.ANY, + clue.getType() != SkyscrapersType.CLUE_WEST)); } // add all to result 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 620a87f68..b13a62bc6 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 @@ -6,7 +6,6 @@ import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType; - import java.awt.*; import java.util.HashSet; import java.util.Set; @@ -14,18 +13,21 @@ public class DuplicateNumberContradictionRule extends ContradictionRule { public DuplicateNumberContradictionRule() { - super("SKYS-CONT-0001", "Duplicate Number", + super( + "SKYS-CONT-0001", + "Duplicate Number", "Skyscrapers of same height cannot be placed in the same row or column.", "edu/rpi/legup/images/skyscrapers/contradictions/DuplicateNumber.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { @@ -35,12 +37,15 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { Set candidates = new HashSet(); - //check row + // check row for (int i = 0; i < skyscrapersboard.getWidth(); i++) { SkyscrapersCell c = skyscrapersboard.getCell(i, loc.y); - if (i != loc.x && cell.getType() == SkyscrapersType.Number && c.getType() == SkyscrapersType.Number && c.getData() == cell.getData()) { - //System.out.print(c.getData()); - //System.out.println(cell.getData()); + if (i != loc.x + && cell.getType() == SkyscrapersType.Number + && c.getType() == SkyscrapersType.Number + && c.getData() == cell.getData()) { + // System.out.print(c.getData()); + // System.out.println(cell.getData()); return null; } } @@ -48,9 +53,12 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { // check column for (int i = 0; i < skyscrapersboard.getHeight(); i++) { SkyscrapersCell c = skyscrapersboard.getCell(loc.x, i); - if (i != loc.y && cell.getType() == SkyscrapersType.Number && c.getType() == SkyscrapersType.Number && c.getData() == cell.getData()) { - //System.out.print(c.getData()); - //System.out.println(cell.getData()); + if (i != loc.y + && cell.getType() == SkyscrapersType.Number + && c.getType() == SkyscrapersType.Number + && c.getData() == cell.getData()) { + // System.out.print(c.getData()); + // System.out.println(cell.getData()); return null; } } 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 e38018745..742bdb253 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 @@ -6,28 +6,28 @@ import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType; - import java.awt.*; import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; public class ExceedingVisibilityContradictionRule extends ContradictionRule { public ExceedingVisibilityContradictionRule() { - super("SKYS-CONT-0002", "Exceeding Visibility", + super( + "SKYS-CONT-0002", + "Exceeding Visibility", "More skyscrapers are visible than there should be.", "edu/rpi/legup/images/skyscrapers/contradictions/ExceedingVisibility.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { @@ -35,22 +35,22 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { SkyscrapersBoard skyscrapersboard = (SkyscrapersBoard) board; Point loc = cell.getLocation(); - //get borders + // get borders int west = skyscrapersboard.getWestClues().get(loc.y).getData(); int east = skyscrapersboard.getEastClues().get(loc.y).getData(); int north = skyscrapersboard.getNorthClues().get(loc.x).getData(); int south = skyscrapersboard.getSouthClues().get(loc.x).getData(); - //check row + // check row int max = 0; int count = 0; List row = skyscrapersboard.getRowCol(loc.y, SkyscrapersType.Number, true); if (row.size() == skyscrapersboard.getWidth()) { - //from west border + // from west border for (SkyscrapersCell c : row) { if (c.getData() > max) { - //System.out.print(c.getData()); - //System.out.println(cell.getData()); + // System.out.print(c.getData()); + // System.out.println(cell.getData()); max = c.getData(); count++; } @@ -61,12 +61,12 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { max = 0; count = 0; - //from east border + // from east border Collections.reverse(row); for (SkyscrapersCell c : row) { if (c.getData() > max) { - //System.out.print(c.getData()); - //System.out.println(cell.getData()); + // System.out.print(c.getData()); + // System.out.println(cell.getData()); max = c.getData(); count++; } @@ -76,17 +76,18 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { } } - //check column - List col = skyscrapersboard.getRowCol(loc.x, SkyscrapersType.Number, false); + // check column + List col = + skyscrapersboard.getRowCol(loc.x, SkyscrapersType.Number, false); if (col.size() == skyscrapersboard.getHeight()) { - //from north border + // from north border max = 0; count = 0; for (SkyscrapersCell c : col) { - //System.out.println(c.getData()); + // System.out.println(c.getData()); if (c.getData() > max) { - //System.out.println(cell.getData()); + // System.out.println(cell.getData()); max = c.getData(); count++; } @@ -95,15 +96,15 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { return null; } - //from south border + // from south border max = 0; count = 0; Collections.reverse(col); for (SkyscrapersCell c : col) { - //System.out.println(c.getData()); + // System.out.println(c.getData()); if (c.getData() > max) { - //System.out.println(cell.getData()); + // System.out.println(cell.getData()); max = c.getData(); count++; } @@ -113,7 +114,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { } } - //System.out.print("Does not contain a contradiction at this index"); + // System.out.print("Does not contain a contradiction at this index"); return super.getNoContradictionMessage(); } @@ -127,7 +128,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { public String checkContradiction(Board board) { SkyscrapersBoard skyscrapersBoard = (SkyscrapersBoard) board; for (int i = 0; i < skyscrapersBoard.getWidth(); i++) { - //checks the middle diagonal (checkContradictionAt checks row/col off each) + // checks the middle diagonal (checkContradictionAt checks row/col off each) String checkStr = checkContradictionAt(board, skyscrapersBoard.getCell(i, i)); if (checkStr == null) { return checkStr; @@ -135,5 +136,4 @@ public String checkContradiction(Board board) { } return "No instance of the contradiction " + this.ruleName + " here"; } - } 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 7d405f122..fa7c9074e 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 @@ -6,28 +6,28 @@ import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType; - import java.awt.*; import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; public class InsufficientVisibilityContradictionRule extends ContradictionRule { public InsufficientVisibilityContradictionRule() { - super("SKYS-CONT-0003", "Insufficient Visibility", + super( + "SKYS-CONT-0003", + "Insufficient Visibility", "Less skyscrapers are visible than there should be.", "edu/rpi/legup/images/skyscrapers/contradictions/InsufficientVisibility.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { @@ -35,22 +35,23 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { SkyscrapersBoard skyscrapersboard = (SkyscrapersBoard) board; Point loc = cell.getLocation(); - //get borders + // get borders int west = skyscrapersboard.getWestClues().get(loc.y).getData(); int east = skyscrapersboard.getEastClues().get(loc.y).getData(); int north = skyscrapersboard.getNorthClues().get(loc.x).getData(); int south = skyscrapersboard.getSouthClues().get(loc.x).getData(); - //check row + // check row int max = 0; int count = 0; - java.util.List row = skyscrapersboard.getRowCol(loc.y, SkyscrapersType.Number, true); + java.util.List row = + skyscrapersboard.getRowCol(loc.y, SkyscrapersType.Number, true); if (row.size() == skyscrapersboard.getWidth()) { - //from west border + // from west border for (SkyscrapersCell c : row) { if (c.getData() > max) { - //System.out.print(c.getData()); - //System.out.println(cell.getData()); + // System.out.print(c.getData()); + // System.out.println(cell.getData()); max = c.getData(); count++; } @@ -61,12 +62,12 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { max = 0; count = 0; - //from east border + // from east border Collections.reverse(row); for (SkyscrapersCell c : row) { if (c.getData() > max) { - //System.out.print(c.getData()); - //System.out.println(cell.getData()); + // System.out.print(c.getData()); + // System.out.println(cell.getData()); max = c.getData(); count++; } @@ -76,17 +77,18 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { } } - //check column - List col = skyscrapersboard.getRowCol(loc.x, SkyscrapersType.Number, false); + // check column + List col = + skyscrapersboard.getRowCol(loc.x, SkyscrapersType.Number, false); if (col.size() == skyscrapersboard.getHeight()) { - //from north border + // from north border max = 0; count = 0; for (SkyscrapersCell c : col) { - //System.out.println(c.getData()); + // System.out.println(c.getData()); if (c.getData() > max) { - //System.out.println(cell.getData()); + // System.out.println(cell.getData()); max = c.getData(); count++; } @@ -95,15 +97,15 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { return null; } - //from south border + // from south border max = 0; count = 0; Collections.reverse(col); for (SkyscrapersCell c : col) { - //System.out.println(c.getData()); + // System.out.println(c.getData()); if (c.getData() > max) { - //System.out.println(cell.getData()); + // System.out.println(cell.getData()); max = c.getData(); count++; } @@ -113,7 +115,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { } } - //System.out.print("Does not contain a contradiction at this index"); + // System.out.print("Does not contain a contradiction at this index"); return super.getNoContradictionMessage(); } @@ -127,7 +129,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { public String checkContradiction(Board board) { SkyscrapersBoard skyscrapersBoard = (SkyscrapersBoard) board; for (int i = 0; i < skyscrapersBoard.getWidth(); i++) { - //checks the middle diagonal (checkContradictionAt checks row/col off each) + // checks the middle diagonal (checkContradictionAt checks row/col off each) String checkStr = checkContradictionAt(board, skyscrapersBoard.getCell(i, i)); if (checkStr == null) { return checkStr; diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastSingularCellDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastSingularCellDirectRule.java index 2cede4117..391448781 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastSingularCellDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastSingularCellDirectRule.java @@ -1,114 +1,129 @@ -package edu.rpi.legup.puzzle.skyscrapers.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType; - -import java.util.ArrayList; - -public class LastSingularCellDirectRule extends DirectRule { - - public LastSingularCellDirectRule() { - super("SKYS-BASC-0002", "Last Cell for Number", - "There is only one cell on this row/col for this number that does not create a duplicate contradiction", - "edu/rpi/legup/images/skyscrapers/rules/LastCell.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement index of the puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - SkyscrapersBoard initialBoard = (SkyscrapersBoard) transition.getParents().get(0).getBoard(); - SkyscrapersCell initCell = (SkyscrapersCell) initialBoard.getPuzzleElement(puzzleElement); - SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); - SkyscrapersCell finalCell = (SkyscrapersCell) finalBoard.getPuzzleElement(puzzleElement); - if (!(initCell.getType() == SkyscrapersType.UNKNOWN && finalCell.getType() == SkyscrapersType.Number)) { - return super.getInvalidUseOfRuleMessage() + ": Modified cells must be number"; - } - - //set all rules used by case rule to false except for dupe, get all cases - boolean dupeTemp = initialBoard.getDupeFlag(); - boolean viewTemp = initialBoard.getViewFlag(); - initialBoard.setDupeFlag(true); - initialBoard.setViewFlag(false); - CellForNumberCaseRule caseRule = new CellForNumberCaseRule(); - ArrayList XCandidates = caseRule.getCasesFor(initialBoard, initialBoard.getWestClues().get(finalCell.getLocation().y), (Integer) finalCell.getData()); - ArrayList YCandidates = caseRule.getCasesFor(initialBoard, initialBoard.getNorthClues().get(finalCell.getLocation().x), (Integer) finalCell.getData()); - initialBoard.setDupeFlag(dupeTemp); - initialBoard.setViewFlag(viewTemp); - - //System.out.println(XCandidates.size()); - //System.out.println(YCandidates.size()); - - //return null if either pass, both messages otherwise - String xCheck = candidateCheck(XCandidates, puzzleElement, finalCell); - String yCheck = candidateCheck(YCandidates, puzzleElement, finalCell); - if (xCheck == null || yCheck == null) { - return null; - } - return super.getInvalidUseOfRuleMessage() + "\nRow" + xCheck + "\nCol" + yCheck; - } - - //helper to check if candidate list is valid - private String candidateCheck(ArrayList candidates, PuzzleElement puzzleElement, SkyscrapersCell finalCell) { - if (candidates.size() == 1) { - if (((SkyscrapersCell) candidates.get(0).getPuzzleElement(puzzleElement)).getType() == SkyscrapersType.Number) { - if (candidates.get(0).getPuzzleElement(puzzleElement).getData() == finalCell.getData()) { - return null; - } - return ": Wrong number in the cell."; - } - return ": No case for this cell."; - } - return ": This cell is not forced."; - } - - private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { - SkyscrapersBoard emptyCase = board.copy(); - emptyCase.getPuzzleElement(cell).setData(SkyscrapersType.UNKNOWN.value); - DuplicateNumberContradictionRule duplicate = new DuplicateNumberContradictionRule(); - if (duplicate.checkContradictionAt(emptyCase, cell) == null) { - System.out.println("no contradiction ln"); - return true; - } - return false; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); - SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); - //System.out.println(lightUpBoard.getPuzzleElements().size()); - for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { - SkyscrapersCell cell = (SkyscrapersCell) element; - if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) { - //cell.setData(SkyscrapersType.BULB.value); - lightUpBoard.addModifiedData(cell); - } - } - if (lightUpBoard.getModifiedData().isEmpty()) { - return null; - } - else { - return lightUpBoard; - } - } -} +package edu.rpi.legup.puzzle.skyscrapers.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType; +import java.util.ArrayList; + +public class LastSingularCellDirectRule extends DirectRule { + + public LastSingularCellDirectRule() { + super( + "SKYS-BASC-0002", + "Last Cell for Number", + "There is only one cell on this row/col for this number that does not create a" + + " duplicate contradiction", + "edu/rpi/legup/images/skyscrapers/rules/LastCell.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement index of the puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + SkyscrapersBoard initialBoard = + (SkyscrapersBoard) transition.getParents().get(0).getBoard(); + SkyscrapersCell initCell = (SkyscrapersCell) initialBoard.getPuzzleElement(puzzleElement); + SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell finalCell = (SkyscrapersCell) finalBoard.getPuzzleElement(puzzleElement); + if (!(initCell.getType() == SkyscrapersType.UNKNOWN + && finalCell.getType() == SkyscrapersType.Number)) { + return super.getInvalidUseOfRuleMessage() + ": Modified cells must be number"; + } + + // set all rules used by case rule to false except for dupe, get all cases + boolean dupeTemp = initialBoard.getDupeFlag(); + boolean viewTemp = initialBoard.getViewFlag(); + initialBoard.setDupeFlag(true); + initialBoard.setViewFlag(false); + CellForNumberCaseRule caseRule = new CellForNumberCaseRule(); + ArrayList XCandidates = + caseRule.getCasesFor( + initialBoard, + initialBoard.getWestClues().get(finalCell.getLocation().y), + (Integer) finalCell.getData()); + ArrayList YCandidates = + caseRule.getCasesFor( + initialBoard, + initialBoard.getNorthClues().get(finalCell.getLocation().x), + (Integer) finalCell.getData()); + initialBoard.setDupeFlag(dupeTemp); + initialBoard.setViewFlag(viewTemp); + + // System.out.println(XCandidates.size()); + // System.out.println(YCandidates.size()); + + // return null if either pass, both messages otherwise + String xCheck = candidateCheck(XCandidates, puzzleElement, finalCell); + String yCheck = candidateCheck(YCandidates, puzzleElement, finalCell); + if (xCheck == null || yCheck == null) { + return null; + } + return super.getInvalidUseOfRuleMessage() + "\nRow" + xCheck + "\nCol" + yCheck; + } + + // helper to check if candidate list is valid + private String candidateCheck( + ArrayList candidates, PuzzleElement puzzleElement, SkyscrapersCell finalCell) { + if (candidates.size() == 1) { + if (((SkyscrapersCell) candidates.get(0).getPuzzleElement(puzzleElement)).getType() + == SkyscrapersType.Number) { + if (candidates.get(0).getPuzzleElement(puzzleElement).getData() + == finalCell.getData()) { + return null; + } + return ": Wrong number in the cell."; + } + return ": No case for this cell."; + } + return ": This cell is not forced."; + } + + private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { + SkyscrapersBoard emptyCase = board.copy(); + emptyCase.getPuzzleElement(cell).setData(SkyscrapersType.UNKNOWN.value); + DuplicateNumberContradictionRule duplicate = new DuplicateNumberContradictionRule(); + if (duplicate.checkContradictionAt(emptyCase, cell) == null) { + System.out.println("no contradiction ln"); + return true; + } + return false; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); + SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); + // System.out.println(lightUpBoard.getPuzzleElements().size()); + for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { + SkyscrapersCell cell = (SkyscrapersCell) element; + if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) { + // cell.setData(SkyscrapersType.BULB.value); + lightUpBoard.addModifiedData(cell); + } + } + if (lightUpBoard.getModifiedData().isEmpty()) { + return null; + } else { + return lightUpBoard; + } + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastSingularNumberDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastSingularNumberDirectRule.java index 280325190..fceee0cd1 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastSingularNumberDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastSingularNumberDirectRule.java @@ -1,97 +1,103 @@ -package edu.rpi.legup.puzzle.skyscrapers.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType; - -import java.util.ArrayList; - -public class LastSingularNumberDirectRule extends DirectRule { - - public LastSingularNumberDirectRule() { - super("SKYS-BASC-0003", "Last Number for Cell", - "There is only one number for this cell that does not create a duplicate contradiction", - "edu/rpi/legup/images/skyscrapers/rules/LastNumber.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement index of the puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - SkyscrapersBoard initialBoard = (SkyscrapersBoard) transition.getParents().get(0).getBoard(); - SkyscrapersCell initCell = (SkyscrapersCell) initialBoard.getPuzzleElement(puzzleElement); - SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); - SkyscrapersCell finalCell = (SkyscrapersCell) finalBoard.getPuzzleElement(puzzleElement); - if (initCell.getType() != SkyscrapersType.UNKNOWN || finalCell.getType() != SkyscrapersType.Number) { - return super.getInvalidUseOfRuleMessage() + ": Modified cells must transition from unknown to number"; - } - - //set all rules used by case rule to false except for dupe, get all cases - boolean dupeTemp = initialBoard.getDupeFlag(); - boolean viewTemp = initialBoard.getViewFlag(); - initialBoard.setDupeFlag(true); - initialBoard.setViewFlag(false); - NumberForCellCaseRule caseRule = new NumberForCellCaseRule(); - ArrayList candidates = caseRule.getCases(initialBoard, puzzleElement); - initialBoard.setDupeFlag(dupeTemp); - initialBoard.setViewFlag(viewTemp); - - //check if given value is the only remaining value - if (candidates.size() == 1) { - if (candidates.get(0).getPuzzleElement(puzzleElement).getData() == finalCell.getData()) { - return null; - } - return super.getInvalidUseOfRuleMessage() + ": Wrong number in the cell."; - } - return super.getInvalidUseOfRuleMessage() + ":This cell is not forced."; - } - - private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { - SkyscrapersBoard emptyCase = board.copy(); - emptyCase.getPuzzleElement(cell).setData(SkyscrapersType.UNKNOWN.value); - DuplicateNumberContradictionRule duplicate = new DuplicateNumberContradictionRule(); - if (duplicate.checkContradictionAt(emptyCase, cell) == null) { - System.out.println("no contradiction ln"); - return true; - } - return false; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); - SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); - //System.out.println(lightUpBoard.getPuzzleElements().size()); - for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { - SkyscrapersCell cell = (SkyscrapersCell) element; - if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) { - //cell.setData(SkyscrapersType.BULB.value); - lightUpBoard.addModifiedData(cell); - } - } - if (lightUpBoard.getModifiedData().isEmpty()) { - return null; - } - else { - return lightUpBoard; - } - } -} +package edu.rpi.legup.puzzle.skyscrapers.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType; +import java.util.ArrayList; + +public class LastSingularNumberDirectRule extends DirectRule { + + public LastSingularNumberDirectRule() { + super( + "SKYS-BASC-0003", + "Last Number for Cell", + "There is only one number for this cell that does not create a duplicate" + + " contradiction", + "edu/rpi/legup/images/skyscrapers/rules/LastNumber.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement index of the puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + SkyscrapersBoard initialBoard = + (SkyscrapersBoard) transition.getParents().get(0).getBoard(); + SkyscrapersCell initCell = (SkyscrapersCell) initialBoard.getPuzzleElement(puzzleElement); + SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell finalCell = (SkyscrapersCell) finalBoard.getPuzzleElement(puzzleElement); + if (initCell.getType() != SkyscrapersType.UNKNOWN + || finalCell.getType() != SkyscrapersType.Number) { + return super.getInvalidUseOfRuleMessage() + + ": Modified cells must transition from unknown to number"; + } + + // set all rules used by case rule to false except for dupe, get all cases + boolean dupeTemp = initialBoard.getDupeFlag(); + boolean viewTemp = initialBoard.getViewFlag(); + initialBoard.setDupeFlag(true); + initialBoard.setViewFlag(false); + NumberForCellCaseRule caseRule = new NumberForCellCaseRule(); + ArrayList candidates = caseRule.getCases(initialBoard, puzzleElement); + initialBoard.setDupeFlag(dupeTemp); + initialBoard.setViewFlag(viewTemp); + + // check if given value is the only remaining value + if (candidates.size() == 1) { + if (candidates.get(0).getPuzzleElement(puzzleElement).getData() + == finalCell.getData()) { + return null; + } + return super.getInvalidUseOfRuleMessage() + ": Wrong number in the cell."; + } + return super.getInvalidUseOfRuleMessage() + ":This cell is not forced."; + } + + private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { + SkyscrapersBoard emptyCase = board.copy(); + emptyCase.getPuzzleElement(cell).setData(SkyscrapersType.UNKNOWN.value); + DuplicateNumberContradictionRule duplicate = new DuplicateNumberContradictionRule(); + if (duplicate.checkContradictionAt(emptyCase, cell) == null) { + System.out.println("no contradiction ln"); + return true; + } + return false; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); + SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); + // System.out.println(lightUpBoard.getPuzzleElements().size()); + for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { + SkyscrapersCell cell = (SkyscrapersCell) element; + if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) { + // cell.setData(SkyscrapersType.BULB.value); + lightUpBoard.addModifiedData(cell); + } + } + if (lightUpBoard.getModifiedData().isEmpty()) { + return null; + } else { + return lightUpBoard; + } + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastVisibleCellDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastVisibleCellDirectRule.java index 3aa28bab8..a853c657d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastVisibleCellDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastVisibleCellDirectRule.java @@ -1,116 +1,132 @@ -package edu.rpi.legup.puzzle.skyscrapers.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType; - -import java.util.ArrayList; - -public class LastVisibleCellDirectRule extends DirectRule { - - public LastVisibleCellDirectRule() { - super("SKYS-BASC-0001", "Last Visible Cell", - "There is only one cell on this row/col for this number that does not create a visibility contradiction", - "edu/rpi/legup/images/skyscrapers/rules/FixedMax.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement index of the puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - //last cell for number based on preemptive visibility rules - SkyscrapersBoard initialBoard = (SkyscrapersBoard) transition.getParents().get(0).getBoard(); - SkyscrapersCell initCell = (SkyscrapersCell) initialBoard.getPuzzleElement(puzzleElement); - SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); - SkyscrapersCell finalCell = (SkyscrapersCell) finalBoard.getPuzzleElement(puzzleElement); - if (initCell.getType() != SkyscrapersType.UNKNOWN || finalCell.getType() != SkyscrapersType.Number) { - return super.getInvalidUseOfRuleMessage() + ": Modified cells must transition from unknown to number"; - } - - //set all rules used by case rule to false except for dupe, get all cases - boolean dupeTemp = initialBoard.getDupeFlag(); - boolean viewTemp = initialBoard.getViewFlag(); - initialBoard.setDupeFlag(false); - initialBoard.setViewFlag(true); - CellForNumberCaseRule caseRule = new CellForNumberCaseRule(); - ArrayList XCandidates = caseRule.getCasesFor(initialBoard, initialBoard.getWestClues().get(finalCell.getLocation().y), (Integer) finalCell.getData()); - ArrayList YCandidates = caseRule.getCasesFor(initialBoard, initialBoard.getNorthClues().get(finalCell.getLocation().x), (Integer) finalCell.getData()); - initialBoard.setDupeFlag(dupeTemp); - initialBoard.setViewFlag(viewTemp); - - //System.out.println(XCandidates.size()); - //System.out.println(YCandidates.size()); - - //return null if either pass, both messages otherwise - String xCheck = candidateCheck(XCandidates, puzzleElement, finalCell); - String yCheck = candidateCheck(YCandidates, puzzleElement, finalCell); - if (xCheck == null || yCheck == null) { - return null; - } - return super.getInvalidUseOfRuleMessage() + "\nRow" + xCheck + "\nCol" + yCheck; - } - - //helper to check if candidate list is valid - private String candidateCheck(ArrayList candidates, PuzzleElement puzzleElement, SkyscrapersCell finalCell) { - if (candidates.size() == 1) { - if (((SkyscrapersCell) candidates.get(0).getPuzzleElement(puzzleElement)).getType() == SkyscrapersType.Number) { - if (candidates.get(0).getPuzzleElement(puzzleElement).getData() == finalCell.getData()) { - return null; - } - return ": Wrong number in the cell."; - } - return ": No case for this cell."; - } - return ": This cell is not forced."; - } - - private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { - SkyscrapersBoard emptyCase = board.copy(); - emptyCase.getPuzzleElement(cell).setData(SkyscrapersType.UNKNOWN.value); - DuplicateNumberContradictionRule duplicate = new DuplicateNumberContradictionRule(); - if (duplicate.checkContradictionAt(emptyCase, cell) == null) { - System.out.println("no contradiction ln"); - return true; - } - return false; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); - SkyscrapersBoard modBoard = (SkyscrapersBoard) node.getBoard().copy(); - //System.out.println(modBoard.getPuzzleElements().size()); - for (PuzzleElement element : modBoard.getPuzzleElements()) { - SkyscrapersCell cell = (SkyscrapersCell) element; - if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) { - //cell.setData(SkyscrapersType.BULB.value); - modBoard.addModifiedData(cell); - } - } - //System.out.println(modBoard.getModifiedData().isEmpty()); - if (modBoard.getModifiedData().isEmpty()) { - return null; - } - else { - return modBoard; - } - } -} +package edu.rpi.legup.puzzle.skyscrapers.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType; +import java.util.ArrayList; + +public class LastVisibleCellDirectRule extends DirectRule { + + public LastVisibleCellDirectRule() { + super( + "SKYS-BASC-0001", + "Last Visible Cell", + "There is only one cell on this row/col for this number that does not create a" + + " visibility contradiction", + "edu/rpi/legup/images/skyscrapers/rules/FixedMax.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement index of the puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + // last cell for number based on preemptive visibility rules + SkyscrapersBoard initialBoard = + (SkyscrapersBoard) transition.getParents().get(0).getBoard(); + SkyscrapersCell initCell = (SkyscrapersCell) initialBoard.getPuzzleElement(puzzleElement); + SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell finalCell = (SkyscrapersCell) finalBoard.getPuzzleElement(puzzleElement); + if (initCell.getType() != SkyscrapersType.UNKNOWN + || finalCell.getType() != SkyscrapersType.Number) { + return super.getInvalidUseOfRuleMessage() + + ": Modified cells must transition from unknown to number"; + } + + // set all rules used by case rule to false except for dupe, get all cases + boolean dupeTemp = initialBoard.getDupeFlag(); + boolean viewTemp = initialBoard.getViewFlag(); + initialBoard.setDupeFlag(false); + initialBoard.setViewFlag(true); + CellForNumberCaseRule caseRule = new CellForNumberCaseRule(); + ArrayList XCandidates = + caseRule.getCasesFor( + initialBoard, + initialBoard.getWestClues().get(finalCell.getLocation().y), + (Integer) finalCell.getData()); + ArrayList YCandidates = + caseRule.getCasesFor( + initialBoard, + initialBoard.getNorthClues().get(finalCell.getLocation().x), + (Integer) finalCell.getData()); + initialBoard.setDupeFlag(dupeTemp); + initialBoard.setViewFlag(viewTemp); + + // System.out.println(XCandidates.size()); + // System.out.println(YCandidates.size()); + + // return null if either pass, both messages otherwise + String xCheck = candidateCheck(XCandidates, puzzleElement, finalCell); + String yCheck = candidateCheck(YCandidates, puzzleElement, finalCell); + if (xCheck == null || yCheck == null) { + return null; + } + return super.getInvalidUseOfRuleMessage() + "\nRow" + xCheck + "\nCol" + yCheck; + } + + // helper to check if candidate list is valid + private String candidateCheck( + ArrayList candidates, PuzzleElement puzzleElement, SkyscrapersCell finalCell) { + if (candidates.size() == 1) { + if (((SkyscrapersCell) candidates.get(0).getPuzzleElement(puzzleElement)).getType() + == SkyscrapersType.Number) { + if (candidates.get(0).getPuzzleElement(puzzleElement).getData() + == finalCell.getData()) { + return null; + } + return ": Wrong number in the cell."; + } + return ": No case for this cell."; + } + return ": This cell is not forced."; + } + + private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { + SkyscrapersBoard emptyCase = board.copy(); + emptyCase.getPuzzleElement(cell).setData(SkyscrapersType.UNKNOWN.value); + DuplicateNumberContradictionRule duplicate = new DuplicateNumberContradictionRule(); + if (duplicate.checkContradictionAt(emptyCase, cell) == null) { + System.out.println("no contradiction ln"); + return true; + } + return false; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); + SkyscrapersBoard modBoard = (SkyscrapersBoard) node.getBoard().copy(); + // System.out.println(modBoard.getPuzzleElements().size()); + for (PuzzleElement element : modBoard.getPuzzleElements()) { + SkyscrapersCell cell = (SkyscrapersCell) element; + if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) { + // cell.setData(SkyscrapersType.BULB.value); + modBoard.addModifiedData(cell); + } + } + // System.out.println(modBoard.getModifiedData().isEmpty()); + if (modBoard.getModifiedData().isEmpty()) { + return null; + } else { + return modBoard; + } + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastVisibleNumberDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastVisibleNumberDirectRule.java index e5524418d..da1057b56 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastVisibleNumberDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/LastVisibleNumberDirectRule.java @@ -1,98 +1,104 @@ -package edu.rpi.legup.puzzle.skyscrapers.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType; - -import java.util.ArrayList; - -public class LastVisibleNumberDirectRule extends DirectRule { - - public LastVisibleNumberDirectRule() { - super("SKYS-BASC-0005", "Last Visible Number", - "There is only one number for this cell that does not create a visibility contradiction", - "edu/rpi/legup/images/skyscrapers/rules/OneEdge.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement index of the puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - //last number for cell based upon preemptive visibility rules - SkyscrapersBoard initialBoard = (SkyscrapersBoard) transition.getParents().get(0).getBoard(); - SkyscrapersCell initCell = (SkyscrapersCell) initialBoard.getPuzzleElement(puzzleElement); - SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); - SkyscrapersCell finalCell = (SkyscrapersCell) finalBoard.getPuzzleElement(puzzleElement); - if (initCell.getType() != SkyscrapersType.UNKNOWN || finalCell.getType() != SkyscrapersType.Number) { - return super.getInvalidUseOfRuleMessage() + ": Modified cells must transition from unknown to number"; - } - - //set all rules used by case rule to false except for dupe, get all cases - boolean dupeTemp = initialBoard.getDupeFlag(); - boolean viewTemp = initialBoard.getViewFlag(); - initialBoard.setDupeFlag(false); - initialBoard.setViewFlag(true); - NumberForCellCaseRule caseRule = new NumberForCellCaseRule(); - ArrayList candidates = caseRule.getCases(initialBoard, puzzleElement); - initialBoard.setDupeFlag(dupeTemp); - initialBoard.setViewFlag(viewTemp); - - //check if given value is the only remaining value - if (candidates.size() == 1) { - if (candidates.get(0).getPuzzleElement(puzzleElement).getData() == finalCell.getData()) { - return null; - } - return super.getInvalidUseOfRuleMessage() + ": Wrong number in the cell."; - } - return super.getInvalidUseOfRuleMessage() + ":This cell is not forced."; - } - - private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { - SkyscrapersBoard emptyCase = board.copy(); - emptyCase.getPuzzleElement(cell).setData(SkyscrapersType.UNKNOWN.value); - DuplicateNumberContradictionRule duplicate = new DuplicateNumberContradictionRule(); - if (duplicate.checkContradictionAt(emptyCase, cell) == null) { - System.out.println("no contradiction ln"); - return true; - } - return false; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); - SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); - //System.out.println(lightUpBoard.getPuzzleElements().size()); - for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { - SkyscrapersCell cell = (SkyscrapersCell) element; - if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) { - //cell.setData(SkyscrapersType.BULB.value); - lightUpBoard.addModifiedData(cell); - } - } - if (lightUpBoard.getModifiedData().isEmpty()) { - return null; - } - else { - return lightUpBoard; - } - } -} +package edu.rpi.legup.puzzle.skyscrapers.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType; +import java.util.ArrayList; + +public class LastVisibleNumberDirectRule extends DirectRule { + + public LastVisibleNumberDirectRule() { + super( + "SKYS-BASC-0005", + "Last Visible Number", + "There is only one number for this cell that does not create a visibility" + + " contradiction", + "edu/rpi/legup/images/skyscrapers/rules/OneEdge.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement index of the puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + // last number for cell based upon preemptive visibility rules + SkyscrapersBoard initialBoard = + (SkyscrapersBoard) transition.getParents().get(0).getBoard(); + SkyscrapersCell initCell = (SkyscrapersCell) initialBoard.getPuzzleElement(puzzleElement); + SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell finalCell = (SkyscrapersCell) finalBoard.getPuzzleElement(puzzleElement); + if (initCell.getType() != SkyscrapersType.UNKNOWN + || finalCell.getType() != SkyscrapersType.Number) { + return super.getInvalidUseOfRuleMessage() + + ": Modified cells must transition from unknown to number"; + } + + // set all rules used by case rule to false except for dupe, get all cases + boolean dupeTemp = initialBoard.getDupeFlag(); + boolean viewTemp = initialBoard.getViewFlag(); + initialBoard.setDupeFlag(false); + initialBoard.setViewFlag(true); + NumberForCellCaseRule caseRule = new NumberForCellCaseRule(); + ArrayList candidates = caseRule.getCases(initialBoard, puzzleElement); + initialBoard.setDupeFlag(dupeTemp); + initialBoard.setViewFlag(viewTemp); + + // check if given value is the only remaining value + if (candidates.size() == 1) { + if (candidates.get(0).getPuzzleElement(puzzleElement).getData() + == finalCell.getData()) { + return null; + } + return super.getInvalidUseOfRuleMessage() + ": Wrong number in the cell."; + } + return super.getInvalidUseOfRuleMessage() + ":This cell is not forced."; + } + + private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { + SkyscrapersBoard emptyCase = board.copy(); + emptyCase.getPuzzleElement(cell).setData(SkyscrapersType.UNKNOWN.value); + DuplicateNumberContradictionRule duplicate = new DuplicateNumberContradictionRule(); + if (duplicate.checkContradictionAt(emptyCase, cell) == null) { + System.out.println("no contradiction ln"); + return true; + } + return false; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); + SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); + // System.out.println(lightUpBoard.getPuzzleElements().size()); + for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { + SkyscrapersCell cell = (SkyscrapersCell) element; + if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) { + // cell.setData(SkyscrapersType.BULB.value); + lightUpBoard.addModifiedData(cell); + } + } + if (lightUpBoard.getModifiedData().isEmpty()) { + return null; + } else { + return lightUpBoard; + } + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NEdgeDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NEdgeDirectRule.java index 78533a819..bbc202e72 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NEdgeDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NEdgeDirectRule.java @@ -1,99 +1,106 @@ -package edu.rpi.legup.puzzle.skyscrapers.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType; - -import java.awt.Point; - -public class NEdgeDirectRule extends DirectRule { - - public NEdgeDirectRule() { - super("SKYS-BASC-0004", "N 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/rules/NEdge.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement index of the puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - SkyscrapersBoard initialBoard = (SkyscrapersBoard) transition.getParents().get(0).getBoard(); - SkyscrapersCell initCell = (SkyscrapersCell) initialBoard.getPuzzleElement(puzzleElement); - SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); - SkyscrapersCell finalCell = (SkyscrapersCell) finalBoard.getPuzzleElement(puzzleElement); - if (!(initCell.getType() == SkyscrapersType.UNKNOWN && finalCell.getType() == SkyscrapersType.Number)) { - return super.getInvalidUseOfRuleMessage() + ": Modified cells must be number"; - } - - SkyscrapersBoard emptyCase = initialBoard.copy(); - emptyCase.getPuzzleElement(finalCell).setData(SkyscrapersType.UNKNOWN.value); - Point loc = finalCell.getLocation(); - int max = initialBoard.getHeight(); - - if (initialBoard.getWestClues().get(loc.y).getData() == max && finalCell.getData() == loc.x + 1) { - return null; - } - if (initialBoard.getEastClues().get(loc.y).getData() == max && finalCell.getData() == max - loc.x) { - return null; - } - if (initialBoard.getNorthClues().get(loc.x).getData() == max && finalCell.getData() == loc.y + 1) { - return null; - } - if (initialBoard.getSouthClues().get(loc.x).getData() == max && finalCell.getData() == max - loc.y) { - return null; - } - - return super.getInvalidUseOfRuleMessage() + ": This cell is not forced."; - - } - - private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { - SkyscrapersBoard emptyCase = board.copy(); - emptyCase.getPuzzleElement(cell).setData(SkyscrapersType.UNKNOWN.value); - DuplicateNumberContradictionRule duplicate = new DuplicateNumberContradictionRule(); - if (duplicate.checkContradictionAt(emptyCase, cell) == null) { - System.out.println("no contradiction ln"); - return true; - } - return false; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); - SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); - //System.out.println(lightUpBoard.getPuzzleElements().size()); - for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { - SkyscrapersCell cell = (SkyscrapersCell) element; - if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) { - //cell.setData(SkyscrapersType.BULB.value); - lightUpBoard.addModifiedData(cell); - } - } - if (lightUpBoard.getModifiedData().isEmpty()) { - return null; - } - else { - return lightUpBoard; - } - } -} +package edu.rpi.legup.puzzle.skyscrapers.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; +import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType; +import java.awt.Point; + +public class NEdgeDirectRule extends DirectRule { + + public NEdgeDirectRule() { + super( + "SKYS-BASC-0004", + "N 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/rules/NEdge.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement index of the puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + SkyscrapersBoard initialBoard = + (SkyscrapersBoard) transition.getParents().get(0).getBoard(); + SkyscrapersCell initCell = (SkyscrapersCell) initialBoard.getPuzzleElement(puzzleElement); + SkyscrapersBoard finalBoard = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell finalCell = (SkyscrapersCell) finalBoard.getPuzzleElement(puzzleElement); + if (!(initCell.getType() == SkyscrapersType.UNKNOWN + && finalCell.getType() == SkyscrapersType.Number)) { + return super.getInvalidUseOfRuleMessage() + ": Modified cells must be number"; + } + + SkyscrapersBoard emptyCase = initialBoard.copy(); + emptyCase.getPuzzleElement(finalCell).setData(SkyscrapersType.UNKNOWN.value); + Point loc = finalCell.getLocation(); + int max = initialBoard.getHeight(); + + if (initialBoard.getWestClues().get(loc.y).getData() == max + && finalCell.getData() == loc.x + 1) { + return null; + } + if (initialBoard.getEastClues().get(loc.y).getData() == max + && finalCell.getData() == max - loc.x) { + return null; + } + if (initialBoard.getNorthClues().get(loc.x).getData() == max + && finalCell.getData() == loc.y + 1) { + return null; + } + if (initialBoard.getSouthClues().get(loc.x).getData() == max + && finalCell.getData() == max - loc.y) { + return null; + } + + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced."; + } + + private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) { + SkyscrapersBoard emptyCase = board.copy(); + emptyCase.getPuzzleElement(cell).setData(SkyscrapersType.UNKNOWN.value); + DuplicateNumberContradictionRule duplicate = new DuplicateNumberContradictionRule(); + if (duplicate.checkContradictionAt(emptyCase, cell) == null) { + System.out.println("no contradiction ln"); + return true; + } + return false; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard(); + SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy(); + // System.out.println(lightUpBoard.getPuzzleElements().size()); + for (PuzzleElement element : lightUpBoard.getPuzzleElements()) { + SkyscrapersCell cell = (SkyscrapersCell) element; + if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) { + // cell.setData(SkyscrapersType.BULB.value); + lightUpBoard.addModifiedData(cell); + } + } + if (lightUpBoard.getModifiedData().isEmpty()) { + return null; + } else { + return lightUpBoard; + } + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NumberForCellCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NumberForCellCaseRule.java index 02000cd6e..145dd6ee2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NumberForCellCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/NumberForCellCaseRule.java @@ -7,9 +7,7 @@ import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersClue; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType; - import java.awt.*; import java.util.ArrayList; import java.util.HashSet; @@ -19,7 +17,9 @@ public class NumberForCellCaseRule extends CaseRule { public NumberForCellCaseRule() { - super("SKYS-CASE-0001", "Number For Cell", + super( + "SKYS-CASE-0001", + "Number For Cell", "A blank cell must have height of 1 to n.", "edu/rpi/legup/images/skyscrapers/cases/NumberForCell.png"); } @@ -40,7 +40,7 @@ public CaseBoard getCaseBoard(Board board) { /** * Gets the possible cases at a specific location based on this case rule * - * @param board the current board state + * @param board the current board state * @param puzzleElement puzzleElement to determine the possible cases for * @return a list of elements the specified could be */ @@ -59,17 +59,18 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { newCell.setData(i); newCase.addModifiedData(newCell); - //if flags + // if flags boolean passed = true; if (skyscrapersboard.getDupeFlag()) { DuplicateNumberContradictionRule DupeRule = new DuplicateNumberContradictionRule(); passed = passed && DupeRule.checkContradictionAt(newCase, newCell) != null; } if (skyscrapersboard.getViewFlag()) { - PreemptiveVisibilityContradictionRule ViewRule = new PreemptiveVisibilityContradictionRule(); + PreemptiveVisibilityContradictionRule ViewRule = + new PreemptiveVisibilityContradictionRule(); passed = passed && ViewRule.checkContradictionAt(newCase, newCell) != null; } - //how should unresolved be handled? should it be? + // how should unresolved be handled? should it be? if (passed) { cases.add(newCase); } @@ -89,43 +90,55 @@ public String checkRuleRaw(TreeTransition transition) { List childTransitions = transition.getParents().get(0).getChildren(); if (childTransitions.size() == 0) { return "This case rule must have at least one child."; - } - else { - if (childTransitions.size() != getCases(transition.getBoard(), childTransitions.get(0).getBoard().getModifiedData().iterator().next()).size()) { + } else { + if (childTransitions.size() + != getCases( + transition.getBoard(), + childTransitions + .get(0) + .getBoard() + .getModifiedData() + .iterator() + .next()) + .size()) { return "Wrong number of children."; } } - - //TreeTransition case1 = childTransitions.get(0); - //TreeTransition case2 = childTransitions.get(1); + // TreeTransition case1 = childTransitions.get(0); + // TreeTransition case2 = childTransitions.get(1); TreeTransition case1 = childTransitions.get(0); - SkyscrapersCell mod1 = (SkyscrapersCell) case1.getBoard().getModifiedData().iterator().next(); + SkyscrapersCell mod1 = + (SkyscrapersCell) case1.getBoard().getModifiedData().iterator().next(); for (int i = 0; i < childTransitions.size(); i++) { TreeTransition case2 = childTransitions.get(i); if (case2.getBoard().getModifiedData().size() != 1) { - return super.getInvalidUseOfRuleMessage() + ": 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(); + SkyscrapersCell mod2 = + (SkyscrapersCell) case2.getBoard().getModifiedData().iterator().next(); if (!mod1.getLocation().equals(mod2.getLocation())) { - return super.getInvalidUseOfRuleMessage() + ": 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)) { - return super.getInvalidUseOfRuleMessage() + ": This case rule must assign a number."; + return super.getInvalidUseOfRuleMessage() + + ": This case rule must assign a number."; } } - //System.out.println("no contradiction"); + // System.out.println("no contradiction"); return null; } /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement index of the puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { @@ -133,28 +146,28 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem } /** - * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid - * Overridden by case rules dependent on more than just the modified data + * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be + * valid Overridden by case rules dependent on more than just the modified data * - * @param board board state at application + * @param board board state at application * @param puzzleElement selected puzzleElement - * @return List of puzzle elements (typically cells) this application of the case rule depends upon. - * Defaults to any element modified by any case + * @return List of puzzle elements (typically cells) this application of the case rule depends + * upon. Defaults to any element modified by any case */ @Override public List dependentElements(Board board, PuzzleElement puzzleElement) { List elements = new ArrayList<>(); SkyscrapersBoard puzzleBoard = (SkyscrapersBoard) board; - SkyscrapersCell point = (SkyscrapersCell)puzzleBoard.getPuzzleElement(puzzleElement); + SkyscrapersCell point = (SkyscrapersCell) puzzleBoard.getPuzzleElement(puzzleElement); List cells = new ArrayList<>(List.of(point)); // if dependent on row/col if (puzzleBoard.getDupeFlag() || puzzleBoard.getViewFlag()) { // add all cells in row/col intersecting given point - cells.addAll(puzzleBoard.getRowCol(point.getLocation().x,SkyscrapersType.ANY,false)); - cells.addAll(puzzleBoard.getRowCol(point.getLocation().y,SkyscrapersType.ANY,true)); + cells.addAll(puzzleBoard.getRowCol(point.getLocation().x, SkyscrapersType.ANY, false)); + cells.addAll(puzzleBoard.getRowCol(point.getLocation().y, SkyscrapersType.ANY, true)); } for (SkyscrapersCell cell : cells) { diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/PreemptiveVisibilityContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/PreemptiveVisibilityContradictionRule.java index 1be26f49a..dc274eb15 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/PreemptiveVisibilityContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/PreemptiveVisibilityContradictionRule.java @@ -6,28 +6,29 @@ import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType; - import java.awt.*; -import java.util.Queue; import java.util.LinkedList; import java.util.List; +import java.util.Queue; public class PreemptiveVisibilityContradictionRule extends ContradictionRule { public PreemptiveVisibilityContradictionRule() { - super("SKYS-CONT-0006", "Preemptive Visibility", + super( + "SKYS-CONT-0006", + "Preemptive Visibility", "Visibility constraints are not met given an incomplete row/col", "edu/rpi/legup/images/skyscrapers/contradictions/PreemptiveVisibility.png"); } /** - * Checks whether there is an instance of a visibility contradiction in every possible row/col based on the specific - * puzzleElement index using this rule + * Checks whether there is an instance of a visibility contradiction in every possible row/col + * based on the specific puzzleElement index using this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement - * @return null if the all possible rows/cols contain a contradiction at the specified puzzleElement, - * otherwise error message + * @return null if the all possible rows/cols contain a contradiction at the specified + * puzzleElement, otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { @@ -35,12 +36,13 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { SkyscrapersCell cell = (SkyscrapersCell) puzzleElement; Point loc = cell.getLocation(); - //Initialize instances of necessary contradiction and case rules - InsufficientVisibilityContradictionRule tooFew = new InsufficientVisibilityContradictionRule(); + // Initialize instances of necessary contradiction and case rules + InsufficientVisibilityContradictionRule tooFew = + new InsufficientVisibilityContradictionRule(); ExceedingVisibilityContradictionRule tooMany = new ExceedingVisibilityContradictionRule(); CellForNumberCaseRule caseRule = new CellForNumberCaseRule(); - //Initialize skyscraperBoard queues for rows and cols + // Initialize skyscraperBoard queues for rows and cols Queue rowQ = new LinkedList<>(); rowQ.add(skyscrapersBoard); Queue colQ = new LinkedList<>(); @@ -48,18 +50,18 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { // find all cases for the corresponding row and column for each possible skyscraper height - //Add every possible case for all heights for each corresponding row and column + // Add every possible case for all heights for each corresponding row and column for (int i = 0; i < skyscrapersBoard.getWidth(); i++) { int num = i + 1; - //check row west clue + // check row west clue List rows; int size = rowQ.size(); for (int j = 0; j < size; j++) { - SkyscrapersBoard temp = rowQ.poll(); //get row from the top of the stack + SkyscrapersBoard temp = rowQ.poll(); // get row from the top of the stack - //don't do anything if already in row + // don't do anything if already in row boolean exists = false; for (SkyscrapersCell c : temp.getRowCol(loc.y, SkyscrapersType.Number, true)) { if (c.getData() == num) { @@ -70,36 +72,37 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { if (exists) { rowQ.add(temp); - } - else { - //set flags + } else { + // set flags boolean dupeTemp = temp.getDupeFlag(); boolean viewTemp = temp.getViewFlag(); temp.setDupeFlag(false); temp.setViewFlag(false); - //get all cases for corresponding row based on west clue - rows = caseRule.getCasesFor(temp, skyscrapersBoard.getWestClues().get(loc.y), num); + // get all cases for corresponding row based on west clue + rows = + caseRule.getCasesFor( + temp, skyscrapersBoard.getWestClues().get(loc.y), num); - //reset flags + // reset flags temp.setDupeFlag(dupeTemp); temp.setViewFlag(viewTemp); - //add all row cases to row queue + // add all row cases to row queue for (Board k : rows) { rowQ.add((SkyscrapersBoard) k); } } } - //check col north clue + // check col north clue List cols; size = colQ.size(); for (int j = 0; j < size; j++) { - SkyscrapersBoard temp = colQ.poll(); //get row from the top of the stack + SkyscrapersBoard temp = colQ.poll(); // get row from the top of the stack - //don't do anything if already in col + // don't do anything if already in col boolean exists = false; for (SkyscrapersCell c : temp.getRowCol(loc.x, SkyscrapersType.Number, false)) { if (c.getData() == num) { @@ -110,22 +113,23 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { if (exists) { colQ.add(temp); - } - else { - //set flags + } else { + // set flags boolean dupeTemp = temp.getDupeFlag(); boolean viewTemp = temp.getViewFlag(); temp.setDupeFlag(false); temp.setViewFlag(false); - //get all cases for corresponding col based on north clue - cols = caseRule.getCasesFor(temp, skyscrapersBoard.getNorthClues().get(loc.x), num); + // get all cases for corresponding col based on north clue + cols = + caseRule.getCasesFor( + temp, skyscrapersBoard.getNorthClues().get(loc.x), num); - //reset flags + // reset flags temp.setDupeFlag(dupeTemp); temp.setViewFlag(viewTemp); - //add all row cases to row queue + // add all row cases to row queue for (Board k : cols) { colQ.add((SkyscrapersBoard) k); } @@ -136,16 +140,24 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { String rowTooFew; String rowTooMany; boolean rowContradiction = true; - //check if each case board has a contradiction + // check if each case board has a contradiction while (rowQ.size() > 0) { SkyscrapersBoard fullRow = rowQ.poll(); - //checks if there is a contradiction given the row based on the west clue - rowTooFew = tooFew.checkContradictionAt(fullRow, cell); // is cell the correct puzzle element to check? + // checks if there is a contradiction given the row based on the west clue + rowTooFew = + tooFew.checkContradictionAt( + fullRow, cell); // is cell the correct puzzle element to check? rowTooMany = tooMany.checkContradictionAt(fullRow, cell); - //boolean that checks if there is a contradiction within all rows - rowContradiction = rowContradiction && (rowTooFew == null || rowTooMany == null);// !null means there isn't a contradiction, so there must be a valid permutation of the array + // boolean that checks if there is a contradiction within all rows + rowContradiction = + rowContradiction + && (rowTooFew == null + || rowTooMany + == null); // !null means there isn't a contradiction, so + // there must be a valid + // permutation of the array } String colTooFew; @@ -154,15 +166,16 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { while (colQ.size() > 0) { SkyscrapersBoard fullCol = colQ.poll(); - //checks if there is a contradiction given the col baesd on the north clue + // checks if there is a contradiction given the col baesd on the north clue colTooFew = tooFew.checkContradictionAt(fullCol, cell); colTooMany = tooMany.checkContradictionAt(fullCol, cell); - //boolean that checks if there is a contradiction within all the cols + // boolean that checks if there is a contradiction within all the cols colContradiction = colContradiction && (colTooFew == null || colTooMany == null); } - //if every possible permutation results in contradictions return null, else no contradiction + // if every possible permutation results in contradictions return null, else no + // contradiction if (rowContradiction || colContradiction) { return null; } @@ -179,7 +192,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { public String checkContradiction(Board board) { SkyscrapersBoard skyscrapersBoard = (SkyscrapersBoard) board; for (int i = 0; i < skyscrapersBoard.getWidth(); i++) { - //checks the middle diagonal (checkContradictionAt checks row/col off each) + // checks the middle diagonal (checkContradictionAt checks row/col off each) String checkStr = checkContradictionAt(board, skyscrapersBoard.getCell(i, i)); if (checkStr == null) { return checkStr; @@ -187,6 +200,4 @@ public String checkContradiction(Board board) { } return "No instance of the contradiction " + this.ruleName + " here"; } - - } 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 ada47efde..d4a3d0486 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 @@ -3,30 +3,27 @@ import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.rules.ContradictionRule; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType; - import java.awt.*; import java.util.ArrayList; -import java.util.HashSet; -import java.util.Set; public class UnresolvedCellContradictionRule extends ContradictionRule { public UnresolvedCellContradictionRule() { - super("SKYS-CONT-0004", "Unresolved Cell", + super( + "SKYS-CONT-0004", + "Unresolved Cell", "Elimination leaves no possible number for a cell.", "edu/rpi/legup/images/skyscrapers/contradictions/UnresolvedCell.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/UnresolvedNumberContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/UnresolvedNumberContradictionRule.java index 21a48caaf..fed429988 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/UnresolvedNumberContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/UnresolvedNumberContradictionRule.java @@ -1,34 +1,33 @@ package edu.rpi.legup.puzzle.skyscrapers.rules; - import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.rules.ContradictionRule; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersType; - import java.awt.*; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Set; public class UnresolvedNumberContradictionRule extends ContradictionRule { public UnresolvedNumberContradictionRule() { - super("SKYS-CONT-0005", "Unresolved Number", + super( + "SKYS-CONT-0005", + "Unresolved Number", "No possible cell for a number without a duplicate contradiction.", - //specify a number? defaulting to every number for now. expand to more than duplicate? + // specify a number? defaulting to every number for now. expand to more than + // duplicate? "edu/rpi/legup/images/skyscrapers/contradictions/UnresolvedNumber.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { @@ -39,39 +38,45 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { CellForNumberCaseRule caseRule = new CellForNumberCaseRule(); for (int i = 0; i < skyscrapersBoard.getWidth(); i++) { int num = i + 1; - //check row - //isn't already present + // check row + // isn't already present boolean exists = false; - for (SkyscrapersCell presentCell : skyscrapersBoard.getRowCol(loc.y, SkyscrapersType.Number, true)) { + for (SkyscrapersCell presentCell : + skyscrapersBoard.getRowCol(loc.y, SkyscrapersType.Number, true)) { if (presentCell.getData() == num) { exists = true; break; } } if (!exists) { - //and no possible cases - if (caseRule.getCasesFor(board, skyscrapersBoard.getWestClues().get(loc.y), num).size() == 0) { + // and no possible cases + if (caseRule.getCasesFor(board, skyscrapersBoard.getWestClues().get(loc.y), num) + .size() + == 0) { return null; } } - //check col - //same process as for row + // check col + // same process as for row exists = false; - for (SkyscrapersCell presentCell : skyscrapersBoard.getRowCol(loc.x, SkyscrapersType.Number, false)) { + for (SkyscrapersCell presentCell : + skyscrapersBoard.getRowCol(loc.x, SkyscrapersType.Number, false)) { if (presentCell.getData() == num) { exists = true; break; } } if (!exists) { - if (caseRule.getCasesFor(board, skyscrapersBoard.getNorthClues().get(loc.x), num).size() == 0) { + if (caseRule.getCasesFor(board, skyscrapersBoard.getNorthClues().get(loc.x), num) + .size() + == 0) { return null; } } } - //System.out.print("Does not contain a contradiction at this index"); + // System.out.print("Does not contain a contradiction at this index"); return super.getNoContradictionMessage(); } @@ -85,7 +90,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { public String checkContradiction(Board board) { SkyscrapersBoard skyscrapersBoard = (SkyscrapersBoard) board; for (int i = 0; i < skyscrapersBoard.getWidth(); i++) { - //checks the middle diagonal (checkContradictionAt checks row/col off each) + // checks the middle diagonal (checkContradictionAt checks row/col off each) String checkStr = checkContradictionAt(board, skyscrapersBoard.getCell(i, i)); if (checkStr == null) { return null; @@ -94,4 +99,3 @@ public String checkContradiction(Board board) { return "No instance of the contradiction " + this.ruleName + " here"; } } - diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/GroupType.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/GroupType.java index a716258fa..a7cd9ac12 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/GroupType.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/GroupType.java @@ -1,5 +1,7 @@ package edu.rpi.legup.puzzle.sudoku; public enum GroupType { - REGION, ROW, COLUMN + REGION, + ROW, + COLUMN } diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/PossibleNumberCaseBoard.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/PossibleNumberCaseBoard.java index 8af2aca2e..0b6971235 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/PossibleNumberCaseBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/PossibleNumberCaseBoard.java @@ -3,7 +3,6 @@ import edu.rpi.legup.model.gameboard.CaseBoard; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.puzzle.sudoku.rules.PossibleNumberCaseRule; - import java.awt.event.MouseEvent; import java.util.HashSet; import java.util.Set; @@ -15,8 +14,8 @@ public class PossibleNumberCaseBoard extends CaseBoard { private Set pickableRows; private Set pickableCols; - - public PossibleNumberCaseBoard(SudokuBoard baseBoard, PossibleNumberCaseRule caseRule, SudokuCell cell) { + public PossibleNumberCaseBoard( + SudokuBoard baseBoard, PossibleNumberCaseRule caseRule, SudokuCell cell) { super(baseBoard, caseRule); this.cell = cell; this.pickableRegions = new HashSet<>(); @@ -37,16 +36,14 @@ public boolean isPickable(PuzzleElement puzzleElement, MouseEvent e) { return true; } } - } - else { + } else { if (e.isControlDown()) { for (int c : pickableCols) { if (c == sudokuCell.getLocation().x) { return true; } } - } - else { + } else { for (int r : pickableRegions) { if (r == sudokuCell.getGroupIndex()) { return true; diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/Sudoku.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/Sudoku.java index ac082e427..877c92665 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/Sudoku.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/Sudoku.java @@ -9,9 +9,7 @@ public class Sudoku extends Puzzle { private SudokuView boardView; - /** - * Sudoku Constructor - */ + /** Sudoku Constructor */ public Sudoku() { super(); @@ -27,9 +25,7 @@ public BoardView getBoardView() { return boardView; } - /** - * Initializes the game board - */ + /** Initializes the game board */ @Override public void initializeView() { boardView = new SudokuView((SudokuBoard) currentBoard); @@ -50,8 +46,8 @@ public Board generatePuzzle(int difficulty) { /** * Determines if the given dimensions are valid for Sudoku * - * @param rows the number of rows - * @param columns the number of columns + * @param rows the number of rows + * @param columns the number of columns * @return true if the given dimensions are valid for Sudoku, false otherwise */ public boolean isValidDimensions(int rows, int columns) { @@ -66,7 +62,8 @@ public boolean isValidDimensions(int rows, int columns) { } // For Sudoku, the number of rows and columns must be a perfect square - // Note: we don't need to check the columns since by this point, we have verified that the number of rows + // Note: we don't need to check the columns since by this point, we have verified that the + // number of rows // equals the number of columns double sqrtRows = Math.sqrt(rows); if (sqrtRows - Math.floor(sqrtRows) != 0) { @@ -107,7 +104,5 @@ public boolean isBoardComplete(Board board) { * @param board the board that has changed */ @Override - public void onBoardChange(Board board) { - - } + public void onBoardChange(Board board) {} } diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuBoard.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuBoard.java index ed3048c88..46e6020bb 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuBoard.java @@ -2,7 +2,6 @@ import edu.rpi.legup.model.gameboard.GridBoard; import edu.rpi.legup.model.gameboard.PuzzleElement; - import java.awt.*; import java.util.HashSet; import java.util.Set; @@ -35,23 +34,23 @@ public SudokuCell getCell(int x, int y) { } /** - * Gets the SudokuCell in the specified group index at the x and y location given - * The group index must be by less than the width (or height) of the board and the - * x and y location is relative to the group. This means the x and y values must be - * less the square root of the width (or height) of the board. + * Gets the SudokuCell in the specified group index at the x and y location given The group + * index must be by less than the width (or height) of the board and the x and y location is + * relative to the group. This means the x and y values must be less the square root of the + * width (or height) of the board. * * @param groupIndex group index of the cell - * @param x x location relative to the group - * @param y y location relative to the group + * @param x x location relative to the group + * @param y y location relative to the group * @return cell in the specified group index at the given x and y location */ public SudokuCell getCell(int groupIndex, int x, int y) { - return getCell(x + (groupIndex % groupSize) * groupSize, y + (groupIndex / groupSize) * groupSize); + return getCell( + x + (groupIndex % groupSize) * groupSize, y + (groupIndex / groupSize) * groupSize); } /** - * Gets the size of the sudoku board - * Standard board is 9x9 + * Gets the size of the sudoku board Standard board is 9x9 * * @return size of the board */ @@ -60,8 +59,7 @@ public int getSize() { } /** - * Gets the minor group size of the sudoku board - * Standard board is 3x3x3x3 + * Gets the minor group size of the sudoku board Standard board is 3x3x3x3 * * @return minor group size */ @@ -139,8 +137,8 @@ public Set getPossibleValues(SudokuCell cell) { } /** - * Called when a {@link PuzzleElement} data on this has changed and passes in the equivalent puzzle element with - * the new data. + * Called when a {@link PuzzleElement} data on this has changed and passes in the equivalent + * puzzle element with the new data. * * @param puzzleElement equivalent puzzle element with the new data. */ diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCell.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCell.java index 0e1595d03..006e6c0a5 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCell.java @@ -1,7 +1,6 @@ package edu.rpi.legup.puzzle.sudoku; import edu.rpi.legup.model.gameboard.GridCell; - import java.awt.*; import java.util.HashSet; import java.util.Set; @@ -14,10 +13,10 @@ public class SudokuCell extends GridCell { /** * SudokuCell Constructor - creates a new Sudoku cell to hold the puzzleElement * - * @param value value of the sudoku cell - * @param location location of the cell on the board + * @param value value of the sudoku cell + * @param location location of the cell on the board * @param groupIndex index of the group the cell is in on the board - * @param size size of the sudoku cell + * @param size size of the sudoku cell */ public SudokuCell(int value, Point location, int groupIndex, int size) { super(value, location); diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCellController.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCellController.java index 18b6cd0a8..9b24f13da 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCellController.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCellController.java @@ -1,46 +1,37 @@ package edu.rpi.legup.puzzle.sudoku; -/*import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; - - -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.puzzle.treetent.TreeTentCell;*/ - import edu.rpi.legup.controller.ElementController; import edu.rpi.legup.model.gameboard.PuzzleElement; - - import java.awt.event.MouseEvent; public class SudokuCellController extends ElementController { @Override - public void changeCell(MouseEvent e, PuzzleElement data) { SudokuCell cell = (SudokuCell) data; System.out.print(111); if (e.getButton() == MouseEvent.BUTTON1) { if (e.isControlDown()) { - this.boardView.getSelectionPopupMenu().show(boardView, this.boardView.getCanvas().getX() + e.getX(), this.boardView.getCanvas().getY() + e.getY()); - } - else { + this.boardView + .getSelectionPopupMenu() + .show( + boardView, + this.boardView.getCanvas().getX() + e.getX(), + this.boardView.getCanvas().getY() + e.getY()); + } else { if (cell.getData() < cell.getMax()) { data.setData(cell.getData() + 1); - } - else { + } else { data.setData(0); } } - } - else { + } else { if (e.getButton() == MouseEvent.BUTTON3) { if (cell.getData() > 0) { data.setData(cell.getData() - 1); - } - else { + } else { data.setData(cell.getMax()); } } } } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCellFactory.java index 90f84d519..1ef24ea59 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCellFactory.java @@ -4,17 +4,16 @@ import edu.rpi.legup.model.gameboard.ElementFactory; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; -import java.awt.*; - public class SudokuCellFactory extends ElementFactory { /** * Creates a puzzleElement based on the xml document Node and adds it to the board * - * @param node node that represents the puzzleElement + * @param node node that represents the puzzleElement * @param board board to add the newly created cell * @return newly created cell from the xml document Node * @throws InvalidFileFormatException if file is invalid @@ -23,7 +22,8 @@ public class SudokuCellFactory extends ElementFactory { public SudokuCell importCell(Node node, Board board) throws InvalidFileFormatException { try { if (!node.getNodeName().equalsIgnoreCase("cell")) { - throw new InvalidFileFormatException("Sudoku Factory: unknown puzzleElement puzzleElement"); + throw new InvalidFileFormatException( + "Sudoku Factory: unknown puzzleElement puzzleElement"); } SudokuBoard sudokuBoard = (SudokuBoard) board; @@ -44,11 +44,10 @@ public SudokuCell importCell(Node node, Board board) throws InvalidFileFormatExc SudokuCell cell = new SudokuCell(value, new Point(x, y), groupIndex, size); cell.setIndex(y * size + x); return cell; - } - catch (NumberFormatException e) { - throw new InvalidFileFormatException("Sudoku Factory: unknown value where integer expected"); - } - catch (NullPointerException e) { + } catch (NumberFormatException e) { + throw new InvalidFileFormatException( + "Sudoku Factory: unknown value where integer expected"); + } catch (NullPointerException e) { throw new InvalidFileFormatException("Sudoku Factory: could not find attribute(s)"); } } @@ -56,7 +55,7 @@ public SudokuCell importCell(Node node, Board board) throws InvalidFileFormatExc /** * Creates a xml document puzzleElement from a cell for exporting * - * @param document xml document + * @param document xml document * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuElementView.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuElementView.java index 46d7e4ec7..c3d236b53 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuElementView.java @@ -3,7 +3,6 @@ import edu.rpi.legup.app.LegupPreferences; import edu.rpi.legup.model.gameboard.GridCell; import edu.rpi.legup.ui.boardview.GridElementView; - import java.awt.*; public class SudokuElementView extends GridElementView { @@ -50,18 +49,24 @@ public void drawElement(Graphics2D graphics2D) { FontMetrics metrics = graphics2D.getFontMetrics(FONT); String value = String.valueOf(val); int xText = location.x + (size.width - metrics.stringWidth(value)) / 2; - int yText = location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent(); + int yText = + location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent(); graphics2D.drawString(value, xText, yText); - } - else { - boolean annotate = LegupPreferences.getInstance().getUserPref(LegupPreferences.SHOW_ANNOTATIONS).equalsIgnoreCase(Boolean.toString(true)); + } else { + boolean annotate = + LegupPreferences.getInstance() + .getUserPref(LegupPreferences.SHOW_ANNOTATIONS) + .equalsIgnoreCase(Boolean.toString(true)); if (annotate) { graphics2D.setColor(FONT_COLOR); graphics2D.setFont(ANNOTATE_FONT); FontMetrics metrics = graphics2D.getFontMetrics(FONT); String value = String.valueOf(cell.getAnnotations()); int xText = location.x + (size.width - metrics.stringWidth(value)) / 2; - int yText = location.y + ((size.height - metrics.getHeight()) / 2) + metrics.getAscent(); + int yText = + location.y + + ((size.height - metrics.getHeight()) / 2) + + metrics.getAscent(); graphics2D.drawString(value, xText, yText); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuExporter.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuExporter.java index 45e320293..f10aabae1 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuExporter.java @@ -2,7 +2,6 @@ import edu.rpi.legup.model.PuzzleExporter; import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; import org.w3c.dom.Document; public class SudokuExporter extends PuzzleExporter { @@ -16,8 +15,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { SudokuBoard board; if (puzzle.getTree() != null) { board = (SudokuBoard) puzzle.getTree().getRootNode().getBoard(); - } - else { + } else { board = (SudokuBoard) puzzle.getBoardView().getBoard(); } @@ -28,7 +26,8 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { for (PuzzleElement puzzleElement : board.getPuzzleElements()) { SudokuCell cell = (SudokuCell) puzzleElement; if (cell.getData() != 0) { - org.w3c.dom.Element cellElement = puzzle.getFactory().exportCell(newDocument, puzzleElement); + org.w3c.dom.Element cellElement = + puzzle.getFactory().exportCell(newDocument, puzzleElement); cellsElement.appendChild(cellElement); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuImporter.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuImporter.java index dccec52d4..68bf1e795 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuImporter.java @@ -2,12 +2,11 @@ import edu.rpi.legup.model.PuzzleImporter; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import java.awt.*; - public class SudokuImporter extends PuzzleImporter { public SudokuImporter(Sudoku sudoku) { super(sudoku); @@ -26,7 +25,7 @@ public boolean acceptsTextInput() { /** * Creates an empty board for building * - * @param rows the number of rows on the board + * @param rows the number of rows on the board * @param columns the number of columns on the board * @throws RuntimeException if board can not be created */ @@ -61,11 +60,13 @@ public void initializeBoard(int rows, int columns) { public void initializeBoard(Node node) throws InvalidFileFormatException { try { if (!node.getNodeName().equalsIgnoreCase("board")) { - throw new InvalidFileFormatException("Sudoku Importer: cannot find board puzzleElement"); + throw new InvalidFileFormatException( + "Sudoku Importer: cannot find board puzzleElement"); } Element boardElement = (Element) node; if (boardElement.getElementsByTagName("cells").getLength() == 0) { - throw new InvalidFileFormatException("Sudoku Importer: no puzzleElement found for board"); + throw new InvalidFileFormatException( + "Sudoku Importer: no puzzleElement found for board"); } Element dataElement = (Element) boardElement.getElementsByTagName("cells").item(0); NodeList elementDataList = dataElement.getElementsByTagName("cell"); @@ -77,16 +78,19 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { size = Integer.valueOf(boardElement.getAttribute("size")); minorSize = (int) Math.sqrt(size); if (minorSize * minorSize != size) { - throw new InvalidFileFormatException("Sudoku Importer: invalid board dimensions"); + throw new InvalidFileFormatException( + "Sudoku Importer: invalid board dimensions"); } sudokuBoard = new SudokuBoard(size); - } - else { + } else { throw new InvalidFileFormatException("Sudoku Importer: invalid board dimensions"); } for (int i = 0; i < elementDataList.getLength(); i++) { - SudokuCell cell = (SudokuCell) puzzle.getFactory().importCell(elementDataList.item(i), sudokuBoard); + SudokuCell cell = + (SudokuCell) + puzzle.getFactory() + .importCell(elementDataList.item(i), sudokuBoard); Point loc = cell.getLocation(); if (cell.getData() != 0) { cell.setModifiable(false); @@ -106,20 +110,21 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { } } } -// -// for(int y = 0; y < size; y++) -// { -// for(int x = 0; x < size; x++) -// { -// SudokuCell cell = sudokuBoard.getCell(x, y); -// System.err.println("(" + x + ", " + y + ") - " + cell.getGroupIndex()); -// } -// } + // + // for(int y = 0; y < size; y++) + // { + // for(int x = 0; x < size; x++) + // { + // SudokuCell cell = sudokuBoard.getCell(x, y); + // System.err.println("(" + x + ", " + y + ") - " + + // cell.getGroupIndex()); + // } + // } puzzle.setCurrentBoard(sudokuBoard); - } - catch (NumberFormatException e) { - throw new InvalidFileFormatException("Sudoku Importer: unknown value where integer expected"); + } catch (NumberFormatException e) { + throw new InvalidFileFormatException( + "Sudoku Importer: unknown value where integer expected"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuView.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuView.java index bb25c3e21..aa58f9a23 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuView.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuView.java @@ -5,10 +5,9 @@ import edu.rpi.legup.ui.boardview.ElementView; import edu.rpi.legup.ui.boardview.GridBoardView; import edu.rpi.legup.ui.boardview.SelectionItemView; - -import javax.swing.*; import java.awt.*; import java.util.Set; +import javax.swing.*; public class SudokuView extends GridBoardView { private static final Color STROKE_COLOR = new Color(0, 0, 0); @@ -21,8 +20,10 @@ public SudokuView(SudokuBoard board) { int minorSize = (int) Math.sqrt(gridSize.width); for (int i = 0; i < gridSize.height; i++) { for (int k = 0; k < gridSize.width; k++) { - Point location = new Point(k * elementSize.width + (k / minorSize) * 4 + 5, - i * elementSize.height + (i / minorSize) * 4 + 5); + Point location = + new Point( + k * elementSize.width + (k / minorSize) * 4 + 5, + i * elementSize.height + (i / minorSize) * 4 + 5); SudokuElementView element = new SudokuElementView(board.getCell(k, i)); element.setIndex(i * gridSize.width + k); element.setSize(elementSize); @@ -30,12 +31,10 @@ public SudokuView(SudokuBoard board) { elementViews.add(element); } } - } /** - * Gets the SudokuElementView from the puzzleElement index or - * null if out of bounds + * Gets the SudokuElementView from the puzzleElement index or null if out of bounds * * @param index index of the ElementView * @return SudokuElementView at the specified index @@ -49,7 +48,9 @@ public void drawGrid(Graphics2D graphics2D) { int minorSize = (int) Math.sqrt(gridSize.width); graphics2D.setColor(STROKE_COLOR); graphics2D.setStroke(MAJOR_STOKE); - graphics2D.drawRect(3, 3, + graphics2D.drawRect( + 3, + 3, gridSize.width * (elementSize.width + 1) + 3, gridSize.height * (elementSize.height + 1) + 3); @@ -81,8 +82,7 @@ public void drawBoard(Graphics2D graphics2D) { ElementView element = elementViews.get(i * gridSize.height + k); if (!element.isHover()) { element.draw(graphics2D); - } - else { + } else { hover = element; } } @@ -107,8 +107,7 @@ public void drawCaseBoard(Graphics2D graphics2D) { ElementView element = elementViews.get(i * gridSize.height + k); if (!element.isHover()) { element.draw(graphics2D); - } - else { + } else { hover = element; } } @@ -117,7 +116,10 @@ public void drawCaseBoard(Graphics2D graphics2D) { graphics2D.setColor(new Color(0x1A, 0x23, 0x7E, 200)); for (int r : caseBoard.getPickableRegions()) { Set region = sudokuBoard.getRegion(r); - int x = Integer.MAX_VALUE, y = Integer.MAX_VALUE, w = Integer.MIN_VALUE, h = Integer.MIN_VALUE; + int x = Integer.MAX_VALUE, + y = Integer.MAX_VALUE, + w = Integer.MIN_VALUE, + h = Integer.MIN_VALUE; for (SudokuCell c : region) { x = Math.min(x, c.getLocation().x); y = Math.min(y, c.getLocation().y); @@ -134,8 +136,8 @@ public void drawCaseBoard(Graphics2D graphics2D) { graphics2D.fillRect(x + 4, y + 4, w - 8, h - 8); } -// if(hover != null) -// hover.draw(graphics2D); + // if(hover != null) + // hover.draw(graphics2D); } protected Dimension getProperSize() { @@ -151,10 +153,14 @@ public DataSelectionView getSelectionPopupMenu() { selectionView.setLayout(layout); for (int r = 1; r <= 3; r++) { for (int c = 1; c <= 3; c++) { - SudokuElementView element = new SudokuElementView(new SudokuCell((r - 1) * 3 + c, null, 0, gridSize.width)); + SudokuElementView element = + new SudokuElementView( + new SudokuCell((r - 1) * 3 + c, null, 0, gridSize.width)); element.setSize(new Dimension(32, 32)); element.setLocation(new Point(0, 0)); - SelectionItemView item = new SelectionItemView(element.getPuzzleElement(), new ImageIcon(element.getImage())); + SelectionItemView item = + new SelectionItemView( + element.getPuzzleElement(), new ImageIcon(element.getImage())); item.addActionListener(elementController); item.setHorizontalTextPosition(SwingConstants.CENTER); selectionView.add(item); diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/elements/NumberTile.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/elements/NumberTile.java index e3159d87c..12183d70d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/elements/NumberTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/elements/NumberTile.java @@ -23,6 +23,4 @@ public int getTileNumber() { public void setTileNumber(int num) { object_num = num; } - - } diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/AdvancedDeductionDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/AdvancedDeductionDirectRule.java index 0be30fa36..190679b41 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/AdvancedDeductionDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/AdvancedDeductionDirectRule.java @@ -1,96 +1,99 @@ -package edu.rpi.legup.puzzle.sudoku.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.sudoku.SudokuBoard; -import edu.rpi.legup.puzzle.sudoku.SudokuCell; - -public class AdvancedDeductionDirectRule extends DirectRule { - - public AdvancedDeductionDirectRule() { - super("SUDO-BASC-0001", "Advanced Deduction", - "Use of group logic deduces more answers by means of forced by Location and forced by Deduction", - "edu/rpi/legup/images/sudoku/AdvancedDeduction.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - SudokuBoard initialBoard = (SudokuBoard) transition.getParents().get(0).getBoard(); - SudokuBoard finalBoard = (SudokuBoard) transition.getBoard(); - - SudokuCell cell = (SudokuCell) finalBoard.getPuzzleElement(puzzleElement); - int index = cell.getIndex(); - int groupSize = initialBoard.getWidth(); - int groupDim = (int) Math.sqrt(groupSize); - int rowIndex = index / groupSize; - int colIndex = index % groupSize; - int relX = rowIndex / groupDim; - int relY = colIndex % groupDim; - int groupNum = rowIndex / groupDim * groupDim + colIndex / groupDim; - boolean[][] possible = new boolean[groupDim][groupDim]; - for (int y = 0; y < groupDim; y++) { - for (int x = 0; x < groupDim; x++) { - SudokuCell c = initialBoard.getCell(groupNum, x, y); - if (c.getData() == cell.getData() && x != relX && y != relY) { - return super.getRuleName() + ": Duplicate value in sub-region"; - } - possible[y][x] = c.getData() == 0; - } - } - for (int y = 0; y < groupDim; y++) { - for (int x = 0; x < groupSize; x++) { - SudokuCell r = initialBoard.getCell(x, (groupNum / groupDim) * groupDim + y); - SudokuCell c = initialBoard.getCell((groupNum % groupDim) * groupDim + y, x); - if (r.getData() == cell.getData()) { - for (int i = 0; i < groupDim; i++) { - possible[y][i] = false; - } - } - if (c.getData() == cell.getData()) { - for (int i = 0; i < groupDim; i++) { - possible[i][y] = false; - } - } - } - } - boolean isForced = false; - for (int y = 0; y < groupDim; y++) { - for (int x = 0; x < groupDim; x++) { - if (possible[y][x] && !isForced) { - isForced = true; - } - else { - if (possible[y][x]) { - return super.getInvalidUseOfRuleMessage() + ": Not forced"; - } - } - } - } - if (!isForced) { - return super.getInvalidUseOfRuleMessage() + ": Not forced"; - } - return null; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.sudoku.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.sudoku.SudokuBoard; +import edu.rpi.legup.puzzle.sudoku.SudokuCell; + +public class AdvancedDeductionDirectRule extends DirectRule { + + public AdvancedDeductionDirectRule() { + super( + "SUDO-BASC-0001", + "Advanced Deduction", + "Use of group logic deduces more answers by means of forced by Location and forced" + + " by Deduction", + "edu/rpi/legup/images/sudoku/AdvancedDeduction.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + SudokuBoard initialBoard = (SudokuBoard) transition.getParents().get(0).getBoard(); + SudokuBoard finalBoard = (SudokuBoard) transition.getBoard(); + + SudokuCell cell = (SudokuCell) finalBoard.getPuzzleElement(puzzleElement); + int index = cell.getIndex(); + int groupSize = initialBoard.getWidth(); + int groupDim = (int) Math.sqrt(groupSize); + int rowIndex = index / groupSize; + int colIndex = index % groupSize; + int relX = rowIndex / groupDim; + int relY = colIndex % groupDim; + int groupNum = rowIndex / groupDim * groupDim + colIndex / groupDim; + boolean[][] possible = new boolean[groupDim][groupDim]; + for (int y = 0; y < groupDim; y++) { + for (int x = 0; x < groupDim; x++) { + SudokuCell c = initialBoard.getCell(groupNum, x, y); + if (c.getData() == cell.getData() && x != relX && y != relY) { + return super.getRuleName() + ": Duplicate value in sub-region"; + } + possible[y][x] = c.getData() == 0; + } + } + for (int y = 0; y < groupDim; y++) { + for (int x = 0; x < groupSize; x++) { + SudokuCell r = initialBoard.getCell(x, (groupNum / groupDim) * groupDim + y); + SudokuCell c = initialBoard.getCell((groupNum % groupDim) * groupDim + y, x); + if (r.getData() == cell.getData()) { + for (int i = 0; i < groupDim; i++) { + possible[y][i] = false; + } + } + if (c.getData() == cell.getData()) { + for (int i = 0; i < groupDim; i++) { + possible[i][y] = false; + } + } + } + } + boolean isForced = false; + for (int y = 0; y < groupDim; y++) { + for (int x = 0; x < groupDim; x++) { + if (possible[y][x] && !isForced) { + isForced = true; + } else { + if (possible[y][x]) { + return super.getInvalidUseOfRuleMessage() + ": Not forced"; + } + } + } + } + if (!isForced) { + return super.getInvalidUseOfRuleMessage() + ": Not forced"; + } + return null; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/LastCellForNumberDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/LastCellForNumberDirectRule.java index 51d963247..fd03ef36c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/LastCellForNumberDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/LastCellForNumberDirectRule.java @@ -1,93 +1,95 @@ -package edu.rpi.legup.puzzle.sudoku.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.sudoku.SudokuBoard; -import edu.rpi.legup.puzzle.sudoku.SudokuCell; - -import java.util.Set; - -public class LastCellForNumberDirectRule extends DirectRule { - public LastCellForNumberDirectRule() { - super("SUDO-BASC-0002", "Last Cell for Number", - "This is the only cell open in its group for some number.", - "edu/rpi/legup/images/sudoku/forcedByElimination.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - SudokuBoard initialBoard = (SudokuBoard) transition.getParents().get(0).getBoard(); - SudokuBoard finalBoard = (SudokuBoard) transition.getBoard(); - - SudokuCell cell = (SudokuCell) finalBoard.getPuzzleElement(puzzleElement); - if (cell.getData() == 0) { - return super.getInvalidUseOfRuleMessage() + ": Cell is not forced at this index"; - } - - int size = initialBoard.getSize(); - - Set region = initialBoard.getRegion(cell.getGroupIndex()); - Set row = initialBoard.getRow(cell.getLocation().y); - Set col = initialBoard.getCol(cell.getLocation().x); - - boolean contains = false; - if (region.size() == size - 1) { - for (SudokuCell c : region) { - if (cell.getData() == c.getData()) { - contains = true; - break; - } - } - if (!contains) { - return null; - } - } - if (row.size() == size - 1) { - contains = false; - for (SudokuCell c : row) { - if (cell.getData() == c.getData()) { - contains = true; - break; - } - } - if (!contains) { - return null; - } - } - if (col.size() == size - 1) { - contains = false; - for (SudokuCell c : col) { - if (cell.getData() == c.getData()) { - contains = true; - break; - } - } - if (!contains) { - return null; - } - } - return super.getInvalidUseOfRuleMessage() + ": Cell is not forced at this index"; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.sudoku.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.sudoku.SudokuBoard; +import edu.rpi.legup.puzzle.sudoku.SudokuCell; +import java.util.Set; + +public class LastCellForNumberDirectRule extends DirectRule { + public LastCellForNumberDirectRule() { + super( + "SUDO-BASC-0002", + "Last Cell for Number", + "This is the only cell open in its group for some number.", + "edu/rpi/legup/images/sudoku/forcedByElimination.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + SudokuBoard initialBoard = (SudokuBoard) transition.getParents().get(0).getBoard(); + SudokuBoard finalBoard = (SudokuBoard) transition.getBoard(); + + SudokuCell cell = (SudokuCell) finalBoard.getPuzzleElement(puzzleElement); + if (cell.getData() == 0) { + return super.getInvalidUseOfRuleMessage() + ": Cell is not forced at this index"; + } + + int size = initialBoard.getSize(); + + Set region = initialBoard.getRegion(cell.getGroupIndex()); + Set row = initialBoard.getRow(cell.getLocation().y); + Set col = initialBoard.getCol(cell.getLocation().x); + + boolean contains = false; + if (region.size() == size - 1) { + for (SudokuCell c : region) { + if (cell.getData() == c.getData()) { + contains = true; + break; + } + } + if (!contains) { + return null; + } + } + if (row.size() == size - 1) { + contains = false; + for (SudokuCell c : row) { + if (cell.getData() == c.getData()) { + contains = true; + break; + } + } + if (!contains) { + return null; + } + } + if (col.size() == size - 1) { + contains = false; + for (SudokuCell c : col) { + if (cell.getData() == c.getData()) { + contains = true; + break; + } + } + if (!contains) { + return null; + } + } + return super.getInvalidUseOfRuleMessage() + ": Cell is not forced at this index"; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/LastNumberForCellDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/LastNumberForCellDirectRule.java index 28e64ce7b..ca0ac3023 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/LastNumberForCellDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/LastNumberForCellDirectRule.java @@ -1,77 +1,81 @@ -package edu.rpi.legup.puzzle.sudoku.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.sudoku.SudokuBoard; -import edu.rpi.legup.puzzle.sudoku.SudokuCell; - -import java.util.HashSet; - -public class LastNumberForCellDirectRule extends DirectRule { - - public LastNumberForCellDirectRule() { - super("SUDO-BASC-0003", "Last Number for Cell", - "This is the only number left that can fit in the cell of a group.", - "edu/rpi/legup/images/sudoku/forcedByDeduction.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - SudokuBoard initialBoard = (SudokuBoard) transition.getParents().get(0).getBoard(); - SudokuBoard finalBoard = (SudokuBoard) transition.getBoard(); - - int index = puzzleElement.getIndex(); - int groupSize = initialBoard.getWidth(); - int groupDim = (int) Math.sqrt(groupSize); - int rowIndex = index / groupSize; - int colIndex = index % groupSize; - int groupNum = rowIndex / groupDim * groupDim + colIndex % groupDim; - HashSet numbers = new HashSet<>(); - for (int i = 1; i <= groupSize; i++) { - numbers.add(i); - } - for (int i = 0; i < groupSize; i++) { - SudokuCell cell = initialBoard.getCell(groupNum, i % groupDim, i / groupDim); - numbers.remove(cell.getData()); - } - for (int i = 0; i < groupSize; i++) { - SudokuCell cell = initialBoard.getCell(i, colIndex); - numbers.remove(cell.getData()); - } - for (int i = 0; i < groupSize; i++) { - SudokuCell cell = initialBoard.getCell(rowIndex, i); - numbers.remove(cell.getData()); - } - if (numbers.size() > 1) { - return super.getInvalidUseOfRuleMessage() + ": The number at the index is not forced"; - } - else { - if (numbers.size() == 1 && numbers.iterator().next() != finalBoard.getPuzzleElement(puzzleElement).getData()) { - return super.getInvalidUseOfRuleMessage() + ": The number at the index is forced but not correct"; - } - } - return null; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.sudoku.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.sudoku.SudokuBoard; +import edu.rpi.legup.puzzle.sudoku.SudokuCell; +import java.util.HashSet; + +public class LastNumberForCellDirectRule extends DirectRule { + + public LastNumberForCellDirectRule() { + super( + "SUDO-BASC-0003", + "Last Number for Cell", + "This is the only number left that can fit in the cell of a group.", + "edu/rpi/legup/images/sudoku/forcedByDeduction.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + SudokuBoard initialBoard = (SudokuBoard) transition.getParents().get(0).getBoard(); + SudokuBoard finalBoard = (SudokuBoard) transition.getBoard(); + + int index = puzzleElement.getIndex(); + int groupSize = initialBoard.getWidth(); + int groupDim = (int) Math.sqrt(groupSize); + int rowIndex = index / groupSize; + int colIndex = index % groupSize; + int groupNum = rowIndex / groupDim * groupDim + colIndex % groupDim; + HashSet numbers = new HashSet<>(); + for (int i = 1; i <= groupSize; i++) { + numbers.add(i); + } + for (int i = 0; i < groupSize; i++) { + SudokuCell cell = initialBoard.getCell(groupNum, i % groupDim, i / groupDim); + numbers.remove(cell.getData()); + } + for (int i = 0; i < groupSize; i++) { + SudokuCell cell = initialBoard.getCell(i, colIndex); + numbers.remove(cell.getData()); + } + for (int i = 0; i < groupSize; i++) { + SudokuCell cell = initialBoard.getCell(rowIndex, i); + numbers.remove(cell.getData()); + } + if (numbers.size() > 1) { + return super.getInvalidUseOfRuleMessage() + ": The number at the index is not forced"; + } else { + if (numbers.size() == 1 + && numbers.iterator().next() + != finalBoard.getPuzzleElement(puzzleElement).getData()) { + return super.getInvalidUseOfRuleMessage() + + ": The number at the index is forced but not correct"; + } + } + return null; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + 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 fb87764fe..e44728d3e 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 @@ -5,25 +5,27 @@ import edu.rpi.legup.model.rules.ContradictionRule; import edu.rpi.legup.puzzle.sudoku.SudokuBoard; import edu.rpi.legup.puzzle.sudoku.SudokuCell; - import java.util.HashSet; import java.util.Set; public class NoSolutionContradictionRule extends ContradictionRule { public NoSolutionContradictionRule() { - super("SUDO-CONT-0001", "No Solution for Cell", + super( + "SUDO-CONT-0001", + "No Solution for Cell", "Process of elimination yields no valid numbers for an empty cell.", "edu/rpi/legup/images/sudoku/NoSolution.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/PossibleCellCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/PossibleCellCaseRule.java index 373b60457..fb6da62d4 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/PossibleCellCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/PossibleCellCaseRule.java @@ -7,14 +7,15 @@ import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.sudoku.SudokuBoard; import edu.rpi.legup.puzzle.sudoku.SudokuCell; - import java.util.ArrayList; import java.util.HashSet; import java.util.Set; public class PossibleCellCaseRule extends CaseRule { public PossibleCellCaseRule() { - super("SUDO-CASE-0001", "Possible Cells for Number", + super( + "SUDO-CASE-0001", + "Possible Cells for Number", "A number has a limited set of cells in which it can be placed.", "edu/rpi/legup/images/sudoku/possible_cells_number.png"); } @@ -31,13 +32,13 @@ public String checkRuleRaw(TreeTransition transition) { } /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { @@ -59,7 +60,7 @@ public CaseBoard getCaseBoard(Board board) { /** * Gets the possible cases at a specific location based on this case rule * - * @param board the current board state + * @param board the current board state * @param puzzleElement equivalent puzzleElement * @return a list of elements the specified could be */ diff --git a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/PossibleNumberCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/PossibleNumberCaseRule.java index 27d6b58b7..e6ab0e64c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/PossibleNumberCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/rules/PossibleNumberCaseRule.java @@ -9,7 +9,6 @@ import edu.rpi.legup.puzzle.sudoku.PossibleNumberCaseBoard; import edu.rpi.legup.puzzle.sudoku.SudokuBoard; import edu.rpi.legup.puzzle.sudoku.SudokuCell; - import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -17,7 +16,9 @@ public class PossibleNumberCaseRule extends CaseRule { public PossibleNumberCaseRule() { - super("SUDO-CASE-0002", "Possible Numbers for Cell", + super( + "SUDO-CASE-0002", + "Possible Numbers for Cell", "An empty cell has a limited set of possible numbers that can fill it.", "edu/rpi/legup/images/sudoku/PossibleValues.png"); } @@ -34,13 +35,13 @@ public String checkRuleRaw(TreeTransition transition) { } /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { @@ -62,7 +63,7 @@ public CaseBoard getCaseBoard(Board board) { /** * Gets the possible cases at a specific location based on this case rule * - * @param board the current board state + * @param board the current board state * @param puzzleElement equivalent puzzleElement * @return a list of elements the specified could be */ @@ -74,13 +75,14 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { /** * Gets the possible cases at a specific location based on this case rule * - * @param board the current board state + * @param board the current board state * @param puzzleElement equivalent puzzleElement - * @param value value that the rule will be applied from - * @param groupType group type + * @param value value that the rule will be applied from + * @param groupType group type * @return a list of elements the specified could be */ - public ArrayList getCases(Board board, PuzzleElement puzzleElement, int value, GroupType groupType) { + public ArrayList getCases( + Board board, PuzzleElement puzzleElement, int value, GroupType groupType) { ArrayList cases = new ArrayList<>(); SudokuBoard sudokuBoard = (SudokuBoard) board; List caseCells = new ArrayList<>(); @@ -89,12 +91,10 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement, int v Set group; if (groupType == GroupType.REGION) { group = sudokuBoard.getRegion(cell.getGroupIndex()); - } - else { + } else { if (groupType == GroupType.ROW) { group = sudokuBoard.getRow(cell.getLocation().y); - } - else { + } else { group = sudokuBoard.getCol(cell.getLocation().x); } } 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 4a5cc2074..955414e8e 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 @@ -5,25 +5,27 @@ import edu.rpi.legup.model.rules.ContradictionRule; import edu.rpi.legup.puzzle.sudoku.SudokuBoard; import edu.rpi.legup.puzzle.sudoku.SudokuCell; - import java.util.HashSet; import java.util.Set; public class RepeatedNumberContradictionRule extends ContradictionRule { public RepeatedNumberContradictionRule() { - super("SUDO-CONT-0002", "Repeated Numbers", + super( + "SUDO-CONT-0002", + "Repeated Numbers", "Two identical numbers are placed in the same group.", "edu/rpi/legup/images/sudoku/RepeatedNumber.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/ClueCommand.java b/src/main/java/edu/rpi/legup/puzzle/treetent/ClueCommand.java index 30af5af51..a11f5f05b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/ClueCommand.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/ClueCommand.java @@ -1,5 +1,7 @@ package edu.rpi.legup.puzzle.treetent; +import static edu.rpi.legup.app.GameBoardFacade.getInstance; + import edu.rpi.legup.history.CommandError; import edu.rpi.legup.history.PuzzleCommand; import edu.rpi.legup.model.Puzzle; @@ -7,14 +9,11 @@ import edu.rpi.legup.ui.proofeditorui.treeview.TreeElementView; import edu.rpi.legup.ui.proofeditorui.treeview.TreeView; import edu.rpi.legup.ui.proofeditorui.treeview.TreeViewSelection; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import static edu.rpi.legup.app.GameBoardFacade.getInstance; - public class ClueCommand extends PuzzleCommand { private TreeViewSelection selection; private TreeTentClueView clueView; @@ -28,9 +27,7 @@ public ClueCommand(TreeViewSelection selection, TreeTentClueView clueView) { this.emptyCells = new ArrayList<>(); } - /** - * Executes a command - */ + /** Executes a command */ @Override public void executeCommand() { Puzzle puzzle = getInstance().getPuzzleModule(); @@ -52,8 +49,7 @@ public void executeCommand() { if (transition == null) { transition = tree.addNewTransition(treeNode); addTran.put(treeNode, transition); - } - else { + } else { treeNode.addChild(transition); } @@ -62,8 +58,7 @@ public void executeCommand() { newSelection.addToSelection(treeView.getElementView(finalTran)); board = (TreeTentBoard) finalTran.getBoard(); - } - else { + } else { finalTran = (TreeTransition) treeElement; newSelection.addToSelection(treeView.getElementView(treeElement)); } @@ -88,7 +83,7 @@ public void executeCommand() { * Gets the reason why the command cannot be executed * * @return if command cannot be executed, returns reason for why the command cannot be executed, - * otherwise null if command can be executed + * otherwise null if command can be executed */ @Override public String getErrorString() { @@ -105,8 +100,7 @@ public String getErrorString() { if (!node.getChildren().isEmpty()) { return CommandError.UNMODIFIABLE_BOARD.toString(); } - } - else { + } else { if (!board.isModifiable()) { return CommandError.UNMODIFIABLE_BOARD.toString(); } @@ -114,17 +108,23 @@ public String getErrorString() { List tempList = new ArrayList<>(); TreeTentClue clue = clueView.getPuzzleElement(); - if (clue.getType() == TreeTentType.CLUE_NORTH || clue.getType() == TreeTentType.CLUE_SOUTH) { - int col = clue.getType() == TreeTentType.CLUE_NORTH ? clue.getClueIndex() : clue.getClueIndex() - 1; + if (clue.getType() == TreeTentType.CLUE_NORTH + || clue.getType() == TreeTentType.CLUE_SOUTH) { + int col = + clue.getType() == TreeTentType.CLUE_NORTH + ? clue.getClueIndex() + : clue.getClueIndex() - 1; for (int i = 0; i < board.getWidth(); i++) { TreeTentCell cell = board.getCell(col, i); if (cell.getType() == TreeTentType.UNKNOWN && cell.isModifiable()) { tempList.add(cell); } } - } - else { - int row = clue.getType() == TreeTentType.CLUE_WEST ? clue.getClueIndex() : clue.getClueIndex() - 1; + } else { + int row = + clue.getType() == TreeTentType.CLUE_WEST + ? clue.getClueIndex() + : clue.getClueIndex() - 1; for (int i = 0; i < board.getWidth(); i++) { TreeTentCell cell = board.getCell(i, row); if (cell.getType() == TreeTentType.UNKNOWN && cell.isModifiable()) { @@ -140,9 +140,7 @@ public String getErrorString() { return null; } - /** - * Undoes an command - */ + /** Undoes an command */ @Override public void undoCommand() { Puzzle puzzle = getInstance().getPuzzleModule(); @@ -163,8 +161,7 @@ public void undoCommand() { puzzle.notifyTreeListeners(listener -> listener.onTreeElementRemoved(finalTran)); board = (TreeTentBoard) finalTran.getBoard(); - } - else { + } else { finalTran = (TreeTransition) treeElement; } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/EditLineCommand.java b/src/main/java/edu/rpi/legup/puzzle/treetent/EditLineCommand.java index d2f8575f1..feece58a9 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/EditLineCommand.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/EditLineCommand.java @@ -1,5 +1,7 @@ package edu.rpi.legup.puzzle.treetent; +import static edu.rpi.legup.app.GameBoardFacade.getInstance; + import edu.rpi.legup.history.CommandError; import edu.rpi.legup.history.PuzzleCommand; import edu.rpi.legup.model.Puzzle; @@ -8,27 +10,23 @@ import edu.rpi.legup.ui.proofeditorui.treeview.TreeElementView; import edu.rpi.legup.ui.proofeditorui.treeview.TreeView; import edu.rpi.legup.ui.proofeditorui.treeview.TreeViewSelection; - import java.awt.*; import java.util.List; -import static edu.rpi.legup.app.GameBoardFacade.getInstance; - public class EditLineCommand extends PuzzleCommand { private TreeTentElementView start; private TreeTentElementView end; private TreeViewSelection selection; - public EditLineCommand(TreeViewSelection selection, TreeTentElementView start, ElementView endDrag) { + public EditLineCommand( + TreeViewSelection selection, TreeTentElementView start, ElementView endDrag) { this.selection = selection; this.start = start; this.end = getViewInDirection(endDrag); } - /** - * Executes a command - */ + /** Executes a command */ @Override public void executeCommand() { Puzzle puzzle = getInstance().getPuzzleModule(); @@ -49,8 +47,7 @@ public void executeCommand() { puzzle.notifyTreeListeners(listener -> listener.onTreeElementAdded(transition)); board = (TreeTentBoard) transition.getBoard(); - } - else { + } else { transition = (TreeTransition) treeElement; } @@ -73,8 +70,7 @@ public void executeCommand() { board.getLines().add(line); notifyLine = line; transition.propagateAddition(notifyLine); - } - else { + } else { board.removeModifiedData(dupLine); board.getLines().remove(dupLine); notifyLine = dupLine; @@ -85,7 +81,8 @@ public void executeCommand() { puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(transition)); - final TreeViewSelection newSelection = new TreeViewSelection(treeView.getElementView(transition)); + final TreeViewSelection newSelection = + new TreeViewSelection(treeView.getElementView(transition)); puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection)); } @@ -93,7 +90,7 @@ public void executeCommand() { * Gets the reason why the command cannot be executed * * @return if command cannot be executed, returns reason for why the command cannot be executed, - * otherwise null if command can be executed + * otherwise null if command can be executed */ @Override public String getErrorString() { @@ -114,13 +111,15 @@ public String getErrorString() { if (!node.getChildren().isEmpty()) { return CommandError.UNMODIFIABLE_BOARD.toString(); } - } - else { + } else { if (!board.isModifiable()) { return CommandError.UNMODIFIABLE_BOARD.toString(); } } - TreeTentLine line = new TreeTentLine((TreeTentCell) start.getPuzzleElement(), (TreeTentCell) end.getPuzzleElement()); + TreeTentLine line = + new TreeTentLine( + (TreeTentCell) start.getPuzzleElement(), + (TreeTentCell) end.getPuzzleElement()); for (TreeTentLine l : board.getLines()) { if (line.compare(l) && !l.isModifiable()) { return CommandError.UNMODIFIABLE_DATA.toString(); @@ -129,17 +128,16 @@ public String getErrorString() { TreeTentCell startCell = (TreeTentCell) start.getPuzzleElement(); TreeTentCell endCell = (TreeTentCell) end.getPuzzleElement(); - if (!((startCell.getType() == TreeTentType.TENT && endCell.getType() == TreeTentType.TREE) || - (endCell.getType() == TreeTentType.TENT && startCell.getType() == TreeTentType.TREE))) { + if (!((startCell.getType() == TreeTentType.TENT && endCell.getType() == TreeTentType.TREE) + || (endCell.getType() == TreeTentType.TENT + && startCell.getType() == TreeTentType.TREE))) { return "The line must connect a tree to a tent."; } return null; } - /** - * Undoes an command - */ + /** Undoes an command */ @Override public void undoCommand() { Puzzle puzzle = getInstance().getPuzzleModule(); @@ -159,8 +157,7 @@ public void undoCommand() { puzzle.notifyTreeListeners(listener -> listener.onTreeElementRemoved(transition)); board = (TreeTentBoard) transition.getBoard(); - } - else { + } else { transition = (TreeTransition) treeElement; } @@ -182,8 +179,7 @@ public void undoCommand() { board.addModifiedData(line); board.getLines().add(line); notifyLine = line; - } - else { + } else { board.removeModifiedData(dupLine); board.getLines().remove(dupLine); notifyLine = dupLine; @@ -206,24 +202,21 @@ private TreeTentElementView getViewInDirection(ElementView endDrag) { Point endLoc = endDrag.getLocation(); double radians = Math.atan2(startLoc.y - endLoc.y, endLoc.x - startLoc.x); if (radians >= Math.PI / 4 && radians < 3 * Math.PI / 4) { - //up + // up xIndex = startLoc.x / size.width; yIndex = (startLoc.y / size.height) - 1; - } - else { + } else { if (radians >= -Math.PI / 4 && radians < Math.PI / 4) { - //right + // right xIndex = (startLoc.x / size.width) + 1; yIndex = startLoc.y / size.height; - } - else { + } else { if (radians >= -3 * Math.PI / 4 && radians < -Math.PI / 4) { - //down + // down xIndex = startLoc.x / size.width; yIndex = (startLoc.y / size.height) + 1; - } - else { - //left + } else { + // left xIndex = (startLoc.x / size.width) - 1; yIndex = startLoc.y / size.height; } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTent.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTent.java index 172584cd0..68c97865d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTent.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTent.java @@ -3,7 +3,6 @@ import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.PuzzleElement; - import java.util.List; public class TreeTent extends Puzzle { @@ -19,9 +18,7 @@ public TreeTent() { this.factory = new TreeTentCellFactory(); } - /** - * Initializes the game board. Called by the invoker of the class - */ + /** Initializes the game board. Called by the invoker of the class */ @Override public void initializeView() { TreeTentBoard board = (TreeTentBoard) currentBoard; @@ -44,8 +41,8 @@ public Board generatePuzzle(int difficulty) { /** * Determines if the given dimensions are valid for Tree Tent * - * @param rows the number of rows - * @param columns the number of columns + * @param rows the number of rows + * @param columns the number of columns * @return true if the given dimensions are valid for Tree Tent, false otherwise */ public boolean isValidDimensions(int rows, int columns) { @@ -70,13 +67,10 @@ public boolean isBoardComplete(Board board) { * @param board the board that has changed */ @Override - public void onBoardChange(Board board) { - - } + public void onBoardChange(Board board) {} /** - * @return if it is valid - * TreeTent puzzle must have same number of clues as the dimension size + * @return if it is valid TreeTent puzzle must have same number of clues as the dimension size */ @Override public boolean checkValidity() { diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java index dc809f34d..09706f92a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java @@ -3,7 +3,6 @@ import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.GridBoard; import edu.rpi.legup.model.gameboard.PuzzleElement; - import java.awt.*; import java.util.ArrayList; import java.util.List; @@ -75,8 +74,7 @@ public PuzzleElement getPuzzleElement(PuzzleElement element) { public TreeTentClue getClue(int x, int y) { if (x == getWidth() && 0 <= y && y < getHeight()) { return rowClues.get(y); - } - else { + } else { if (y == getHeight() && 0 <= x && x < getWidth()) { return colClues.get(x); } @@ -85,7 +83,8 @@ public TreeTentClue getClue(int x, int y) { } /** - * Called when a {@link PuzzleElement} has been added and passes in the equivalent puzzle element with the data. + * Called when a {@link PuzzleElement} has been added and passes in the equivalent puzzle + * element with the data. * * @param puzzleElement equivalent puzzle element with the data. */ @@ -97,7 +96,8 @@ public void notifyAddition(PuzzleElement puzzleElement) { } /** - * Called when a {@link PuzzleElement} has been deleted and passes in the equivalent puzzle element with the data. + * Called when a {@link PuzzleElement} has been deleted and passes in the equivalent puzzle + * element with the data. * * @param puzzleElement equivalent puzzle element with the data. */ @@ -118,8 +118,8 @@ public void notifyDeletion(PuzzleElement puzzleElement) { * * @param cell The cell to get adjacent cells from. * @param type The cell types to get. - * @return List of adjacent cells in the form { up, right, down, left }. - * If an adjacent cell is null, it will not be added to the list. + * @return List of adjacent cells in the form { up, right, down, left }. If an adjacent cell is + * null, it will not be added to the list. */ public List getAdjacent(TreeTentCell cell, TreeTentType type) { List adj = new ArrayList<>(); @@ -138,7 +138,8 @@ public List getAdjacent(TreeTentCell cell, TreeTentType type) { * * @param cell the base cell * @param type the type to look for - * @return a list of TreeTentCells that are diagonals of the given TreeTentCell and are of the given TreeTentType + * @return a list of TreeTentCells that are diagonals of the given TreeTentCell and are of the + * given TreeTentType */ public List getDiagonals(TreeTentCell cell, TreeTentType type) { List dia = new ArrayList<>(); @@ -166,7 +167,7 @@ public List getDiagonals(TreeTentCell cell, TreeTentType type) { * Creates and returns a list of TreeTentCells that match the given TreeTentType * * @param index the row or column number - * @param type type of TreeTent element + * @param type type of TreeTent element * @param isRow boolean value beased on whether a row of column is being checked * @return List of TreeTentCells that match the given TreeTentType */ @@ -179,8 +180,7 @@ public List getRowCol(int index, TreeTentType type, boolean isRow) list.add(cell); } } - } - else { + } else { for (int i = 0; i < dimension.width; i++) { TreeTentCell cell = getCell(index, i); if (cell.getType() == type) { diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCell.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCell.java index b6411a5cf..c7c9f0d21 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCell.java @@ -2,7 +2,6 @@ import edu.rpi.legup.model.elements.Element; import edu.rpi.legup.model.gameboard.GridCell; - import java.awt.*; import java.awt.event.MouseEvent; diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCellFactory.java index 20b8066a4..1697b8bd5 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCellFactory.java @@ -4,17 +4,16 @@ import edu.rpi.legup.model.gameboard.ElementFactory; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; -import java.awt.*; - public class TreeTentCellFactory extends ElementFactory { /** * Creates a puzzleElement based on the xml document Node and adds it to the board * - * @param node node that represents the puzzleElement + * @param node node that represents the puzzleElement * @param board board to add the newly created cell * @return newly created cell from the xml document Node * @throws InvalidFileFormatException if file is invalid @@ -32,7 +31,8 @@ public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormat int x = Integer.valueOf(attributeList.getNamedItem("x").getNodeValue()); int y = Integer.valueOf(attributeList.getNamedItem("y").getNodeValue()); if (x >= width || y >= height) { - throw new InvalidFileFormatException("TreeTent Factory: cell location out of bounds"); + throw new InvalidFileFormatException( + "TreeTent Factory: cell location out of bounds"); } if (value < 0 || value > 3) { throw new InvalidFileFormatException("TreeTent Factory: cell unknown value"); @@ -41,30 +41,29 @@ public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormat TreeTentCell cell = new TreeTentCell(TreeTentType.valueOf(value), new Point(x, y)); cell.setIndex(y * height + x); return cell; - } - else { + } else { if (node.getNodeName().equalsIgnoreCase("line")) { int x1 = Integer.valueOf(attributeList.getNamedItem("x1").getNodeValue()); int y1 = Integer.valueOf(attributeList.getNamedItem("y1").getNodeValue()); int x2 = Integer.valueOf(attributeList.getNamedItem("x2").getNodeValue()); int y2 = Integer.valueOf(attributeList.getNamedItem("y2").getNodeValue()); if (x1 >= width || y1 >= height || x2 >= width || y2 >= height) { - throw new InvalidFileFormatException("TreeTent Factory: line location out of bounds"); + throw new InvalidFileFormatException( + "TreeTent Factory: line location out of bounds"); } TreeTentCell c1 = treeTentBoard.getCell(x1, y1); TreeTentCell c2 = treeTentBoard.getCell(x2, y2); return new TreeTentLine(c1, c2); - } - else { - throw new InvalidFileFormatException("TreeTent Factory: unknown puzzleElement puzzleElement"); + } else { + throw new InvalidFileFormatException( + "TreeTent Factory: unknown puzzleElement puzzleElement"); } } - } - catch (NumberFormatException e) { - throw new InvalidFileFormatException("TreeTent Factory: unknown value where integer expected"); - } - catch (NullPointerException e) { + } catch (NumberFormatException e) { + throw new InvalidFileFormatException( + "TreeTent Factory: unknown value where integer expected"); + } catch (NullPointerException e) { throw new InvalidFileFormatException("TreeTent Factory: could not find attribute(s)"); } } @@ -72,7 +71,7 @@ public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormat /** * Creates a xml document puzzleElement from a cell for exporting * - * @param document xml document + * @param document xml document * @param puzzleElement PuzzleElement cell * @return xml PuzzleElement */ @@ -88,8 +87,7 @@ public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleEle cellElement.setAttribute("y", String.valueOf(loc.y)); return cellElement; - } - else { + } else { org.w3c.dom.Element lineElement = document.createElement("line"); TreeTentLine line = (TreeTentLine) puzzleElement; diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentClueView.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentClueView.java index 4e7b24b13..d1b230d20 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentClueView.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentClueView.java @@ -1,7 +1,6 @@ package edu.rpi.legup.puzzle.treetent; import edu.rpi.legup.ui.boardview.ElementView; - import java.awt.*; public class TreeTentClueView extends ElementView { diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentController.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentController.java index 1f431594c..79e074657 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentController.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentController.java @@ -1,5 +1,7 @@ package edu.rpi.legup.puzzle.treetent; +import static edu.rpi.legup.app.GameBoardFacade.getInstance; + import edu.rpi.legup.app.GameBoardFacade; import edu.rpi.legup.controller.ElementController; import edu.rpi.legup.history.AutoCaseRuleCommand; @@ -13,11 +15,8 @@ import edu.rpi.legup.ui.proofeditorui.treeview.TreePanel; import edu.rpi.legup.ui.proofeditorui.treeview.TreeView; import edu.rpi.legup.ui.proofeditorui.treeview.TreeViewSelection; - import java.awt.event.MouseEvent; -import static edu.rpi.legup.app.GameBoardFacade.getInstance; - public class TreeTentController extends ElementController { private ElementView lastCellPressed; @@ -40,9 +39,11 @@ public void mousePressed(MouseEvent e) { @Override public void mouseReleased(MouseEvent e) { - if (GameBoardFacade.getInstance().getLegupUI().getTreePanel() != null && e.getButton() != MouseEvent.BUTTON2) { + if (GameBoardFacade.getInstance().getLegupUI().getTreePanel() != null + && e.getButton() != MouseEvent.BUTTON2) { TreePanel treePanel = GameBoardFacade.getInstance().getLegupUI().getTreePanel(); - TreeView treeView = GameBoardFacade.getInstance().getLegupUI().getTreePanel().getTreeView(); + TreeView treeView = + GameBoardFacade.getInstance().getLegupUI().getTreePanel().getTreeView(); BoardView boardView = getInstance().getLegupUI().getBoardView(); lastCellPressed = boardView.getElement(e.getPoint()); Board board = boardView.getBoard(); @@ -51,17 +52,17 @@ public void mouseReleased(MouseEvent e) { if (dragStart != null) { if (board instanceof CaseBoard) { CaseBoard caseBoard = (CaseBoard) board; - AutoCaseRuleCommand autoCaseRuleCommand = new AutoCaseRuleCommand(dragStart, selection, caseBoard.getCaseRule(), caseBoard, e); + AutoCaseRuleCommand autoCaseRuleCommand = + new AutoCaseRuleCommand( + dragStart, selection, caseBoard.getCaseRule(), caseBoard, e); if (autoCaseRuleCommand.canExecute()) { autoCaseRuleCommand.execute(); getInstance().getHistory().pushChange(autoCaseRuleCommand); treePanel.updateError(""); - } - else { + } else { treePanel.updateError(autoCaseRuleCommand.getError()); } - } - else { + } else { if (dragStart == lastCellPressed) { if (dragStart.getPuzzleElement().getIndex() >= 0) { ICommand edit = new EditDataCommand(lastCellPressed, selection, e); @@ -69,32 +70,32 @@ public void mouseReleased(MouseEvent e) { edit.execute(); getInstance().getHistory().pushChange(edit); treePanel.updateError(""); - } - else { + } else { treePanel.updateError(edit.getError()); } - } - else { - ClueCommand edit = new ClueCommand(selection, (TreeTentClueView) dragStart); + } else { + ClueCommand edit = + new ClueCommand(selection, (TreeTentClueView) dragStart); if (edit.canExecute()) { edit.execute(); getInstance().getHistory().pushChange(edit); treePanel.updateError(""); - } - else { + } else { treePanel.updateError(edit.getError()); } } - } - else { + } else { if (lastCellPressed != null) { if (dragStart instanceof TreeTentElementView) { - ICommand editLine = new EditLineCommand(selection, (TreeTentElementView) dragStart, lastCellPressed); + ICommand editLine = + new EditLineCommand( + selection, + (TreeTentElementView) dragStart, + lastCellPressed); if (editLine.canExecute()) { editLine.execute(); getInstance().getHistory().pushChange(editLine); - } - else { + } else { treePanel.updateError(editLine.getError()); } } @@ -113,26 +114,21 @@ public void changeCell(MouseEvent e, PuzzleElement element) { if (e.getButton() == MouseEvent.BUTTON1) { if (cell.getData() == TreeTentType.UNKNOWN) { element.setData(TreeTentType.GRASS); - } - else { + } else { if (cell.getData() == TreeTentType.GRASS) { element.setData(TreeTentType.TENT); - } - else { + } else { element.setData(TreeTentType.UNKNOWN); } } - } - else { + } else { if (e.getButton() == MouseEvent.BUTTON3) { if (cell.getData() == TreeTentType.UNKNOWN) { element.setData(TreeTentType.TENT); - } - else { + } else { if (cell.getData() == TreeTentType.GRASS) { element.setData(TreeTentType.UNKNOWN); - } - else { + } else { element.setData(TreeTentType.GRASS); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentElementView.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentElementView.java index 0c8698f83..1196ab075 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentElementView.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentElementView.java @@ -1,7 +1,6 @@ package edu.rpi.legup.puzzle.treetent; import edu.rpi.legup.ui.boardview.GridElementView; - import java.awt.*; import java.awt.geom.Rectangle2D; @@ -23,25 +22,47 @@ public void drawElement(Graphics2D graphics2D) { if (type == TreeTentType.UNKNOWN) { graphics2D.setStroke(new BasicStroke(1)); graphics2D.setColor(Color.LIGHT_GRAY); - graphics2D.fill(new Rectangle2D.Double(location.x + 0.5f, location.y + 0.5f, size.width - 1, size.height - 1)); + graphics2D.fill( + new Rectangle2D.Double( + location.x + 0.5f, location.y + 0.5f, size.width - 1, size.height - 1)); graphics2D.setColor(Color.BLACK); - graphics2D.draw(new Rectangle2D.Double(location.x + 0.5f, location.y + 0.5f, size.width - 1, size.height - 1)); - } - else { + graphics2D.draw( + new Rectangle2D.Double( + location.x + 0.5f, location.y + 0.5f, size.width - 1, size.height - 1)); + } else { if (type == TreeTentType.TREE) { - graphics2D.drawImage(TreeTentView.TREE, location.x, location.y, size.width, size.height, null, null); + graphics2D.drawImage( + TreeTentView.TREE, + location.x, + location.y, + size.width, + size.height, + null, + null); graphics2D.setColor(Color.BLACK); graphics2D.drawRect(location.x, location.y, size.width, size.height); - } - else { + } else { if (type == TreeTentType.GRASS) { - graphics2D.drawImage(TreeTentView.GRASS, location.x, location.y, size.width, size.height, null, null); + graphics2D.drawImage( + TreeTentView.GRASS, + location.x, + location.y, + size.width, + size.height, + null, + null); graphics2D.setColor(Color.BLACK); graphics2D.drawRect(location.x, location.y, size.width, size.height); - } - else { + } else { if (type == TreeTentType.TENT) { - graphics2D.drawImage(TreeTentView.TENT, location.x, location.y, size.width, size.height, null, null); + graphics2D.drawImage( + TreeTentView.TENT, + location.x, + location.y, + size.width, + size.height, + null, + null); graphics2D.setColor(Color.BLACK); graphics2D.drawRect(location.x, location.y, size.width, size.height); } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentExporter.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentExporter.java index c438d8ee4..475aaab1e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentExporter.java @@ -21,8 +21,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { TreeTentBoard board; if (puzzle.getTree() != null) { board = (TreeTentBoard) puzzle.getTree().getRootNode().getBoard(); - } - else { + } else { board = (TreeTentBoard) puzzle.getBoardView().getBoard(); } @@ -34,7 +33,8 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { for (PuzzleElement puzzleElement : board.getPuzzleElements()) { TreeTentCell cell = (TreeTentCell) puzzleElement; if (cell.getData() != TreeTentType.UNKNOWN) { - org.w3c.dom.Element cellElement = puzzle.getFactory().exportCell(newDocument, puzzleElement); + org.w3c.dom.Element cellElement = + puzzle.getFactory().exportCell(newDocument, puzzleElement); cellsElement.appendChild(cellElement); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentImporter.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentImporter.java index 2b4861c9f..0117f41ce 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentImporter.java @@ -2,12 +2,11 @@ import edu.rpi.legup.model.PuzzleImporter; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import java.awt.*; - public class TreeTentImporter extends PuzzleImporter { public TreeTentImporter(TreeTent treeTent) { super(treeTent); @@ -26,7 +25,7 @@ public boolean acceptsTextInput() { /** * Creates an empty board for building * - * @param rows the number of rows on the board + * @param rows the number of rows on the board * @param columns the number of columns on the board * @throws RuntimeException if board can not be created */ @@ -66,11 +65,13 @@ public void initializeBoard(int rows, int columns) { public void initializeBoard(Node node) throws InvalidFileFormatException { try { if (!node.getNodeName().equalsIgnoreCase("board")) { - throw new InvalidFileFormatException("TreeTent Importer: cannot find board puzzleElement"); + throw new InvalidFileFormatException( + "TreeTent Importer: cannot find board puzzleElement"); } Element boardElement = (Element) node; if (boardElement.getElementsByTagName("cells").getLength() == 0) { - throw new InvalidFileFormatException("TreeTent Importer: no puzzleElement found for board"); + throw new InvalidFileFormatException( + "TreeTent Importer: no puzzleElement found for board"); } Element dataElement = (Element) boardElement.getElementsByTagName("cells").item(0); NodeList elementDataList = dataElement.getElementsByTagName("cell"); @@ -79,9 +80,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { if (!boardElement.getAttribute("size").isEmpty()) { int size = Integer.valueOf(boardElement.getAttribute("size")); treeTentBoard = new TreeTentBoard(size); - } - else { - if (!boardElement.getAttribute("width").isEmpty() && !boardElement.getAttribute("height").isEmpty()) { + } else { + if (!boardElement.getAttribute("width").isEmpty() + && !boardElement.getAttribute("height").isEmpty()) { int width = Integer.valueOf(boardElement.getAttribute("width")); int height = Integer.valueOf(boardElement.getAttribute("height")); treeTentBoard = new TreeTentBoard(width, height); @@ -96,7 +97,10 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { int height = treeTentBoard.getHeight(); for (int i = 0; i < elementDataList.getLength(); i++) { - TreeTentCell cell = (TreeTentCell) puzzle.getFactory().importCell(elementDataList.item(i), treeTentBoard); + TreeTentCell cell = + (TreeTentCell) + puzzle.getFactory() + .importCell(elementDataList.item(i), treeTentBoard); Point loc = cell.getLocation(); if (cell.getData() != TreeTentType.UNKNOWN) { cell.setModifiable(false); @@ -125,19 +129,31 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { Element axis2 = (Element) axes.item(1); if (!axis1.hasAttribute("side") || !axis1.hasAttribute("side")) { - throw new InvalidFileFormatException("TreeTent Importer: side attribute of axis not specified"); + throw new InvalidFileFormatException( + "TreeTent Importer: side attribute of axis not specified"); } String side1 = axis1.getAttribute("side"); String side2 = axis2.getAttribute("side"); - if (side1.equalsIgnoreCase(side2) || !(side1.equalsIgnoreCase("east") || side1.equalsIgnoreCase("south")) || - !(side2.equalsIgnoreCase("east") || side2.equalsIgnoreCase("south"))) { - throw new InvalidFileFormatException("TreeTent Importer: axes must be different and be {east | south}"); + if (side1.equalsIgnoreCase(side2) + || !(side1.equalsIgnoreCase("east") || side1.equalsIgnoreCase("south")) + || !(side2.equalsIgnoreCase("east") || side2.equalsIgnoreCase("south"))) { + throw new InvalidFileFormatException( + "TreeTent Importer: axes must be different and be {east | south}"); } - NodeList eastClues = side1.equalsIgnoreCase("east") ? axis1.getElementsByTagName("clue") : axis2.getElementsByTagName("clue"); - NodeList southClues = side1.equalsIgnoreCase("south") ? axis1.getElementsByTagName("clue") : axis2.getElementsByTagName("clue"); - - if (eastClues.getLength() != treeTentBoard.getHeight() || southClues.getLength() != treeTentBoard.getWidth()) { - throw new InvalidFileFormatException("TreeTent Importer: there must be same number of clues as the dimension of the board"); + NodeList eastClues = + side1.equalsIgnoreCase("east") + ? axis1.getElementsByTagName("clue") + : axis2.getElementsByTagName("clue"); + NodeList southClues = + side1.equalsIgnoreCase("south") + ? axis1.getElementsByTagName("clue") + : axis2.getElementsByTagName("clue"); + + if (eastClues.getLength() != treeTentBoard.getHeight() + || southClues.getLength() != treeTentBoard.getWidth()) { + throw new InvalidFileFormatException( + "TreeTent Importer: there must be same number of clues as the dimension of" + + " the board"); } for (int i = 0; i < eastClues.getLength(); i++) { @@ -146,13 +162,16 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { int index = TreeTentClue.colStringToColNum(clue.getAttribute("index")); if (index - 1 < 0 || index - 1 > treeTentBoard.getHeight()) { - throw new InvalidFileFormatException("TreeTent Importer: clue index out of bounds"); + throw new InvalidFileFormatException( + "TreeTent Importer: clue index out of bounds"); } if (treeTentBoard.getRowClues().get(index - 1) != null) { throw new InvalidFileFormatException("TreeTent Importer: duplicate clue index"); } - treeTentBoard.getRowClues().set(index - 1, new TreeTentClue(value, index, TreeTentType.CLUE_EAST)); + treeTentBoard + .getRowClues() + .set(index - 1, new TreeTentClue(value, index, TreeTentType.CLUE_EAST)); } for (int i = 0; i < southClues.getLength(); i++) { @@ -161,27 +180,35 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { int index = Integer.valueOf(clue.getAttribute("index")); if (index - 1 < 0 || index - 1 > treeTentBoard.getWidth()) { - throw new InvalidFileFormatException("TreeTent Importer: clue index out of bounds"); + throw new InvalidFileFormatException( + "TreeTent Importer: clue index out of bounds"); } if (treeTentBoard.getColClues().get(index - 1) != null) { throw new InvalidFileFormatException("TreeTent Importer: duplicate clue index"); } - treeTentBoard.getColClues().set(index - 1, new TreeTentClue(value, index, TreeTentType.CLUE_SOUTH)); + treeTentBoard + .getColClues() + .set(index - 1, new TreeTentClue(value, index, TreeTentType.CLUE_SOUTH)); } if (boardElement.getElementsByTagName("lines").getLength() == 1) { Element linesElement = (Element) boardElement.getElementsByTagName("lines").item(0); NodeList linesList = linesElement.getElementsByTagName("line"); for (int i = 0; i < linesList.getLength(); i++) { - treeTentBoard.getLines().add((TreeTentLine) puzzle.getFactory().importCell(linesList.item(i), treeTentBoard)); + treeTentBoard + .getLines() + .add( + (TreeTentLine) + puzzle.getFactory() + .importCell(linesList.item(i), treeTentBoard)); } } puzzle.setCurrentBoard(treeTentBoard); - } - catch (NumberFormatException e) { - throw new InvalidFileFormatException("TreeTent Importer: unknown value where integer expected"); + } catch (NumberFormatException e) { + throw new InvalidFileFormatException( + "TreeTent Importer: unknown value where integer expected"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentLine.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentLine.java index 9444cb425..dae10a1ae 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentLine.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentLine.java @@ -26,8 +26,10 @@ public void setC2(TreeTentCell c2) { } public boolean compare(TreeTentLine line) { - return ((line.getC1().getLocation().equals(data.getKey().getLocation()) && line.getC2().getLocation().equals(data.getValue().getLocation())) || - (line.getC1().getLocation().equals(data.getValue().getLocation()) && line.getC2().getLocation().equals(data.getKey().getLocation()))); + return ((line.getC1().getLocation().equals(data.getKey().getLocation()) + && line.getC2().getLocation().equals(data.getValue().getLocation())) + || (line.getC1().getLocation().equals(data.getValue().getLocation()) + && line.getC2().getLocation().equals(data.getKey().getLocation()))); } /** diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentLineView.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentLineView.java index 833dcb5b5..6d478cff8 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentLineView.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentLineView.java @@ -1,7 +1,6 @@ package edu.rpi.legup.puzzle.treetent; import edu.rpi.legup.ui.boardview.ElementView; - import java.awt.*; public class TreeTentLineView extends ElementView { @@ -24,7 +23,7 @@ public void draw(Graphics2D graphics2D) { int x2 = (p2.x + 1) * size.width + size.width / 2; int y2 = (p2.y + 1) * size.height + size.height / 2; - //graphics2D.setColor(LINE_COLOR); + // graphics2D.setColor(LINE_COLOR); graphics2D.setColor(line.isModified() ? Color.GREEN : Color.WHITE); graphics2D.setStroke(LINE_STROKE); graphics2D.drawLine(x1, y1, x2, y2); diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentType.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentType.java index 890cdfe29..230283418 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentType.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentType.java @@ -1,10 +1,14 @@ package edu.rpi.legup.puzzle.treetent; -import edu.rpi.legup.puzzle.masyu.MasyuType; - public enum TreeTentType { - UNKNOWN, TREE, GRASS, TENT, - CLUE_NORTH, CLUE_EAST, CLUE_SOUTH, CLUE_WEST; + UNKNOWN, + TREE, + GRASS, + TENT, + CLUE_NORTH, + CLUE_EAST, + CLUE_SOUTH, + CLUE_WEST; public static TreeTentType valueOf(int num) { switch (num) { @@ -18,4 +22,4 @@ public static TreeTentType valueOf(int num) { return UNKNOWN; } } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentView.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentView.java index 23a500231..3b8cadad6 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentView.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentView.java @@ -6,26 +6,33 @@ import edu.rpi.legup.model.tree.TreeElement; import edu.rpi.legup.ui.boardview.ElementView; import edu.rpi.legup.ui.boardview.GridBoardView; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import javax.imageio.ImageIO; import java.awt.*; import java.io.IOException; import java.util.ArrayList; +import javax.imageio.ImageIO; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class TreeTentView extends GridBoardView { - private final static Logger LOGGER = LogManager.getLogger(TreeTentView.class.getName()); + private static final Logger LOGGER = LogManager.getLogger(TreeTentView.class.getName()); static Image TREE, GRASS, TENT; static { try { - TREE = ImageIO.read(ClassLoader.getSystemResourceAsStream("edu/rpi/legup/images/treetent/tree.png")); - GRASS = ImageIO.read(ClassLoader.getSystemResourceAsStream("edu/rpi/legup/images/treetent/grass.png")); - TENT = ImageIO.read(ClassLoader.getSystemResourceAsStream("edu/rpi/legup/images/treetent/tent.png")); - } - catch (IOException e) { + TREE = + ImageIO.read( + ClassLoader.getSystemResourceAsStream( + "edu/rpi/legup/images/treetent/tree.png")); + GRASS = + ImageIO.read( + ClassLoader.getSystemResourceAsStream( + "edu/rpi/legup/images/treetent/grass.png")); + TENT = + ImageIO.read( + ClassLoader.getSystemResourceAsStream( + "edu/rpi/legup/images/treetent/tent.png")); + } catch (IOException e) { LOGGER.error("Failed to open TreeTent images"); } } @@ -53,7 +60,8 @@ public TreeTentView(TreeTentBoard board) { TreeTentElementView elementView = new TreeTentElementView(cell); elementView.setIndex(cell.getIndex()); elementView.setSize(elementSize); - elementView.setLocation(new Point((loc.x + 1) * elementSize.width, (loc.y + 1) * elementSize.height)); + elementView.setLocation( + new Point((loc.x + 1) * elementSize.width, (loc.y + 1) * elementSize.height)); elementViews.add(elementView); } @@ -64,12 +72,16 @@ public TreeTentView(TreeTentBoard board) { } for (int i = 0; i < gridSize.height; i++) { - TreeTentClueView row = new TreeTentClueView(new TreeTentClue(i, i, TreeTentType.CLUE_WEST)); + TreeTentClueView row = + new TreeTentClueView(new TreeTentClue(i, i, TreeTentType.CLUE_WEST)); row.setLocation(new Point(0, (i + 1) * elementSize.height)); row.setSize(elementSize); TreeTentClueView clue = new TreeTentClueView(board.getRowClues().get(i)); - clue.setLocation(new Point((gridSize.width + 1) * elementSize.width, (i + 1) * elementSize.height)); + clue.setLocation( + new Point( + (gridSize.width + 1) * elementSize.width, + (i + 1) * elementSize.height)); clue.setSize(elementSize); westClues.add(row); @@ -77,12 +89,16 @@ public TreeTentView(TreeTentBoard board) { } for (int i = 0; i < gridSize.width; i++) { - TreeTentClueView col = new TreeTentClueView(new TreeTentClue(i, i, TreeTentType.CLUE_NORTH)); + TreeTentClueView col = + new TreeTentClueView(new TreeTentClue(i, i, TreeTentType.CLUE_NORTH)); col.setLocation(new Point((i + 1) * elementSize.width, 0)); col.setSize(elementSize); TreeTentClueView clue = new TreeTentClueView(board.getColClues().get(i)); - clue.setLocation(new Point((i + 1) * elementSize.width, (gridSize.height + 1) * elementSize.height)); + clue.setLocation( + new Point( + (i + 1) * elementSize.width, + (gridSize.height + 1) * elementSize.height)); clue.setSize(elementSize); northClues.add(col); @@ -91,15 +107,18 @@ public TreeTentView(TreeTentBoard board) { } /** - * Gets the ElementView from the location specified or - * null if one does not exists at that location + * Gets the ElementView from the location specified or null if one does not exists at that + * location * * @param point location on the viewport * @return ElementView at the specified location */ @Override public ElementView getElement(Point point) { - Point scaledPoint = new Point((int) Math.round(point.x / getScale()), (int) Math.round(point.y / getScale())); + Point scaledPoint = + new Point( + (int) Math.round(point.x / getScale()), + (int) Math.round(point.y / getScale())); for (ElementView element : elementViews) { if (element.isWithinBounds(scaledPoint)) { return element; @@ -167,8 +186,7 @@ public void onTreeElementChanged(TreeElement treeElement) { TreeTentBoard treeTentBoard; if (board instanceof CaseBoard) { treeTentBoard = (TreeTentBoard) ((CaseBoard) board).getBaseBoard(); - } - else { + } else { treeTentBoard = (TreeTentBoard) board; } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/elements/GrassTile.java b/src/main/java/edu/rpi/legup/puzzle/treetent/elements/GrassTile.java index b85b5e337..5356120a8 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/elements/GrassTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/elements/GrassTile.java @@ -5,7 +5,10 @@ public class GrassTile extends PlaceableElement { public GrassTile() { - super("TREE-PlAC-0002", "Grass Tile", "The grass crest tile", "edu/rpi/legup/images/treetent/grass.png"); + super( + "TREE-PlAC-0002", + "Grass Tile", + "The grass crest tile", + "edu/rpi/legup/images/treetent/grass.png"); } - -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/elements/TentTile.java b/src/main/java/edu/rpi/legup/puzzle/treetent/elements/TentTile.java index 2f4fee1eb..950aebfa7 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/elements/TentTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/elements/TentTile.java @@ -5,7 +5,10 @@ public class TentTile extends PlaceableElement { public TentTile() { - super("TREE-PLAC-0001", "Tent Tile", "The tent tile", "edu/rpi/legup/images/treetent/tent.png"); + super( + "TREE-PLAC-0001", + "Tent Tile", + "The tent tile", + "edu/rpi/legup/images/treetent/tent.png"); } - -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/elements/TreeTile.java b/src/main/java/edu/rpi/legup/puzzle/treetent/elements/TreeTile.java index a91928fe4..d04886ed5 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/elements/TreeTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/elements/TreeTile.java @@ -1,12 +1,14 @@ package edu.rpi.legup.puzzle.treetent.elements; import edu.rpi.legup.model.elements.NonPlaceableElement; -import edu.rpi.legup.model.elements.PlaceableElement; public class TreeTile extends NonPlaceableElement { public TreeTile() { - super("TREE-UNPL-0001", "Tree Tile", "The tree tile", "edu/rpi/legup/images/treetent/tree.png"); + super( + "TREE-UNPL-0001", + "Tree Tile", + "The tree tile", + "edu/rpi/legup/images/treetent/tree.png"); } - } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/elements/UnknownTile.java b/src/main/java/edu/rpi/legup/puzzle/treetent/elements/UnknownTile.java index 73c8ca263..a54240efd 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/elements/UnknownTile.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/elements/UnknownTile.java @@ -4,6 +4,10 @@ public class UnknownTile extends NonPlaceableElement { public UnknownTile() { - super("TREE-UNPL-0002", "Unknown Tile", "The blank tile", "edu/rpi/legup/images/treetent/UnknownTile.png"); + super( + "TREE-UNPL-0002", + "Unknown Tile", + "The blank tile", + "edu/rpi/legup/images/treetent/UnknownTile.png"); } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/EmptyFieldDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/EmptyFieldDirectRule.java index adfad52f6..c91a60b1a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/EmptyFieldDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/EmptyFieldDirectRule.java @@ -1,87 +1,89 @@ -package edu.rpi.legup.puzzle.treetent.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.treetent.TreeTentBoard; -import edu.rpi.legup.puzzle.treetent.TreeTentCell; -import edu.rpi.legup.puzzle.treetent.TreeTentLine; -import edu.rpi.legup.puzzle.treetent.TreeTentType; - -import java.util.List; - -public class EmptyFieldDirectRule extends DirectRule { - public EmptyFieldDirectRule() { - super("TREE-BASC-0001", "Empty Field", - "Blank cells not adjacent to an unlinked tree are grass.", - "edu/rpi/legup/images/treetent/noTreesAround.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - if (puzzleElement instanceof TreeTentLine) { - 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 super.getInvalidUseOfRuleMessage() + ": This cell must be grass"; - } - - if (isForced(finalBoard, finalCell)) { - return null; - } - else { - return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be empty."; - } - } - - /** - * Returns a boolean value based on whether the specified cell has adjacent cells (true - no adjacent, false - has adjacent) - * - * @param board the TreeTent board - * @param cell the specified TreeTent cell - * @return true - no adjacent, false - has adjacent - */ - private boolean isForced(TreeTentBoard board, TreeTentCell cell) { - List adjCells = board.getAdjacent(cell, TreeTentType.TREE); - return adjCells.isEmpty(); - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - TreeTentBoard treeTentBoard = (TreeTentBoard) node.getBoard().copy(); - for (PuzzleElement element : treeTentBoard.getPuzzleElements()) { - TreeTentCell cell = (TreeTentCell) element; - if (cell.getType() == TreeTentType.UNKNOWN && isForced(treeTentBoard, cell)) { - cell.setData(TreeTentType.GRASS); - treeTentBoard.addModifiedData(cell); - } - } - if (treeTentBoard.getModifiedData().isEmpty()) { - return null; - } - else { - return treeTentBoard; - } - } -} +package edu.rpi.legup.puzzle.treetent.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.treetent.TreeTentBoard; +import edu.rpi.legup.puzzle.treetent.TreeTentCell; +import edu.rpi.legup.puzzle.treetent.TreeTentLine; +import edu.rpi.legup.puzzle.treetent.TreeTentType; +import java.util.List; + +public class EmptyFieldDirectRule extends DirectRule { + public EmptyFieldDirectRule() { + super( + "TREE-BASC-0001", + "Empty Field", + "Blank cells not adjacent to an unlinked tree are grass.", + "edu/rpi/legup/images/treetent/noTreesAround.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + if (puzzleElement instanceof TreeTentLine) { + 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 super.getInvalidUseOfRuleMessage() + ": This cell must be grass"; + } + + if (isForced(finalBoard, finalCell)) { + return null; + } else { + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be empty."; + } + } + + /** + * Returns a boolean value based on whether the specified cell has adjacent cells (true - no + * adjacent, false - has adjacent) + * + * @param board the TreeTent board + * @param cell the specified TreeTent cell + * @return true - no adjacent, false - has adjacent + */ + private boolean isForced(TreeTentBoard board, TreeTentCell cell) { + List adjCells = board.getAdjacent(cell, TreeTentType.TREE); + return adjCells.isEmpty(); + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + TreeTentBoard treeTentBoard = (TreeTentBoard) node.getBoard().copy(); + for (PuzzleElement element : treeTentBoard.getPuzzleElements()) { + TreeTentCell cell = (TreeTentCell) element; + if (cell.getType() == TreeTentType.UNKNOWN && isForced(treeTentBoard, cell)) { + cell.setData(TreeTentType.GRASS); + treeTentBoard.addModifiedData(cell); + } + } + if (treeTentBoard.getModifiedData().isEmpty()) { + return null; + } else { + return treeTentBoard; + } + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FillinRowCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FillinRowCaseRule.java index 698b3aa5e..0116c0dcd 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FillinRowCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FillinRowCaseRule.java @@ -7,17 +7,18 @@ import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.treetent.TreeTentBoard; import edu.rpi.legup.puzzle.treetent.TreeTentCell; -import edu.rpi.legup.puzzle.treetent.TreeTentType; import edu.rpi.legup.puzzle.treetent.TreeTentClue; - +import edu.rpi.legup.puzzle.treetent.TreeTentType; +import java.awt.*; import java.util.ArrayList; import java.util.List; -import java.awt.*; public class FillinRowCaseRule extends CaseRule { public FillinRowCaseRule() { - super("TREE-CASE-0001", "Fill In row", + super( + "TREE-CASE-0001", + "Fill In row", "A row must have the number of tents of its clue.", "edu/rpi/legup/images/treetent/case_rowcount.png"); } @@ -36,8 +37,14 @@ public CaseBoard getCaseBoard(Board board) { ArrayList clues = treeTentBoard.getRowClues(); clues.addAll(treeTentBoard.getColClues()); for (PuzzleElement element : clues) { - // if ((((TreeTentCell) element).getType() == TreeTentType.CLUE_SOUTH && treeTentBoard.getRowCol(((TreeTentCell)element).getLocation().y, TreeTentType.UNKNOWN, true).size() != 0) || - // (((TreeTentCell) element).getType() == TreeTentType.CLUE_EAST && treeTentBoard.getRowCol(((TreeTentCell)element).getLocation().x, TreeTentType.UNKNOWN, false).size() != 0)) { + // if ((((TreeTentCell) element).getType() == TreeTentType.CLUE_SOUTH && + // treeTentBoard.getRowCol(((TreeTentCell)element).getLocation().y, + // TreeTentType.UNKNOWN, + // true).size() != 0) || + // (((TreeTentCell) element).getType() == TreeTentType.CLUE_EAST && + // treeTentBoard.getRowCol(((TreeTentCell)element).getLocation().x, + // TreeTentType.UNKNOWN, + // false).size() != 0)) { // caseBoard.addPickableElement(element); // } caseBoard.addPickableElement(element); @@ -48,7 +55,7 @@ public CaseBoard getCaseBoard(Board board) { /** * Gets the possible cases at a specific location based on this case rule * - * @param board the current board state + * @param board the current board state * @param puzzleElement equivalent puzzleElement * @return a list of elements the specified could be */ @@ -62,29 +69,46 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { TreeTentBoard tBoard = (TreeTentBoard) board; if (clue.getType() == TreeTentType.CLUE_SOUTH) { group = tBoard.getRowCol(clueIndex, TreeTentType.UNKNOWN, false); - tentsLeft = tBoard.getRowClues().get(clueIndex).getData() - tBoard.getRowCol(clueIndex, TreeTentType.TENT, false).size(); + tentsLeft = + tBoard.getRowClues().get(clueIndex).getData() + - tBoard.getRowCol(clueIndex, TreeTentType.TENT, false).size(); cases = genCombinations(tBoard, group, tentsLeft, clueIndex, false); - } - else { + } else { group = tBoard.getRowCol(clueIndex, TreeTentType.UNKNOWN, true); - tentsLeft = tBoard.getRowClues().get(clueIndex).getData() - tBoard.getRowCol(clueIndex, TreeTentType.TENT, true).size(); + tentsLeft = + tBoard.getRowClues().get(clueIndex).getData() + - tBoard.getRowCol(clueIndex, TreeTentType.TENT, true).size(); cases = genCombinations(tBoard, group, tentsLeft, clueIndex, true); } - //generate every combination (nCr) - //call goodBoard for each generated combination - //alternitive would be to implement collision avoidance while generating instead of after + // generate every combination (nCr) + // call goodBoard for each generated combination + // alternitive would be to implement collision avoidance while generating instead of after if (cases.size() > 0) { return cases; } return null; } - private ArrayList genCombinations(TreeTentBoard iBoard, List tiles, int target, Integer index, boolean isRow) { - return genCombRecursive(iBoard, tiles, tiles, target, 0, new ArrayList(), index, isRow); + private ArrayList genCombinations( + TreeTentBoard iBoard, + List tiles, + int target, + Integer index, + boolean isRow) { + return genCombRecursive( + iBoard, tiles, tiles, target, 0, new ArrayList(), index, isRow); } - private ArrayList genCombRecursive(TreeTentBoard iBoard, List original, List tiles, int target, int current, List selected, Integer index, boolean isRow) { + private ArrayList genCombRecursive( + TreeTentBoard iBoard, + List original, + List tiles, + int target, + int current, + List selected, + Integer index, + boolean isRow) { ArrayList b = new ArrayList<>(); if (target == current) { TreeTentBoard temp = iBoard.copy(); @@ -93,13 +117,11 @@ private ArrayList genCombRecursive(TreeTentBoard iBoard, List genCombRecursive(TreeTentBoard iBoard, List sub = tiles.subList(i + 1, tiles.size()); List next = new ArrayList(selected); next.add(tiles.get(i)); - b.addAll(genCombRecursive(iBoard, original, sub, target, current + 1, next, index, isRow)); + b.addAll( + genCombRecursive( + iBoard, original, sub, target, current + 1, next, index, isRow)); } return b; } - //Effectively runs TouchingTents check on all the added tents to make sure that the proposed board is valid. - //Could check more or less in the future depending on how "smart" this case rule should be. + // Effectively runs TouchingTents check on all the added tents to make sure that the proposed + // board is valid. + // Could check more or less in the future depending on how "smart" this case rule should be. private boolean goodBoard(TreeTentBoard board, Integer index, boolean isRow) { List tents; if (isRow) { tents = board.getRowCol(index, TreeTentType.TENT, true); - } - else { + } else { tents = board.getRowCol(index, TreeTentType.TENT, false); } @@ -148,13 +172,13 @@ public String checkRuleRaw(TreeTransition transition) { } /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { @@ -162,13 +186,13 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem } /** - * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid - * Overridden by case rules dependent on more than just the modified data + * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be + * valid Overridden by case rules dependent on more than just the modified data * - * @param board board state at application + * @param board board state at application * @param puzzleElement selected puzzleElement - * @return List of puzzle elements (typically cells) this application of the case rule depends upon. - * Defaults to any element modified by any case + * @return List of puzzle elements (typically cells) this application of the case rule depends + * upon. Defaults to any element modified by any case */ @Override public List dependentElements(Board board, PuzzleElement puzzleElement) { @@ -179,7 +203,7 @@ public List dependentElements(Board board, PuzzleElement puzzleEl // add all elements of filled row for (int i = 0; i < treeTentBoard.getWidth(); i++) { - TreeTentCell cell = treeTentBoard.getCell(i, clue.getClueIndex()-1); + TreeTentCell cell = treeTentBoard.getCell(i, clue.getClueIndex() - 1); elements.add(board.getPuzzleElement((cell))); } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithGrassDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithGrassDirectRule.java index 40ee11e99..838a3ca24 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithGrassDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithGrassDirectRule.java @@ -1,86 +1,87 @@ -package edu.rpi.legup.puzzle.treetent.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.treetent.TreeTentBoard; -import edu.rpi.legup.puzzle.treetent.TreeTentCell; -import edu.rpi.legup.puzzle.treetent.TreeTentLine; -import edu.rpi.legup.puzzle.treetent.TreeTentType; - -import java.awt.*; -import java.util.List; - -public class FinishWithGrassDirectRule extends DirectRule { - - public FinishWithGrassDirectRule() { - super("TREE-BASC-0002", "Finish with Grass", - "Grass can be added to finish a row or column that has reached its tent limit.", - "edu/rpi/legup/images/treetent/finishGrass.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - if (puzzleElement instanceof TreeTentLine) { - 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 super.getInvalidUseOfRuleMessage() + ": This cell must be grass."; - } - - if (isForced(initialBoard, initCell)) { - return null; - } - else { - return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be grass."; - } - } - - private boolean isForced(TreeTentBoard board, TreeTentCell cell) { - Point loc = cell.getLocation(); - List tentsRow = board.getRowCol(loc.y, TreeTentType.TENT, true); - List tentsCol = board.getRowCol(loc.x, TreeTentType.TENT, false); - - return tentsRow.size() >= board.getRowClues().get(loc.y).getData() || - tentsCol.size() >= board.getColClues().get(loc.x).getData(); - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - TreeTentBoard treeTentBoard = (TreeTentBoard) node.getBoard().copy(); - for (PuzzleElement element : treeTentBoard.getPuzzleElements()) { - TreeTentCell cell = (TreeTentCell) element; - if (cell.getType() == TreeTentType.UNKNOWN && isForced(treeTentBoard, cell)) { - cell.setData(TreeTentType.GRASS); - treeTentBoard.addModifiedData(cell); - } - } - if (treeTentBoard.getModifiedData().isEmpty()) { - return null; - } - else { - return treeTentBoard; - } - } -} +package edu.rpi.legup.puzzle.treetent.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.treetent.TreeTentBoard; +import edu.rpi.legup.puzzle.treetent.TreeTentCell; +import edu.rpi.legup.puzzle.treetent.TreeTentLine; +import edu.rpi.legup.puzzle.treetent.TreeTentType; +import java.awt.*; +import java.util.List; + +public class FinishWithGrassDirectRule extends DirectRule { + + public FinishWithGrassDirectRule() { + super( + "TREE-BASC-0002", + "Finish with Grass", + "Grass can be added to finish a row or column that has reached its tent limit.", + "edu/rpi/legup/images/treetent/finishGrass.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + if (puzzleElement instanceof TreeTentLine) { + 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 super.getInvalidUseOfRuleMessage() + ": This cell must be grass."; + } + + if (isForced(initialBoard, initCell)) { + return null; + } else { + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be grass."; + } + } + + private boolean isForced(TreeTentBoard board, TreeTentCell cell) { + Point loc = cell.getLocation(); + List tentsRow = board.getRowCol(loc.y, TreeTentType.TENT, true); + List tentsCol = board.getRowCol(loc.x, TreeTentType.TENT, false); + + return tentsRow.size() >= board.getRowClues().get(loc.y).getData() + || tentsCol.size() >= board.getColClues().get(loc.x).getData(); + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + TreeTentBoard treeTentBoard = (TreeTentBoard) node.getBoard().copy(); + for (PuzzleElement element : treeTentBoard.getPuzzleElements()) { + TreeTentCell cell = (TreeTentCell) element; + if (cell.getType() == TreeTentType.UNKNOWN && isForced(treeTentBoard, cell)) { + cell.setData(TreeTentType.GRASS); + treeTentBoard.addModifiedData(cell); + } + } + if (treeTentBoard.getModifiedData().isEmpty()) { + return null; + } else { + return treeTentBoard; + } + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithTentsDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithTentsDirectRule.java index 145a9760a..ae1a72e9d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithTentsDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FinishWithTentsDirectRule.java @@ -1,88 +1,90 @@ -package edu.rpi.legup.puzzle.treetent.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.treetent.TreeTentBoard; -import edu.rpi.legup.puzzle.treetent.TreeTentCell; -import edu.rpi.legup.puzzle.treetent.TreeTentLine; -import edu.rpi.legup.puzzle.treetent.TreeTentType; - -import java.awt.*; -import java.util.List; - -public class FinishWithTentsDirectRule extends DirectRule { - - public FinishWithTentsDirectRule() { - super("TREE-BASC-0003", "Finish with Tents", - "Tents can be added to finish a row or column that has one open spot per required tent.", - "edu/rpi/legup/images/treetent/finishTent.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - if (puzzleElement instanceof TreeTentLine) { - 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 super.getInvalidUseOfRuleMessage() + ": This cell must be a tent."; - } - - if (isForced(initialBoard, initCell)) { - return null; - } - else { - return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be tent."; - } - } - - private boolean isForced(TreeTentBoard board, TreeTentCell cell) { - Point loc = cell.getLocation(); - List tentsRow = board.getRowCol(loc.y, TreeTentType.TENT, true); - List unknownsRow = board.getRowCol(loc.y, TreeTentType.UNKNOWN, true); - List tentsCol = board.getRowCol(loc.x, TreeTentType.TENT, false); - List unknownsCol = board.getRowCol(loc.x, TreeTentType.UNKNOWN, false); - - return unknownsRow.size() <= board.getRowClues().get(loc.y).getData() - tentsRow.size() || - unknownsCol.size() <= board.getColClues().get(loc.x).getData() - tentsCol.size(); - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - TreeTentBoard treeTentBoard = (TreeTentBoard) node.getBoard().copy(); - for (PuzzleElement element : treeTentBoard.getPuzzleElements()) { - TreeTentCell cell = (TreeTentCell) element; - if (cell.getType() == TreeTentType.UNKNOWN && isForced(treeTentBoard, cell)) { - cell.setData(TreeTentType.TENT); - treeTentBoard.addModifiedData(cell); - } - } - if (treeTentBoard.getModifiedData().isEmpty()) { - return null; - } - else { - return treeTentBoard; - } - } -} +package edu.rpi.legup.puzzle.treetent.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.treetent.TreeTentBoard; +import edu.rpi.legup.puzzle.treetent.TreeTentCell; +import edu.rpi.legup.puzzle.treetent.TreeTentLine; +import edu.rpi.legup.puzzle.treetent.TreeTentType; +import java.awt.*; +import java.util.List; + +public class FinishWithTentsDirectRule extends DirectRule { + + public FinishWithTentsDirectRule() { + super( + "TREE-BASC-0003", + "Finish with Tents", + "Tents can be added to finish a row or column that has one open spot per required" + + " tent.", + "edu/rpi/legup/images/treetent/finishTent.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + if (puzzleElement instanceof TreeTentLine) { + 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 super.getInvalidUseOfRuleMessage() + ": This cell must be a tent."; + } + + if (isForced(initialBoard, initCell)) { + return null; + } else { + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be tent."; + } + } + + private boolean isForced(TreeTentBoard board, TreeTentCell cell) { + Point loc = cell.getLocation(); + List tentsRow = board.getRowCol(loc.y, TreeTentType.TENT, true); + List unknownsRow = board.getRowCol(loc.y, TreeTentType.UNKNOWN, true); + List tentsCol = board.getRowCol(loc.x, TreeTentType.TENT, false); + List unknownsCol = board.getRowCol(loc.x, TreeTentType.UNKNOWN, false); + + return unknownsRow.size() <= board.getRowClues().get(loc.y).getData() - tentsRow.size() + || unknownsCol.size() <= board.getColClues().get(loc.x).getData() - tentsCol.size(); + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + TreeTentBoard treeTentBoard = (TreeTentBoard) node.getBoard().copy(); + for (PuzzleElement element : treeTentBoard.getPuzzleElements()) { + TreeTentCell cell = (TreeTentCell) element; + if (cell.getType() == TreeTentType.UNKNOWN && isForced(treeTentBoard, cell)) { + cell.setData(TreeTentType.TENT); + treeTentBoard.addModifiedData(cell); + } + } + if (treeTentBoard.getModifiedData().isEmpty()) { + return null; + } else { + return treeTentBoard; + } + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LastCampingSpotDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LastCampingSpotDirectRule.java index ffb33e4c0..53f7b9831 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LastCampingSpotDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LastCampingSpotDirectRule.java @@ -1,102 +1,104 @@ -package edu.rpi.legup.puzzle.treetent.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.treetent.TreeTentBoard; -import edu.rpi.legup.puzzle.treetent.TreeTentCell; -import edu.rpi.legup.puzzle.treetent.TreeTentLine; -import edu.rpi.legup.puzzle.treetent.TreeTentType; - -import java.util.List; - -public class LastCampingSpotDirectRule extends DirectRule { - - public LastCampingSpotDirectRule() { - super("TREE-BASC-0004", "Last Camping Spot", - "If an unlinked tree is adjacent to only one blank cell and not adjacent to any unlinked tents, the blank cell must be a tent.", - "edu/rpi/legup/images/treetent/oneTentPosition.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - if (puzzleElement instanceof TreeTentLine) { - 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 super.getInvalidUseOfRuleMessage() + ": This cell must be a tent."; - } - - if (isForced(finalBoard, finalCell)) { - return null; - } - else { - return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be tent."; - } - } - - private boolean isForced(TreeTentBoard board, TreeTentCell cell) { - List adjTrees = board.getAdjacent(cell, TreeTentType.TREE); - for (TreeTentCell c : adjTrees) { - List unkAroundTree = board.getAdjacent(c, TreeTentType.UNKNOWN); - List tntAroundTree = board.getAdjacent(c, TreeTentType.TENT); - if (unkAroundTree.size() == 0) { - if (tntAroundTree.size() == 1) { - return true; - } - else { - for (TreeTentCell t : tntAroundTree) { - if (t == cell) { - continue; - } - List treesAroundTents = board.getAdjacent(t, TreeTentType.TREE); - if (treesAroundTents.size() == 1) { - return false; - } - } - return true; - } - } - } - return false; - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - TreeTentBoard treeTentBoard = (TreeTentBoard) node.getBoard().copy(); - for (PuzzleElement element : treeTentBoard.getPuzzleElements()) { - TreeTentCell cell = (TreeTentCell) element; - if (cell.getType() == TreeTentType.UNKNOWN && isForced(treeTentBoard, cell)) { - cell.setData(TreeTentType.TENT); - treeTentBoard.addModifiedData(cell); - } - } - if (treeTentBoard.getModifiedData().isEmpty()) { - return null; - } - else { - return treeTentBoard; - } - } -} +package edu.rpi.legup.puzzle.treetent.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.treetent.TreeTentBoard; +import edu.rpi.legup.puzzle.treetent.TreeTentCell; +import edu.rpi.legup.puzzle.treetent.TreeTentLine; +import edu.rpi.legup.puzzle.treetent.TreeTentType; +import java.util.List; + +public class LastCampingSpotDirectRule extends DirectRule { + + public LastCampingSpotDirectRule() { + super( + "TREE-BASC-0004", + "Last Camping Spot", + "If an unlinked tree is adjacent to only one blank cell and not adjacent to any" + + " unlinked tents, the blank cell must be a tent.", + "edu/rpi/legup/images/treetent/oneTentPosition.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + if (puzzleElement instanceof TreeTentLine) { + 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 super.getInvalidUseOfRuleMessage() + ": This cell must be a tent."; + } + + if (isForced(finalBoard, finalCell)) { + return null; + } else { + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be tent."; + } + } + + private boolean isForced(TreeTentBoard board, TreeTentCell cell) { + List adjTrees = board.getAdjacent(cell, TreeTentType.TREE); + for (TreeTentCell c : adjTrees) { + List unkAroundTree = board.getAdjacent(c, TreeTentType.UNKNOWN); + List tntAroundTree = board.getAdjacent(c, TreeTentType.TENT); + if (unkAroundTree.size() == 0) { + if (tntAroundTree.size() == 1) { + return true; + } else { + for (TreeTentCell t : tntAroundTree) { + if (t == cell) { + continue; + } + List treesAroundTents = + board.getAdjacent(t, TreeTentType.TREE); + if (treesAroundTents.size() == 1) { + return false; + } + } + return true; + } + } + } + return false; + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + TreeTentBoard treeTentBoard = (TreeTentBoard) node.getBoard().copy(); + for (PuzzleElement element : treeTentBoard.getPuzzleElements()) { + TreeTentCell cell = (TreeTentCell) element; + if (cell.getType() == TreeTentType.UNKNOWN && isForced(treeTentBoard, cell)) { + cell.setData(TreeTentType.TENT); + treeTentBoard.addModifiedData(cell); + } + } + if (treeTentBoard.getModifiedData().isEmpty()) { + return null; + } else { + return treeTentBoard; + } + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LinkTentCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LinkTentCaseRule.java index 39b1d0251..bd303174a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LinkTentCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/LinkTentCaseRule.java @@ -6,10 +6,9 @@ import edu.rpi.legup.model.rules.CaseRule; import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.treetent.TreeTentBoard; -import edu.rpi.legup.puzzle.treetent.TreeTentType; import edu.rpi.legup.puzzle.treetent.TreeTentCell; import edu.rpi.legup.puzzle.treetent.TreeTentLine; - +import edu.rpi.legup.puzzle.treetent.TreeTentType; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -17,7 +16,9 @@ public class LinkTentCaseRule extends CaseRule { public LinkTentCaseRule() { - super("TREE-CASE-0002", "Links from tent", + super( + "TREE-CASE-0002", + "Links from tent", "A tent must link to exactly one adjacent tree.", "edu/rpi/legup/images/treetent/caseLinkTent.png"); } @@ -28,11 +29,15 @@ public CaseBoard getCaseBoard(Board board) { treeTentBoard.setModifiable(false); CaseBoard caseBoard = new CaseBoard(treeTentBoard, this); for (PuzzleElement element : treeTentBoard.getPuzzleElements()) { - if (((TreeTentCell) element).getType() == TreeTentType.TENT && !getCases(board, element).isEmpty()) { + if (((TreeTentCell) element).getType() == TreeTentType.TENT + && !getCases(board, element).isEmpty()) { Boolean canAdd = true; List lines = treeTentBoard.getLines(); for (TreeTentLine l : lines) { - if (l.getC1().getLocation().equals(((TreeTentCell) element).getLocation()) || l.getC2().getLocation().equals(((TreeTentCell) element).getLocation())) { + if (l.getC1().getLocation().equals(((TreeTentCell) element).getLocation()) + || l.getC2() + .getLocation() + .equals(((TreeTentCell) element).getLocation())) { canAdd = false; break; } @@ -48,7 +53,7 @@ public CaseBoard getCaseBoard(Board board) { /** * Gets the possible cases at a specific location based on this case rule * - * @param board the current board state + * @param board the current board state * @param puzzleElement equivalent puzzleElement * @return a list of elements the specified could be */ @@ -62,13 +67,17 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { for (TreeTentCell tree : adj) { Boolean makeline = true; for (TreeTentLine l : ((TreeTentBoard) board).getLines()) { - if (l.getC1().getLocation().equals(tree.getLocation()) || l.getC2().getLocation().equals(tree.getLocation())) { + if (l.getC1().getLocation().equals(tree.getLocation()) + || l.getC2().getLocation().equals(tree.getLocation())) { makeline = false; } } if (makeline) { TreeTentBoard temp = ((TreeTentBoard) board).copy(); - TreeTentLine l = new TreeTentLine((TreeTentCell) temp.getPuzzleElement(cell), (TreeTentCell) temp.getPuzzleElement(tree)); + TreeTentLine l = + new TreeTentLine( + (TreeTentCell) temp.getPuzzleElement(cell), + (TreeTentCell) temp.getPuzzleElement(tree)); temp.getLines().add(l); temp.addModifiedData(l); cases.add(temp); @@ -87,12 +96,14 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { public String checkRuleRaw(TreeTransition transition) { Set modCells = transition.getBoard().getModifiedData(); if (modCells.size() != 1) { - return super.getInvalidUseOfRuleMessage() + ": 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 super.getInvalidUseOfRuleMessage() + ": This case rule only involves tree and tent connection lines"; + return super.getInvalidUseOfRuleMessage() + + ": This case rule only involves tree and tent connection lines"; } TreeTentCell tent = null; if (line.getC1().getType() == TreeTentType.TENT) { @@ -122,7 +133,8 @@ public String checkRuleRaw(TreeTransition transition) { } PuzzleElement tElement = tBoard.getModifiedData().iterator().next(); if (!(tElement instanceof TreeTentLine)) { - return super.getInvalidUseOfRuleMessage() + ": 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; @@ -138,13 +150,13 @@ public String checkRuleRaw(TreeTransition transition) { } /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { @@ -152,13 +164,13 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem } /** - * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid - * Overridden by case rules dependent on more than just the modified data + * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be + * valid Overridden by case rules dependent on more than just the modified data * - * @param board board state at application + * @param board board state at application * @param puzzleElement selected puzzleElement - * @return List of puzzle elements (typically cells) this application of the case rule depends upon. - * Defaults to any element modified by any case + * @return List of puzzle elements (typically cells) this application of the case rule depends + * upon. Defaults to any element modified by any case */ @Override public List dependentElements(Board board, PuzzleElement puzzleElement) { 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 72ffd62eb..03d039898 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 @@ -9,7 +9,6 @@ import edu.rpi.legup.puzzle.treetent.TreeTentCell; import edu.rpi.legup.puzzle.treetent.TreeTentLine; import edu.rpi.legup.puzzle.treetent.TreeTentType; - import java.awt.Point; import java.util.ArrayList; import java.util.List; @@ -18,7 +17,9 @@ public class LinkTreeCaseRule extends CaseRule { public LinkTreeCaseRule() { - super("TREE-CASE-0003", "Links from tree", + super( + "TREE-CASE-0003", + "Links from tree", "A tree must link to exactly one adjacent tent.", "edu/rpi/legup/images/treetent/caseLinkTree.png"); } @@ -29,13 +30,16 @@ public CaseBoard getCaseBoard(Board board) { treeTentBoard.setModifiable(false); CaseBoard caseBoard = new CaseBoard(treeTentBoard, this); for (PuzzleElement element : treeTentBoard.getPuzzleElements()) { - if (((TreeTentCell) element).getType() == TreeTentType.TREE && - !getCases(treeTentBoard, element).isEmpty()) { + if (((TreeTentCell) element).getType() == TreeTentType.TREE + && !getCases(treeTentBoard, element).isEmpty()) { Boolean canAdd = true; List lines = treeTentBoard.getLines(); for (TreeTentLine l : lines) { - if (l.getC1().getLocation().equals(((TreeTentCell) element).getLocation()) || l.getC2().getLocation().equals(((TreeTentCell) element).getLocation())) { + if (l.getC1().getLocation().equals(((TreeTentCell) element).getLocation()) + || l.getC2() + .getLocation() + .equals(((TreeTentCell) element).getLocation())) { canAdd = false; break; } @@ -43,7 +47,6 @@ public CaseBoard getCaseBoard(Board board) { if (canAdd) { caseBoard.addPickableElement(element); } - } } return caseBoard; @@ -52,7 +55,7 @@ public CaseBoard getCaseBoard(Board board) { /** * Gets the possible cases at a specific location based on this case rule * - * @param board the current board state + * @param board the current board state * @param puzzleElement equivalent puzzleElement * @return a list of elements the specified could be */ @@ -65,7 +68,8 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { for (TreeTentCell c : adjCells) { Boolean makeline = true; for (TreeTentLine l : treeTentBoard.getLines()) { - if (l.getC1().getLocation().equals(c.getLocation()) || l.getC2().getLocation().equals(c.getLocation())) { + if (l.getC1().getLocation().equals(c.getLocation()) + || l.getC2().getLocation().equals(c.getLocation())) { makeline = false; } } @@ -90,12 +94,14 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { public String checkRuleRaw(TreeTransition transition) { Set modCells = transition.getBoard().getModifiedData(); if (modCells.size() != 1) { - return super.getInvalidUseOfRuleMessage() + ": 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 super.getInvalidUseOfRuleMessage() + ": 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) { @@ -125,7 +131,8 @@ public String checkRuleRaw(TreeTransition transition) { } PuzzleElement tElement = tBoard.getModifiedData().iterator().next(); if (!(tElement instanceof TreeTentLine)) { - return super.getInvalidUseOfRuleMessage() + ": 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; @@ -141,13 +148,13 @@ public String checkRuleRaw(TreeTransition transition) { } /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { @@ -155,17 +162,18 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem } /** - * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be valid - * Overridden by case rules dependent on more than just the modified data + * Returns the elements necessary for the cases returned by getCases(board,puzzleElement) to be + * valid Overridden by case rules dependent on more than just the modified data * - * @param board board state at application + * @param board board state at application * @param puzzleElement selected puzzleElement - * @return List of puzzle elements (typically cells) this application of the case rule depends upon. - * Defaults to any element modified by any case + * @return List of puzzle elements (typically cells) this application of the case rule depends + * upon. Defaults to any element modified by any case */ @Override public List dependentElements(Board board, PuzzleElement puzzleElement) { - List elements = new ArrayList<>(List.of(board.getPuzzleElement(puzzleElement))); + List elements = + new ArrayList<>(List.of(board.getPuzzleElement(puzzleElement))); TreeTentBoard treeTentBoard = (TreeTentBoard) board; TreeTentCell point = (TreeTentCell) puzzleElement; 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 2e5c2f043..912fa6d20 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 @@ -5,27 +5,29 @@ import edu.rpi.legup.model.rules.ContradictionRule; import edu.rpi.legup.puzzle.treetent.TreeTentBoard; import edu.rpi.legup.puzzle.treetent.TreeTentCell; -import edu.rpi.legup.puzzle.treetent.TreeTentType; import edu.rpi.legup.puzzle.treetent.TreeTentLine; - -import java.util.List; +import edu.rpi.legup.puzzle.treetent.TreeTentType; import java.util.Iterator; +import java.util.List; public class NoTentForTreeContradictionRule extends ContradictionRule { public NoTentForTreeContradictionRule() { - super("TREE-CONT-0001", "No Tent For Tree", + super( + "TREE-CONT-0001", + "No Tent For Tree", "Each tree must link to a tent.", "edu/rpi/legup/images/treetent/contra_NoTentForTree.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { @@ -38,8 +40,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { int adjUnknown = treeTentBoard.getAdjacent(cell, TreeTentType.UNKNOWN).size(); if (adjTent == 0 && adjUnknown == 0) { return null; - } - else { + } else { if (adjTent != 0) { List lines = treeTentBoard.getLines(); List adjTents = treeTentBoard.getAdjacent(cell, TreeTentType.TENT); @@ -47,10 +48,12 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { Iterator i = adjTents.iterator(); while (i.hasNext()) { TreeTentCell t = i.next(); - if (t.getLocation().equals(l.getC1().getLocation()) && !(cell.getLocation().equals(l.getC2().getLocation()))) { + if (t.getLocation().equals(l.getC1().getLocation()) + && !(cell.getLocation().equals(l.getC2().getLocation()))) { i.remove(); } - if (t.getLocation().equals(l.getC2().getLocation()) && !(cell.getLocation().equals(l.getC2().getLocation()))) { + if (t.getLocation().equals(l.getC2().getLocation()) + && !(cell.getLocation().equals(l.getC2().getLocation()))) { i.remove(); } } 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 67f023dd7..9bc3fddea 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 @@ -7,25 +7,27 @@ import edu.rpi.legup.puzzle.treetent.TreeTentCell; import edu.rpi.legup.puzzle.treetent.TreeTentLine; import edu.rpi.legup.puzzle.treetent.TreeTentType; - -import java.util.List; import java.util.Iterator; +import java.util.List; public class NoTreeForTentContradictionRule extends ContradictionRule { public NoTreeForTentContradictionRule() { - super("TREE-CONT-0002", "No Tree For Tent", + super( + "TREE-CONT-0002", + "No Tree For Tent", "Each tent must link to a tree.", "edu/rpi/legup/images/treetent/contra_NoTreeForTent.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { @@ -40,10 +42,12 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { Iterator i = adjTrees.iterator(); while (i.hasNext()) { TreeTentCell t = i.next(); - if (t.getLocation().equals(l.getC1().getLocation()) && !(cell.getLocation().equals(l.getC2().getLocation()))) { + if (t.getLocation().equals(l.getC1().getLocation()) + && !(cell.getLocation().equals(l.getC2().getLocation()))) { i.remove(); } - if (t.getLocation().equals(l.getC2().getLocation()) && !(cell.getLocation().equals(l.getC2().getLocation()))) { + if (t.getLocation().equals(l.getC2().getLocation()) + && !(cell.getLocation().equals(l.getC2().getLocation()))) { i.remove(); } } @@ -51,8 +55,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { int adjTree = adjTrees.size(); if (adjTree == 0) { return null; - } - else { + } else { return super.getNoContradictionMessage(); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/SurroundTentWithGrassDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/SurroundTentWithGrassDirectRule.java index 44e9dfcc4..e800dc416 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/SurroundTentWithGrassDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/SurroundTentWithGrassDirectRule.java @@ -1,85 +1,86 @@ -package edu.rpi.legup.puzzle.treetent.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.treetent.TreeTentBoard; -import edu.rpi.legup.puzzle.treetent.TreeTentCell; -import edu.rpi.legup.puzzle.treetent.TreeTentLine; -import edu.rpi.legup.puzzle.treetent.TreeTentType; - -import java.util.List; - -public class SurroundTentWithGrassDirectRule extends DirectRule { - - public SurroundTentWithGrassDirectRule() { - super("TREE-BASC-0005", "Surround Tent with Grass", - "Blank cells adjacent or diagonal to a tent are grass.", - "edu/rpi/legup/images/treetent/aroundTent.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - if (puzzleElement == null) { - return null; - } - if (puzzleElement instanceof TreeTentLine) { - 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 super.getInvalidUseOfRuleMessage() + ": This cell must be a tent."; - } - - if (isForced(initialBoard, initCell)) { - return null; - } - else { - return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be tent."; - } - } - - private boolean isForced(TreeTentBoard board, TreeTentCell cell) { - List tents = board.getAdjacent(cell, TreeTentType.TENT); - tents.addAll(board.getDiagonals(cell, TreeTentType.TENT)); - return !tents.isEmpty(); - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - TreeTentBoard treeTentBoard = (TreeTentBoard) node.getBoard().copy(); - for (PuzzleElement element : treeTentBoard.getPuzzleElements()) { - TreeTentCell cell = (TreeTentCell) element; - if (cell.getType() == TreeTentType.UNKNOWN && isForced(treeTentBoard, cell)) { - cell.setData(TreeTentType.GRASS); - treeTentBoard.addModifiedData(cell); - } - } - if (treeTentBoard.getModifiedData().isEmpty()) { - return null; - } - else { - return treeTentBoard; - } - } -} +package edu.rpi.legup.puzzle.treetent.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.treetent.TreeTentBoard; +import edu.rpi.legup.puzzle.treetent.TreeTentCell; +import edu.rpi.legup.puzzle.treetent.TreeTentLine; +import edu.rpi.legup.puzzle.treetent.TreeTentType; +import java.util.List; + +public class SurroundTentWithGrassDirectRule extends DirectRule { + + public SurroundTentWithGrassDirectRule() { + super( + "TREE-BASC-0005", + "Surround Tent with Grass", + "Blank cells adjacent or diagonal to a tent are grass.", + "edu/rpi/legup/images/treetent/aroundTent.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + if (puzzleElement == null) { + return null; + } + if (puzzleElement instanceof TreeTentLine) { + 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 super.getInvalidUseOfRuleMessage() + ": This cell must be a tent."; + } + + if (isForced(initialBoard, initCell)) { + return null; + } else { + return super.getInvalidUseOfRuleMessage() + ": This cell is not forced to be tent."; + } + } + + private boolean isForced(TreeTentBoard board, TreeTentCell cell) { + List tents = board.getAdjacent(cell, TreeTentType.TENT); + tents.addAll(board.getDiagonals(cell, TreeTentType.TENT)); + return !tents.isEmpty(); + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + TreeTentBoard treeTentBoard = (TreeTentBoard) node.getBoard().copy(); + for (PuzzleElement element : treeTentBoard.getPuzzleElements()) { + TreeTentCell cell = (TreeTentCell) element; + if (cell.getType() == TreeTentType.UNKNOWN && isForced(treeTentBoard, cell)) { + cell.setData(TreeTentType.GRASS); + treeTentBoard.addModifiedData(cell); + } + } + if (treeTentBoard.getModifiedData().isEmpty()) { + return null; + } else { + return treeTentBoard; + } + } +} diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TentForTreeDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TentForTreeDirectRule.java index 03a83e516..8044faa0e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TentForTreeDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TentForTreeDirectRule.java @@ -1,124 +1,125 @@ -package edu.rpi.legup.puzzle.treetent.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.treetent.TreeTentBoard; -import edu.rpi.legup.puzzle.treetent.TreeTentCell; -import edu.rpi.legup.puzzle.treetent.TreeTentLine; -import edu.rpi.legup.puzzle.treetent.TreeTentType; - -import java.util.ArrayList; - -import java.util.List; - -public class TentForTreeDirectRule extends DirectRule { - - public TentForTreeDirectRule() { - super("TREE-BASC-0006", "Tent for Tree", - "If only one unlinked tent and no blank cells are adjacent to an unlinked tree, the unlinked tree must link to the unlinked tent.", - "edu/rpi/legup/images/treetent/NewTreeLink.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - if (!(puzzleElement instanceof TreeTentLine)) { - return super.getInvalidUseOfRuleMessage() + ": Lines must be created for this rule."; - } - TreeTentBoard board = (TreeTentBoard) transition.getBoard(); - TreeTentLine line = (TreeTentLine) board.getPuzzleElement(puzzleElement); - TreeTentCell tree, tent; - if (line.getC1().getType() == TreeTentType.TREE && line.getC2().getType() == TreeTentType.TENT) { - tree = line.getC1(); - tent = line.getC2(); - } - else { - if (line.getC2().getType() == TreeTentType.TREE && line.getC1().getType() == TreeTentType.TENT) { - tree = line.getC2(); - tent = line.getC1(); - } - else { - return super.getInvalidUseOfRuleMessage() + ": This line must connect a tree to a tent."; - } - } - int forced = isForced(board, tree, tent, line); - if (forced == 1) { - return null; - } - else { - if (forced == -1) { - return super.getInvalidUseOfRuleMessage() + ": This tree already has a link"; - } - else { - if (forced == -2) { - return super.getInvalidUseOfRuleMessage() + ": This tent already has a link"; - } - else { - return super.getInvalidUseOfRuleMessage() + ": This tree and tent don't need to be linked."; - } - } - } - } - - private Integer isForced(TreeTentBoard board, TreeTentCell tree, TreeTentCell tent, TreeTentLine line) { - List adjTents = board.getAdjacent(tree, TreeTentType.TENT); - adjTents.remove(tent); - List lines = board.getLines(); - lines.remove(line); - for (TreeTentLine l : lines) { - ArrayList toRemove = new ArrayList<>(); - if (l.getC1().getLocation().equals(tree.getLocation()) || l.getC2().getLocation().equals(tree.getLocation())) { - return -2; - } - for (TreeTentCell c : adjTents) { - if (l.getC1().getLocation().equals(c.getLocation())) { - if (l.getC2().getLocation().equals(tree.getLocation())) { - return -1; - } - toRemove.add(c); - - } - else { - if (l.getC2().getLocation().equals(c.getLocation())) { - if (l.getC1().getLocation().equals(tree.getLocation())) { - return -1; - } - toRemove.add(c); - } - } - } - for (TreeTentCell c : toRemove) { - adjTents.remove(c); - } - toRemove.clear(); - } - if (adjTents.size() == 0) { - return 1; - } - else { - return 0; - } - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.treetent.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.treetent.TreeTentBoard; +import edu.rpi.legup.puzzle.treetent.TreeTentCell; +import edu.rpi.legup.puzzle.treetent.TreeTentLine; +import edu.rpi.legup.puzzle.treetent.TreeTentType; +import java.util.ArrayList; +import java.util.List; + +public class TentForTreeDirectRule extends DirectRule { + + public TentForTreeDirectRule() { + super( + "TREE-BASC-0006", + "Tent for Tree", + "If only one unlinked tent and no blank cells are adjacent to an unlinked tree, the" + + " unlinked tree must link to the unlinked tent.", + "edu/rpi/legup/images/treetent/NewTreeLink.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + if (!(puzzleElement instanceof TreeTentLine)) { + return super.getInvalidUseOfRuleMessage() + ": Lines must be created for this rule."; + } + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + TreeTentLine line = (TreeTentLine) board.getPuzzleElement(puzzleElement); + TreeTentCell tree, tent; + if (line.getC1().getType() == TreeTentType.TREE + && line.getC2().getType() == TreeTentType.TENT) { + tree = line.getC1(); + tent = line.getC2(); + } else { + if (line.getC2().getType() == TreeTentType.TREE + && line.getC1().getType() == TreeTentType.TENT) { + tree = line.getC2(); + tent = line.getC1(); + } else { + return super.getInvalidUseOfRuleMessage() + + ": This line must connect a tree to a tent."; + } + } + int forced = isForced(board, tree, tent, line); + if (forced == 1) { + return null; + } else { + if (forced == -1) { + return super.getInvalidUseOfRuleMessage() + ": This tree already has a link"; + } else { + if (forced == -2) { + return super.getInvalidUseOfRuleMessage() + ": This tent already has a link"; + } else { + return super.getInvalidUseOfRuleMessage() + + ": This tree and tent don't need to be linked."; + } + } + } + } + + private Integer isForced( + TreeTentBoard board, TreeTentCell tree, TreeTentCell tent, TreeTentLine line) { + List adjTents = board.getAdjacent(tree, TreeTentType.TENT); + adjTents.remove(tent); + List lines = board.getLines(); + lines.remove(line); + for (TreeTentLine l : lines) { + ArrayList toRemove = new ArrayList<>(); + if (l.getC1().getLocation().equals(tree.getLocation()) + || l.getC2().getLocation().equals(tree.getLocation())) { + return -2; + } + for (TreeTentCell c : adjTents) { + if (l.getC1().getLocation().equals(c.getLocation())) { + if (l.getC2().getLocation().equals(tree.getLocation())) { + return -1; + } + toRemove.add(c); + + } else { + if (l.getC2().getLocation().equals(c.getLocation())) { + if (l.getC1().getLocation().equals(tree.getLocation())) { + return -1; + } + toRemove.add(c); + } + } + } + for (TreeTentCell c : toRemove) { + adjTents.remove(c); + } + toRemove.clear(); + } + if (adjTents.size() == 0) { + return 1; + } else { + return 0; + } + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} 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 b0e9db109..63478f83e 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 @@ -8,14 +8,15 @@ import edu.rpi.legup.puzzle.treetent.TreeTentBoard; import edu.rpi.legup.puzzle.treetent.TreeTentCell; import edu.rpi.legup.puzzle.treetent.TreeTentType; - import java.util.ArrayList; import java.util.List; public class TentOrGrassCaseRule extends CaseRule { public TentOrGrassCaseRule() { - super("TREE-CASE-0004", "Tent or Grass", + super( + "TREE-CASE-0004", + "Tent or Grass", "Each blank cell is either a tent or grass.", "edu/rpi/legup/images/treetent/caseTentOrGrass.png"); } @@ -36,7 +37,7 @@ public CaseBoard getCaseBoard(Board board) { /** * Gets the possible cases at a specific location based on this case rule * - * @param board the current board state + * @param board the current board state * @param puzzleElement equivalent puzzleElement * @return a list of elements the specified could be */ @@ -74,33 +75,36 @@ public String checkRuleRaw(TreeTransition transition) { TreeTransition case1 = childTransitions.get(0); TreeTransition case2 = childTransitions.get(1); - if (case1.getBoard().getModifiedData().size() != 1 || - case2.getBoard().getModifiedData().size() != 1) { - return super.getInvalidUseOfRuleMessage() + ": This case rule must have 1 modified cell for each case."; + if (case1.getBoard().getModifiedData().size() != 1 + || case2.getBoard().getModifiedData().size() != 1) { + 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 super.getInvalidUseOfRuleMessage() + ": 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 super.getInvalidUseOfRuleMessage() + ": This case rule must have a tent and a grass cell."; + if (!((mod1.getType() == TreeTentType.TENT && mod2.getType() == TreeTentType.GRASS) + || (mod2.getType() == TreeTentType.TENT && mod1.getType() == TreeTentType.GRASS))) { + return super.getInvalidUseOfRuleMessage() + + ": This case rule must have a tent and a grass cell."; } return null; } /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule * - * @param transition transition to check + * @param transition transition to check * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { 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 92b951feb..7b3f43dbe 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 @@ -6,24 +6,26 @@ import edu.rpi.legup.puzzle.treetent.TreeTentBoard; import edu.rpi.legup.puzzle.treetent.TreeTentCell; import edu.rpi.legup.puzzle.treetent.TreeTentType; - import java.awt.*; public class TooFewTentsContradictionRule extends ContradictionRule { public TooFewTentsContradictionRule() { - super("TREE-CONT-0003", "Too Few Tents", + super( + "TREE-CONT-0003", + "Too Few Tents", "Rows and columns cannot have fewer tents than their clue.", "edu/rpi/legup/images/treetent/too_few_tents.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { @@ -36,11 +38,10 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { int rowUnknowns = treeTentBoard.getRowCol(loc.y, TreeTentType.UNKNOWN, true).size(); int colUnknowns = treeTentBoard.getRowCol(loc.x, TreeTentType.UNKNOWN, false).size(); - if (rowTents + rowUnknowns < treeTentBoard.getRowClues().get(loc.y).getData() || - colTents + colUnknowns < treeTentBoard.getColClues().get(loc.x).getData()) { + if (rowTents + rowUnknowns < treeTentBoard.getRowClues().get(loc.y).getData() + || colTents + colUnknowns < treeTentBoard.getColClues().get(loc.x).getData()) { return null; - } - else { + } else { 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 8bc908d0c..dcc65feb6 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 @@ -6,24 +6,26 @@ import edu.rpi.legup.puzzle.treetent.TreeTentBoard; import edu.rpi.legup.puzzle.treetent.TreeTentCell; import edu.rpi.legup.puzzle.treetent.TreeTentType; - import java.awt.*; public class TooManyTentsContradictionRule extends ContradictionRule { public TooManyTentsContradictionRule() { - super("TREE-CONT-0004", "Too Many Tents", + super( + "TREE-CONT-0004", + "Too Many Tents", "Rows and columns cannot have more tents than their clue.", "edu/rpi/legup/images/treetent/too_many_tents.png"); } /** - * Checks whether the transition has a contradiction at the specific puzzleElement index using this rule + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent puzzleElement * @return null if the transition contains a contradiction at the specified puzzleElement, - * otherwise error message + * otherwise error message */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { @@ -34,11 +36,10 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { int rowTents = treeTentBoard.getRowCol(loc.y, TreeTentType.TENT, true).size(); int colTents = treeTentBoard.getRowCol(loc.x, TreeTentType.TENT, false).size(); - if (rowTents > treeTentBoard.getRowClues().get(loc.y).getData() || - colTents > treeTentBoard.getColClues().get(loc.x).getData()) { + if (rowTents > treeTentBoard.getRowClues().get(loc.y).getData() + || colTents > treeTentBoard.getColClues().get(loc.x).getData()) { return null; - } - else { + } else { 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 a07153a31..d9dd36e12 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 @@ -10,20 +10,21 @@ public class TouchingTentsContradictionRule extends ContradictionRule { public TouchingTentsContradictionRule() { - super("TREE-CONT-0005", "Touching Tents", + super( + "TREE-CONT-0005", + "Touching Tents", "Tents cannot touch other tents.", "edu/rpi/legup/images/treetent/contra_adjacentTents.png"); } /** - * Checks whether the transition has a contradiction at the specific - * {@link PuzzleElement} index using this rule + * Checks whether the transition has a contradiction at the specific {@link PuzzleElement} index + * using this rule * - * @param board board to check contradiction + * @param board board to check contradiction * @param puzzleElement equivalent {@link PuzzleElement} - * @return null if the transition contains a - * contradiction at the specified puzzleElement, - * otherwise error message. + * @return null if the transition contains a contradiction at the specified + * puzzleElement, otherwise error message. */ @Override public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { @@ -36,8 +37,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { int diagTree = treeTentBoard.getDiagonals(cell, TreeTentType.TENT).size(); if (adjTree > 0 || diagTree > 0) { return null; - } - else { + } else { return super.getNoContradictionMessage(); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TreeForTentDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TreeForTentDirectRule.java index 63d43e9a4..d4360c7f6 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TreeForTentDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/TreeForTentDirectRule.java @@ -1,122 +1,124 @@ -package edu.rpi.legup.puzzle.treetent.rules; - -import java.util.List; -import java.util.ArrayList; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.treetent.TreeTentLine; -import edu.rpi.legup.puzzle.treetent.TreeTentBoard; -import edu.rpi.legup.puzzle.treetent.TreeTentType; -import edu.rpi.legup.puzzle.treetent.TreeTentCell; - -public class TreeForTentDirectRule extends DirectRule { - public TreeForTentDirectRule() { - super("TREE-BASC-0007", "Tree for Tent", - "If only one unlinked tree is adjacent to an unlinked tent, the unlinked tent must link to the unlinked tree.", - "edu/rpi/legup/images/treetent/NewTentLink.png"); - } - - /** - * Checks whether the child node logically follows from the parent node - * at the specific puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified puzzleElement, - * otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - if (!(puzzleElement instanceof TreeTentLine)) { - return super.getInvalidUseOfRuleMessage() + ": Lines must be created for this rule."; - } - TreeTentBoard board = (TreeTentBoard) transition.getBoard(); - TreeTentLine line = (TreeTentLine) board.getPuzzleElement(puzzleElement); - TreeTentCell tree, tent; - if (line.getC1().getType() == TreeTentType.TREE && line.getC2().getType() == TreeTentType.TENT) { - tree = line.getC1(); - tent = line.getC2(); - } - else { - if (line.getC2().getType() == TreeTentType.TREE && line.getC1().getType() == TreeTentType.TENT) { - tree = line.getC2(); - tent = line.getC1(); - } - else { - return super.getInvalidUseOfRuleMessage() + ": This line must connect a tree to a tent."; - } - } - int forced = isForced(board, tree, tent, line); - if (forced == 1) { - return null; - } - else { - if (forced == -1) { - return super.getInvalidUseOfRuleMessage() + ": This tent already has a link"; - } - else { - if (forced == -2) { - return super.getInvalidUseOfRuleMessage() + ": This tree already has a link"; - } - else { - return super.getInvalidUseOfRuleMessage() + ": This tree and tent don't need to be linked."; - } - } - } - } - - private Integer isForced(TreeTentBoard board, TreeTentCell tree, TreeTentCell tent, TreeTentLine line) { - List adjTrees = board.getAdjacent(tent, TreeTentType.TREE); - adjTrees.remove(tree); - List lines = board.getLines(); - lines.remove(line); - for (TreeTentLine l : lines) { - ArrayList toRemove = new ArrayList<>(); - if (l.getC1().getLocation().equals(tree.getLocation()) || l.getC2().getLocation().equals(tree.getLocation())) { - return -2; - } - for (TreeTentCell c : adjTrees) { - if (l.getC1().getLocation().equals(c.getLocation())) { - if (l.getC2().getLocation().equals(tent.getLocation())) { - return -1; - } - toRemove.add(c); - - } - else { - if (l.getC2().getLocation().equals(c.getLocation())) { - if (l.getC1().getLocation().equals(tent.getLocation())) { - return -1; - } - toRemove.add(c); - } - } - } - for (TreeTentCell c : toRemove) { - adjTrees.remove(c); - } - toRemove.clear(); - } - if (adjTrees.size() == 0) { - return 1; - } - else { - return 0; - } - } - - /** - * Creates a transition {@link Board} that has this rule applied to it using the {@link TreeNode}. - * - * @param node tree node used to create default transition board - * @return default board or null if this rule cannot be applied to this tree node - */ - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} +package edu.rpi.legup.puzzle.treetent.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.treetent.TreeTentBoard; +import edu.rpi.legup.puzzle.treetent.TreeTentCell; +import edu.rpi.legup.puzzle.treetent.TreeTentLine; +import edu.rpi.legup.puzzle.treetent.TreeTentType; +import java.util.ArrayList; +import java.util.List; + +public class TreeForTentDirectRule extends DirectRule { + public TreeForTentDirectRule() { + super( + "TREE-BASC-0007", + "Tree for Tent", + "If only one unlinked tree is adjacent to an unlinked tent, the unlinked tent must" + + " link to the unlinked tree.", + "edu/rpi/legup/images/treetent/NewTentLink.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + @Override + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + if (!(puzzleElement instanceof TreeTentLine)) { + return super.getInvalidUseOfRuleMessage() + ": Lines must be created for this rule."; + } + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + TreeTentLine line = (TreeTentLine) board.getPuzzleElement(puzzleElement); + TreeTentCell tree, tent; + if (line.getC1().getType() == TreeTentType.TREE + && line.getC2().getType() == TreeTentType.TENT) { + tree = line.getC1(); + tent = line.getC2(); + } else { + if (line.getC2().getType() == TreeTentType.TREE + && line.getC1().getType() == TreeTentType.TENT) { + tree = line.getC2(); + tent = line.getC1(); + } else { + return super.getInvalidUseOfRuleMessage() + + ": This line must connect a tree to a tent."; + } + } + int forced = isForced(board, tree, tent, line); + if (forced == 1) { + return null; + } else { + if (forced == -1) { + return super.getInvalidUseOfRuleMessage() + ": This tent already has a link"; + } else { + if (forced == -2) { + return super.getInvalidUseOfRuleMessage() + ": This tree already has a link"; + } else { + return super.getInvalidUseOfRuleMessage() + + ": This tree and tent don't need to be linked."; + } + } + } + } + + private Integer isForced( + TreeTentBoard board, TreeTentCell tree, TreeTentCell tent, TreeTentLine line) { + List adjTrees = board.getAdjacent(tent, TreeTentType.TREE); + adjTrees.remove(tree); + List lines = board.getLines(); + lines.remove(line); + for (TreeTentLine l : lines) { + ArrayList toRemove = new ArrayList<>(); + if (l.getC1().getLocation().equals(tree.getLocation()) + || l.getC2().getLocation().equals(tree.getLocation())) { + return -2; + } + for (TreeTentCell c : adjTrees) { + if (l.getC1().getLocation().equals(c.getLocation())) { + if (l.getC2().getLocation().equals(tent.getLocation())) { + return -1; + } + toRemove.add(c); + + } else { + if (l.getC2().getLocation().equals(c.getLocation())) { + if (l.getC1().getLocation().equals(tent.getLocation())) { + return -1; + } + toRemove.add(c); + } + } + } + for (TreeTentCell c : toRemove) { + adjTrees.remove(c); + } + toRemove.clear(); + } + if (adjTrees.size() == 0) { + return 1; + } else { + return 0; + } + } + + /** + * Creates a transition {@link Board} that has this rule applied to it using the {@link + * TreeNode}. + * + * @param node tree node used to create default transition board + * @return default board or null if this rule cannot be applied to this tree node + */ + @Override + public Board getDefaultBoard(TreeNode node) { + return null; + } +} diff --git a/src/main/java/edu/rpi/legup/save/ExportFileException.java b/src/main/java/edu/rpi/legup/save/ExportFileException.java index 46ebac9e0..9def1f392 100644 --- a/src/main/java/edu/rpi/legup/save/ExportFileException.java +++ b/src/main/java/edu/rpi/legup/save/ExportFileException.java @@ -5,5 +5,4 @@ public class ExportFileException extends Exception { public ExportFileException(String message) { super("Export File Exception: " + message); } - } diff --git a/src/main/java/edu/rpi/legup/save/InvalidFileFormatException.java b/src/main/java/edu/rpi/legup/save/InvalidFileFormatException.java index 94c229411..1e24c5762 100644 --- a/src/main/java/edu/rpi/legup/save/InvalidFileFormatException.java +++ b/src/main/java/edu/rpi/legup/save/InvalidFileFormatException.java @@ -5,5 +5,4 @@ public class InvalidFileFormatException extends Exception { public InvalidFileFormatException(String message) { super("InvalidFileFormatException: " + message); } - } diff --git a/src/main/java/edu/rpi/legup/save/SavableBoard.java b/src/main/java/edu/rpi/legup/save/SavableBoard.java index a7799a15a..bd246303b 100644 --- a/src/main/java/edu/rpi/legup/save/SavableBoard.java +++ b/src/main/java/edu/rpi/legup/save/SavableBoard.java @@ -1,10 +1,5 @@ package edu.rpi.legup.save; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import java.io.FileInputStream; import java.io.InputStream; @@ -17,7 +12,5 @@ public class SavableBoard { public SavableBoard(String filePath) throws Exception { this.filePath = filePath; this.inputStream = new FileInputStream(filePath); - - } } diff --git a/src/main/java/edu/rpi/legup/save/SavableProof.java b/src/main/java/edu/rpi/legup/save/SavableProof.java index 101e56125..4f6e4697c 100644 --- a/src/main/java/edu/rpi/legup/save/SavableProof.java +++ b/src/main/java/edu/rpi/legup/save/SavableProof.java @@ -1,5 +1,3 @@ package edu.rpi.legup.save; -public class SavableProof { - -} +public class SavableProof {} diff --git a/src/main/java/edu/rpi/legup/ui/CreatePuzzleDialog.java b/src/main/java/edu/rpi/legup/ui/CreatePuzzleDialog.java index fa049ab38..70fbea033 100644 --- a/src/main/java/edu/rpi/legup/ui/CreatePuzzleDialog.java +++ b/src/main/java/edu/rpi/legup/ui/CreatePuzzleDialog.java @@ -3,40 +3,39 @@ import edu.rpi.legup.app.Config; import edu.rpi.legup.app.GameBoardFacade; import edu.rpi.legup.controller.CursorController; - -import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Arrays; import java.util.Objects; +import javax.swing.*; public class CreatePuzzleDialog extends JDialog { private HomePanel homePanel; private String[] games; private JComboBox gameBox; - private ActionListener gameBoxListener = new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JComboBox comboBox = (JComboBox) e.getSource(); - String puzzleName = (String) comboBox.getSelectedItem(); - if (puzzleName.equals("ShortTruthTable")) { - textInputScrollPane.setVisible(true); - rowsLabel.setVisible(false); - rows.setVisible(false); - columnsLabel.setVisible(false); - columns.setVisible(false); - } - else { - textInputScrollPane.setVisible(false); - rowsLabel.setVisible(true); - rows.setVisible(true); - columnsLabel.setVisible(true); - columns.setVisible(true); - } - } - }; + private ActionListener gameBoxListener = + new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JComboBox comboBox = (JComboBox) e.getSource(); + String puzzleName = (String) comboBox.getSelectedItem(); + if (puzzleName.equals("ShortTruthTable")) { + textInputScrollPane.setVisible(true); + rowsLabel.setVisible(false); + rows.setVisible(false); + columnsLabel.setVisible(false); + columns.setVisible(false); + } else { + textInputScrollPane.setVisible(false); + rowsLabel.setVisible(true); + rows.setVisible(true); + columnsLabel.setVisible(true); + columns.setVisible(true); + } + } + }; private JLabel puzzleLabel; private JLabel rowsLabel; @@ -48,53 +47,64 @@ public void actionPerformed(ActionEvent e) { private JScrollPane textInputScrollPane; private JButton ok = new JButton("Ok"); - private ActionListener okButtonListener = new ActionListener() { - /** - * Attempts to open the puzzle editor interface for the given game with the given dimensions - * @param ae the event to be processed - */ - @Override - public void actionPerformed(ActionEvent ae) { - String game = Config.convertDisplayNameToClassName((String) gameBox.getSelectedItem()); - - // Check if all 3 TextFields are filled - if (game.equals("ShortTruthTable") && textArea.getText().equals("")) { - System.out.println("Unfilled fields"); - return; - } - if (!game.equals("ShortTruthTable") && (game.equals("") || rows.getText().equals("") || columns.getText().equals(""))) { - System.out.println("Unfilled fields"); - return; - } - - try { - if (game.equals("ShortTruthTable")) { - homePanel.openEditorWithNewPuzzle("ShortTruthTable", textArea.getText().split("\n")); - } - else { - homePanel.openEditorWithNewPuzzle(game, Integer.valueOf(rows.getText()), Integer.valueOf(columns.getText())); + private ActionListener okButtonListener = + new ActionListener() { + /** + * Attempts to open the puzzle editor interface for the given game with the given + * dimensions + * + * @param ae the event to be processed + */ + @Override + public void actionPerformed(ActionEvent ae) { + String game = + Config.convertDisplayNameToClassName( + (String) gameBox.getSelectedItem()); + + // Check if all 3 TextFields are filled + if (game.equals("ShortTruthTable") && textArea.getText().isEmpty()) { + System.out.println("Unfilled fields"); + return; + } + if (!game.equals("ShortTruthTable") + && (game.isEmpty() + || rows.getText().isEmpty() + || columns.getText().isEmpty())) { + System.out.println("Unfilled fields"); + return; + } + + try { + if (game.equals("ShortTruthTable")) { + homePanel.openEditorWithNewPuzzle( + "ShortTruthTable", textArea.getText().split("\n")); + } else { + homePanel.openEditorWithNewPuzzle( + game, + Integer.valueOf(rows.getText()), + Integer.valueOf(columns.getText())); + } + setVisible(false); + } catch (IllegalArgumentException e) { + System.out.println("Failed to open editor with new puzzle"); + e.printStackTrace(System.out); + } } - setVisible(false); - } - catch (IllegalArgumentException e) { - System.out.println("Failed to open editor with new puzzle"); - e.printStackTrace(System.out); - } - } - }; + }; private JButton cancel = new JButton("Cancel"); - private ActionListener cancelButtonListener = new ActionListener() { - /** - * Dispose the puzzle creation dialog - * - * @param e the event to be processed - */ - @Override - public void actionPerformed(ActionEvent e) { - dispose(); - } - }; + private ActionListener cancelButtonListener = + new ActionListener() { + /** + * Dispose the puzzle creation dialog + * + * @param e the event to be processed + */ + @Override + public void actionPerformed(ActionEvent e) { + dispose(); + } + }; public CreatePuzzleDialog(JFrame parent, HomePanel homePanel) { super(parent, true); @@ -140,7 +150,11 @@ public CreatePuzzleDialog(JFrame parent, HomePanel homePanel) { c.add(columns); textArea = new JTextArea(); - textInputScrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + textInputScrollPane = + new JScrollPane( + textArea, + JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); textInputScrollPane.setBounds(10, 70, this.getWidth() - 30, 50); c.add(textInputScrollPane); @@ -153,8 +167,7 @@ public CreatePuzzleDialog(JFrame parent, HomePanel homePanel) { rows.setVisible(false); columnsLabel.setVisible(false); columns.setVisible(false); - } - else { + } else { textInputScrollPane.setVisible(false); rowsLabel.setVisible(true); rows.setVisible(true); @@ -166,12 +179,17 @@ public CreatePuzzleDialog(JFrame parent, HomePanel homePanel) { gameBox.addActionListener(cursorSelectedGame); ActionListener cursorPressedOk = CursorController.createListener(this, okButtonListener); ok.addActionListener(cursorPressedOk); - ActionListener cursorPressedCancel = CursorController.createListener(this, cancelButtonListener); + ActionListener cursorPressedCancel = + CursorController.createListener(this, cancelButtonListener); cancel.addActionListener(cursorPressedCancel); } public void initPuzzles() { - this.games = GameBoardFacade.getInstance().getConfig().getFileCreationEnabledPuzzles().toArray(new String[0]); + this.games = + GameBoardFacade.getInstance() + .getConfig() + .getFileCreationEnabledPuzzles() + .toArray(new String[0]); Arrays.sort(this.games); gameBox = new JComboBox(this.games); } @@ -183,25 +201,26 @@ public void actionPerformed(ActionEvent e) { try { if (game.equals("ShortTruthTable")) { - this.homePanel.openEditorWithNewPuzzle("ShortTruthTable", this.textArea.getText().split("\n")); - } - else { - this.homePanel.openEditorWithNewPuzzle(game, Integer.valueOf(this.rows.getText()), Integer.valueOf(this.columns.getText())); - + this.homePanel.openEditorWithNewPuzzle( + "ShortTruthTable", this.textArea.getText().split("\n")); + } else { + this.homePanel.openEditorWithNewPuzzle( + game, + Integer.valueOf(this.rows.getText()), + Integer.valueOf(this.columns.getText())); } this.setVisible(false); + } catch (IllegalArgumentException exception) { + // Don't do anything. This is here to prevent the dialog from closing if the + // dimensions are + // invalid. } - catch (IllegalArgumentException exception) { - // Don't do anything. This is here to prevent the dialog from closing if the dimensions are invalid. - } - } - else { + } else { if (e.getSource() == cancel) { this.setVisible(false); - } - else { + } else { // Unknown Action Event } } } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/ui/DynamicView.java b/src/main/java/edu/rpi/legup/ui/DynamicView.java index 038f87d23..8d3024c86 100644 --- a/src/main/java/edu/rpi/legup/ui/DynamicView.java +++ b/src/main/java/edu/rpi/legup/ui/DynamicView.java @@ -1,21 +1,20 @@ package edu.rpi.legup.ui; +import static java.awt.BorderLayout.*; + import edu.rpi.legup.app.GameBoardFacade; import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialFonts; - -import javax.imageio.ImageIO; -import javax.swing.*; -import javax.swing.event.ChangeEvent; import java.awt.*; import java.awt.event.*; import java.io.IOException; import java.util.Hashtable; import java.util.Objects; - -import static java.awt.BorderLayout.*; +import javax.imageio.ImageIO; +import javax.swing.*; +import javax.swing.event.ChangeEvent; public class DynamicView extends JPanel { @@ -42,16 +41,14 @@ public DynamicView(ScrollView scrollView, DynamicViewType type) { /** * Sets up the zoomer for the given DynamicViewType * - * @param type The DynamicView that we are setting up the zoomer for (so - * the zoomer for the board view or the zoomer for the proof - * tree view) + * @param type The DynamicView that we are setting up the zoomer for (so the zoomer for the + * board view or the zoomer for the proof tree view) * @return A JPanel containing the zoomer */ private JPanel setUpZoomer(DynamicViewType type) { if (type == DynamicViewType.BOARD) { return setUpBoardZoomer(); - } - else { + } else { if (type == DynamicViewType.PROOF_TREE) { return setUpProofTreeZoomer(); } @@ -79,17 +76,20 @@ private JPanel setUpBoardZoomer() { */ private JPanel setUpProofTreeZoomer() { final String label = "Resize Proof"; - ActionListener listener = (ActionListener) -> GameBoardFacade.getInstance().getLegupUI().getProofEditor().fitTreeViewToScreen(); + ActionListener listener = + (ActionListener) -> + GameBoardFacade.getInstance() + .getLegupUI() + .getProofEditor() + .fitTreeViewToScreen(); return this.setUpZoomerHelper(label, listener); } /** * Creates the zoomer * - * @param label A string containing the label to be displayed - * on the fit to screen button - * @param listener A listener that determines what the resize - * button will do + * @param label A string containing the label to be displayed on the fit to screen button + * @param listener A listener that determines what the resize button will do * @return A JPanel containing the zoomer */ private JPanel setUpZoomerHelper(final String label, ActionListener listener) { @@ -111,39 +111,51 @@ private JPanel setUpZoomerHelper(final String label, ActionListener listener) { JSlider zoomSlider = new JSlider(25, 400, 100); - JButton plus = new JButton(new ImageIcon(ImageIO.read( - Objects.requireNonNull(ClassLoader.getSystemClassLoader().getResource( - "edu/rpi/legup/imgs/add.png"))))); + JButton plus = + new JButton( + new ImageIcon( + ImageIO.read( + Objects.requireNonNull( + ClassLoader.getSystemClassLoader() + .getResource( + "edu/rpi/legup/imgs/add.png"))))); plus.setFocusPainted(false); plus.setFont(MaterialFonts.getRegularFont(10f)); plus.setPreferredSize(new Dimension(20, 20)); - plus.addActionListener((ActionEvent e) -> zoomSlider.setValue(zoomSlider.getValue() + 25)); - - - JButton minus = new JButton(new ImageIcon(ImageIO.read( - Objects.requireNonNull(ClassLoader.getSystemClassLoader().getResource( - "edu/rpi/legup/imgs/remove.png"))))); + plus.addActionListener( + (ActionEvent e) -> zoomSlider.setValue(zoomSlider.getValue() + 25)); + + JButton minus = + new JButton( + new ImageIcon( + ImageIO.read( + Objects.requireNonNull( + ClassLoader.getSystemClassLoader() + .getResource( + "edu/rpi/legup/imgs/remove.png"))))); minus.setFocusPainted(false); minus.setPreferredSize(new Dimension(20, 20)); minus.setFont(MaterialFonts.getRegularFont(10f)); - minus.addActionListener((ActionEvent e) -> zoomSlider.setValue(zoomSlider.getValue() - 25)); + minus.addActionListener( + (ActionEvent e) -> zoomSlider.setValue(zoomSlider.getValue() - 25)); this.scrollView.setWheelScrollingEnabled(true); zoomSlider.setPreferredSize(new Dimension(160, 30)); - scrollView.addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - zoomSlider.setValue(scrollView.getZoom()); - zoomLabel.setText(zoomSlider.getValue() + "%"); - } - }); - - zoomSlider.addChangeListener((ChangeEvent e) -> { - scrollView.zoomTo(zoomSlider.getValue() / 100.0); - zoomLabel.setText(zoomSlider.getValue() + "%"); - }); - + scrollView.addComponentListener( + new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + zoomSlider.setValue(scrollView.getZoom()); + zoomLabel.setText(zoomSlider.getValue() + "%"); + } + }); + + zoomSlider.addChangeListener( + (ChangeEvent e) -> { + scrollView.zoomTo(zoomSlider.getValue() / 100.0); + zoomLabel.setText(zoomSlider.getValue() + "%"); + }); zoomSlider.setMajorTickSpacing(100); zoomSlider.setMinorTickSpacing(25); @@ -167,8 +179,7 @@ public void componentResized(ComponentEvent e) { zoomWrapper.setLayout(new BorderLayout()); zoomWrapper.add(status, WEST); zoomWrapper.add(zoomer, EAST); - } - catch (IOException e) { + } catch (IOException e) { e.printStackTrace(); } return zoomWrapper; diff --git a/src/main/java/edu/rpi/legup/ui/HomePanel.java b/src/main/java/edu/rpi/legup/ui/HomePanel.java index 2270c92b8..11f51eb0e 100644 --- a/src/main/java/edu/rpi/legup/ui/HomePanel.java +++ b/src/main/java/edu/rpi/legup/ui/HomePanel.java @@ -3,35 +3,30 @@ import edu.rpi.legup.app.GameBoardFacade; import edu.rpi.legup.app.LegupPreferences; import edu.rpi.legup.controller.CursorController; -import edu.rpi.legup.save.InvalidFileFormatException; import edu.rpi.legup.model.Puzzle; -import edu.rpi.legup.model.PuzzleExporter; -import edu.rpi.legup.save.ExportFileException; - -import javax.swing.*; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import javax.xml.parsers.ParserConfigurationException; +import edu.rpi.legup.save.InvalidFileFormatException; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.*; +import java.io.FileWriter; +import java.net.URI; +import java.net.URL; import java.util.Objects; - +import javax.swing.*; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; -import java.io.FileWriter; -import java.net.URI; -import java.net.URL; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - public class HomePanel extends LegupPanel { - private final static Logger LOGGER = LogManager.getLogger(HomePanel.class.getName()); + private static final Logger LOGGER = LogManager.getLogger(HomePanel.class.getName()); private LegupUI legupUI; private JFrame frame; private JButton[] buttons; @@ -41,33 +36,35 @@ public class HomePanel extends LegupPanel { private final int buttonSize = 100; - private ActionListener openProofListener = new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - Object[] items = legupUI.getProofEditor().promptPuzzle(); - if (items == null) { - // The attempt to prompt a puzzle ended gracefully (cancel) - return; - } - String fileName = (String) items[0]; - File puzzleFile = (File) items[1]; - legupUI.getProofEditor().loadPuzzle(fileName, puzzleFile); - } - }; - - private ActionListener openPuzzleListener = new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - Object[] items = legupUI.getPuzzleEditor().promptPuzzle(); - if (items == null) { - // The attempt to prompt a puzzle ended gracefully (cancel) - return; - } - String fileName = (String) items[0]; - File puzzleFile = (File) items[1]; - legupUI.getPuzzleEditor().loadPuzzle(fileName, puzzleFile); - } - }; + private ActionListener openProofListener = + new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Object[] items = legupUI.getProofEditor().promptPuzzle(); + if (items == null) { + // The attempt to prompt a puzzle ended gracefully (cancel) + return; + } + String fileName = (String) items[0]; + File puzzleFile = (File) items[1]; + legupUI.getProofEditor().loadPuzzle(fileName, puzzleFile); + } + }; + + private ActionListener openPuzzleListener = + new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Object[] items = legupUI.getPuzzleEditor().promptPuzzle(); + if (items == null) { + // The attempt to prompt a puzzle ended gracefully (cancel) + return; + } + String fileName = (String) items[0]; + File puzzleFile = (File) items[1]; + legupUI.getPuzzleEditor().loadPuzzle(fileName, puzzleFile); + } + }; public HomePanel(FileDialog fileDialog, JFrame frame, LegupUI legupUI) { this.legupUI = legupUI; @@ -82,22 +79,24 @@ public JMenuBar getMenuBar() { JMenu settings = new JMenu("Settings"); menuBar.add(settings); JMenuItem preferences = new JMenuItem("Preferences"); - preferences.addActionListener(a -> { - PreferencesDialog preferencesDialog = new PreferencesDialog(this.frame); - System.out.println("Preferences clicked"); - }); + preferences.addActionListener( + a -> { + PreferencesDialog preferencesDialog = new PreferencesDialog(this.frame); + System.out.println("Preferences clicked"); + }); settings.addSeparator(); settings.add(preferences); JMenuItem contribute = new JMenuItem("Contribute to Legup"); - contribute.addActionListener(l -> { - try { - java.awt.Desktop.getDesktop().browse(URI.create("https://github.com/Bram-Hub/Legup")); - } - catch (IOException e) { - LOGGER.error("Can't open web page"); - } - }); + contribute.addActionListener( + l -> { + try { + java.awt.Desktop.getDesktop() + .browse(URI.create("https://github.com/Bram-Hub/Legup")); + } catch (IOException e) { + LOGGER.error("Can't open web page"); + } + }); settings.add(contribute); return this.menuBar; @@ -118,14 +117,17 @@ private static ImageIcon resizeButtonIcon(ImageIcon icon, int width, int height) private void initButtons() { this.buttons = new JButton[4]; - this.buttons[0] = new JButton("Solve Puzzle") { - { - setSize(buttonSize, buttonSize); - setMaximumSize(getSize()); - } - }; + this.buttons[0] = + new JButton("Solve Puzzle") { + { + setSize(buttonSize, buttonSize); + setMaximumSize(getSize()); + } + }; - URL button0IconLocation = ClassLoader.getSystemClassLoader().getResource("edu/rpi/legup/images/Legup/homepanel/proof_file.png"); + URL button0IconLocation = + ClassLoader.getSystemClassLoader() + .getResource("edu/rpi/legup/images/Legup/homepanel/proof_file.png"); ImageIcon button0Icon = new ImageIcon(button0IconLocation); this.buttons[0].setFocusPainted(false); this.buttons[0].setIcon(resizeButtonIcon(button0Icon, this.buttonSize, this.buttonSize)); @@ -133,13 +135,16 @@ private void initButtons() { this.buttons[0].setVerticalTextPosition(AbstractButton.BOTTOM); this.buttons[0].addActionListener(CursorController.createListener(this, openProofListener)); - this.buttons[1] = new JButton("Create Puzzle") { - { - setSize(buttonSize, buttonSize); - setMaximumSize(getSize()); - } - }; - URL button1IconLocation = ClassLoader.getSystemClassLoader().getResource("edu/rpi/legup/images/Legup/homepanel/new_puzzle_file.png"); + this.buttons[1] = + new JButton("Create Puzzle") { + { + setSize(buttonSize, buttonSize); + setMaximumSize(getSize()); + } + }; + URL button1IconLocation = + ClassLoader.getSystemClassLoader() + .getResource("edu/rpi/legup/images/Legup/homepanel/new_puzzle_file.png"); ImageIcon button1Icon = new ImageIcon(button1IconLocation); this.buttons[1].setFocusPainted(false); this.buttons[1].setIcon(resizeButtonIcon(button1Icon, this.buttonSize, this.buttonSize)); @@ -147,21 +152,25 @@ private void initButtons() { this.buttons[1].setVerticalTextPosition(AbstractButton.BOTTOM); this.buttons[1].addActionListener(l -> this.openNewPuzzleDialog()); - this.buttons[2] = new JButton("Edit Puzzle") { - { - setSize(buttonSize, buttonSize); - setMaximumSize(getSize()); - } - }; - URL button2IconLocation = ClassLoader.getSystemClassLoader().getResource("edu/rpi/legup/images/Legup/homepanel/puzzle_file.png"); + this.buttons[2] = + new JButton("Edit Puzzle") { + { + setSize(buttonSize, buttonSize); + setMaximumSize(getSize()); + } + }; + URL button2IconLocation = + ClassLoader.getSystemClassLoader() + .getResource("edu/rpi/legup/images/Legup/homepanel/puzzle_file.png"); ImageIcon button2Icon = new ImageIcon(button2IconLocation); this.buttons[2].setFocusPainted(false); this.buttons[2].setIcon(resizeButtonIcon(button2Icon, this.buttonSize, this.buttonSize)); this.buttons[2].setHorizontalTextPosition(AbstractButton.CENTER); this.buttons[2].setVerticalTextPosition(AbstractButton.BOTTOM); - this.buttons[2].addActionListener(CursorController.createListener(this, openPuzzleListener)); // PLACEHOLDER + this.buttons[2].addActionListener( + CursorController.createListener(this, openPuzzleListener)); // PLACEHOLDER - for (int i = 0; i < this.buttons.length-1; i++) { // -1 to avoid the batch grader button + for (int i = 0; i < this.buttons.length - 1; i++) { // -1 to avoid the batch grader button this.buttons[i].setBounds(200, 200, 700, 700); } this.buttons[3] = new JButton("Batch Grader"); @@ -169,19 +178,18 @@ private void initButtons() { this.buttons[3].setHorizontalTextPosition(AbstractButton.CENTER); this.buttons[3].setVerticalTextPosition(AbstractButton.BOTTOM); - this.buttons[3].addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - try { - use_xml_to_check(); - } - catch (Exception ex) { - throw new RuntimeException(ex); - } - System.out.println("finished checking the folder"); - - } - }); + this.buttons[3].addActionListener( + new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + use_xml_to_check(); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + System.out.println("finished checking the folder"); + } + }); } public void checkFolder() { @@ -230,7 +238,8 @@ public void checkFolder() { } writer.append(fileEntry.getName()); writer.append(","); - String fileName = folderEntry.getAbsolutePath() + File.separator + fileEntry.getName(); + String fileName = + folderEntry.getAbsolutePath() + File.separator + fileEntry.getName(); System.out.println("This is path " + fileName); File puzzleFile = new File(fileName); if (puzzleFile != null && puzzleFile.exists()) { @@ -238,21 +247,20 @@ public void checkFolder() { legupUI.displayPanel(1); legupUI.getProofEditor(); GameBoardFacade.getInstance().loadPuzzle(fileName); - String puzzleName = GameBoardFacade.getInstance().getPuzzleModule().getName(); + String puzzleName = + GameBoardFacade.getInstance().getPuzzleModule().getName(); legupUI.setTitle(puzzleName + " - " + puzzleFile.getName()); facade = GameBoardFacade.getInstance(); Puzzle puzzle = facade.getPuzzleModule(); if (puzzle.isPuzzleComplete()) { writer.append("Solved"); System.out.println(fileEntry.getName() + " solved"); - } - else { + } else { writer.append("Not Solved"); System.out.println(fileEntry.getName() + " not solved"); } writer.append("\n"); - } - catch (InvalidFileFormatException e) { + } catch (InvalidFileFormatException e) { LOGGER.error(e.getMessage()); } } @@ -262,15 +270,15 @@ public void checkFolder() { writer.append("\n"); } } - } - catch (IOException ex) { + } catch (IOException ex) { LOGGER.error(ex.getMessage()); this.buttons[3].addActionListener((ActionEvent e) -> use_xml_to_check()); } } /** - * @effect batch grade using .xml parser - go through a collection of files and report their "solved?" status + * @effect batch grade using .xml parser - go through a collection of files and report their + * "solved?" status */ private void use_xml_to_check() { /* Select a folder, go through each .xml file in the subfolders, look for "isSolved" flag */ @@ -288,26 +296,24 @@ private void use_xml_to_check() { try (BufferedWriter writer = new BufferedWriter(new FileWriter(resultFile))) { writer.append("Name,File Name,Puzzle Type,Solved?,Last Saved\n"); // Go through student folders, recurse for inner folders - for (final File folderEntry : Objects.requireNonNull(folder.listFiles(File::isDirectory))) { + for (final File folderEntry : + Objects.requireNonNull(folder.listFiles(File::isDirectory))) { String path = folderEntry.getName(); // use this helper function to write to the .csv file recursive_parser(folderEntry, writer, path, path); } - } - catch (IOException ex) { + } catch (IOException ex) { LOGGER.error(ex.getMessage()); } if (resultFile.exists()) { try { Desktop desktop = Desktop.getDesktop(); desktop.open(resultFile); - } - catch (IOException ex) { + } catch (IOException ex) { LOGGER.error(ex.getMessage()); } } JOptionPane.showMessageDialog(null, "Batch grading complete."); - } /** @@ -321,8 +327,7 @@ public boolean isxmlfile(File file) { DocumentBuilder builder = factory.newDocumentBuilder(); builder.parse(file); flag = true; - } - catch (Exception e) { + } catch (Exception e) { flag = false; } return flag; @@ -335,7 +340,8 @@ public boolean isxmlfile(File file) { * @param name - student's name (the first subfolders of the main folder) * @throws IOException */ - private void recursive_parser(File folder, BufferedWriter writer, String path, String name) throws IOException { + private void recursive_parser(File folder, BufferedWriter writer, String path, String name) + throws IOException { // Empty folder if (Objects.requireNonNull(folder.listFiles()).length == 0) { writer.append(path).append(",Empty folder,Ungradeable\n"); @@ -368,94 +374,97 @@ private void recursive_parser(File folder, BufferedWriter writer, String path, S path = folder.getAbsolutePath() + File.separator + fileEntry.getName(); System.out.println(path); if (isxmlfile(fileEntry)) { - saxParser.parse(path, new DefaultHandler() { - @Override - public void startDocument() throws SAXException { - } - boolean solvedFlagExists = false; - boolean puzzleTypeExists = false; - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { - // append file type to the writer - if (qName.equals("puzzle") && attributes.getQName(0) == "name" && !puzzleTypeExists) { - try { - writer.write(attributes.getValue(0)); - writer.write(","); - puzzleTypeExists = true; - } - catch (IOException e) { - throw new RuntimeException(e); - } - } - // append the "solved?" status of the proof to the writer - else if (qName.equals("solved") && !solvedFlagExists) { - String isSolved = attributes.getValue(0); - String lastSaved = attributes.getValue(1); - if (isSolved != null) { - if (isSolved.equals("true")) { + saxParser.parse( + path, + new DefaultHandler() { + @Override + public void startDocument() throws SAXException {} + + boolean solvedFlagExists = false; + boolean puzzleTypeExists = false; + + @Override + public void startElement( + String uri, + String localName, + String qName, + Attributes attributes) + throws SAXException { + // append file type to the writer + if (qName.equals("puzzle") + && attributes.getQName(0) == "name" + && !puzzleTypeExists) { try { - writer.write("Solved"); - } - catch (IOException e) { + writer.write(attributes.getValue(0)); + writer.write(","); + puzzleTypeExists = true; + } catch (IOException e) { throw new RuntimeException(e); } } - else if (isSolved.equals("false")) { - try { - writer.write("Not Solved"); + // append the "solved?" status of the proof to the writer + else if (qName.equals("solved") && !solvedFlagExists) { + String isSolved = attributes.getValue(0); + String lastSaved = attributes.getValue(1); + if (isSolved != null) { + if (isSolved.equals("true")) { + try { + writer.write("Solved"); + } catch (IOException e) { + throw new RuntimeException(e); + } + } else if (isSolved.equals("false")) { + try { + writer.write("Not Solved"); + } catch (IOException e) { + throw new RuntimeException(e); + } + } else { + try { + writer.write("Error"); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } - catch (IOException e) { - throw new RuntimeException(e); + // append when is this proof last saved + if (lastSaved != null) { + try { + writer.write(","); + writer.write(lastSaved); + } catch (IOException e) { + throw new RuntimeException(e); + } } + solvedFlagExists = true; } - else { - try { - writer.write("Error"); + } + + @Override + public void characters(char[] ch, int start, int length) + throws SAXException {} + + @Override + public void endElement(String uri, String localName, String qName) + throws SAXException {} + + @Override + public void endDocument() throws SAXException { + if (!puzzleTypeExists) { + try { + writer.write("not a LEGUP puzzle!"); + } catch (IOException e) { + throw new RuntimeException(e); } - catch (IOException e) { + } else if (!solvedFlagExists) { + try { + writer.write("missing flag!"); + } catch (IOException e) { throw new RuntimeException(e); } } } - // append when is this proof last saved - if (lastSaved != null) { - try { - writer.write(","); - writer.write(lastSaved); - } - catch (IOException e) { - throw new RuntimeException(e); - } - } - solvedFlagExists = true; - } - } - @Override - public void characters(char[] ch, int start, int length) throws SAXException { - } - @Override - public void endElement(String uri, String localName, String qName) throws SAXException { - } - @Override - public void endDocument() throws SAXException { - if (!puzzleTypeExists) { - try { - writer.write("not a LEGUP puzzle!"); - } - catch (IOException e) { - throw new RuntimeException(e); - } - } - else if (!solvedFlagExists) { - try { - writer.write("missing flag!"); - } - catch (IOException e) { - throw new RuntimeException(e); - } - } - } - }); + }); } // If wrong file type, ungradeable else { @@ -463,14 +472,14 @@ else if (!solvedFlagExists) { } writer.write("\n"); } - } - catch (ParserConfigurationException | SAXException | IOException e) { + } catch (ParserConfigurationException | SAXException | IOException e) { LOGGER.error(e.getMessage()); } } private void initText() { - // TODO: add version text after auto-changing version label is implemented. (text[2] = version) + // TODO: add version text after auto-changing version label is implemented. (text[2] = + // version) this.text = new JLabel[2]; JLabel welcome = new JLabel("Welcome to LEGUP"); @@ -508,7 +517,6 @@ private void render() { batchGraderButton.add(this.buttons[3]); batchGraderButton.setAlignmentX(Component.CENTER_ALIGNMENT); - this.add(Box.createRigidArea(new Dimension(0, 5))); for (int i = 0; i < this.text.length; i++) { this.add(this.text[i]); @@ -535,7 +543,8 @@ private void checkProofAll() { */ LegupPreferences preferences = LegupPreferences.getInstance(); - File preferredDirectory = new File(preferences.getUserPref(LegupPreferences.WORK_DIRECTORY)); + File preferredDirectory = + new File(preferences.getUserPref(LegupPreferences.WORK_DIRECTORY)); folderBrowser = new JFileChooser(preferredDirectory); folderBrowser.showOpenDialog(this); @@ -553,13 +562,13 @@ private void checkProofAll() { writer.append("Name,File Name,Puzzle Type,Score,Solved?\n"); // Go through student folders - for (final File folderEntry : Objects.requireNonNull(folder.listFiles(File::isDirectory))) { + for (final File folderEntry : + Objects.requireNonNull(folder.listFiles(File::isDirectory))) { // Write path String path = folderEntry.getName(); traverseDir(folderEntry, writer, path); } - } - catch (IOException ex) { + } catch (IOException ex) { LOGGER.error(ex.getMessage()); } JOptionPane.showMessageDialog(null, "Batch grading complete."); @@ -605,29 +614,28 @@ private void traverseDir(File folder, BufferedWriter writer, String path) throws writer.append(puzzle.getName()).append(","); if (puzzle.isPuzzleComplete()) { writer.append("Solved\n"); - } - else { + } else { writer.append("Unsolved\n"); } - } - catch (InvalidFileFormatException e) { + } catch (InvalidFileFormatException e) { writer.append(fName).append("InvalidFile,Ungradeable\n"); } - } - else { + } else { LOGGER.debug("Failed to run sim"); } } } - public void openEditorWithNewPuzzle(String game, int rows, int columns) throws IllegalArgumentException { + public void openEditorWithNewPuzzle(String game, int rows, int columns) + throws IllegalArgumentException { // Validate the dimensions GameBoardFacade facade = GameBoardFacade.getInstance(); boolean isValidDimensions = facade.validateDimensions(game, rows, columns); if (!isValidDimensions) { - JOptionPane.showMessageDialog(null, - "The dimensions you entered are invalid. Please double check \n" + - "the number of rows and columns and try again.", + JOptionPane.showMessageDialog( + null, + "The dimensions you entered are invalid. Please double check \n" + + "the number of rows and columns and try again.", "ERROR: Invalid Dimensions", JOptionPane.ERROR_MESSAGE); throw new IllegalArgumentException("ERROR: Invalid dimensions given"); @@ -641,17 +649,18 @@ public void openEditorWithNewPuzzle(String game, int rows, int columns) throws I /** * Opens the puzzle editor for the specified game with the given statements * - * @param game a String containing the name of the game - * @param statements an array of statements + * @param game a String containing the name of the game + * @param statements an array of statements */ public void openEditorWithNewPuzzle(String game, String[] statements) { // Validate the text input GameBoardFacade facade = GameBoardFacade.getInstance(); boolean isValidTextInput = facade.validateTextInput(game, statements); if (!isValidTextInput) { - JOptionPane.showMessageDialog(null, - "The input you entered is invalid. Please double check \n" + - "your statements and try again.", + JOptionPane.showMessageDialog( + null, + "The input you entered is invalid. Please double check \n" + + "your statements and try again.", "ERROR: Invalid Text Input", JOptionPane.ERROR_MESSAGE); throw new IllegalArgumentException("ERROR: Invalid dimensions given"); diff --git a/src/main/java/edu/rpi/legup/ui/LegupPanel.java b/src/main/java/edu/rpi/legup/ui/LegupPanel.java index 708348145..d16167b3d 100644 --- a/src/main/java/edu/rpi/legup/ui/LegupPanel.java +++ b/src/main/java/edu/rpi/legup/ui/LegupPanel.java @@ -3,10 +3,7 @@ import javax.swing.*; public abstract class LegupPanel extends JPanel { - /** - * Alerts panel that it will be going visible now - */ - + /** Alerts panel that it will be going visible now */ protected final int TOOLBAR_ICON_SCALE = 40; public abstract void makeVisible(); diff --git a/src/main/java/edu/rpi/legup/ui/LegupUI.java b/src/main/java/edu/rpi/legup/ui/LegupUI.java index 452bbb487..eb8b1663c 100644 --- a/src/main/java/edu/rpi/legup/ui/LegupUI.java +++ b/src/main/java/edu/rpi/legup/ui/LegupUI.java @@ -1,25 +1,21 @@ package edu.rpi.legup.ui; -import java.awt.*; -import java.awt.event.*; -import java.security.InvalidParameterException; -import java.util.Objects; - -import javax.swing.*; - - -import com.formdev.flatlaf.FlatLightLaf; import com.formdev.flatlaf.FlatDarkLaf; +import com.formdev.flatlaf.FlatLightLaf; import edu.rpi.legup.app.GameBoardFacade; import edu.rpi.legup.app.LegupPreferences; import edu.rpi.legup.ui.boardview.BoardView; import edu.rpi.legup.ui.proofeditorui.treeview.TreePanel; - +import java.awt.*; +import java.awt.event.*; +import java.security.InvalidParameterException; +import java.util.Objects; +import javax.swing.*; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public class LegupUI extends JFrame implements WindowListener { - private final static Logger LOGGER = LogManager.getLogger(LegupUI.class.getName()); + private static final Logger LOGGER = LogManager.getLogger(LegupUI.class.getName()); protected FileDialog fileDialog; protected JPanel window; @@ -27,22 +23,20 @@ public class LegupUI extends JFrame implements WindowListener { /** * Identifies operating system + * * @return operating system, either mac or win */ public static String getOS() { String os = System.getProperty("os.name").toLowerCase(); if (os.contains("mac")) { os = "mac"; - } - else { + } else { os = "win"; } return os; } - /** - * LegupUI Constructor - creates a new LegupUI to setup the menu and toolbar - */ + /** LegupUI Constructor - creates a new LegupUI to setup the menu and toolbar */ public LegupUI() { setTitle("LEGUP"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -51,12 +45,10 @@ public LegupUI() { try { if (Boolean.valueOf(prefs.getUserPref(LegupPreferences.DARK_MODE))) { UIManager.setLookAndFeel(new FlatDarkLaf()); - } - else { + } else { UIManager.setLookAndFeel(new FlatLightLaf()); } - } - catch (UnsupportedLookAndFeelException e) { + } catch (UnsupportedLookAndFeelException e) { System.err.println("Not supported ui look and feel"); } @@ -65,27 +57,36 @@ public LegupUI() { initPanels(); displayPanel(0); - setIconImage(new ImageIcon(Objects.requireNonNull(ClassLoader.getSystemClassLoader().getResource( - "edu/rpi/legup/images/Legup/Direct Rules.gif"))).getImage()); - - if (LegupPreferences.getInstance().getUserPref(LegupPreferences.START_FULL_SCREEN).equals(Boolean.toString(true))) { + setIconImage( + new ImageIcon( + Objects.requireNonNull( + ClassLoader.getSystemClassLoader() + .getResource( + "edu/rpi/legup/images/Legup/Direct" + + " Rules.gif"))) + .getImage()); + + if (LegupPreferences.getInstance() + .getUserPref(LegupPreferences.START_FULL_SCREEN) + .equals(Boolean.toString(true))) { setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH); } this.addWindowListener(this); - addKeyListener(new KeyAdapter() { - /** - * Invoked when a key has been typed. - * This event occurs when a key press is followed by a key release. - * - * @param e - */ - @Override - public void keyTyped(KeyEvent e) { - System.err.println(e.getKeyChar()); - super.keyTyped(e); - } - }); + addKeyListener( + new KeyAdapter() { + /** + * Invoked when a key has been typed. This event occurs when a key press is + * followed by a key release. + * + * @param e + */ + @Override + public void keyTyped(KeyEvent e) { + System.err.println(e.getKeyChar()); + super.keyTyped(e); + } + }); setMinimumSize(getPreferredSize()); setVisible(true); } @@ -99,7 +100,6 @@ private void initPanels() { panels[0] = new HomePanel(this.fileDialog, this, this); panels[1] = new ProofEditorPanel(this.fileDialog, this, this); panels[2] = new PuzzleEditorPanel(this.fileDialog, this, this); - } protected void displayPanel(int option) { @@ -128,7 +128,14 @@ public void repaintTree() { } private void directions() { - JOptionPane.showMessageDialog(null, "For every move you make, you must provide a rules for it (located in the Rules panel).\n" + "While working on the edu.rpi.legup.puzzle, you may click on the \"Check\" button to test your proof for correctness.", "Directions", JOptionPane.PLAIN_MESSAGE); + JOptionPane.showMessageDialog( + null, + "For every move you make, you must provide a rules for it (located in the Rules" + + " panel).\n" + + "While working on the edu.rpi.legup.puzzle, you may click on the \"Check\"" + + " button to test your proof for correctness.", + "Directions", + JOptionPane.PLAIN_MESSAGE); } public void showStatus(String status, boolean error) { @@ -143,27 +150,23 @@ public void showStatus(String status, boolean error, int timer) { // TODO: implement } - //ask to edu.rpi.legup.save current proof + // ask to edu.rpi.legup.save current proof public boolean noquit(String instr) { int n = JOptionPane.showConfirmDialog(null, instr, "Confirm", JOptionPane.YES_NO_OPTION); return n != JOptionPane.YES_OPTION; } @Override - public void windowOpened(WindowEvent e) { - - } + public void windowOpened(WindowEvent e) {} public void windowClosing(WindowEvent e) { if (GameBoardFacade.getInstance().getHistory().getIndex() > -1) { if (noquit("Exiting LEGUP?")) { this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - } - else { + } else { this.setDefaultCloseOperation(EXIT_ON_CLOSE); } - } - else { + } else { this.setDefaultCloseOperation(EXIT_ON_CLOSE); } } @@ -172,21 +175,13 @@ public void windowClosed(WindowEvent e) { System.exit(0); } - public void windowIconified(WindowEvent e) { - - } + public void windowIconified(WindowEvent e) {} - public void windowDeiconified(WindowEvent e) { - - } + public void windowDeiconified(WindowEvent e) {} - public void windowActivated(WindowEvent e) { + public void windowActivated(WindowEvent e) {} - } - - public void windowDeactivated(WindowEvent e) { - - } + public void windowDeactivated(WindowEvent e) {} public BoardView getBoardView() { return getProofEditor().getBoardView(); diff --git a/src/main/java/edu/rpi/legup/ui/ManualPuzzleCreatorDialog.java b/src/main/java/edu/rpi/legup/ui/ManualPuzzleCreatorDialog.java index 6e3fb4f67..01d696f19 100644 --- a/src/main/java/edu/rpi/legup/ui/ManualPuzzleCreatorDialog.java +++ b/src/main/java/edu/rpi/legup/ui/ManualPuzzleCreatorDialog.java @@ -1,13 +1,9 @@ package edu.rpi.legup.ui; -import javax.swing.*; import java.awt.*; +import javax.swing.*; public class ManualPuzzleCreatorDialog extends JDialog { - - public ManualPuzzleCreatorDialog() { - - } - + public ManualPuzzleCreatorDialog() {} } diff --git a/src/main/java/edu/rpi/legup/ui/PickGameDialog.java b/src/main/java/edu/rpi/legup/ui/PickGameDialog.java index 24fc4602f..f703ffcbc 100644 --- a/src/main/java/edu/rpi/legup/ui/PickGameDialog.java +++ b/src/main/java/edu/rpi/legup/ui/PickGameDialog.java @@ -1,15 +1,11 @@ package edu.rpi.legup.ui; - import edu.rpi.legup.app.GameBoardFacade; - import java.awt.Container; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; - import java.io.File; - import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; @@ -36,7 +32,6 @@ public class PickGameDialog extends JDialog implements ActionListener { JButton ok = new JButton("Ok"); JButton cancel = new JButton("Cancel"); - JCheckBox autotreeCheckBox = new JCheckBox("Auto-tree"); JCheckBox showtreeCheckBox = new JCheckBox("Show tree"); JCheckBox autojustifyCheckBox = new JCheckBox("Auto-justify"); @@ -47,9 +42,9 @@ public class PickGameDialog extends JDialog implements ActionListener { /** * Initialize the dialog * - * @param parent the parent JFrame - * @param pickBothAtOnce if true they can pick a game type and a specific edu.rpi.legup.puzzle, if - * false they can only pick a game type + * @param parent the parent JFrame + * @param pickBothAtOnce if true they can pick a game type and a specific edu.rpi.legup.puzzle, + * if false they can only pick a game type */ public PickGameDialog(JFrame parent, boolean pickBothAtOnce) { super(parent, true); @@ -75,15 +70,13 @@ public PickGameDialog(JFrame parent, boolean pickBothAtOnce) { if (pickBoth) { gameLabel.setBounds(10, 10, 70, 25); gameBox.setBounds(80, 10, 190, 25); - } - else { + } else { gameLabel.setBounds(10, 30, 70, 25); gameBox.setBounds(80, 30, 190, 25); } puzzleLabel.setBounds(10, 40, 70, 25); - puzzleBox.setBounds(80, 40, 190, 25); puzzleButton.setBounds(270, 40, 25, 25); @@ -93,7 +86,6 @@ public PickGameDialog(JFrame parent, boolean pickBothAtOnce) { c.add(gameLabel); c.add(gameBox); - if (pickBoth) { c.add(puzzleLabel); c.add(puzzleBox); @@ -147,24 +139,25 @@ public String getGame() { public void actionPerformed(ActionEvent e) { if (e.getSource() == gameBox) { int index = gameBox.getSelectedIndex(); - } - else { + } else { if (e.getSource() == ok) { okPressed = true; setVisible(false); - } - else { + } else { if (e.getSource() == cancel) { okPressed = false; setVisible(false); - } - else { + } else { if (e.getSource() == puzzleButton) { - File f = new File("puzzlefiles" + File.separator + gameBox.getSelectedItem().toString().toLowerCase() + File.separator); + File f = + new File( + "puzzlefiles" + + File.separator + + gameBox.getSelectedItem().toString().toLowerCase() + + File.separator); if (f.exists() && f.isDirectory()) { puzzleChooser = new JFileChooser(f); - } - else { + } else { puzzleChooser = new JFileChooser(); } if (puzzleChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { diff --git a/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java b/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java index 4eee69d4d..475f4bb68 100644 --- a/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java +++ b/src/main/java/edu/rpi/legup/ui/PreferencesDialog.java @@ -1,33 +1,37 @@ package edu.rpi.legup.ui; +import com.formdev.flatlaf.FlatDarkLaf; +import com.formdev.flatlaf.FlatLightLaf; import edu.rpi.legup.app.LegupPreferences; import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.rules.Rule; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialBorders; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialFonts; - -import javax.imageio.ImageIO; -import javax.swing.*; +import edu.rpi.legup.ui.proofeditorui.rulesview.RuleFrame; import java.awt.*; import java.awt.event.*; import java.io.File; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; - -import com.formdev.flatlaf.FlatLightLaf; -import com.formdev.flatlaf.FlatDarkLaf; -import edu.rpi.legup.ui.proofeditorui.rulesview.RuleFrame; -import edu.rpi.legup.ui.proofeditorui.rulesview.RulePanel; +import javax.imageio.ImageIO; +import javax.swing.*; public class PreferencesDialog extends JDialog { - private RuleFrame rulesFrame; - private final static Logger LOGGER = Logger.getLogger(PreferencesDialog.class.getName()); + private static final Logger LOGGER = Logger.getLogger(PreferencesDialog.class.getName()); - private JCheckBox fullScreen, autoUpdate, darkMode, showMistakes, showAnnotations, allowDefault, generateCases, immFeedback, colorBlind; + private JCheckBox fullScreen, + autoUpdate, + darkMode, + showMistakes, + showAnnotations, + allowDefault, + generateCases, + immFeedback, + colorBlind; private JTextField workDirectory; @@ -35,9 +39,10 @@ public class PreferencesDialog extends JDialog { static { try { - folderIcon = ImageIO.read(PreferencesDialog.class.getResource("/edu/rpi/legup/imgs/folder.png")); - } - catch (IOException e) { + folderIcon = + ImageIO.read( + PreferencesDialog.class.getResource("/edu/rpi/legup/imgs/folder.png")); + } catch (IOException e) { LOGGER.log(Level.SEVERE, "Unable to locate icons"); } } @@ -66,22 +71,25 @@ public PreferencesDialog(Frame frame) { JToolBar toolbar = new JToolBar(); toolbar.setBorder(null); JButton okButton = new JButton("Ok"); - okButton.addActionListener(l -> { - applyPreferences(); - this.setVisible(false); - this.dispose(); - }); + okButton.addActionListener( + l -> { + applyPreferences(); + this.setVisible(false); + this.dispose(); + }); toolbar.add(okButton); JButton cancelButton = new JButton("Cancel"); - cancelButton.addActionListener(l -> { - this.setVisible(false); - this.dispose(); - }); + cancelButton.addActionListener( + l -> { + this.setVisible(false); + this.dispose(); + }); toolbar.add(cancelButton); JButton applyButton = new JButton("Apply"); - applyButton.addActionListener(l -> { - applyPreferences(); - }); + applyButton.addActionListener( + l -> { + applyPreferences(); + }); toolbar.add(applyButton); bottomPanel.add(toolbar, BorderLayout.EAST); @@ -98,13 +106,11 @@ private void toggleDarkMode(LegupPreferences prefs) { try { if (Boolean.valueOf(prefs.getUserPref(LegupPreferences.DARK_MODE))) { UIManager.setLookAndFeel(new FlatDarkLaf()); - } - else { + } else { UIManager.setLookAndFeel(new FlatLightLaf()); } com.formdev.flatlaf.FlatLaf.updateUI(); - } - catch (UnsupportedLookAndFeelException e) { + } catch (UnsupportedLookAndFeelException e) { System.err.println("Not supported ui look and feel"); } } @@ -126,115 +132,162 @@ private JScrollPane createGeneralTab() { workDirectory = new JTextField(prefs.getUserPref(LegupPreferences.WORK_DIRECTORY)); workRow.add(workDirectory, BorderLayout.CENTER); JButton openDir = new JButton(new ImageIcon(folderIcon)); - openDir.addActionListener(a -> { - JFileChooser chooser = new JFileChooser(); - chooser.setCurrentDirectory(new File(workDirectory.getText())); - chooser.setDialogTitle("Choose work directory"); - chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - chooser.setAcceptAllFileFilterUsed(false); - chooser.setVisible(true); - - if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { - File newFile = chooser.getSelectedFile(); - workDirectory.setText(newFile.toString()); - } - }); + openDir.addActionListener( + a -> { + JFileChooser chooser = new JFileChooser(); + chooser.setCurrentDirectory(new File(workDirectory.getText())); + chooser.setDialogTitle("Choose work directory"); + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + chooser.setAcceptAllFileFilterUsed(false); + chooser.setVisible(true); + + if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { + File newFile = chooser.getSelectedFile(); + workDirectory.setText(newFile.toString()); + } + }); workRow.add(openDir, BorderLayout.EAST); workRow.setMaximumSize(new Dimension(Integer.MAX_VALUE, workRow.getPreferredSize().height)); contentPane.add(workRow); - fullScreen = new JCheckBox("Full Screen", Boolean.valueOf(prefs.getUserPref(LegupPreferences.START_FULL_SCREEN))); + fullScreen = + new JCheckBox( + "Full Screen", + Boolean.valueOf(prefs.getUserPref(LegupPreferences.START_FULL_SCREEN))); fullScreen.setToolTipText("If checked this starts Legup in full screen."); JPanel fullScreenRow = new JPanel(); fullScreenRow.setLayout(new BorderLayout()); fullScreenRow.add(fullScreen, BorderLayout.WEST); - fullScreenRow.setMaximumSize(new Dimension(Integer.MAX_VALUE, fullScreenRow.getPreferredSize().height)); + fullScreenRow.setMaximumSize( + new Dimension(Integer.MAX_VALUE, fullScreenRow.getPreferredSize().height)); contentPane.add(fullScreenRow); - autoUpdate = new JCheckBox("Automatically Check for Updates", Boolean.valueOf(prefs.getUserPref(LegupPreferences.AUTO_UPDATE))); - autoUpdate.setToolTipText("If checked this automatically checks for updates on startup of Legup"); + autoUpdate = + new JCheckBox( + "Automatically Check for Updates", + Boolean.valueOf(prefs.getUserPref(LegupPreferences.AUTO_UPDATE))); + autoUpdate.setToolTipText( + "If checked this automatically checks for updates on startup of Legup"); JPanel autoUpdateRow = new JPanel(); autoUpdateRow.setLayout(new BorderLayout()); autoUpdateRow.add(autoUpdate, BorderLayout.WEST); - autoUpdateRow.setMaximumSize(new Dimension(Integer.MAX_VALUE, autoUpdateRow.getPreferredSize().height)); + autoUpdateRow.setMaximumSize( + new Dimension(Integer.MAX_VALUE, autoUpdateRow.getPreferredSize().height)); contentPane.add(autoUpdateRow); -// contentPane.add(Box.createRigidArea(new Dimension(0, 10))); + // contentPane.add(Box.createRigidArea(new Dimension(0, 10))); - darkMode = new JCheckBox("Dark Mode", Boolean.valueOf(prefs.getUserPref(LegupPreferences.DARK_MODE))); + darkMode = + new JCheckBox( + "Dark Mode", + Boolean.valueOf(prefs.getUserPref(LegupPreferences.DARK_MODE))); darkMode.setToolTipText("This turns dark mode on and off"); JPanel darkModeRow = new JPanel(); darkModeRow.setLayout(new BorderLayout()); darkModeRow.add(darkMode, BorderLayout.WEST); - darkModeRow.setMaximumSize(new Dimension(Integer.MAX_VALUE, darkModeRow.getPreferredSize().height)); + darkModeRow.setMaximumSize( + new Dimension(Integer.MAX_VALUE, darkModeRow.getPreferredSize().height)); contentPane.add(darkModeRow); contentPane.add(Box.createRigidArea(new Dimension(0, 10))); contentPane.add(createLeftLabel("Board View Preferences")); contentPane.add(createLineSeparator()); - showMistakes = new JCheckBox("Show Mistakes", Boolean.valueOf(prefs.getUserPref(LegupPreferences.SHOW_MISTAKES))); - showMistakes.setToolTipText("If checked this show incorrectly applied rule applications in red on the board"); + showMistakes = + new JCheckBox( + "Show Mistakes", + Boolean.valueOf(prefs.getUserPref(LegupPreferences.SHOW_MISTAKES))); + showMistakes.setToolTipText( + "If checked this show incorrectly applied rule applications in red on the board"); JPanel showMistakesRow = new JPanel(); showMistakesRow.setLayout(new BorderLayout()); showMistakesRow.add(showMistakes, BorderLayout.WEST); - showMistakesRow.setMaximumSize(new Dimension(Integer.MAX_VALUE, showMistakesRow.getPreferredSize().height)); + showMistakesRow.setMaximumSize( + new Dimension(Integer.MAX_VALUE, showMistakesRow.getPreferredSize().height)); contentPane.add(showMistakesRow); - showAnnotations = new JCheckBox("Show Annotations", Boolean.valueOf(prefs.getUserPref(LegupPreferences.SHOW_ANNOTATIONS))); - showAnnotations.setToolTipText("If checked this show incorrectly applied rule applications in red on the board"); + showAnnotations = + new JCheckBox( + "Show Annotations", + Boolean.valueOf(prefs.getUserPref(LegupPreferences.SHOW_ANNOTATIONS))); + showAnnotations.setToolTipText( + "If checked this show incorrectly applied rule applications in red on the board"); JPanel showAnnotationsRow = new JPanel(); showAnnotationsRow.setLayout(new BorderLayout()); showAnnotationsRow.add(showAnnotations, BorderLayout.WEST); - showAnnotationsRow.setMaximumSize(new Dimension(Integer.MAX_VALUE, showAnnotationsRow.getPreferredSize().height)); + showAnnotationsRow.setMaximumSize( + new Dimension(Integer.MAX_VALUE, showAnnotationsRow.getPreferredSize().height)); contentPane.add(showAnnotationsRow); contentPane.add(Box.createRigidArea(new Dimension(0, 10))); contentPane.add(createLeftLabel("Tree View Preferences")); contentPane.add(createLineSeparator()); - allowDefault = new JCheckBox("Allow Default Rule Applications", Boolean.valueOf(prefs.getUserPref(LegupPreferences.ALLOW_DEFAULT_RULES))); + allowDefault = + new JCheckBox( + "Allow Default Rule Applications", + Boolean.valueOf(prefs.getUserPref(LegupPreferences.ALLOW_DEFAULT_RULES))); allowDefault.setEnabled(false); - allowDefault.setToolTipText("If checked this automatically applies a rule where it can on the board"); + allowDefault.setToolTipText( + "If checked this automatically applies a rule where it can on the board"); JPanel allowDefaultRow = new JPanel(); allowDefaultRow.setLayout(new BorderLayout()); allowDefaultRow.add(allowDefault, BorderLayout.WEST); - allowDefaultRow.setMaximumSize(new Dimension(Integer.MAX_VALUE, allowDefaultRow.getPreferredSize().height)); + allowDefaultRow.setMaximumSize( + new Dimension(Integer.MAX_VALUE, allowDefaultRow.getPreferredSize().height)); contentPane.add(allowDefaultRow); - generateCases = new JCheckBox("Automatically Generate Cases", Boolean.valueOf(prefs.getUserPref(LegupPreferences.AUTO_GENERATE_CASES))); - generateCases.setToolTipText("If checked this automatically generates all cases for a case rule"); + generateCases = + new JCheckBox( + "Automatically Generate Cases", + Boolean.valueOf(prefs.getUserPref(LegupPreferences.AUTO_GENERATE_CASES))); + generateCases.setToolTipText( + "If checked this automatically generates all cases for a case rule"); JPanel generateCasesRow = new JPanel(); generateCasesRow.setLayout(new BorderLayout()); generateCasesRow.add(generateCases, BorderLayout.WEST); - generateCasesRow.setMaximumSize(new Dimension(Integer.MAX_VALUE, generateCasesRow.getPreferredSize().height)); + generateCasesRow.setMaximumSize( + new Dimension(Integer.MAX_VALUE, generateCasesRow.getPreferredSize().height)); contentPane.add(generateCasesRow); contentPane.add(Box.createRigidArea(new Dimension(0, 10))); - immFeedback = new JCheckBox("Provide Immediate Feedback", Boolean.valueOf(prefs.getUserPref(LegupPreferences.IMMEDIATE_FEEDBACK))); - immFeedback.setToolTipText("If checked this will update the colors of the tree view elements immediately"); + immFeedback = + new JCheckBox( + "Provide Immediate Feedback", + Boolean.valueOf(prefs.getUserPref(LegupPreferences.IMMEDIATE_FEEDBACK))); + immFeedback.setToolTipText( + "If checked this will update the colors of the tree view elements immediately"); JPanel immFeedbackRow = new JPanel(); immFeedbackRow.setLayout(new BorderLayout()); immFeedbackRow.add(immFeedback, BorderLayout.WEST); - immFeedbackRow.setMaximumSize(new Dimension(Integer.MAX_VALUE, immFeedbackRow.getPreferredSize().height)); + immFeedbackRow.setMaximumSize( + new Dimension(Integer.MAX_VALUE, immFeedbackRow.getPreferredSize().height)); contentPane.add(immFeedbackRow); contentPane.add(createLeftLabel("Instructor Preferences")); contentPane.add(createLineSeparator()); - immFeedback = new JCheckBox("Instructor Mode", Boolean.valueOf(prefs.getUserPref(LegupPreferences.IMMEDIATE_FEEDBACK))); + immFeedback = + new JCheckBox( + "Instructor Mode", + Boolean.valueOf(prefs.getUserPref(LegupPreferences.IMMEDIATE_FEEDBACK))); immFeedback.setToolTipText("Currently unimplemented, this does nothing right now"); immFeedbackRow.setLayout(new BorderLayout()); immFeedbackRow.add(immFeedback, BorderLayout.WEST); - immFeedbackRow.setMaximumSize(new Dimension(Integer.MAX_VALUE, immFeedbackRow.getPreferredSize().height)); + immFeedbackRow.setMaximumSize( + new Dimension(Integer.MAX_VALUE, immFeedbackRow.getPreferredSize().height)); contentPane.add(immFeedbackRow); contentPane.add(createLeftLabel("Color Preferences")); contentPane.add(createLineSeparator()); - colorBlind = new JCheckBox("Deuteranomaly(red/green colorblindness)", Boolean.valueOf(prefs.getUserPref(LegupPreferences.COLOR_BLIND))); + colorBlind = + new JCheckBox( + "Deuteranomaly(red/green colorblindness)", + Boolean.valueOf(prefs.getUserPref(LegupPreferences.COLOR_BLIND))); JPanel colorBlindRow = new JPanel(); colorBlindRow.setLayout(new BorderLayout()); colorBlindRow.add(colorBlind, BorderLayout.WEST); - colorBlindRow.setMaximumSize(new Dimension(Integer.MAX_VALUE, showMistakesRow.getPreferredSize().height)); + colorBlindRow.setMaximumSize( + new Dimension(Integer.MAX_VALUE, showMistakesRow.getPreferredSize().height)); contentPane.add(colorBlindRow); scrollPane.setViewportView(contentPane); @@ -293,38 +346,40 @@ private JPanel createRuleRow(Rule rule) { ruleAcc.setHorizontalAlignment(JLabel.CENTER); ruleAcc.setBorder(MaterialBorders.LIGHT_LINE_BORDER); ruleAcc.setPreferredSize(new Dimension(60, 20)); - ruleAcc.addMouseListener(new MouseAdapter() { - @Override - public void mouseEntered(MouseEvent e) { - ruleAcc.requestFocusInWindow(); - } - }); - - ruleAcc.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - int keyCode = e.getKeyCode(); - String combo = ""; - if (e.isControlDown()) { - combo += "Ctrl + "; - } - else { - if (e.isShiftDown()) { - combo += "Shift + "; + ruleAcc.addMouseListener( + new MouseAdapter() { + @Override + public void mouseEntered(MouseEvent e) { + ruleAcc.requestFocusInWindow(); } - else { - if (e.isAltDown()) { - combo += "Alt + "; + }); + + ruleAcc.addKeyListener( + new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + int keyCode = e.getKeyCode(); + String combo = ""; + if (e.isControlDown()) { + combo += "Ctrl + "; + } else { + if (e.isShiftDown()) { + combo += "Shift + "; + } else { + if (e.isAltDown()) { + combo += "Alt + "; + } + } } + if (keyCode == KeyEvent.VK_CONTROL + || keyCode == KeyEvent.VK_SHIFT + || keyCode == KeyEvent.VK_ALT) { + return; + } + combo += KeyEvent.getKeyText(keyCode); + ruleAcc.setText(combo); } - } - if (keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_SHIFT || keyCode == KeyEvent.VK_ALT) { - return; - } - combo += KeyEvent.getKeyText(keyCode); - ruleAcc.setText(combo); - } - }); + }); ruleRow.add(ruleAcc, BorderLayout.EAST); @@ -340,7 +395,8 @@ private JPanel createLeftLabel(String text) { label.setHorizontalAlignment(JLabel.LEFT); labelRow.add(label, BorderLayout.WEST); - labelRow.setMaximumSize(new Dimension(Integer.MAX_VALUE, labelRow.getPreferredSize().height)); + labelRow.setMaximumSize( + new Dimension(Integer.MAX_VALUE, labelRow.getPreferredSize().height)); return labelRow; } @@ -353,17 +409,23 @@ private JSeparator createLineSeparator() { public void applyPreferences() { LegupPreferences prefs = LegupPreferences.getInstance(); prefs.setUserPref(LegupPreferences.WORK_DIRECTORY, workDirectory.getText()); - prefs.setUserPref(LegupPreferences.START_FULL_SCREEN, Boolean.toString(fullScreen.isSelected())); + prefs.setUserPref( + LegupPreferences.START_FULL_SCREEN, Boolean.toString(fullScreen.isSelected())); prefs.setUserPref(LegupPreferences.AUTO_UPDATE, Boolean.toString(autoUpdate.isSelected())); prefs.setUserPref(LegupPreferences.DARK_MODE, Boolean.toString(darkMode.isSelected())); - prefs.setUserPref(LegupPreferences.SHOW_MISTAKES, Boolean.toString(showMistakes.isSelected())); - prefs.setUserPref(LegupPreferences.SHOW_ANNOTATIONS, Boolean.toString(showAnnotations.isSelected())); - prefs.setUserPref(LegupPreferences.ALLOW_DEFAULT_RULES, Boolean.toString(allowDefault.isSelected())); - prefs.setUserPref(LegupPreferences.AUTO_GENERATE_CASES, Boolean.toString(generateCases.isSelected())); - prefs.setUserPref(LegupPreferences.IMMEDIATE_FEEDBACK, Boolean.toString(immFeedback.isSelected())); + prefs.setUserPref( + LegupPreferences.SHOW_MISTAKES, Boolean.toString(showMistakes.isSelected())); + prefs.setUserPref( + LegupPreferences.SHOW_ANNOTATIONS, Boolean.toString(showAnnotations.isSelected())); + prefs.setUserPref( + LegupPreferences.ALLOW_DEFAULT_RULES, Boolean.toString(allowDefault.isSelected())); + prefs.setUserPref( + LegupPreferences.AUTO_GENERATE_CASES, Boolean.toString(generateCases.isSelected())); + prefs.setUserPref( + LegupPreferences.IMMEDIATE_FEEDBACK, Boolean.toString(immFeedback.isSelected())); prefs.setUserPref(LegupPreferences.COLOR_BLIND, Boolean.toString(colorBlind.isSelected())); - if(rulesFrame != null) { + if (rulesFrame != null) { rulesFrame.getCasePanel().updateRules(); rulesFrame.getDirectRulePanel().updateRules(); rulesFrame.getContradictionPanel().updateRules(); @@ -372,4 +434,4 @@ public void applyPreferences() { // toggle dark mode based on updated NIGHT_MODE variable toggleDarkMode(prefs); } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java index e83f660e7..956f83ba4 100644 --- a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java @@ -17,14 +17,8 @@ import edu.rpi.legup.ui.boardview.BoardView; import edu.rpi.legup.ui.proofeditorui.rulesview.RuleFrame; import edu.rpi.legup.ui.proofeditorui.treeview.TreePanel; -import edu.rpi.legup.ui.proofeditorui.treeview.TreeView; import edu.rpi.legup.ui.proofeditorui.treeview.TreeViewSelection; import edu.rpi.legup.user.Submission; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import javax.swing.*; -import javax.swing.border.TitledBorder; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -37,9 +31,13 @@ import java.net.URL; import java.util.List; import java.util.Objects; +import javax.swing.*; +import javax.swing.border.TitledBorder; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class ProofEditorPanel extends LegupPanel implements IHistoryListener { - private final static Logger LOGGER = LogManager.getLogger(ProofEditorPanel.class.getName()); + private static final Logger LOGGER = LogManager.getLogger(ProofEditorPanel.class.getName()); private JMenuBar mBar; private TreePanel treePanel; private FileDialog fileDialog; @@ -51,7 +49,13 @@ public class ProofEditorPanel extends LegupPanel implements IHistoryListener { private JButton[] toolBarButtons; private JMenu file; - private JMenuItem newPuzzle, resetPuzzle, saveProofAs, saveProofChange, helpTutorial, preferences, exit; + private JMenuItem newPuzzle, + resetPuzzle, + saveProofAs, + saveProofChange, + helpTutorial, + preferences, + exit; private JMenu edit; private JMenuItem undo, redo, fitBoardToScreen, fitTreeToScreen; @@ -60,7 +64,6 @@ public class ProofEditorPanel extends LegupPanel implements IHistoryListener { private JMenu proof; private JMenuItem add, delete, merge, collapse; private JCheckBoxMenuItem allowDefault, caseRuleGen, imdFeedback; - private JMenu about, help; private JMenuItem helpLegup, aboutLegup; @@ -78,9 +81,25 @@ public class ProofEditorPanel extends LegupPanel implements IHistoryListener { public static final int IMD_FEEDBACK = 32; public static final int INTERN_RO = 64; public static final int AUTO_JUST = 128; - final static int[] TOOLBAR_SEPARATOR_BEFORE = {2, 4, 8}; - private static final String[] PROFILES = {"No Assistance", "Rigorous Proof", "Casual Proof", "Assisted Proof", "Guided Proof", "Training-Wheels Proof", "No Restrictions"}; - private static final int[] PROF_FLAGS = {0, ALLOW_JUST | REQ_STEP_JUST, ALLOW_JUST, ALLOW_HINTS | ALLOW_JUST | AUTO_JUST, ALLOW_HINTS | ALLOW_JUST | REQ_STEP_JUST, ALLOW_HINTS | ALLOW_DEFAPP | ALLOW_JUST | IMD_FEEDBACK | INTERN_RO, ALLOW_HINTS | ALLOW_DEFAPP | ALLOW_FULLAI | ALLOW_JUST}; + static final int[] TOOLBAR_SEPARATOR_BEFORE = {2, 4, 8}; + private static final String[] PROFILES = { + "No Assistance", + "Rigorous Proof", + "Casual Proof", + "Assisted Proof", + "Guided Proof", + "Training-Wheels Proof", + "No Restrictions" + }; + private static final int[] PROF_FLAGS = { + 0, + ALLOW_JUST | REQ_STEP_JUST, + ALLOW_JUST, + ALLOW_HINTS | ALLOW_JUST | AUTO_JUST, + ALLOW_HINTS | ALLOW_JUST | REQ_STEP_JUST, + ALLOW_HINTS | ALLOW_DEFAPP | ALLOW_JUST | IMD_FEEDBACK | INTERN_RO, + ALLOW_HINTS | ALLOW_DEFAPP | ALLOW_FULLAI | ALLOW_JUST + }; private JMenu proofMode = new JMenu("Proof Mode"); private JCheckBoxMenuItem[] proofModeItems = new JCheckBoxMenuItem[PROF_FLAGS.length]; @@ -116,7 +135,8 @@ public JMenuBar getMenuBar() { file = new JMenu("File"); newPuzzle = new JMenuItem("Open"); resetPuzzle = new JMenuItem("Reset Puzzle"); -// genPuzzle = new JMenuItem("Puzzle Generators"); // TODO: implement puzzle generator + // genPuzzle = new JMenuItem("Puzzle Generators"); // TODO: implement puzzle + // generator saveProofAs = new JMenuItem("Save As"); // create a new file to save saveProofChange = new JMenuItem("Save"); // save to the current file preferences = new JMenuItem("Preferences"); @@ -139,9 +159,10 @@ public JMenuBar getMenuBar() { add = new JMenuItem("Add"); add.addActionListener(a -> treePanel.add()); if (os.equals("mac")) { - add.setAccelerator(KeyStroke.getKeyStroke('A', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } - else { + add.setAccelerator( + KeyStroke.getKeyStroke( + 'A', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } else { add.setAccelerator(KeyStroke.getKeyStroke('A', InputEvent.CTRL_DOWN_MASK)); } proof.add(add); @@ -149,9 +170,10 @@ public JMenuBar getMenuBar() { delete = new JMenuItem("Delete"); delete.addActionListener(a -> treePanel.delete()); if (os.equals("mac")) { - delete.setAccelerator(KeyStroke.getKeyStroke('D', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } - else { + delete.setAccelerator( + KeyStroke.getKeyStroke( + 'D', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } else { delete.setAccelerator(KeyStroke.getKeyStroke('D', InputEvent.CTRL_DOWN_MASK)); } proof.add(delete); @@ -159,9 +181,10 @@ public JMenuBar getMenuBar() { merge = new JMenuItem("Merge"); merge.addActionListener(a -> treePanel.merge()); if (os.equals("mac")) { - merge.setAccelerator(KeyStroke.getKeyStroke('M', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } - else { + merge.setAccelerator( + KeyStroke.getKeyStroke( + 'M', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } else { merge.setAccelerator(KeyStroke.getKeyStroke('M', InputEvent.CTRL_DOWN_MASK)); } proof.add(merge); @@ -169,33 +192,58 @@ public JMenuBar getMenuBar() { collapse = new JMenuItem("Collapse"); collapse.addActionListener(a -> treePanel.collapse()); if (os.equals("mac")) { - collapse.setAccelerator(KeyStroke.getKeyStroke('C', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } - else { + collapse.setAccelerator( + KeyStroke.getKeyStroke( + 'C', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } else { collapse.setAccelerator(KeyStroke.getKeyStroke('C', InputEvent.CTRL_DOWN_MASK)); } collapse.setEnabled(false); proof.add(collapse); - allowDefault = new JCheckBoxMenuItem("Allow Default Rule Applications", - LegupPreferences.getInstance().getUserPref(LegupPreferences.ALLOW_DEFAULT_RULES).equalsIgnoreCase(Boolean.toString(true))); - allowDefault.addChangeListener(e -> { - LegupPreferences.getInstance().setUserPref(LegupPreferences.ALLOW_DEFAULT_RULES, Boolean.toString(allowDefault.isSelected())); - }); + allowDefault = + new JCheckBoxMenuItem( + "Allow Default Rule Applications", + LegupPreferences.getInstance() + .getUserPref(LegupPreferences.ALLOW_DEFAULT_RULES) + .equalsIgnoreCase(Boolean.toString(true))); + allowDefault.addChangeListener( + e -> { + LegupPreferences.getInstance() + .setUserPref( + LegupPreferences.ALLOW_DEFAULT_RULES, + Boolean.toString(allowDefault.isSelected())); + }); proof.add(allowDefault); - caseRuleGen = new JCheckBoxMenuItem("Automatically generate cases for CaseRule", - LegupPreferences.getInstance().getUserPref(LegupPreferences.AUTO_GENERATE_CASES).equalsIgnoreCase(Boolean.toString(true))); - caseRuleGen.addChangeListener(e -> { - LegupPreferences.getInstance().setUserPref(LegupPreferences.AUTO_GENERATE_CASES, Boolean.toString(caseRuleGen.isSelected())); - }); + caseRuleGen = + new JCheckBoxMenuItem( + "Automatically generate cases for CaseRule", + LegupPreferences.getInstance() + .getUserPref(LegupPreferences.AUTO_GENERATE_CASES) + .equalsIgnoreCase(Boolean.toString(true))); + caseRuleGen.addChangeListener( + e -> { + LegupPreferences.getInstance() + .setUserPref( + LegupPreferences.AUTO_GENERATE_CASES, + Boolean.toString(caseRuleGen.isSelected())); + }); proof.add(caseRuleGen); - imdFeedback = new JCheckBoxMenuItem("Provide immediate feedback", - LegupPreferences.getInstance().getUserPref(LegupPreferences.IMMEDIATE_FEEDBACK).equalsIgnoreCase(Boolean.toString(true))); - imdFeedback.addChangeListener(e -> { - LegupPreferences.getInstance().setUserPref(LegupPreferences.IMMEDIATE_FEEDBACK, Boolean.toString(imdFeedback.isSelected())); - }); + imdFeedback = + new JCheckBoxMenuItem( + "Provide immediate feedback", + LegupPreferences.getInstance() + .getUserPref(LegupPreferences.IMMEDIATE_FEEDBACK) + .equalsIgnoreCase(Boolean.toString(true))); + imdFeedback.addChangeListener( + e -> { + LegupPreferences.getInstance() + .setUserPref( + LegupPreferences.IMMEDIATE_FEEDBACK, + Boolean.toString(imdFeedback.isSelected())); + }); proof.add(imdFeedback); about = new JMenu("About"); @@ -206,38 +254,60 @@ public JMenuBar getMenuBar() { file.add(newPuzzle); newPuzzle.addActionListener((ActionEvent) -> loadPuzzle()); if (os.equals("mac")) { - newPuzzle.setAccelerator(KeyStroke.getKeyStroke('N', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } - else { + newPuzzle.setAccelerator( + KeyStroke.getKeyStroke( + 'N', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } else { newPuzzle.setAccelerator(KeyStroke.getKeyStroke('N', InputEvent.CTRL_DOWN_MASK)); } file.add(resetPuzzle); - resetPuzzle.addActionListener(a -> { - Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); - if (puzzle != null) { - Tree tree = GameBoardFacade.getInstance().getTree(); - TreeNode rootNode = tree.getRootNode(); - if (rootNode != null) { - int confirmReset = JOptionPane.showConfirmDialog(this, "Reset Puzzle to Root Node?", "Confirm Reset", JOptionPane.YES_NO_OPTION); - if (confirmReset == JOptionPane.YES_OPTION) { - - List children = rootNode.getChildren(); - children.forEach(t -> puzzle.notifyTreeListeners(l -> l.onTreeElementRemoved(t))); - children.forEach(t -> puzzle.notifyBoardListeners(l -> l.onTreeElementChanged(t))); - rootNode.clearChildren(); - final TreeViewSelection selection = new TreeViewSelection(treePanel.getTreeView().getElementView(rootNode)); - puzzle.notifyTreeListeners(l -> l.onTreeSelectionChanged(selection)); - puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(selection.getFirstSelection().getTreeElement())); - GameBoardFacade.getInstance().getHistory().clear(); + resetPuzzle.addActionListener( + a -> { + Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); + if (puzzle != null) { + Tree tree = GameBoardFacade.getInstance().getTree(); + TreeNode rootNode = tree.getRootNode(); + if (rootNode != null) { + int confirmReset = + JOptionPane.showConfirmDialog( + this, + "Reset Puzzle to Root Node?", + "Confirm Reset", + JOptionPane.YES_NO_OPTION); + if (confirmReset == JOptionPane.YES_OPTION) { + + List children = rootNode.getChildren(); + children.forEach( + t -> + puzzle.notifyTreeListeners( + l -> l.onTreeElementRemoved(t))); + children.forEach( + t -> + puzzle.notifyBoardListeners( + l -> l.onTreeElementChanged(t))); + rootNode.clearChildren(); + final TreeViewSelection selection = + new TreeViewSelection( + treePanel.getTreeView().getElementView(rootNode)); + puzzle.notifyTreeListeners( + l -> l.onTreeSelectionChanged(selection)); + puzzle.notifyBoardListeners( + listener -> + listener.onTreeElementChanged( + selection + .getFirstSelection() + .getTreeElement())); + GameBoardFacade.getInstance().getHistory().clear(); + } + } } - } - } - }); + }); if (os.equals("mac")) { - resetPuzzle.setAccelerator(KeyStroke.getKeyStroke('R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } - else { + resetPuzzle.setAccelerator( + KeyStroke.getKeyStroke( + 'R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } else { resetPuzzle.setAccelerator(KeyStroke.getKeyStroke('R', InputEvent.CTRL_DOWN_MASK)); } file.addSeparator(); @@ -245,40 +315,44 @@ public JMenuBar getMenuBar() { file.add(saveProofAs); saveProofAs.addActionListener((ActionEvent) -> saveProofAs()); - - //save proof as... + // save proof as... if (os.equals("mac")) { - saveProofAs.setAccelerator(KeyStroke.getKeyStroke('S', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } - else { + saveProofAs.setAccelerator( + KeyStroke.getKeyStroke( + 'S', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } else { saveProofAs.setAccelerator(KeyStroke.getKeyStroke('S', InputEvent.CTRL_DOWN_MASK)); } // save proof change if (os.equals("mac")) { - saveProofChange.setAccelerator(KeyStroke.getKeyStroke('A', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } - else { + saveProofChange.setAccelerator( + KeyStroke.getKeyStroke( + 'A', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } else { saveProofChange.setAccelerator(KeyStroke.getKeyStroke('A', InputEvent.CTRL_DOWN_MASK)); } - file.add(saveProofChange); saveProofChange.addActionListener((ActionEvent) -> saveProofChange()); file.addSeparator(); // preference file.add(preferences); - preferences.addActionListener(a -> { - PreferencesDialog preferencesDialog = PreferencesDialog.CreateDialogForProofEditor(this.frame, this.ruleFrame); - }); + preferences.addActionListener( + a -> { + PreferencesDialog preferencesDialog = + PreferencesDialog.CreateDialogForProofEditor( + this.frame, this.ruleFrame); + }); file.addSeparator(); // help function if (os.equals("mac")) { - helpTutorial.setAccelerator(KeyStroke.getKeyStroke('H', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } - else { + helpTutorial.setAccelerator( + KeyStroke.getKeyStroke( + 'H', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } else { helpTutorial.setAccelerator(KeyStroke.getKeyStroke('H', InputEvent.CTRL_DOWN_MASK)); } file.add(helpTutorial); @@ -286,56 +360,75 @@ public JMenuBar getMenuBar() { helpTutorial.addActionListener((ActionEvent) -> helpTutorial()); file.addSeparator(); - - //exit + // exit file.add(exit); exit.addActionListener((ActionEvent) -> exitEditor()); if (os.equals("mac")) { - exit.setAccelerator(KeyStroke.getKeyStroke('Q', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } - else { + exit.setAccelerator( + KeyStroke.getKeyStroke( + 'Q', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } else { exit.setAccelerator(KeyStroke.getKeyStroke('Q', InputEvent.CTRL_DOWN_MASK)); } mBar.add(edit); - edit.add(undo); - undo.addActionListener((ActionEvent) -> - GameBoardFacade.getInstance().getHistory().undo()); + undo.addActionListener((ActionEvent) -> GameBoardFacade.getInstance().getHistory().undo()); if (os.equals("mac")) { - undo.setAccelerator(KeyStroke.getKeyStroke('Z', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } - else { + undo.setAccelerator( + KeyStroke.getKeyStroke( + 'Z', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } else { undo.setAccelerator(KeyStroke.getKeyStroke('Z', InputEvent.CTRL_DOWN_MASK)); } edit.add(redo); // Created action to support two keybinds (CTRL-SHIFT-Z, CTRL-Y) - Action redoAction = new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - GameBoardFacade.getInstance().getHistory().redo(); - } - }; + Action redoAction = + new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + GameBoardFacade.getInstance().getHistory().redo(); + } + }; if (os.equals("mac")) { - redo.getInputMap(WHEN_IN_FOCUSED_WINDOW).put( - KeyStroke.getKeyStroke('Z', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() + InputEvent.SHIFT_DOWN_MASK), "redoAction"); - redo.getInputMap(WHEN_IN_FOCUSED_WINDOW).put( - KeyStroke.getKeyStroke('Y', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "redoAction"); - redo.setAccelerator(KeyStroke.getKeyStroke('Z', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() + InputEvent.SHIFT_DOWN_MASK)); - } - else { - redo.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('Y', InputEvent.CTRL_DOWN_MASK), "redoAction"); - redo.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('Z', InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK), "redoAction"); + redo.getInputMap(WHEN_IN_FOCUSED_WINDOW) + .put( + KeyStroke.getKeyStroke( + 'Z', + Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() + + InputEvent.SHIFT_DOWN_MASK), + "redoAction"); + redo.getInputMap(WHEN_IN_FOCUSED_WINDOW) + .put( + KeyStroke.getKeyStroke( + 'Y', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), + "redoAction"); + redo.setAccelerator( + KeyStroke.getKeyStroke( + 'Z', + Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() + + InputEvent.SHIFT_DOWN_MASK)); + } else { + redo.getInputMap(WHEN_IN_FOCUSED_WINDOW) + .put(KeyStroke.getKeyStroke('Y', InputEvent.CTRL_DOWN_MASK), "redoAction"); + redo.getInputMap(WHEN_IN_FOCUSED_WINDOW) + .put( + KeyStroke.getKeyStroke( + 'Z', InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK), + "redoAction"); redo.getActionMap().put("redoAction", redoAction); // Button in menu will show CTRL-SHIFT-Z as primary keybind - redo.setAccelerator(KeyStroke.getKeyStroke('Z', InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK)); + redo.setAccelerator( + KeyStroke.getKeyStroke( + 'Z', InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK)); } edit.add(fitBoardToScreen); - fitBoardToScreen.addActionListener((ActionEvent) -> dynamicBoardView.fitBoardViewToScreen()); + fitBoardToScreen.addActionListener( + (ActionEvent) -> dynamicBoardView.fitBoardViewToScreen()); edit.add(fitTreeToScreen); fitTreeToScreen.addActionListener((ActionEvent) -> this.fitTreeViewToScreen()); @@ -343,19 +436,21 @@ public void actionPerformed(ActionEvent e) { mBar.add(proof); about.add(aboutLegup); - aboutLegup.addActionListener(l -> { - JOptionPane.showMessageDialog(null, "Version: 5.1.0"); - }); + aboutLegup.addActionListener( + l -> { + JOptionPane.showMessageDialog(null, "Version: 5.1.0"); + }); about.add(helpLegup); - helpLegup.addActionListener(l -> { - try { - java.awt.Desktop.getDesktop().browse(URI.create("https://github.com/Bram-Hub/LEGUP/wiki")); - } - catch (IOException e) { - LOGGER.error("Can't open web page"); - } - }); + helpLegup.addActionListener( + l -> { + try { + java.awt.Desktop.getDesktop() + .browse(URI.create("https://github.com/Bram-Hub/LEGUP/wiki")); + } catch (IOException e) { + LOGGER.error("Can't open web page"); + } + }); mBar.add(about); @@ -402,16 +497,15 @@ public Object[] promptPuzzle() { if (puzzlePath != null) { fileName = puzzlePath.getAbsolutePath(); - String lastDirectoryPath = fileName.substring(0, fileName.lastIndexOf(File.separator)); + String lastDirectoryPath = fileName.substring(0, fileName.lastIndexOf(File.separator)); preferences.setSavedPath(lastDirectoryPath); puzzleFile = puzzlePath; - } - else { + } else { // The attempt to prompt a puzzle ended gracefully (cancel) return null; } - return new Object[]{fileName, puzzleFile}; + return new Object[] {fileName, puzzleFile}; } public void loadPuzzle() { @@ -432,25 +526,35 @@ public void loadPuzzle(String fileName, File puzzleFile) { GameBoardFacade.getInstance().loadPuzzle(fileName); String puzzleName = GameBoardFacade.getInstance().getPuzzleModule().getName(); frame.setTitle(puzzleName + " - " + puzzleFile.getName()); - } - catch (InvalidFileFormatException e) { + } catch (InvalidFileFormatException e) { legupUI.displayPanel(0); LOGGER.error(e.getMessage()); - if (e.getMessage().contains("Proof Tree construction error: could not find rule by ID")) { // TO DO: make error message not hardcoded - JOptionPane.showMessageDialog(null, "This file runs on an outdated version of Legup\nand is not compatible with the current version.", "Error", JOptionPane.ERROR_MESSAGE); + if (e.getMessage() + .contains( + "Proof Tree construction error: could not find rule by ID")) { // TO + // DO: make error + // message not + // hardcoded + JOptionPane.showMessageDialog( + null, + "This file runs on an outdated version of Legup\n" + + "and is not compatible with the current version.", + "Error", + JOptionPane.ERROR_MESSAGE); loadPuzzle(); - } - else { - JOptionPane.showMessageDialog(null, "File does not exist or it cannot be read", "Error", JOptionPane.ERROR_MESSAGE); + } else { + JOptionPane.showMessageDialog( + null, + "File does not exist or it cannot be read", + "Error", + JOptionPane.ERROR_MESSAGE); loadPuzzle(); } } } } - /** - * save the proof in the current file - */ + /** save the proof in the current file */ private void direct_save() { Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); if (puzzle == null) { @@ -464,16 +568,13 @@ private void direct_save() { throw new ExportFileException("Puzzle exporter null"); } exporter.exportPuzzle(fileName); - } - catch (ExportFileException e) { + } catch (ExportFileException e) { e.printStackTrace(); } } } - /** - * Create a new file and save proof to it - */ + /** Create a new file and save proof to it */ private void saveProofAs() { Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); if (puzzle == null) { @@ -484,9 +585,9 @@ private void saveProofAs() { fileDialog.setTitle("Save As"); String curFileName = GameBoardFacade.getInstance().getCurFileName(); if (curFileName == null) { - fileDialog.setDirectory(LegupPreferences.getInstance().getUserPref(LegupPreferences.WORK_DIRECTORY)); - } - else { + fileDialog.setDirectory( + LegupPreferences.getInstance().getUserPref(LegupPreferences.WORK_DIRECTORY)); + } else { File curFile = new File(curFileName); fileDialog.setDirectory(curFile.getParent()); } @@ -504,8 +605,7 @@ private void saveProofAs() { throw new ExportFileException("Puzzle exporter null"); } exporter.exportPuzzle(fileName); - } - catch (ExportFileException e) { + } catch (ExportFileException e) { e.printStackTrace(); } } @@ -513,7 +613,7 @@ private void saveProofAs() { // Hyperlink for help button; links to wiki page for tutorials private void helpTutorial() { - //redirecting to certain help link in wiki + // redirecting to certain help link in wiki Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); if (puzzle == null) { return; @@ -541,32 +641,30 @@ private void helpTutorial() { } Runtime rt = Runtime.getRuntime(); try { - //rt.exec("rundll32 url.dll,FileProtocolHandler "+url); + // rt.exec("rundll32 url.dll,FileProtocolHandler "+url); java.awt.Desktop.getDesktop().browse(java.net.URI.create(url)); - } - catch (IOException e) { + } catch (IOException e) { e.printStackTrace(); } } - //add the new function need to implement + // add the new function need to implement public void add_drop() { // add the mouse event then we can use the new listener to implement and // we should create a need jbuttom for it to ship the rule we select. JPanel panel = new JPanel(); JButton moveing_buttom = new JButton(); moveing_buttom.setFocusPainted(false); - moveing_buttom.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - //get the selected rule - } - }); + moveing_buttom.addActionListener( + new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + // get the selected rule + } + }); panel.add(moveing_buttom); - } - // Quick save proof to the current file with a pop window to show "successfully saved" private void saveProofChange() { Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); @@ -582,27 +680,23 @@ private void saveProofChange() { } exporter.exportPuzzle(fileName); // Save confirmation - JOptionPane.showMessageDialog(null, "Successfully Saved", "Confirm", JOptionPane.INFORMATION_MESSAGE); - } - catch (ExportFileException e) { + JOptionPane.showMessageDialog( + null, "Successfully Saved", "Confirm", JOptionPane.INFORMATION_MESSAGE); + } catch (ExportFileException e) { e.printStackTrace(); } } - } - - //ask to edu.rpi.legup.save current proof + // ask to edu.rpi.legup.save current proof public boolean noquit(String instr) { int n = JOptionPane.showConfirmDialog(null, instr, "Confirm", JOptionPane.YES_NO_OPTION); return n != JOptionPane.YES_OPTION; } - /** - * Sets the main content for the edu.rpi.legup.user interface - */ + /** Sets the main content for the edu.rpi.legup.user interface */ protected void setupContent() { -// JPanel consoleBox = new JPanel(new BorderLayout()); + // JPanel consoleBox = new JPanel(new BorderLayout()); JPanel treeBox = new JPanel(new BorderLayout()); JPanel ruleBox = new JPanel(new BorderLayout()); @@ -612,13 +706,15 @@ protected void setupContent() { treePanel = new TreePanel(); - dynamicBoardView = new DynamicView(new ScrollView(new BoardController()), DynamicViewType.BOARD); + dynamicBoardView = + new DynamicView(new ScrollView(new BoardController()), DynamicViewType.BOARD); TitledBorder titleBoard = BorderFactory.createTitledBorder("Board"); titleBoard.setTitleJustification(TitledBorder.CENTER); dynamicBoardView.setBorder(titleBoard); JPanel boardPanel = new JPanel(new BorderLayout()); - topHalfPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, ruleFrame, dynamicBoardView); + topHalfPanel = + new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, ruleFrame, dynamicBoardView); mainPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, topHalfPanel, treePanel); topHalfPanel.setPreferredSize(new Dimension(600, 400)); mainPanel.setPreferredSize(new Dimension(600, 600)); @@ -631,16 +727,16 @@ protected void setupContent() { ruleBox.add(boardPanel); treeBox.add(ruleBox); this.add(treeBox); -// consoleBox.add(treeBox); -// -// getContentPane().add(consoleBox); + // consoleBox.add(treeBox); + // + // getContentPane().add(consoleBox); -// JPopupPanel popupPanel = new JPopupPanel(); -// setGlassPane(popupPanel); -// popupPanel.setVisible(true); + // JPopupPanel popupPanel = new JPopupPanel(); + // setGlassPane(popupPanel); + // popupPanel.setVisible(true); mainPanel.setDividerLocation(mainPanel.getMaximumDividerLocation() + 100); -// frame.pack(); + // frame.pack(); revalidate(); } @@ -648,12 +744,19 @@ private void setupToolBar() { setToolBarButtons(new JButton[ToolbarName.values().length]); for (int i = 0; i < ToolbarName.values().length; i++) { String toolBarName = ToolbarName.values()[i].toString(); - URL resourceLocation = ClassLoader.getSystemClassLoader().getResource("edu/rpi/legup/images/Legup/" + toolBarName + ".png"); + URL resourceLocation = + ClassLoader.getSystemClassLoader() + .getResource("edu/rpi/legup/images/Legup/" + toolBarName + ".png"); // Scale the image icons down to make the buttons smaller ImageIcon imageIcon = new ImageIcon(resourceLocation); Image image = imageIcon.getImage(); - imageIcon = new ImageIcon(image.getScaledInstance(this.TOOLBAR_ICON_SCALE, this.TOOLBAR_ICON_SCALE, Image.SCALE_SMOOTH)); + imageIcon = + new ImageIcon( + image.getScaledInstance( + this.TOOLBAR_ICON_SCALE, + this.TOOLBAR_ICON_SCALE, + Image.SCALE_SMOOTH)); JButton button = new JButton(toolBarName, imageIcon); button.setFocusPainted(false); @@ -679,23 +782,27 @@ private void setupToolBar() { getToolBarButtons()[i].setHorizontalTextPosition(SwingConstants.CENTER); } -// toolBarButtons[ToolbarName.OPEN_PUZZLE.ordinal()].addActionListener((ActionEvent e) -> promptPuzzle()); -// toolBarButtons[ToolbarName.SAVE.ordinal()].addActionListener((ActionEvent e) -> saveProof()); -// toolBarButtons[ToolbarName.UNDO.ordinal()].addActionListener((ActionEvent e) -> GameBoardFacade.getInstance().getHistory().undo()); -// toolBarButtons[ToolbarName.REDO.ordinal()].addActionListener((ActionEvent e) -> GameBoardFacade.getInstance().getHistory().redo()); - toolBarButtons[ToolbarName.HINT.ordinal()].addActionListener((ActionEvent e) -> { - }); - toolBarButtons[ToolbarName.CHECK.ordinal()].addActionListener((ActionEvent e) -> checkProof()); - toolBarButtons[ToolbarName.SUBMIT.ordinal()].addActionListener((ActionEvent e) -> { - }); - toolBarButtons[ToolbarName.DIRECTIONS.ordinal()].addActionListener((ActionEvent e) -> { - }); - - toolBarButtons[ToolbarName.CHECK_ALL.ordinal()].addActionListener((ActionEvent e) -> checkProofAll()); - -// toolBarButtons[ToolbarName.SAVE.ordinal()].setEnabled(false); -// toolBarButtons[ToolbarName.UNDO.ordinal()].setEnabled(false); -// toolBarButtons[ToolbarName.REDO.ordinal()].setEnabled(false); + // toolBarButtons[ToolbarName.OPEN_PUZZLE.ordinal()].addActionListener((ActionEvent + // e) -> + // promptPuzzle()); + // toolBarButtons[ToolbarName.SAVE.ordinal()].addActionListener((ActionEvent e) -> + // saveProof()); + // toolBarButtons[ToolbarName.UNDO.ordinal()].addActionListener((ActionEvent e) -> + // GameBoardFacade.getInstance().getHistory().undo()); + // toolBarButtons[ToolbarName.REDO.ordinal()].addActionListener((ActionEvent e) -> + // GameBoardFacade.getInstance().getHistory().redo()); + toolBarButtons[ToolbarName.HINT.ordinal()].addActionListener((ActionEvent e) -> {}); + toolBarButtons[ToolbarName.CHECK.ordinal()].addActionListener( + (ActionEvent e) -> checkProof()); + toolBarButtons[ToolbarName.SUBMIT.ordinal()].addActionListener((ActionEvent e) -> {}); + toolBarButtons[ToolbarName.DIRECTIONS.ordinal()].addActionListener((ActionEvent e) -> {}); + + toolBarButtons[ToolbarName.CHECK_ALL.ordinal()].addActionListener( + (ActionEvent e) -> checkProofAll()); + + // toolBarButtons[ToolbarName.SAVE.ordinal()].setEnabled(false); + // toolBarButtons[ToolbarName.UNDO.ordinal()].setEnabled(false); + // toolBarButtons[ToolbarName.REDO.ordinal()].setEnabled(false); toolBarButtons[ToolbarName.HINT.ordinal()].setEnabled(false); toolBarButtons[ToolbarName.CHECK.ordinal()].setEnabled(false); toolBarButtons[ToolbarName.SUBMIT.ordinal()].setEnabled(false); @@ -723,15 +830,13 @@ public JButton[] getToolBarButtons() { return toolBarButtons; } - /** - * Checks the proof for correctness - */ + /** Checks the proof for correctness */ private void checkProof() { GameBoardFacade facade = GameBoardFacade.getInstance(); Tree tree = GameBoardFacade.getInstance().getTree(); Board board = facade.getBoard(); Board finalBoard = null; - boolean delayStatus = true; //board.evalDelayStatus(); + boolean delayStatus = true; // board.evalDelayStatus(); repaintAll(); @@ -745,10 +850,10 @@ private void checkProof() { submission.submit(); }*/ JOptionPane.showMessageDialog(null, "Congratulations! Your proof is correct."); - } - else { + } else { String message = "\nThe game board is not solved."; - JOptionPane.showMessageDialog(null, message, "Invalid proof.", JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog( + null, message, "Invalid proof.", JOptionPane.ERROR_MESSAGE); } } @@ -780,9 +885,8 @@ public void setPuzzleView(Puzzle puzzle) { ruleFrame.getContradictionPanel().setRules(puzzle.getContradictionRules()); ruleFrame.getSearchPanel().setSearchBar(puzzle); - toolBarButtons[ToolbarName.CHECK.ordinal()].setEnabled(true); -// toolBarButtons[ToolbarName.SAVE.ordinal()].setEnabled(true); + // toolBarButtons[ToolbarName.SAVE.ordinal()].setEnabled(true); reloadGui(); } @@ -795,9 +899,7 @@ public void repaintTree() { treePanel.repaintTreeView(GameBoardFacade.getInstance().getTree()); } - /** - * Checks the proof for all files - */ + /** Checks the proof for all files */ private void checkProofAll() { GameBoardFacade facade = GameBoardFacade.getInstance(); @@ -812,7 +914,8 @@ private void checkProofAll() { */ LegupPreferences preferences = LegupPreferences.getInstance(); - File preferredDirectory = new File(preferences.getUserPref(LegupPreferences.WORK_DIRECTORY)); + File preferredDirectory = + new File(preferences.getUserPref(LegupPreferences.WORK_DIRECTORY)); folderBrowser = new JFileChooser(preferredDirectory); folderBrowser.showOpenDialog(this); @@ -830,13 +933,13 @@ private void checkProofAll() { writer.append("Name,File Name,Puzzle Type,Score,Solved?\n"); // Go through student folders - for (final File folderEntry : Objects.requireNonNull(folder.listFiles(File::isDirectory))) { + for (final File folderEntry : + Objects.requireNonNull(folder.listFiles(File::isDirectory))) { // Write path String path = folderEntry.getName(); traverseDir(folderEntry, writer, path); } - } - catch (IOException ex) { + } catch (IOException ex) { LOGGER.error(ex.getMessage()); } JOptionPane.showMessageDialog(null, "Batch grading complete."); @@ -888,16 +991,13 @@ private void traverseDir(File folder, BufferedWriter writer, String path) throws writer.append(puzzle.getName()).append(","); if (puzzle.isPuzzleComplete()) { writer.append("1,Solved\n"); - } - else { + } else { writer.append("0,Unsolved\n"); } - } - catch (InvalidFileFormatException e) { + } catch (InvalidFileFormatException e) { writer.append(fName).append(",Invalid,,Ungradeable\n"); } - } - else { + } else { LOGGER.debug("Failed to run sim"); } } @@ -924,44 +1024,41 @@ public TreePanel getTreePanel() { public void onPushChange(ICommand command) { LOGGER.info("Pushing " + command.getClass().getSimpleName() + " to stack."); undo.setEnabled(true); -// toolBarButtons[ToolbarName.UNDO.ordinal()].setEnabled(true); + // toolBarButtons[ToolbarName.UNDO.ordinal()].setEnabled(true); redo.setEnabled(false); -// toolBarButtons[ToolbarName.REDO.ordinal()].setEnabled(false); + // toolBarButtons[ToolbarName.REDO.ordinal()].setEnabled(false); String puzzleName = GameBoardFacade.getInstance().getPuzzleModule().getName(); File puzzleFile = new File(GameBoardFacade.getInstance().getCurFileName()); frame.setTitle(puzzleName + " - " + puzzleFile.getName() + " *"); } - /** - * Called when the history is cleared - */ + /** Called when the history is cleared */ @Override public void onClearHistory() { - //undo.setEnabled(false); -// toolBarButtons[ToolbarName.UNDO.ordinal()].setEnabled(false); - //redo.setEnabled(false); -// toolBarButtons[ToolbarName.REDO.ordinal()].setEnabled(false); + // undo.setEnabled(false); + // toolBarButtons[ToolbarName.UNDO.ordinal()].setEnabled(false); + // redo.setEnabled(false); + // toolBarButtons[ToolbarName.REDO.ordinal()].setEnabled(false); } /** * Called when an action is redone * * @param isBottom true if there are no more actions to undo, false otherwise - * @param isTop true if there are no more changes to redo, false otherwise + * @param isTop true if there are no more changes to redo, false otherwise */ @Override public void onRedo(boolean isBottom, boolean isTop) { undo.setEnabled(!isBottom); -// toolBarButtons[ToolbarName.UNDO.ordinal()].setEnabled(!isBottom); + // toolBarButtons[ToolbarName.UNDO.ordinal()].setEnabled(!isBottom); redo.setEnabled(!isTop); -// toolBarButtons[ToolbarName.REDO.ordinal()].setEnabled(!isTop); + // toolBarButtons[ToolbarName.REDO.ordinal()].setEnabled(!isTop); if (isBottom) { String puzzleName = GameBoardFacade.getInstance().getPuzzleModule().getName(); File puzzleFile = new File(GameBoardFacade.getInstance().getCurFileName()); frame.setTitle(puzzleName + " - " + puzzleFile.getName()); - } - else { + } else { String puzzleName = GameBoardFacade.getInstance().getPuzzleModule().getName(); File puzzleFile = new File(GameBoardFacade.getInstance().getCurFileName()); frame.setTitle(puzzleName + " - " + puzzleFile.getName() + " *"); @@ -972,44 +1069,49 @@ public void onRedo(boolean isBottom, boolean isTop) { * Called when an action is undone * * @param isBottom true if there are no more actions to undo, false otherwise - * @param isTop true if there are no more changes to redo, false otherwise + * @param isTop true if there are no more changes to redo, false otherwise */ @Override public void onUndo(boolean isBottom, boolean isTop) { undo.setEnabled(!isBottom); -// toolBarButtons[ToolbarName.UNDO.ordinal()].setEnabled(!isBottom); + // toolBarButtons[ToolbarName.UNDO.ordinal()].setEnabled(!isBottom); redo.setEnabled(!isTop); -// toolBarButtons[ToolbarName.REDO.ordinal()].setEnabled(!isTop); + // toolBarButtons[ToolbarName.REDO.ordinal()].setEnabled(!isTop); String puzzleName = GameBoardFacade.getInstance().getPuzzleModule().getName(); File puzzleFile = new File(GameBoardFacade.getInstance().getCurFileName()); if (isBottom) { frame.setTitle(puzzleName + " - " + puzzleFile.getName()); - } - else { + } else { frame.setTitle(puzzleName + " - " + puzzleFile.getName() + " *"); } } - /** - * Submits the proof file - */ + /** Submits the proof file */ private void submit() { GameBoardFacade facade = GameBoardFacade.getInstance(); Board board = facade.getBoard(); - boolean delayStatus = true; //board.evalDelayStatus(); + boolean delayStatus = true; // board.evalDelayStatus(); repaintAll(); Puzzle pm = facade.getPuzzleModule(); if (pm.isPuzzleComplete() && delayStatus) { // 0 means yes, 1 means no (Java's fault...) - int confirm = JOptionPane.showConfirmDialog(null, "Are you sure you wish to submit?", "Proof Submission", JOptionPane.YES_NO_OPTION); + int confirm = + JOptionPane.showConfirmDialog( + null, + "Are you sure you wish to submit?", + "Proof Submission", + JOptionPane.YES_NO_OPTION); if (confirm == 0) { Submission submission = new Submission(board); submission.submit(); } - } - else { - JOptionPane.showConfirmDialog(null, "Your proof is incorrect! Are you sure you wish to submit?", "Proof Submission", JOptionPane.YES_NO_OPTION); + } else { + JOptionPane.showConfirmDialog( + null, + "Your proof is incorrect! Are you sure you wish to submit?", + "Proof Submission", + JOptionPane.YES_NO_OPTION); Submission submit = new Submission(board); } } diff --git a/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java b/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java index 2c4f37c85..b3cd30ffb 100644 --- a/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java @@ -1,27 +1,19 @@ package edu.rpi.legup.ui; +import static java.lang.System.exit; + import edu.rpi.legup.app.GameBoardFacade; import edu.rpi.legup.app.LegupPreferences; import edu.rpi.legup.controller.BoardController; import edu.rpi.legup.controller.EditorElementController; -import edu.rpi.legup.controller.ElementController; import edu.rpi.legup.history.ICommand; import edu.rpi.legup.history.IHistoryListener; import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.PuzzleExporter; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.puzzle.treetent.TreeTentBoard; -import edu.rpi.legup.puzzle.treetent.TreeTentCell; -import edu.rpi.legup.puzzle.treetent.TreeTentType; import edu.rpi.legup.save.ExportFileException; import edu.rpi.legup.save.InvalidFileFormatException; import edu.rpi.legup.ui.boardview.BoardView; import edu.rpi.legup.ui.puzzleeditorui.elementsview.ElementFrame; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import javax.swing.*; -import javax.swing.border.TitledBorder; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -30,14 +22,15 @@ import java.io.IOException; import java.net.URI; import java.net.URL; -import java.util.List; import java.util.Objects; - -import static java.lang.System.exit; +import javax.swing.*; +import javax.swing.border.TitledBorder; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class PuzzleEditorPanel extends LegupPanel implements IHistoryListener { - private final static Logger LOGGER = LogManager.getLogger(PuzzleEditorPanel.class.getName()); + private static final Logger LOGGER = LogManager.getLogger(PuzzleEditorPanel.class.getName()); private JMenu[] menus; private JMenuItem helpLegup, aboutLegup; private JMenuBar menuBar; @@ -50,14 +43,14 @@ public class PuzzleEditorPanel extends LegupPanel implements IHistoryListener { private DynamicView dynamicBoardView; private BoardView boardView; private TitledBorder boardBorder; - //private JSplitPane splitPanel, topHalfPanel; + // private JSplitPane splitPanel, topHalfPanel; private FileDialog fileDialog; private JMenuItem undo, redo, fitBoardToScreen; private ElementFrame elementFrame; private JPanel treePanel; private LegupUI legupUI; private EditorElementController editorElementController; - final static int[] TOOLBAR_SEPARATOR_BEFORE = {2, 4, 8}; + static final int[] TOOLBAR_SEPARATOR_BEFORE = {2, 4, 8}; public PuzzleEditorPanel(FileDialog fileDialog, JFrame frame, LegupUI legupUI) { this.fileDialog = fileDialog; @@ -75,13 +68,15 @@ protected void setupContent() { elementFrame = new ElementFrame(editorElementController); elementBox.add(elementFrame, BorderLayout.WEST); - dynamicBoardView = new DynamicView(new ScrollView(new BoardController()), DynamicViewType.BOARD); + dynamicBoardView = + new DynamicView(new ScrollView(new BoardController()), DynamicViewType.BOARD); TitledBorder titleBoard = BorderFactory.createTitledBorder("Board"); titleBoard.setTitleJustification(TitledBorder.CENTER); dynamicBoardView.setBorder(titleBoard); JPanel boardPanel = new JPanel(new BorderLayout()); - splitPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, elementFrame, dynamicBoardView); + splitPanel = + new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, elementFrame, dynamicBoardView); splitPanel.setPreferredSize(new Dimension(600, 400)); boardPanel.add(splitPanel); @@ -110,9 +105,10 @@ public void setMenuBar() { JMenuItem newPuzzle = new JMenuItem("New"); newPuzzle.addActionListener((ActionEvent) -> loadPuzzle()); if (os.equals("mac")) { - newPuzzle.setAccelerator(KeyStroke.getKeyStroke('N', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } - else { + newPuzzle.setAccelerator( + KeyStroke.getKeyStroke( + 'N', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } else { newPuzzle.setAccelerator(KeyStroke.getKeyStroke('N', InputEvent.CTRL_DOWN_MASK)); } // file>save @@ -121,18 +117,20 @@ public void setMenuBar() { JMenuItem directSavePuzzle = new JMenuItem("Direct Save Proof "); directSavePuzzle.addActionListener((ActionEvent) -> direct_save()); if (os.equals("mac")) { - newPuzzle.setAccelerator(KeyStroke.getKeyStroke('D', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } - else { + newPuzzle.setAccelerator( + KeyStroke.getKeyStroke( + 'D', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } else { newPuzzle.setAccelerator(KeyStroke.getKeyStroke('D', InputEvent.CTRL_DOWN_MASK)); } JMenuItem exit = new JMenuItem("Exit"); exit.addActionListener((ActionEvent) -> exitEditor()); if (os.equals("mac")) { - exit.setAccelerator(KeyStroke.getKeyStroke('Q', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } - else { + exit.setAccelerator( + KeyStroke.getKeyStroke( + 'Q', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } else { exit.setAccelerator(KeyStroke.getKeyStroke('Q', InputEvent.CTRL_DOWN_MASK)); } menus[0].add(newPuzzle); @@ -149,43 +147,62 @@ public void setMenuBar() { fitBoardToScreen = new JMenuItem("Fit Board to Screen"); menus[1].add(undo); - undo.addActionListener((ActionEvent) -> - GameBoardFacade.getInstance().getHistory().undo()); + undo.addActionListener((ActionEvent) -> GameBoardFacade.getInstance().getHistory().undo()); if (os.equals("mac")) { - undo.setAccelerator(KeyStroke.getKeyStroke('Z', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - } - else { + undo.setAccelerator( + KeyStroke.getKeyStroke( + 'Z', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + } else { undo.setAccelerator(KeyStroke.getKeyStroke('Z', InputEvent.CTRL_DOWN_MASK)); } menus[1].add(redo); // Created action to support two keybinds (CTRL-SHIFT-Z, CTRL-Y) - Action redoAction = new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - GameBoardFacade.getInstance().getHistory().redo(); - } - }; + Action redoAction = + new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + GameBoardFacade.getInstance().getHistory().redo(); + } + }; if (os.equals("mac")) { - redo.getInputMap(WHEN_IN_FOCUSED_WINDOW).put( - KeyStroke.getKeyStroke('Z', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() + InputEvent.SHIFT_DOWN_MASK), "redoAction"); - redo.getInputMap(WHEN_IN_FOCUSED_WINDOW).put( - KeyStroke.getKeyStroke('Y', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "redoAction"); - redo.setAccelerator(KeyStroke.getKeyStroke('Z', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() + InputEvent.SHIFT_DOWN_MASK)); - } - else { - redo.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('Y', InputEvent.CTRL_DOWN_MASK), "redoAction"); - redo.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('Z', InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK), "redoAction"); + redo.getInputMap(WHEN_IN_FOCUSED_WINDOW) + .put( + KeyStroke.getKeyStroke( + 'Z', + Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() + + InputEvent.SHIFT_DOWN_MASK), + "redoAction"); + redo.getInputMap(WHEN_IN_FOCUSED_WINDOW) + .put( + KeyStroke.getKeyStroke( + 'Y', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), + "redoAction"); + redo.setAccelerator( + KeyStroke.getKeyStroke( + 'Z', + Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() + + InputEvent.SHIFT_DOWN_MASK)); + } else { + redo.getInputMap(WHEN_IN_FOCUSED_WINDOW) + .put(KeyStroke.getKeyStroke('Y', InputEvent.CTRL_DOWN_MASK), "redoAction"); + redo.getInputMap(WHEN_IN_FOCUSED_WINDOW) + .put( + KeyStroke.getKeyStroke( + 'Z', InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK), + "redoAction"); redo.getActionMap().put("redoAction", redoAction); // Button in menu will show CTRL-SHIFT-Z as primary keybind - redo.setAccelerator(KeyStroke.getKeyStroke('Z', InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK)); + redo.setAccelerator( + KeyStroke.getKeyStroke( + 'Z', InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK)); } - menus[1].add(fitBoardToScreen); - fitBoardToScreen.addActionListener((ActionEvent) -> dynamicBoardView.fitBoardViewToScreen()); + fitBoardToScreen.addActionListener( + (ActionEvent) -> dynamicBoardView.fitBoardViewToScreen()); // HELP menus[2] = new JMenu("Help"); @@ -193,18 +210,20 @@ public void actionPerformed(ActionEvent e) { aboutLegup = new JMenuItem("About Legup"); menus[2].add(helpLegup); menus[2].add(aboutLegup); - helpLegup.addActionListener(l -> { - try { - java.awt.Desktop.getDesktop().browse(URI.create("https://github.com/Bram-Hub/LEGUP/wiki")); - } - catch (IOException e) { - LOGGER.error("Can't open web page"); - } - }); + helpLegup.addActionListener( + l -> { + try { + java.awt.Desktop.getDesktop() + .browse(URI.create("https://github.com/Bram-Hub/LEGUP/wiki")); + } catch (IOException e) { + LOGGER.error("Can't open web page"); + } + }); menus[2].add(aboutLegup); - aboutLegup.addActionListener(l -> { - JOptionPane.showMessageDialog(null, "Version: 5.1.0"); - }); + aboutLegup.addActionListener( + l -> { + JOptionPane.showMessageDialog(null, "Version: 5.1.0"); + }); // add menus to menubar for (JMenu menu : menus) { menuBar.add(menu); @@ -234,12 +253,19 @@ private void setupToolBar() { int lastone = 0; for (int i = 0; i < ToolbarName.values().length - 1; i++) { String toolBarName = ToolbarName.values()[i].toString(); - URL resourceLocation = ClassLoader.getSystemClassLoader().getResource("edu/rpi/legup/images/Legup/" + toolBarName + ".png"); + URL resourceLocation = + ClassLoader.getSystemClassLoader() + .getResource("edu/rpi/legup/images/Legup/" + toolBarName + ".png"); // Scale the image icons down to make the buttons smaller ImageIcon imageIcon = new ImageIcon(resourceLocation); Image image = imageIcon.getImage(); - imageIcon = new ImageIcon(image.getScaledInstance(this.TOOLBAR_ICON_SCALE, this.TOOLBAR_ICON_SCALE, Image.SCALE_SMOOTH)); + imageIcon = + new ImageIcon( + image.getScaledInstance( + this.TOOLBAR_ICON_SCALE, + this.TOOLBAR_ICON_SCALE, + Image.SCALE_SMOOTH)); JButton button = new JButton(toolBarName, imageIcon); button.setFocusPainted(false); @@ -247,33 +273,42 @@ private void setupToolBar() { lastone = i; } - - URL check_and_save = ClassLoader.getSystemClassLoader().getResource("edu/rpi/legup/images/Legup/Check.png"); + URL check_and_save = + ClassLoader.getSystemClassLoader() + .getResource("edu/rpi/legup/images/Legup/Check.png"); ImageIcon imageIcon = new ImageIcon(check_and_save); Image image = imageIcon.getImage(); - imageIcon = new ImageIcon(image.getScaledInstance(this.TOOLBAR_ICON_SCALE, this.TOOLBAR_ICON_SCALE, Image.SCALE_SMOOTH)); + imageIcon = + new ImageIcon( + image.getScaledInstance( + this.TOOLBAR_ICON_SCALE, + this.TOOLBAR_ICON_SCALE, + Image.SCALE_SMOOTH)); JButton checkandsave = new JButton("check and Save", imageIcon); checkandsave.setFocusPainted(false); - checkandsave.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - //savePuzzle(); - String filename = savePuzzle(); - File puzzlename = new File(filename); - System.out.println(filename); - - - GameBoardFacade.getInstance().getLegupUI().displayPanel(1); - GameBoardFacade.getInstance().getLegupUI().getProofEditor().loadPuzzle(filename, new File(filename)); - String puzzleName = GameBoardFacade.getInstance().getPuzzleModule().getName(); - frame.setTitle(puzzleName + " - " + puzzlename.getName()); - } - }); + checkandsave.addActionListener( + new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + // savePuzzle(); + String filename = savePuzzle(); + File puzzlename = new File(filename); + System.out.println(filename); + + GameBoardFacade.getInstance().getLegupUI().displayPanel(1); + GameBoardFacade.getInstance() + .getLegupUI() + .getProofEditor() + .loadPuzzle(filename, new File(filename)); + String puzzleName = + GameBoardFacade.getInstance().getPuzzleModule().getName(); + frame.setTitle(puzzleName + " - " + puzzlename.getName()); + } + }); getToolBarButtons()[lastone + 1] = checkandsave; System.out.println("it is create new file"); - toolBar = new JToolBar(); toolBar.setFloatable(false); toolBar.setRollover(true); @@ -293,20 +328,22 @@ public void actionPerformed(ActionEvent e) { getToolBarButtons()[i].setHorizontalTextPosition(SwingConstants.CENTER); } -// toolBarButtons[ToolbarName.OPEN_PUZZLE.ordinal()].addActionListener((ActionEvent e) -> promptPuzzle()); -// toolBarButtons[ToolbarName.SAVE.ordinal()].addActionListener((ActionEvent e) -> saveProof()); -// toolBarButtons[ToolbarName.UNDO.ordinal()].addActionListener((ActionEvent e) -> GameBoardFacade.getInstance().getHistory().undo()); -// toolBarButtons[ToolbarName.REDO.ordinal()].addActionListener((ActionEvent e) -> GameBoardFacade.getInstance().getHistory().redo()); - toolBarButtons[ToolbarName.HINT.ordinal()].addActionListener((ActionEvent e) -> { - }); - toolBarButtons[ToolbarName.SUBMIT.ordinal()].addActionListener((ActionEvent e) -> { - }); - toolBarButtons[ToolbarName.DIRECTIONS.ordinal()].addActionListener((ActionEvent e) -> { - }); - -// toolBarButtons[ToolbarName.SAVE.ordinal()].setEnabled(false); -// toolBarButtons[ToolbarName.UNDO.ordinal()].setEnabled(false); -// toolBarButtons[ToolbarName.REDO.ordinal()].setEnabled(false); + // toolBarButtons[ToolbarName.OPEN_PUZZLE.ordinal()].addActionListener((ActionEvent + // e) -> + // promptPuzzle()); + // toolBarButtons[ToolbarName.SAVE.ordinal()].addActionListener((ActionEvent e) -> + // saveProof()); + // toolBarButtons[ToolbarName.UNDO.ordinal()].addActionListener((ActionEvent e) -> + // GameBoardFacade.getInstance().getHistory().undo()); + // toolBarButtons[ToolbarName.REDO.ordinal()].addActionListener((ActionEvent e) -> + // GameBoardFacade.getInstance().getHistory().redo()); + toolBarButtons[ToolbarName.HINT.ordinal()].addActionListener((ActionEvent e) -> {}); + toolBarButtons[ToolbarName.SUBMIT.ordinal()].addActionListener((ActionEvent e) -> {}); + toolBarButtons[ToolbarName.DIRECTIONS.ordinal()].addActionListener((ActionEvent e) -> {}); + + // toolBarButtons[ToolbarName.SAVE.ordinal()].setEnabled(false); + // toolBarButtons[ToolbarName.UNDO.ordinal()].setEnabled(false); + // toolBarButtons[ToolbarName.REDO.ordinal()].setEnabled(false); toolBarButtons[ToolbarName.HINT.ordinal()].setEnabled(false); toolBarButtons[ToolbarName.SUBMIT.ordinal()].setEnabled(false); toolBarButtons[ToolbarName.DIRECTIONS.ordinal()].setEnabled(false); @@ -314,15 +351,14 @@ public void actionPerformed(ActionEvent e) { this.add(toolBar, BorderLayout.NORTH); } - public void loadPuzzleFromHome(String game, int rows, int columns) throws IllegalArgumentException { + public void loadPuzzleFromHome(String game, int rows, int columns) + throws IllegalArgumentException { GameBoardFacade facade = GameBoardFacade.getInstance(); try { facade.loadPuzzle(game, rows, columns); - } - catch (IllegalArgumentException exception) { + } catch (IllegalArgumentException exception) { throw new IllegalArgumentException(exception.getMessage()); - } - catch (RuntimeException e) { + } catch (RuntimeException e) { e.printStackTrace(); LOGGER.error(e.getMessage()); } @@ -332,11 +368,9 @@ public void loadPuzzleFromHome(String game, String[] statements) { GameBoardFacade facade = GameBoardFacade.getInstance(); try { facade.loadPuzzle(game, statements); - } - catch (IllegalArgumentException exception) { + } catch (IllegalArgumentException exception) { throw new IllegalArgumentException(exception.getMessage()); - } - catch (RuntimeException e) { + } catch (RuntimeException e) { e.printStackTrace(); LOGGER.error(e.getMessage()); } @@ -365,13 +399,12 @@ public Object[] promptPuzzle() { if (fileDialog.getDirectory() != null && fileDialog.getFile() != null) { fileName = fileDialog.getDirectory() + File.separator + fileDialog.getFile(); puzzleFile = new File(fileName); - } - else { + } else { // The attempt to prompt a puzzle ended gracefully (cancel) return null; } - return new Object[]{fileName, puzzleFile}; + return new Object[] {fileName, puzzleFile}; } public void loadPuzzle() { @@ -392,11 +425,14 @@ public void loadPuzzle(String fileName, File puzzleFile) { GameBoardFacade.getInstance().loadPuzzleEditor(fileName); String puzzleName = GameBoardFacade.getInstance().getPuzzleModule().getName(); frame.setTitle(puzzleName + " - " + puzzleFile.getName()); - } - catch (InvalidFileFormatException e) { + } catch (InvalidFileFormatException e) { legupUI.displayPanel(0); LOGGER.error(e.getMessage()); - JOptionPane.showMessageDialog(null, "File does not exist, cannot be read, or cannot be edited", "Error", JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog( + null, + "File does not exist, cannot be read, or cannot be edited", + "Error", + JOptionPane.ERROR_MESSAGE); loadPuzzle(); } } @@ -408,24 +444,18 @@ public boolean noQuit(String instr) { } @Override - public void onPushChange(ICommand command) { - - } + public void onPushChange(ICommand command) {} @Override - public void onUndo(boolean isBottom, boolean isTop) { - - } + public void onUndo(boolean isBottom, boolean isTop) {} @Override - public void onRedo(boolean isBottom, boolean isTop) { - - } + public void onRedo(boolean isBottom, boolean isTop) {} @Override public void onClearHistory() { - //undo.setEnabled(false); - //redo.setEnabled(false); + // undo.setEnabled(false); + // redo.setEnabled(false); } public BoardView getBoardView() { @@ -453,7 +483,8 @@ public void setPuzzleView(Puzzle puzzle) { this.splitPanel.setVisible(true); } - TitledBorder titleBoard = BorderFactory.createTitledBorder(boardView.getClass().getSimpleName()); + TitledBorder titleBoard = + BorderFactory.createTitledBorder(boardView.getClass().getSimpleName()); titleBoard.setTitleJustification(TitledBorder.CENTER); dynamicBoardView.setBorder(titleBoard); @@ -464,13 +495,10 @@ public void setPuzzleView(Puzzle puzzle) { } toolBarButtons[ToolbarName.CHECK.ordinal()].setEnabled(true); -// toolBarButtons[ToolbarName.SAVE.ordinal()].setEnabled(true); + // toolBarButtons[ToolbarName.SAVE.ordinal()].setEnabled(true); } - /** - * Saves a puzzle - */ - + /** Saves a puzzle */ private void direct_save() { Puzzle puzzle = GameBoardFacade.getInstance().getPuzzleModule(); if (puzzle == null) { @@ -484,8 +512,7 @@ private void direct_save() { throw new ExportFileException("Puzzle exporter null"); } exporter.exportPuzzle(fileName); - } - catch (ExportFileException e) { + } catch (ExportFileException e) { e.printStackTrace(); } } @@ -500,8 +527,11 @@ private String savePuzzle() { // for TreeTent, need to check validity before saving if (Objects.equals(puzzle.getName(), "TreeTent")) { if (!puzzle.checkValidity()) { - int input = JOptionPane.showConfirmDialog(null, "The puzzle you edited is not " + - "valid, would you still like to save? "); + int input = + JOptionPane.showConfirmDialog( + null, + "The puzzle you edited is not " + + "valid, would you still like to save? "); if (input != 0) { return ""; } @@ -516,9 +546,9 @@ private String savePuzzle() { fileDialog.setTitle("Save Proof"); String curFileName = GameBoardFacade.getInstance().getCurFileName(); if (curFileName == null) { - fileDialog.setDirectory(LegupPreferences.getInstance().getUserPref(LegupPreferences.WORK_DIRECTORY)); - } - else { + fileDialog.setDirectory( + LegupPreferences.getInstance().getUserPref(LegupPreferences.WORK_DIRECTORY)); + } else { File curFile = new File(curFileName); fileDialog.setDirectory(curFile.getParent()); } @@ -536,18 +566,14 @@ private String savePuzzle() { throw new ExportFileException("Puzzle exporter null"); } exporter.exportPuzzle(fileName); - } - catch (ExportFileException e) { + } catch (ExportFileException e) { e.printStackTrace(); } } return fileName; } - public DynamicView getDynamicBoardView() { return dynamicBoardView; } - - } diff --git a/src/main/java/edu/rpi/legup/ui/ScrollView.java b/src/main/java/edu/rpi/legup/ui/ScrollView.java index 8f9144fda..0bf8335a2 100644 --- a/src/main/java/edu/rpi/legup/ui/ScrollView.java +++ b/src/main/java/edu/rpi/legup/ui/ScrollView.java @@ -1,17 +1,13 @@ package edu.rpi.legup.ui; import edu.rpi.legup.controller.Controller; - import java.awt.*; -import java.lang.Double; - import java.util.TreeSet; import java.util.logging.Logger; - import javax.swing.*; public class ScrollView extends JScrollPane { - private final static Logger LOGGER = Logger.getLogger(ScrollView.class.getName()); + private static final Logger LOGGER = Logger.getLogger(ScrollView.class.getName()); private static final double minScale = 0.25; private static final double maxScale = 4.0; @@ -28,8 +24,8 @@ public class ScrollView extends JScrollPane { private ZoomWidget widget; /** - * ScrollView Constructor - creates a ScrollView object using - * the controller handle the ui events + * ScrollView Constructor - creates a ScrollView object using the controller handle the ui + * events * * @param controller controller that handles the ui events */ @@ -107,9 +103,7 @@ public void layoutContainer(Container parent) { }; } - /** - * Updates zoomSize and view viewSize with the new scale - */ + /** Updates zoomSize and view viewSize with the new scale */ private void updateSize() { zoomSize.setSize((int) (viewSize.width * scale), (int) (viewSize.height * scale)); viewport.setViewSize(zoomSize); @@ -118,7 +112,7 @@ private void updateSize() { /** * Updates the viewport position * - * @param point point to set the viewport to + * @param point point to set the viewport to * @param magnification magnification to set the viewport to */ public void updatePosition(Point point, double magnification) { @@ -131,13 +125,16 @@ public void updatePosition(Point point, double magnification) { /** * Zooms in or out on a position within the dynamicView * - * @param n level of zoom - n less than 0 is zoom in, n greater than 0 is zoom out + * @param n level of zoom - n less than 0 is zoom in, n greater than 0 is zoom out * @param point position to zoom in on */ public void zoom(int n, Point point) { // if no Point is given, keep current center if (point == null) { - point = new Point(viewport.getWidth() / 2 + viewport.getX(), viewport.getHeight() / 2 + viewport.getY()); + point = + new Point( + viewport.getWidth() / 2 + viewport.getX(), + viewport.getHeight() / 2 + viewport.getY()); } // magnification level double mag = (double) n * 1.05; @@ -153,8 +150,7 @@ public void zoom(int n, Point point) { updateSize(); updatePosition(point, mag); // zoom out - } - else { + } else { mag = 1 / mag; // check zoom bounds if (scale * mag < minScale) { @@ -182,8 +178,10 @@ public void zoomTo(double newScale) { } // calculate the newScale and center point double mag = newScale / scale; - Point p = new Point(viewport.getWidth() / 2 + viewport.getX(), - viewport.getHeight() / 2 + viewport.getY()); + Point p = + new Point( + viewport.getWidth() / 2 + viewport.getX(), + viewport.getHeight() / 2 + viewport.getY()); // set scale directly scale = newScale; @@ -192,8 +190,7 @@ public void zoomTo(double newScale) { updateSize(); updatePosition(p, mag); // zoom out - } - else { + } else { updatePosition(p, mag); updateSize(); } @@ -201,9 +198,7 @@ public void zoomTo(double newScale) { revalidate(); } - /** - * Get the ideal zoom based on the viewSize - */ + /** Get the ideal zoom based on the viewSize */ public void zoomFit() { if (viewport.getWidth() != 0 && viewport.getHeight() != 0) { double fitWidth = (viewport.getWidth() - 8.0) / viewSize.width; @@ -213,9 +208,7 @@ public void zoomFit() { } } - /** - * Zooms in to the next zoom level - */ + /** Zooms in to the next zoom level */ public void zoomIn() { // find the next valid zoom level Double newScale = zoomLevels.higher(scale); @@ -224,9 +217,7 @@ public void zoomIn() { } } - /** - * Zooms out to the previous zoom level - */ + /** Zooms out to the previous zoom level */ public void zoomOut() { // find the next valid zoom level Double newScale = zoomLevels.lower(scale); @@ -301,17 +292,18 @@ public ZoomablePane getCanvas() { * @param graphics2D Graphics2D object used for drawing */ protected void draw(Graphics2D graphics2D) { - graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - graphics2D.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + graphics2D.setRenderingHint( + RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + graphics2D.setRenderingHint( + RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); canvas.paint(graphics2D); } /** * Scroll up or down on the ScrollView * - * @param mag The magnitude for scroll up - * positive is scroll up, negative is scroll down, - * recommend to use getWheelRotation() as the mag + * @param mag The magnitude for scroll up positive is scroll up, negative is scroll down, + * recommend to use getWheelRotation() as the mag */ public void scroll(int mag) { Point point = super.viewport.getViewPosition(); diff --git a/src/main/java/edu/rpi/legup/ui/ToolbarName.java b/src/main/java/edu/rpi/legup/ui/ToolbarName.java index 3df635b05..ba02ebd2e 100644 --- a/src/main/java/edu/rpi/legup/ui/ToolbarName.java +++ b/src/main/java/edu/rpi/legup/ui/ToolbarName.java @@ -1,7 +1,11 @@ package edu.rpi.legup.ui; public enum ToolbarName { - HINT, CHECK, SUBMIT, DIRECTIONS, CHECK_ALL; + HINT, + CHECK, + SUBMIT, + DIRECTIONS, + CHECK_ALL; /** * Gets the String representation of the ToolbarName enum @@ -15,12 +19,12 @@ public String toString() { str = str.substring(0, 1).toUpperCase() + str.substring(1); for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == ' ') { - str = str.substring(0, i + 1) + - str.substring(i + 1, i + 2).toUpperCase() + - str.substring(i + 2); + str = + str.substring(0, i + 1) + + str.substring(i + 1, i + 2).toUpperCase() + + str.substring(i + 2); } } return str; } - } diff --git a/src/main/java/edu/rpi/legup/ui/WrapLayout.java b/src/main/java/edu/rpi/legup/ui/WrapLayout.java index c37eb02f4..1e25b36d2 100644 --- a/src/main/java/edu/rpi/legup/ui/WrapLayout.java +++ b/src/main/java/edu/rpi/legup/ui/WrapLayout.java @@ -1,29 +1,25 @@ package edu.rpi.legup.ui; +import java.awt.*; import javax.swing.JScrollPane; import javax.swing.SwingUtilities; -import java.awt.*; -/** - * FlowLayout subclass that fully supports wrapping of components. - */ +/** FlowLayout subclass that fully supports wrapping of components. */ public class WrapLayout extends FlowLayout { private Dimension preferredLayoutSize; /** - * Constructs a new WrapLayout with a left - * alignment and a default 5-unit horizontal and vertical gap. + * Constructs a new WrapLayout with a left alignment and a default 5-unit + * horizontal and vertical gap. */ public WrapLayout() { super(LEFT); } /** - * Constructs a new FlowLayout with the specified - * alignment and a default 5-unit horizontal and vertical gap. - * The value of the alignment argument must be one of - * WrapLayout, WrapLayout, - * or WrapLayout. + * Constructs a new FlowLayout with the specified alignment and a default 5-unit + * horizontal and vertical gap. The value of the alignment argument must be one of + * WrapLayout, WrapLayout, or WrapLayout. * * @param align the alignment value */ @@ -32,28 +28,27 @@ public WrapLayout(int align) { } /** - * Creates a new flow layout manager with the indicated alignment - * and the indicated horizontal and vertical gaps. - *

- * The value of the alignment argument must be one of - * WrapLayout, WrapLayout, - * or WrapLayout. + * Creates a new flow layout manager with the indicated alignment and the indicated horizontal + * and vertical gaps. + * + *

The value of the alignment argument must be one of WrapLayout, + * WrapLayout + * , or WrapLayout. * * @param align the alignment value - * @param hgap the horizontal gap between components - * @param vgap the vertical gap between components + * @param hgap the horizontal gap between components + * @param vgap the vertical gap between components */ public WrapLayout(int align, int hgap, int vgap) { super(align, hgap, vgap); } /** - * Returns the preferred dimensions for this layout given the - * visible components in the specified target container. + * Returns the preferred dimensions for this layout given the visible components in the + * specified target container. * * @param target the component which needs to be laid out - * @return the preferred dimensions to lay out the - * subcomponents of the specified container + * @return the preferred dimensions to lay out the subcomponents of the specified container */ @Override public Dimension preferredLayoutSize(Container target) { @@ -61,12 +56,11 @@ public Dimension preferredLayoutSize(Container target) { } /** - * Returns the minimum dimensions needed to layout the visible - * components contained in the specified target container. + * Returns the minimum dimensions needed to layout the visible components contained in the + * specified target container. * * @param target the component which needs to be laid out - * @return the minimum dimensions to lay out the - * subcomponents of the specified container + * @return the minimum dimensions to lay out the subcomponents of the specified container */ @Override public Dimension minimumLayoutSize(Container target) { @@ -76,10 +70,9 @@ public Dimension minimumLayoutSize(Container target) { } /** - * Returns the minimum or preferred dimension needed to layout the target - * container. + * Returns the minimum or preferred dimension needed to layout the target container. * - * @param target target to get layout dimension for + * @param target target to get layout dimension for * @param preferred should preferred dimension be calculated * @return the dimension to layout the target container */ @@ -155,11 +148,11 @@ private Dimension layoutSize(Container target, boolean preferred) { } /** - * A new row has been completed. Use the dimensions of this row - * to update the preferred dimension for the container. + * A new row has been completed. Use the dimensions of this row to update the preferred + * dimension for the container. * - * @param dim update the width and height when appropriate - * @param rowWidth the width of the row to add + * @param dim update the width and height when appropriate + * @param rowWidth the width of the row to add * @param rowHeight the height of the row to add */ private void addRow(Dimension dim, int rowWidth, int rowHeight) { @@ -171,4 +164,4 @@ private void addRow(Dimension dim, int rowWidth, int rowHeight) { dim.height += rowHeight; } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/ui/ZoomWidget.java b/src/main/java/edu/rpi/legup/ui/ZoomWidget.java index 1e423c346..aa5b65c4e 100644 --- a/src/main/java/edu/rpi/legup/ui/ZoomWidget.java +++ b/src/main/java/edu/rpi/legup/ui/ZoomWidget.java @@ -2,25 +2,24 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; - +import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPopupMenu; import javax.swing.JSlider; import javax.swing.SwingConstants; -import javax.swing.event.ChangeListener; import javax.swing.event.ChangeEvent; -import javax.swing.ImageIcon; - +import javax.swing.event.ChangeListener; public class ZoomWidget extends JLabel { private ScrollView parent; private PopupSlider palette = new PopupSlider(); - private MouseAdapter open = new MouseAdapter() { - public void mouseClicked(MouseEvent e) { - palette.slider.setValue(parent.getZoom()); - palette.show(e.getComponent(), 0, 0); - } - }; + private MouseAdapter open = + new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + palette.slider.setValue(parent.getZoom()); + palette.show(e.getComponent(), 0, 0); + } + }; /** * ZoomWidget Constructor creates a zoom widget for a ScrollView object @@ -33,9 +32,7 @@ public ZoomWidget(ScrollView parent) { addMouseListener(open); } - /** - * - */ + /** */ private class PopupSlider extends JPopupMenu implements ChangeListener { private static final long serialVersionUID = 8225019381200459814L; diff --git a/src/main/java/edu/rpi/legup/ui/ZoomablePane.java b/src/main/java/edu/rpi/legup/ui/ZoomablePane.java index 86cfd866f..934d31c53 100644 --- a/src/main/java/edu/rpi/legup/ui/ZoomablePane.java +++ b/src/main/java/edu/rpi/legup/ui/ZoomablePane.java @@ -1,9 +1,9 @@ package edu.rpi.legup.ui; -import javax.swing.*; +import java.awt.AWTEvent; import java.awt.Graphics; import java.awt.Graphics2D; -import java.awt.AWTEvent; +import javax.swing.*; public class ZoomablePane extends JLayeredPane { private ScrollView viewer; diff --git a/src/main/java/edu/rpi/legup/ui/boardview/BoardView.java b/src/main/java/edu/rpi/legup/ui/boardview/BoardView.java index 602672a9e..ca03f1e25 100644 --- a/src/main/java/edu/rpi/legup/ui/boardview/BoardView.java +++ b/src/main/java/edu/rpi/legup/ui/boardview/BoardView.java @@ -8,7 +8,6 @@ import edu.rpi.legup.model.observer.IBoardListener; import edu.rpi.legup.model.tree.TreeElement; import edu.rpi.legup.ui.ScrollView; - import java.awt.*; import java.util.ArrayList; @@ -19,9 +18,9 @@ public abstract class BoardView extends ScrollView implements IBoardListener { protected ElementController elementController; protected ElementSelection selection; - /** - * BoardView Constructor creates a view for the board object using the controller handle the ui events + * BoardView Constructor creates a view for the board object using the controller handle the ui + * events * * @param boardController controller that handles the ui events * @param elementController controller that handles the ui events @@ -40,9 +39,7 @@ public BoardView(BoardController boardController, ElementController elementContr addKeyListener(elementController); } - /** - * Initializes the initial dimension of the viewport for the BoardView - */ + /** Initializes the initial dimension of the viewport for the BoardView */ public abstract void initSize(); /** @@ -70,13 +67,17 @@ public void setElementViews(ArrayList elements) { } /** - * Gets the ElementView from the location specified or null if one does not exists at that location + * Gets the ElementView from the location specified or null if one does not exists at that + * location * * @param point location on the viewport * @return ElementView at the specified location */ public ElementView getElement(Point point) { - Point scaledPoint = new Point((int) Math.round(point.x / getScale()), (int) Math.round(point.y / getScale())); + Point scaledPoint = + new Point( + (int) Math.round(point.x / getScale()), + (int) Math.round(point.y / getScale())); for (ElementView element : elementViews) { if (element.isWithinBounds(scaledPoint)) { return element; @@ -114,10 +115,10 @@ public void setBoard(Board board) { if (board instanceof CaseBoard) { setCasePickable(); - } - else { + } else { for (ElementView elementView : elementViews) { - elementView.setPuzzleElement(board.getPuzzleElement(elementView.getPuzzleElement())); + elementView.setPuzzleElement( + board.getPuzzleElement(elementView.getPuzzleElement())); elementView.setShowCasePicker(false); } } @@ -129,7 +130,8 @@ protected void setCasePickable() { Board baseBoard = caseBoard.getBaseBoard(); for (ElementView elementView : elementViews) { - PuzzleElement puzzleElement = baseBoard.getPuzzleElement(elementView.getPuzzleElement()); + PuzzleElement puzzleElement = + baseBoard.getPuzzleElement(elementView.getPuzzleElement()); elementView.setPuzzleElement(puzzleElement); elementView.setShowCasePicker(true); elementView.setCaseRulePickable(caseBoard.isPickable(puzzleElement, null)); diff --git a/src/main/java/edu/rpi/legup/ui/boardview/DataSelectionView.java b/src/main/java/edu/rpi/legup/ui/boardview/DataSelectionView.java index 8257fd47c..cedfa08fe 100644 --- a/src/main/java/edu/rpi/legup/ui/boardview/DataSelectionView.java +++ b/src/main/java/edu/rpi/legup/ui/boardview/DataSelectionView.java @@ -1,10 +1,9 @@ package edu.rpi.legup.ui.boardview; import edu.rpi.legup.controller.ElementController; - +import java.awt.*; import javax.swing.*; import javax.swing.border.BevelBorder; -import java.awt.*; public class DataSelectionView extends JPopupMenu { diff --git a/src/main/java/edu/rpi/legup/ui/boardview/ElementSelection.java b/src/main/java/edu/rpi/legup/ui/boardview/ElementSelection.java index d8f88f979..8e6f2cb18 100644 --- a/src/main/java/edu/rpi/legup/ui/boardview/ElementSelection.java +++ b/src/main/java/edu/rpi/legup/ui/boardview/ElementSelection.java @@ -26,8 +26,7 @@ public void toggleSelection(ElementView elementView) { if (selection.contains(elementView)) { selection.remove(elementView); elementView.setSelected(false); - } - else { + } else { selection.add(elementView); elementView.setSelected(true); } diff --git a/src/main/java/edu/rpi/legup/ui/boardview/ElementView.java b/src/main/java/edu/rpi/legup/ui/boardview/ElementView.java index 008c1a5f5..83b2cb099 100644 --- a/src/main/java/edu/rpi/legup/ui/boardview/ElementView.java +++ b/src/main/java/edu/rpi/legup/ui/boardview/ElementView.java @@ -1,14 +1,13 @@ package edu.rpi.legup.ui.boardview; import edu.rpi.legup.model.gameboard.PuzzleElement; - -import javax.swing.*; import java.awt.*; import java.awt.geom.AffineTransform; import java.awt.geom.PathIterator; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; +import javax.swing.*; public abstract class ElementView implements Shape { protected int index; @@ -47,8 +46,10 @@ public ElementView(PuzzleElement puzzleElement) { * @return true if the point is within the ElementView, false otherwise */ public boolean isWithinBounds(Point point) { - return point.x >= location.x && point.x <= location.x + size.width && - point.y >= location.y && point.y <= location.y + size.height; + return point.x >= location.x + && point.x <= location.x + size.width + && point.y >= location.y + && point.y <= location.y + size.height; } /** @@ -74,7 +75,9 @@ public void draw(Graphics2D graphics2D) { public void drawElement(Graphics2D graphics2D) { graphics2D.setStroke(new BasicStroke(1)); - graphics2D.draw(new Rectangle2D.Double(location.x + 0.5f, location.y + 0.5f, size.width - 2, size.height - 2)); + graphics2D.draw( + new Rectangle2D.Double( + location.x + 0.5f, location.y + 0.5f, size.width - 2, size.height - 2)); graphics2D.setColor(Color.BLACK); FontMetrics metrics = graphics2D.getFontMetrics(graphics2D.getFont()); @@ -84,29 +87,34 @@ public void drawElement(Graphics2D graphics2D) { graphics2D.drawString(String.valueOf(puzzleElement.getData()), xText, yText); } - public void drawGiven(Graphics2D graphics2D) { - - } + public void drawGiven(Graphics2D graphics2D) {} public void drawHover(Graphics2D graphics2D) { graphics2D.setColor(hoverColor); graphics2D.setStroke(new BasicStroke(2)); - graphics2D.draw(new Rectangle2D.Double(location.x + 1.5f, location.y + 1.5f, size.width - 3, size.height - 3)); + graphics2D.draw( + new Rectangle2D.Double( + location.x + 1.5f, location.y + 1.5f, size.width - 3, size.height - 3)); } public void drawModified(Graphics2D graphics2D) { graphics2D.setColor(puzzleElement.isValid() ? modifiedColor : invalidColor); graphics2D.setStroke(new BasicStroke(2)); - graphics2D.draw(new Rectangle2D.Double(location.x + 1.5f, location.y + 1.5f, size.width - 3, size.height - 3)); + graphics2D.draw( + new Rectangle2D.Double( + location.x + 1.5f, location.y + 1.5f, size.width - 3, size.height - 3)); } public void drawCase(Graphics2D graphics2D) { graphics2D.setColor(caseColor); - graphics2D.fill(new Rectangle2D.Double(location.x + 1.5f, location.y + 1.5f, size.width - 3, size.height - 3)); + graphics2D.fill( + new Rectangle2D.Double( + location.x + 1.5f, location.y + 1.5f, size.width - 3, size.height - 3)); } public BufferedImage getImage() { - BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); + BufferedImage image = + new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics2D = image.createGraphics(); drawElement(graphics2D); graphics2D.dispose(); @@ -194,9 +202,8 @@ public void setShowCasePicker(boolean showCasePicker) { } /** - * Gets the isCaseRulePickable field to determine if this ElementView - * should be highlighted in some way to indicate if it can be chosen by - * the CaseRule + * Gets the isCaseRulePickable field to determine if this ElementView should be highlighted in + * some way to indicate if it can be chosen by the CaseRule * * @return true if the ElementView can be chosen for the CaseRule, false otherwise */ @@ -205,11 +212,11 @@ public boolean isCaseRulePickable() { } /** - * Sets the isCaseRulePickable field to determine if this ElementView - * should be highlighted in some way to indicate if it can be chosen by - * the CaseRule + * Sets the isCaseRulePickable field to determine if this ElementView should be highlighted in + * some way to indicate if it can be chosen by the CaseRule * - * @param isCaseRulePickable true if the ElementView can be chosen for the CaseRule, false otherwise + * @param isCaseRulePickable true if the ElementView can be chosen for the CaseRule, false + * otherwise */ public void setCaseRulePickable(boolean isCaseRulePickable) { this.isCaseRulePickable = isCaseRulePickable; @@ -276,8 +283,10 @@ public JMenuItem getSelectionMenuItem() { @Override public boolean contains(double x, double y) { - return x >= location.x && x <= location.x + size.width && - y >= location.y && y <= location.y + size.height; + return x >= location.x + && x <= location.x + size.width + && y >= location.y + && y <= location.y + size.height; } @Override @@ -287,24 +296,32 @@ public boolean contains(Point2D point) { @Override public boolean intersects(double x, double y, double width, double height) { - return (x + width >= location.x && x <= location.x + size.width) || - (y + height >= location.y && y <= location.y + size.height); + return (x + width >= location.x && x <= location.x + size.width) + || (y + height >= location.y && y <= location.y + size.height); } @Override public boolean intersects(Rectangle2D rectangle2D) { - return intersects(rectangle2D.getX(), rectangle2D.getY(), rectangle2D.getWidth(), rectangle2D.getHeight()); + return intersects( + rectangle2D.getX(), + rectangle2D.getY(), + rectangle2D.getWidth(), + rectangle2D.getHeight()); } @Override public boolean contains(double x, double y, double width, double height) { - return (x + width >= location.x && x <= location.x + size.width) && - (y + height >= location.y && y <= location.y + size.height); + return (x + width >= location.x && x <= location.x + size.width) + && (y + height >= location.y && y <= location.y + size.height); } @Override public boolean contains(Rectangle2D rectangle2D) { - return contains(rectangle2D.getX(), rectangle2D.getY(), rectangle2D.getWidth(), rectangle2D.getHeight()); + return contains( + rectangle2D.getX(), + rectangle2D.getY(), + rectangle2D.getWidth(), + rectangle2D.getHeight()); } @Override @@ -314,7 +331,8 @@ public PathIterator getPathIterator(AffineTransform at) { @Override public PathIterator getPathIterator(AffineTransform at, double flatness) { - return new Rectangle(location.x, location.y, size.width, size.height).getPathIterator(at, flatness); + return new Rectangle(location.x, location.y, size.width, size.height) + .getPathIterator(at, flatness); } @Override diff --git a/src/main/java/edu/rpi/legup/ui/boardview/GridBoardView.java b/src/main/java/edu/rpi/legup/ui/boardview/GridBoardView.java index 5fdacc6b0..c40303192 100644 --- a/src/main/java/edu/rpi/legup/ui/boardview/GridBoardView.java +++ b/src/main/java/edu/rpi/legup/ui/boardview/GridBoardView.java @@ -2,7 +2,6 @@ import edu.rpi.legup.controller.BoardController; import edu.rpi.legup.controller.ElementController; - import java.awt.Color; import java.awt.Dimension; @@ -11,13 +10,17 @@ public class GridBoardView extends BoardView { protected Dimension elementSize; /** - * GridBoardView Constructor creates a GridBoardView object using the controller handle the ui events + * GridBoardView Constructor creates a GridBoardView object using the controller handle the ui + * events * * @param boardController controller that handles the ui events * @param gridSize dimension of the grid * @param elementController controller that handles the ui events */ - public GridBoardView(BoardController boardController, ElementController elementController, Dimension gridSize) { + public GridBoardView( + BoardController boardController, + ElementController elementController, + Dimension gridSize) { this(boardController, elementController); this.gridSize = gridSize; this.elementSize = new Dimension(30, 30); @@ -25,7 +28,8 @@ public GridBoardView(BoardController boardController, ElementController elementC } /** - * GridBoardView Constructor creates a GridBoardView object using the controller handle the ui events + * GridBoardView Constructor creates a GridBoardView object using the controller handle the ui + * events * * @param boardController controller that handles the ui events */ @@ -35,8 +39,7 @@ private GridBoardView(BoardController boardController, ElementController element } /** - * Gets the GridElementView from the puzzleElement index or - * null if out of bounds + * Gets the GridElementView from the puzzleElement index or null if out of bounds * * @param index index of the ElementView * @return GridElementView at the specified index @@ -55,9 +58,7 @@ public GridElementView getElement(int xIndex, int yIndex) { return null; } - /** - * Initializes the initial dimension of the viewport for the GridBoardView - */ + /** Initializes the initial dimension of the viewport for the GridBoardView */ @Override public void initSize() { setSize(getProperSize()); @@ -83,6 +84,4 @@ public DataSelectionView getSelectionPopupMenu() { public Dimension getElementSize() { return this.elementSize; } - } - diff --git a/src/main/java/edu/rpi/legup/ui/boardview/SelectionItemView.java b/src/main/java/edu/rpi/legup/ui/boardview/SelectionItemView.java index 1ce5033c7..b2d3e31dd 100644 --- a/src/main/java/edu/rpi/legup/ui/boardview/SelectionItemView.java +++ b/src/main/java/edu/rpi/legup/ui/boardview/SelectionItemView.java @@ -1,7 +1,6 @@ package edu.rpi.legup.ui.boardview; import edu.rpi.legup.model.gameboard.PuzzleElement; - import javax.swing.*; public class SelectionItemView extends JMenuItem { diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupLookAndFeel.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupLookAndFeel.java index 84804e1a0..8469343f3 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupLookAndFeel.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/LegupLookAndFeel.java @@ -5,20 +5,17 @@ import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialFonts; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialImages; - +import java.awt.*; import javax.swing.*; import javax.swing.plaf.basic.BasicLookAndFeel; -import java.awt.*; public class LegupLookAndFeel extends BasicLookAndFeel { /** - * Return a short string that identifies this look and feel, e.g. - * "CDE/Motif". This string should be appropriate for a menu item. - * Distinct look and feels should have different names, e.g. - * a subclass of MotifLookAndFeel that changes the way a few components - * are rendered should be called "CDE/Motif My Way"; something - * that would be useful to a user trying to select a L&F from a list - * of names. + * Return a short string that identifies this look and feel, e.g. "CDE/Motif". This string + * should be appropriate for a menu item. Distinct look and feels should have different names, + * e.g. a subclass of MotifLookAndFeel that changes the way a few components are rendered should + * be called "CDE/Motif My Way"; something that would be useful to a user trying to select a + * L&F from a list of names. * * @return short identifier for the look and feel */ @@ -28,13 +25,11 @@ public String getName() { } /** - * Return a string that identifies this look and feel. This string - * will be used by applications/services that want to recognize - * well known look and feel implementations. Presently - * the well known names are "Motif", "Windows", "Mac", "Metal". Note - * that a LookAndFeel derived from a well known superclass - * that doesn't make any fundamental changes to the look or feel - * shouldn't override this method. + * Return a string that identifies this look and feel. This string will be used by + * applications/services that want to recognize well known look and feel implementations. + * Presently the well known names are "Motif", "Windows", "Mac", "Metal". Note that a + * LookAndFeel derived from a well known superclass that doesn't make any fundamental changes to + * the look or feel shouldn't override this method. * * @return identifier for the look and feel */ @@ -44,9 +39,9 @@ public String getID() { } /** - * Return a one line description of this look and feel implementation, - * e.g. "The CDE/Motif Look and Feel". This string is intended for - * the user, e.g. in the title of a window or in a ToolTip message. + * Return a one line description of this look and feel implementation, e.g. "The CDE/Motif Look + * and Feel". This string is intended for the user, e.g. in the title of a window or in a + * ToolTip message. * * @return short description for the look and feel */ @@ -56,14 +51,11 @@ public String getDescription() { } /** - * If the underlying platform has a "native" look and feel, and - * this is an implementation of it, return {@code true}. For - * example, when the underlying platform is Solaris running CDE - * a CDE/Motif look and feel implementation would return {@code - * true}. + * If the underlying platform has a "native" look and feel, and this is an implementation of it, + * return {@code true}. For example, when the underlying platform is Solaris running CDE a + * CDE/Motif look and feel implementation would return {@code true}. * - * @return {@code true} if this look and feel represents the underlying - * platform look and feel + * @return {@code true} if this look and feel represents the underlying platform look and feel */ @Override public boolean isNativeLookAndFeel() { @@ -71,10 +63,9 @@ public boolean isNativeLookAndFeel() { } /** - * Return {@code true} if the underlying platform supports and or permits - * this look and feel. This method returns {@code false} if the look - * and feel depends on special resources or legal agreements that - * aren't defined for the current platform. + * Return {@code true} if the underlying platform supports and or permits this look and feel. + * This method returns {@code false} if the look and feel depends on special resources or legal + * agreements that aren't defined for the current platform. * * @return {@code true} if this is a supported look and feel * @see UIManager#setLookAndFeel @@ -85,16 +76,12 @@ public boolean isSupportedLookAndFeel() { } /** - * Initializes the look and feel. While this method is public, - * it should only be invoked by the {@code UIManager} when a - * look and feel is installed as the current look and feel. This - * method is invoked before the {@code UIManager} invokes - * {@code getDefaults}. This method is intended to perform any - * initialization for the look and feel. Subclasses - * should do any one-time setup they need here, rather than - * in a static initializer, because look and feel class objects - * may be loaded just to discover that {@code isSupportedLookAndFeel()} - * returns {@code false}. + * Initializes the look and feel. While this method is public, it should only be invoked by the + * {@code UIManager} when a look and feel is installed as the current look and feel. This method + * is invoked before the {@code UIManager} invokes {@code getDefaults}. This method is intended + * to perform any initialization for the look and feel. Subclasses should do any one-time setup + * they need here, rather than in a static initializer, because look and feel class objects may + * be loaded just to discover that {@code isSupportedLookAndFeel()} returns {@code false}. * * @see #uninitialize * @see UIManager#setLookAndFeel @@ -105,15 +92,12 @@ public void initialize() { } /** - * Populates {@code table} with mappings from {@code uiClassID} to the - * fully qualified name of the ui class. The value for a - * particular {@code uiClassID} is {@code - * "javax.swing.plaf.basic.Basic + uiClassID"}. For example, the - * value for the {@code uiClassID} {@code TreeUI} is {@code - * "javax.swing.plaf.basic.BasicTreeUI"}. + * Populates {@code table} with mappings from {@code uiClassID} to the fully qualified name of + * the ui class. The value for a particular {@code uiClassID} is {@code + * "javax.swing.plaf.basic.Basic + uiClassID"}. For example, the value for the {@code uiClassID} + * {@code TreeUI} is {@code "javax.swing.plaf.basic.BasicTreeUI"}. * - * @param table the {@code UIDefaults} instance the entries are - * added to + * @param table the {@code UIDefaults} instance the entries are added to * @throws NullPointerException if {@code table} is {@code null} * @see LookAndFeel * @see #getDefaults @@ -132,7 +116,7 @@ protected void initClassDefaults(UIDefaults table) { table.put("PanelUI", MaterialPanelUI.class.getCanonicalName()); table.put("LabelUI", MaterialLabelUI.class.getCanonicalName()); table.put("MenuItemUI", MaterialMenuItemUI.class.getCanonicalName()); -// table.put ("MenuBarUI", .class.getCanonicalName()); + // table.put ("MenuBarUI", .class.getCanonicalName()); table.put("MenuUI", MaterialMenuUI.class.getCanonicalName()); table.put("CheckBoxUI", MaterialCheckBoxUI.class.getCanonicalName()); table.put("RadioButtonUI", MaterialRadioButtonUI.class.getCanonicalName()); @@ -152,7 +136,7 @@ protected void initClassDefaults(UIDefaults table) { table.put("FileChooserUI", MaterialFileChooserUI.class.getCanonicalName()); table.put("ToolTipUI", MaterialToolTipUI.class.getCanonicalName()); table.put("SplitPaneUI", MaterialSplitPaneUI.class.getCanonicalName()); -// table.put ("ColorChooserUI", ); + // table.put ("ColorChooserUI", ); } @Override @@ -175,7 +159,11 @@ protected void initComponentDefaults(UIDefaults table) { table.put("ComboBox.font", MaterialFonts.REGULAR); table.put("ComboBox.background", Color.WHITE); table.put("ComboBox.foreground", Color.BLACK); - table.put("ComboBox.border", BorderFactory.createCompoundBorder(MaterialBorders.LIGHT_LINE_BORDER, BorderFactory.createEmptyBorder(0, 5, 0, 0))); + table.put( + "ComboBox.border", + BorderFactory.createCompoundBorder( + MaterialBorders.LIGHT_LINE_BORDER, + BorderFactory.createEmptyBorder(0, 5, 0, 0))); table.put("ComboBox.buttonBackground", MaterialColors.GRAY_300); table.put("ComboBox.selectionBackground", Color.WHITE); table.put("ComboBox.selectionForeground", Color.BLACK); @@ -251,7 +239,9 @@ protected void initComponentDefaults(UIDefaults table) { table.put("Slider.background", Color.WHITE); table.put("Slider.foreground", MaterialColors.GRAY_700); table.put("Slider.trackColor", Color.BLACK); -// table.put ("Slider.border", BorderFactory.createCompoundBorder(MaterialBorders.LIGHT_LINE_BORDER, BorderFactory.createEmptyBorder (5, 5, 5, 5))); + // table.put ("Slider.border", + // BorderFactory.createCompoundBorder(MaterialBorders.LIGHT_LINE_BORDER, + // BorderFactory.createEmptyBorder (5, 5, 5, 5))); table.put("SplitPane.border", MaterialBorders.LIGHT_LINE_BORDER); table.put("SplitPane.background", Color.WHITE); @@ -275,7 +265,11 @@ protected void initComponentDefaults(UIDefaults table) { table.put("Table.gridColor", MaterialColors.GRAY_200); table.put("TableHeader.background", MaterialColors.GRAY_200); table.put("TableHeader.font", MaterialFonts.BOLD); - table.put("TableHeader.cellBorder", BorderFactory.createCompoundBorder(MaterialBorders.LIGHT_LINE_BORDER, BorderFactory.createEmptyBorder(5, 5, 5, 5))); + table.put( + "TableHeader.cellBorder", + BorderFactory.createCompoundBorder( + MaterialBorders.LIGHT_LINE_BORDER, + BorderFactory.createEmptyBorder(5, 5, 5, 5))); table.put("TextArea.background", MaterialColors.GRAY_200); table.put("TextArea.border", BorderFactory.createEmptyBorder()); @@ -306,21 +300,27 @@ protected void initComponentDefaults(UIDefaults table) { table.put("RadioButtonMenuItem.foreground", Color.BLACK); table.put("RadioButtonMenuItem.selectionForeground", Color.BLACK); - //If it changes the background of the menuitem it must change this too, irrespective of its setting + // If it changes the background of the menuitem it must change this too, irrespective of its + // setting table.put("RadioButtonMenuItem.background", UIManager.getColor("MenuItem.background")); table.put("RadioButtonMenuItem.selectionBackground", MaterialColors.GRAY_200); table.put("RadioButtonMenuItem.border", BorderFactory.createEmptyBorder(5, 5, 5, 5)); table.put("RadioButtonMenuItem.checkIcon", new ImageIcon(MaterialImages.RADIO_BUTTON_OFF)); - table.put("RadioButtonMenuItem.selectedCheckIcon", new ImageIcon(MaterialImages.RADIO_BUTTON_ON)); + table.put( + "RadioButtonMenuItem.selectedCheckIcon", + new ImageIcon(MaterialImages.RADIO_BUTTON_ON)); - //If it changes the background of the menuitem it must change this too, irrespective of its setting + // If it changes the background of the menuitem it must change this too, irrespective of its + // setting table.put("CheckBoxMenuItem.background", UIManager.getColor("MenuItem.background")); table.put("CheckBoxMenuItem.selectionBackground", MaterialColors.GRAY_200); table.put("CheckBoxMenuItem.foreground", Color.BLACK); table.put("CheckBoxMenuItem.selectionForeground", Color.BLACK); table.put("CheckBoxMenuItem.border", BorderFactory.createEmptyBorder(5, 5, 5, 5)); table.put("CheckBoxMenuItem.checkIcon", new ImageIcon(MaterialImages.UNCHECKED_BOX)); - table.put("CheckBoxMenuItem.selectedCheckIcon", new ImageIcon(MaterialImages.PAINTED_CHECKED_BOX)); + table.put( + "CheckBoxMenuItem.selectedCheckIcon", + new ImageIcon(MaterialImages.PAINTED_CHECKED_BOX)); table.put("TextPane.border", MaterialBorders.LIGHT_LINE_BORDER); table.put("TextPane.background", MaterialColors.GRAY_50); diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/animation/MaterialUIMovement.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/animation/MaterialUIMovement.java index fe82238ab..db7d604a0 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/animation/MaterialUIMovement.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/animation/MaterialUIMovement.java @@ -1,12 +1,11 @@ package edu.rpi.legup.ui.lookandfeel.animation; -import javax.swing.JComponent; import java.awt.Color; +import javax.swing.JComponent; public class MaterialUIMovement { - private MaterialUIMovement() { - } + private MaterialUIMovement() {} public static void add(JComponent c, Color fadeTo, int steps, int interval) { new MaterialUITimer(c, fadeTo, steps, interval); diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/animation/MaterialUITimer.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/animation/MaterialUITimer.java index b5b3bbd76..f989185c7 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/animation/MaterialUITimer.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/animation/MaterialUITimer.java @@ -1,12 +1,12 @@ package edu.rpi.legup.ui.lookandfeel.animation; -import javax.swing.JComponent; -import javax.swing.Timer; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; +import javax.swing.JComponent; +import javax.swing.Timer; public class MaterialUITimer implements MouseListener, ActionListener { @@ -72,14 +72,10 @@ public void mousePressed(MouseEvent me) { } @Override - public void mouseReleased(MouseEvent me) { - - } + public void mouseReleased(MouseEvent me) {} @Override - public void mouseClicked(MouseEvent me) { - - } + public void mouseClicked(MouseEvent me) {} @Override public void mouseExited(MouseEvent me) { @@ -100,8 +96,7 @@ public void actionPerformed(ActionEvent ae) { if (forward) { component.setBackground(nextColor()); ++alpha; - } - else { + } else { component.setBackground(previousColor()); --alpha; } @@ -110,4 +105,4 @@ public void actionPerformed(ActionEvent ae) { timer.stop(); } } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialButtonUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialButtonUI.java index fe23536d3..debe6e215 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialButtonUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialButtonUI.java @@ -3,13 +3,12 @@ import edu.rpi.legup.ui.lookandfeel.animation.MaterialUIMovement; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Graphics; import javax.swing.AbstractButton; import javax.swing.JComponent; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicButtonUI; -import java.awt.Graphics; public class MaterialButtonUI extends BasicButtonUI { @@ -42,4 +41,4 @@ private void paintBackground(Graphics g, JComponent c) { g.setColor(c.getBackground()); g.fillRoundRect(0, 0, c.getWidth(), c.getHeight(), 7, 7); } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialCheckBoxMenuItemUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialCheckBoxMenuItemUI.java index e5068a8ed..8f0df3604 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialCheckBoxMenuItemUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialCheckBoxMenuItemUI.java @@ -1,20 +1,18 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Color; +import java.awt.Graphics; import javax.swing.Icon; import javax.swing.JCheckBoxMenuItem; import javax.swing.JComponent; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI; -import java.awt.Color; -import java.awt.Graphics; /** * @author https://github.com/vincenzopalazzo */ - public class MaterialCheckBoxMenuItemUI extends BasicCheckBoxMenuItemUI { public static ComponentUI createUI(JComponent c) { @@ -32,12 +30,33 @@ public void paint(Graphics g, JComponent c) { } @Override - protected void paintMenuItem(Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap) { + protected void paintMenuItem( + Graphics g, + JComponent c, + Icon checkIcon, + Icon arrowIcon, + Color background, + Color foreground, + int defaultTextIconGap) { JCheckBoxMenuItem checkBoxMenuItem = (JCheckBoxMenuItem) c; if (checkBoxMenuItem.isSelected()) { - super.paintMenuItem(MaterialDrawingUtils.getAliasedGraphics(g), checkBoxMenuItem, UIManager.getIcon("CheckBoxMenuItem.selectedCheckIcon"), arrowIcon, background, foreground, defaultTextIconGap); + super.paintMenuItem( + MaterialDrawingUtils.getAliasedGraphics(g), + checkBoxMenuItem, + UIManager.getIcon("CheckBoxMenuItem.selectedCheckIcon"), + arrowIcon, + background, + foreground, + defaultTextIconGap); return; } - super.paintMenuItem(MaterialDrawingUtils.getAliasedGraphics(g), checkBoxMenuItem, UIManager.getIcon("CheckBoxMenuItem.checkIcon"), arrowIcon, background, foreground, defaultTextIconGap); + super.paintMenuItem( + MaterialDrawingUtils.getAliasedGraphics(g), + checkBoxMenuItem, + UIManager.getIcon("CheckBoxMenuItem.checkIcon"), + arrowIcon, + background, + foreground, + defaultTextIconGap); } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialCheckBoxUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialCheckBoxUI.java index a85e9079e..4a9725d52 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialCheckBoxUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialCheckBoxUI.java @@ -1,15 +1,14 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Graphics; import javax.swing.JCheckBox; import javax.swing.JComponent; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicCheckBoxUI; -import java.awt.Graphics; -//TODO cambio colore icone combo box +// TODO cambio colore icone combo box public class MaterialCheckBoxUI extends BasicCheckBoxUI { public static ComponentUI createUI(JComponent c) { diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialComboBoxRenderer.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialComboBoxRenderer.java index d6df89d44..73573d8f8 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialComboBoxRenderer.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialComboBoxRenderer.java @@ -1,23 +1,28 @@ package edu.rpi.legup.ui.lookandfeel.components; +import java.awt.Component; import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JList; import javax.swing.UIManager; import javax.swing.plaf.basic.BasicComboBoxRenderer; -import java.awt.Component; public class MaterialComboBoxRenderer extends BasicComboBoxRenderer { @Override - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - JComponent component = (JComponent) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + public Component getListCellRendererComponent( + JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + JComponent component = + (JComponent) + super.getListCellRendererComponent( + list, value, index, isSelected, cellHasFocus); component.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); component.setForeground(UIManager.getColor("ComboBox.foreground")); - component.setBackground(isSelected || cellHasFocus ? - UIManager.getColor("ComboBox.selectedInDropDownBackground") : - UIManager.getColor("ComboBox.background")); + component.setBackground( + isSelected || cellHasFocus + ? UIManager.getColor("ComboBox.selectedInDropDownBackground") + : UIManager.getColor("ComboBox.background")); return component; } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialComboBoxUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialComboBoxUI.java index f9d6fa090..8cd52995b 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialComboBoxUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialComboBoxUI.java @@ -1,7 +1,7 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Graphics; import javax.swing.BorderFactory; import javax.swing.Icon; import javax.swing.JButton; @@ -12,7 +12,6 @@ import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicArrowButton; import javax.swing.plaf.basic.BasicComboBoxUI; -import java.awt.Graphics; public class MaterialComboBoxUI extends BasicComboBoxUI { @@ -39,8 +38,7 @@ protected JButton createArrowButton() { JButton button; if (icon != null) { button = new JButton(icon); - } - else { + } else { button = new BasicArrowButton(SwingConstants.SOUTH); } button.setFocusPainted(false); diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialEditorPaneUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialEditorPaneUI.java index 92d6770e0..786f289bb 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialEditorPaneUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialEditorPaneUI.java @@ -7,7 +7,6 @@ /** * @author https://github.com/vincenzopalazzo */ - public class MaterialEditorPaneUI extends BasicEditorPaneUI { public static ComponentUI createUI(JComponent c) { diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialFileChooserUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialFileChooserUI.java index 9a4ffc9d4..b8046c569 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialFileChooserUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialFileChooserUI.java @@ -2,13 +2,12 @@ import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialImages; - +import java.awt.Graphics; import javax.swing.ImageIcon; import javax.swing.JComponent; import javax.swing.JFileChooser; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.metal.MetalFileChooserUI; -import java.awt.Graphics; public class MaterialFileChooserUI extends MetalFileChooserUI { diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialLabelUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialLabelUI.java index e06509a82..e19fc1fed 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialLabelUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialLabelUI.java @@ -1,13 +1,12 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Graphics; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicLabelUI; -import java.awt.Graphics; public class MaterialLabelUI extends BasicLabelUI { diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuBarUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuBarUI.java index 8d5625559..011d61862 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuBarUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuBarUI.java @@ -1,13 +1,12 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Graphics; import javax.swing.JComponent; import javax.swing.JMenuBar; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicMenuBarUI; -import java.awt.Graphics; public class MaterialMenuBarUI extends BasicMenuBarUI { diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuItemUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuItemUI.java index d7a23d1a3..a8c572b62 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuItemUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuItemUI.java @@ -1,14 +1,13 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Graphics; import javax.swing.JComponent; import javax.swing.JMenuItem; import javax.swing.SwingConstants; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicMenuItemUI; -import java.awt.Graphics; public class MaterialMenuItemUI extends BasicMenuItemUI { diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuUI.java index 7461cbea0..16c1b9270 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialMenuUI.java @@ -1,13 +1,12 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Graphics; import javax.swing.JComponent; import javax.swing.JMenu; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicMenuUI; -import java.awt.Graphics; public class MaterialMenuUI extends BasicMenuUI { diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPanelUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPanelUI.java index cf786be3f..ae7a9be6b 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPanelUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPanelUI.java @@ -1,13 +1,12 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Graphics; import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicPanelUI; -import java.awt.Graphics; public class MaterialPanelUI extends BasicPanelUI { diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPasswordFieldUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPasswordFieldUI.java index 61aa84fc7..d4778402b 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPasswordFieldUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPasswordFieldUI.java @@ -2,18 +2,6 @@ import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.JComponent; -import javax.swing.JPasswordField; -import javax.swing.KeyStroke; -import javax.swing.plaf.ComponentUI; -import javax.swing.plaf.basic.BasicPasswordFieldUI; -import javax.swing.text.Element; -import javax.swing.text.PasswordView; -import javax.swing.text.View; import java.awt.Color; import java.awt.FontMetrics; import java.awt.Graphics; @@ -26,8 +14,20 @@ import java.awt.event.KeyEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.BorderFactory; +import javax.swing.JComponent; +import javax.swing.JPasswordField; +import javax.swing.KeyStroke; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.basic.BasicPasswordFieldUI; +import javax.swing.text.Element; +import javax.swing.text.PasswordView; +import javax.swing.text.View; -public class MaterialPasswordFieldUI extends BasicPasswordFieldUI implements FocusListener, PropertyChangeListener { +public class MaterialPasswordFieldUI extends BasicPasswordFieldUI + implements FocusListener, PropertyChangeListener { private Color focusedBackground; private Color unfocusedBackground; @@ -64,47 +64,65 @@ protected void installListeners() { protected void installKeyboardActions() { super.installKeyboardActions(); - Action selectAll = new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - getComponent().selectAll(); - } - }; - - Action delete = new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - if (getComponent().getSelectedText() == null) { - int pos = getComponent().getCaretPosition() - 1; - - if (pos >= 0) { - getComponent().select(pos, pos + 1); - getComponent().replaceSelection(""); + Action selectAll = + new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + getComponent().selectAll(); } - } - else { - getComponent().replaceSelection(""); - } - } - }; - - Action left = new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - getComponent().setCaretPosition(Math.max(0, getComponent().getCaretPosition() - 1)); - } - }; - - Action right = new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - getComponent().setCaretPosition(Math.min(getComponent().getText().length(), getComponent().getCaretPosition() + 1)); - } - }; - - // note getMenuShortcutKeyMask() is deprecated in Java 10 - change to getMenuShortcutKeyMaskEx() - getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "selectAll"); - getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), "delete"); + }; + + Action delete = + new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + if (getComponent().getSelectedText() == null) { + int pos = getComponent().getCaretPosition() - 1; + + if (pos >= 0) { + getComponent().select(pos, pos + 1); + getComponent().replaceSelection(""); + } + } else { + getComponent().replaceSelection(""); + } + } + }; + + Action left = + new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + getComponent() + .setCaretPosition( + Math.max(0, getComponent().getCaretPosition() - 1)); + } + }; + + Action right = + new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + getComponent() + .setCaretPosition( + Math.min( + getComponent().getText().length(), + getComponent().getCaretPosition() + 1)); + } + }; + + // note getMenuShortcutKeyMask() is deprecated in Java 10 - change to + // getMenuShortcutKeyMaskEx() + getComponent() + .getInputMap() + .put( + KeyStroke.getKeyStroke( + KeyEvent.VK_A, + Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), + "selectAll"); + getComponent() + .getInputMap() + .put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), "delete"); getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), "left"); getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), "right"); @@ -122,15 +140,17 @@ public void paintSafely(Graphics g) { if (getComponent().hasFocus()) { c.setBackground(focusedBackground); c.setSelectionColor(focusedSelectionBackground); - } - else { + } else { c.setBackground(unfocusedBackground); c.setSelectionColor(unfocusedSelectionBackground); } int x = getComponent().getInsets().left; int y = getComponent().getInsets().top; - int w = getComponent().getWidth() - getComponent().getInsets().left - getComponent().getInsets().right; + int w = + getComponent().getWidth() + - getComponent().getInsets().left + - getComponent().getInsets().right; g.setColor(c.getBackground()); g.fillRect(x, c.getHeight() - y, w, 2); @@ -160,7 +180,8 @@ public void propertyChange(PropertyChangeEvent pce) { if (!newColor.equals(focusedBackground) && !newColor.equals(unfocusedBackground)) { this.focusedBackground = (Color) pce.getNewValue(); - this.focusedSelectionBackground = MaterialColors.bleach(this.focusedBackground, 0.3f); + this.focusedSelectionBackground = + MaterialColors.bleach(this.focusedBackground, 0.3f); } } } @@ -176,7 +197,9 @@ private MaterialPasswordView(Element elem) { super(elem); } - // depreciated in Java 9 and above - replace method with float drawEchoCharacter(Graphics2D g, float x, float y, char c) + // depreciated in Java 9 and above - replace method with float drawEchoCharacter(Graphics2D + // g, + // float x, float y, char c) @Override protected int drawEchoCharacter(Graphics g, int x, int y, char c) { Graphics2D g2 = (Graphics2D) g.create(); @@ -192,4 +215,4 @@ protected int drawEchoCharacter(Graphics g, int x, int y, char c) { return x + fm.charWidth(c); } } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPopupMenuUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPopupMenuUI.java index 3fdb79961..d7baaf5df 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPopupMenuUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialPopupMenuUI.java @@ -1,13 +1,12 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Graphics; import javax.swing.JComponent; import javax.swing.JPopupMenu; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicPopupMenuUI; -import java.awt.Graphics; public class MaterialPopupMenuUI extends BasicPopupMenuUI { diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialProgressBarUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialProgressBarUI.java index 111b7ef92..7f91a779f 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialProgressBarUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialProgressBarUI.java @@ -3,17 +3,15 @@ import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialBorders; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Graphics; import javax.swing.JComponent; import javax.swing.JProgressBar; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicProgressBarUI; -import java.awt.Graphics; /** * @author https://github.com/vincenzopalazzo */ - public class MaterialProgressBarUI extends BasicProgressBarUI { public static ComponentUI createUI(JComponent c) { @@ -34,5 +32,4 @@ public void installUI(JComponent c) { public void paint(Graphics g, JComponent c) { super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); } - } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialRadioButtonMenuItemUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialRadioButtonMenuItemUI.java index d08e52f05..69a9cae53 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialRadioButtonMenuItemUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialRadioButtonMenuItemUI.java @@ -1,20 +1,18 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Color; +import java.awt.Graphics; import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.JRadioButtonMenuItem; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicRadioButtonMenuItemUI; -import java.awt.Color; -import java.awt.Graphics; /** * @author https://github.com/vincenzopalazzo */ - public class MaterialRadioButtonMenuItemUI extends BasicRadioButtonMenuItemUI { public static ComponentUI createUI(JComponent c) { @@ -25,7 +23,7 @@ public static ComponentUI createUI(JComponent c) { public void installUI(JComponent c) { super.installUI(c); JRadioButtonMenuItem j = (JRadioButtonMenuItem) c; - //j.setBackground(MaterialColors.WHITE); + // j.setBackground(MaterialColors.WHITE); j.setBorder(UIManager.getBorder("MenuItem.border")); } @@ -35,12 +33,33 @@ public void paint(Graphics g, JComponent c) { } @Override - protected void paintMenuItem(Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap) { + protected void paintMenuItem( + Graphics g, + JComponent c, + Icon checkIcon, + Icon arrowIcon, + Color background, + Color foreground, + int defaultTextIconGap) { JRadioButtonMenuItem j = (JRadioButtonMenuItem) c; if (j.isSelected()) { - super.paintMenuItem(MaterialDrawingUtils.getAliasedGraphics(g), c, UIManager.getIcon("RadioButtonMenuItem.selectedCheckIcon"), arrowIcon, background, foreground, defaultTextIconGap); + super.paintMenuItem( + MaterialDrawingUtils.getAliasedGraphics(g), + c, + UIManager.getIcon("RadioButtonMenuItem.selectedCheckIcon"), + arrowIcon, + background, + foreground, + defaultTextIconGap); return; } - super.paintMenuItem(MaterialDrawingUtils.getAliasedGraphics(g), c, UIManager.getIcon("RadioButtonMenuItem.checkIcon"), arrowIcon, background, foreground, defaultTextIconGap); + super.paintMenuItem( + MaterialDrawingUtils.getAliasedGraphics(g), + c, + UIManager.getIcon("RadioButtonMenuItem.checkIcon"), + arrowIcon, + background, + foreground, + defaultTextIconGap); } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialRadioButtonUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialRadioButtonUI.java index 047270369..6418d4f17 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialRadioButtonUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialRadioButtonUI.java @@ -1,18 +1,17 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Graphics; import javax.swing.JComponent; import javax.swing.JRadioButton; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicRadioButtonUI; -import java.awt.Graphics; /* * Contributed by https://github.com/downToHell * */ -//TODO cambio colore del radio button. +// TODO cambio colore del radio button. public class MaterialRadioButtonUI extends BasicRadioButtonUI { public static ComponentUI createUI(JComponent c) { @@ -35,4 +34,4 @@ public void installUI(JComponent c) { public void paint(Graphics g, JComponent c) { super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialScrollBarUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialScrollBarUI.java index 4bf5bbb0f..164209b3f 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialScrollBarUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialScrollBarUI.java @@ -1,7 +1,7 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Graphics; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JScrollBar; @@ -9,7 +9,6 @@ import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicArrowButton; import javax.swing.plaf.basic.BasicScrollBarUI; -import java.awt.Graphics; /* * Contributed by https://github.com/downToHell @@ -62,4 +61,4 @@ protected JButton createIncreaseButton(int orientation) { return button; } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSeparatorUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSeparatorUI.java index 05cd5b60e..042b53d1b 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSeparatorUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSeparatorUI.java @@ -1,11 +1,10 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Graphics; import javax.swing.JComponent; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicSeparatorUI; -import java.awt.Graphics; public class MaterialSeparatorUI extends BasicSeparatorUI { diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSliderUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSliderUI.java index ab9d75484..7ac2fe350 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSliderUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSliderUI.java @@ -2,21 +2,21 @@ import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Dimension; +import java.awt.Graphics; import javax.swing.JComponent; import javax.swing.JSlider; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicSliderUI; -import java.awt.Dimension; -import java.awt.Graphics; -//TODO cambio grafica slider +// TODO cambio grafica slider public class MaterialSliderUI extends BasicSliderUI { private static final int NORMAL_THUMB_RADIUS = 6; private static final int DRAG_THUMB_RADIUS = 10; - private static final Dimension THUMB_SIZE = new Dimension(DRAG_THUMB_RADIUS * 2, DRAG_THUMB_RADIUS * 2); + private static final Dimension THUMB_SIZE = + new Dimension(DRAG_THUMB_RADIUS * 2, DRAG_THUMB_RADIUS * 2); public MaterialSliderUI(JSlider slider) { super(slider); @@ -81,33 +81,48 @@ public void paintTrack(Graphics g) { private Line getTrack(boolean loaded) { if (slider.getOrientation() == JSlider.HORIZONTAL) { - Line left = new Line(trackRect.x, thumbRect.y + thumbRect.height / 2, thumbRect.x + thumbRect.width / 2, thumbRect.y + thumbRect.height / 2); - Line right = new Line(thumbRect.x + thumbRect.width / 2, thumbRect.y + thumbRect.height / 2, trackRect.x + trackRect.width, thumbRect.y + thumbRect.height / 2); + Line left = + new Line( + trackRect.x, + thumbRect.y + thumbRect.height / 2, + thumbRect.x + thumbRect.width / 2, + thumbRect.y + thumbRect.height / 2); + Line right = + new Line( + thumbRect.x + thumbRect.width / 2, + thumbRect.y + thumbRect.height / 2, + trackRect.x + trackRect.width, + thumbRect.y + thumbRect.height / 2); if (loaded) { return slider.getInverted() ? right : left; - } - else { + } else { return slider.getInverted() ? left : right; } - } - else { - Line top = new Line(thumbRect.x + thumbRect.width / 2, trackRect.y, thumbRect.x + thumbRect.width / 2, thumbRect.y + thumbRect.height / 2); - Line bottom = new Line(thumbRect.x + thumbRect.width / 2, thumbRect.y + thumbRect.height / 2, thumbRect.x + thumbRect.width / 2, trackRect.y + trackRect.height); + } else { + Line top = + new Line( + thumbRect.x + thumbRect.width / 2, + trackRect.y, + thumbRect.x + thumbRect.width / 2, + thumbRect.y + thumbRect.height / 2); + Line bottom = + new Line( + thumbRect.x + thumbRect.width / 2, + thumbRect.y + thumbRect.height / 2, + thumbRect.x + thumbRect.width / 2, + trackRect.y + trackRect.height); if (loaded) { return slider.getInverted() ? top : bottom; - } - else { + } else { return slider.getInverted() ? bottom : top; } } } @Override - public void paintFocus(Graphics g) { - - } + public void paintFocus(Graphics g) {} @Override public void paint(Graphics g, JComponent c) { diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSpinnerUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSpinnerUI.java index 0a74c9d99..ecfcbab17 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSpinnerUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSpinnerUI.java @@ -1,7 +1,8 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Component; +import java.awt.Graphics; import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JComponent; @@ -11,8 +12,6 @@ import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicArrowButton; import javax.swing.plaf.basic.BasicSpinnerUI; -import java.awt.Component; -import java.awt.Graphics; public class MaterialSpinnerUI extends BasicSpinnerUI { @@ -51,8 +50,7 @@ protected Component createNextButton() { JButton button; if (icon != null) { button = new JButton(icon); - } - else { + } else { button = new BasicArrowButton(SwingConstants.NORTH); } button.setFocusPainted(false); @@ -70,8 +68,7 @@ protected Component createPreviousButton() { JButton button; if (icon != null) { button = new JButton(icon); - } - else { + } else { button = new BasicArrowButton(SwingConstants.SOUTH); } button.setFocusPainted(false); diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSplitPaneDivider.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSplitPaneDivider.java index 23d798644..0ec5db987 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSplitPaneDivider.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSplitPaneDivider.java @@ -6,18 +6,18 @@ public class MaterialSplitPaneDivider extends BasicSplitPaneDivider { public MaterialSplitPaneDivider(BasicSplitPaneUI ui) { super(ui); -// oneTouchSize = DefaultLookup.getInt(ui.getSplitPane(), ui, -// "SplitPane.oneTouchButtonSize", ONE_TOUCH_SIZE); -// oneTouchOffset = DefaultLookup.getInt(ui.getSplitPane(), ui, -// "SplitPane.oneTouchButtonOffset", ONE_TOUCH_OFFSET); -// centerOneTouchButtons = DefaultLookup.getBoolean(ui.getSplitPane(), -// ui, "SplitPane.centerOneTouchButtons", true); -// setLayout(new DividerLayout()); -// setBasicSplitPaneUI(ui); -// orientation = splitPane.getOrientation(); -// setCursor((orientation == JSplitPane.HORIZONTAL_SPLIT) ? -// Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR) : -// Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR)); -// setBackground(UIManager.getColor("SplitPane.background")); + // oneTouchSize = DefaultLookup.getInt(ui.getSplitPane(), ui, + // "SplitPane.oneTouchButtonSize", ONE_TOUCH_SIZE); + // oneTouchOffset = DefaultLookup.getInt(ui.getSplitPane(), ui, + // "SplitPane.oneTouchButtonOffset", ONE_TOUCH_OFFSET); + // centerOneTouchButtons = DefaultLookup.getBoolean(ui.getSplitPane(), + // ui, "SplitPane.centerOneTouchButtons", true); + // setLayout(new DividerLayout()); + // setBasicSplitPaneUI(ui); + // orientation = splitPane.getOrientation(); + // setCursor((orientation == JSplitPane.HORIZONTAL_SPLIT) ? + // Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR) : + // Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR)); + // setBackground(UIManager.getColor("SplitPane.background")); } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSplitPaneUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSplitPaneUI.java index 90bd79b5e..33cee1316 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSplitPaneUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialSplitPaneUI.java @@ -15,13 +15,13 @@ public void installUI(JComponent c) { splitPane.setDividerSize(UIManager.getInt("SplitPane.dividerSize")); } -// /** -// * Creates the default divider. -// * -// * @return the default divider -// */ -// @Override -// public BasicSplitPaneDivider createDefaultDivider() { -// return new MaterialSplitPaneDivider(this); -// } + // /** + // * Creates the default divider. + // * + // * @return the default divider + // */ + // @Override + // public BasicSplitPaneDivider createDefaultDivider() { + // return new MaterialSplitPaneDivider(this); + // } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTabbedPaneUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTabbedPaneUI.java index 0441cca35..878ed8479 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTabbedPaneUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTabbedPaneUI.java @@ -1,14 +1,13 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Graphics; +import java.awt.Rectangle; import javax.swing.JComponent; import javax.swing.JTabbedPane; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicTabbedPaneUI; -import java.awt.Graphics; -import java.awt.Rectangle; public class MaterialTabbedPaneUI extends BasicTabbedPaneUI { @@ -38,25 +37,60 @@ public void paint(Graphics g, JComponent c) { } @Override - protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) { + protected void paintTabBackground( + Graphics g, + int tabPlacement, + int tabIndex, + int x, + int y, + int w, + int h, + boolean isSelected) { g.setColor(isSelected ? lightHighlight : tabPane.getBackground()); g.fillRect(x, y, w, h); } @Override - protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) { + protected void paintTabBorder( + Graphics g, + int tabPlacement, + int tabIndex, + int x, + int y, + int w, + int h, + boolean isSelected) { g.setColor(UIManager.getColor("TabbedPane.borderHighlightColor")); g.drawRect(x, y, w, h); } @Override - protected void paintFocusIndicator(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect, boolean isSelected) { + protected void paintFocusIndicator( + Graphics g, + int tabPlacement, + Rectangle[] rects, + int tabIndex, + Rectangle iconRect, + Rectangle textRect, + boolean isSelected) { // do nothing } @Override - protected void paintTab(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect) { + protected void paintTab( + Graphics g, + int tabPlacement, + Rectangle[] rects, + int tabIndex, + Rectangle iconRect, + Rectangle textRect) { // for some reason tabs aren't painted properly by paint() - super.paintTab(MaterialDrawingUtils.getAliasedGraphics(g), tabPlacement, rects, tabIndex, iconRect, textRect); + super.paintTab( + MaterialDrawingUtils.getAliasedGraphics(g), + tabPlacement, + rects, + tabIndex, + iconRect, + textRect); } } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableCellEditor.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableCellEditor.java index 329102fbe..b4e07e95f 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableCellEditor.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableCellEditor.java @@ -1,9 +1,9 @@ package edu.rpi.legup.ui.lookandfeel.components; +import java.awt.Component; import javax.swing.DefaultCellEditor; import javax.swing.JTable; import javax.swing.JTextField; -import java.awt.Component; public class MaterialTableCellEditor extends DefaultCellEditor { @@ -19,8 +19,12 @@ private static JTextField init() { } @Override - public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int rowIndex, int vColIndex) { - JTextField textField = (JTextField) super.getTableCellEditorComponent(table, value, isSelected, rowIndex, vColIndex); + public Component getTableCellEditorComponent( + JTable table, Object value, boolean isSelected, int rowIndex, int vColIndex) { + JTextField textField = + (JTextField) + super.getTableCellEditorComponent( + table, value, isSelected, rowIndex, vColIndex); textField.setText(value.toString()); return textField; diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableCellRenderer.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableCellRenderer.java index 86c76e005..8fe0438e8 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableCellRenderer.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableCellRenderer.java @@ -1,17 +1,21 @@ package edu.rpi.legup.ui.lookandfeel.components; +import java.awt.Component; import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JTable; import javax.swing.SwingConstants; import javax.swing.table.DefaultTableCellRenderer; -import java.awt.Component; public class MaterialTableCellRenderer extends DefaultTableCellRenderer { @Override - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { - JComponent component = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + public Component getTableCellRendererComponent( + JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + JComponent component = + (JComponent) + super.getTableCellRendererComponent( + table, value, isSelected, hasFocus, row, column); // hides yellow selection highlight component.setBorder(BorderFactory.createEmptyBorder()); diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableHeaderCellRenderer.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableHeaderCellRenderer.java index 2cdfb0fa9..01f4db191 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableHeaderCellRenderer.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableHeaderCellRenderer.java @@ -1,17 +1,21 @@ package edu.rpi.legup.ui.lookandfeel.components; +import java.awt.Component; import javax.swing.JComponent; import javax.swing.JTable; import javax.swing.SwingConstants; import javax.swing.UIManager; import javax.swing.table.DefaultTableCellRenderer; -import java.awt.Component; public class MaterialTableHeaderCellRenderer extends DefaultTableCellRenderer { @Override - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { - JComponent component = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + public Component getTableCellRendererComponent( + JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + JComponent component = + (JComponent) + super.getTableCellRendererComponent( + table, value, isSelected, hasFocus, row, column); component.setBorder(UIManager.getBorder("TableHeader.cellBorder")); component.setFont(UIManager.getFont("TableHeader.font")); component.setBackground(UIManager.getColor("TableHeader.background")); diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableHeaderUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableHeaderUI.java index 82144615b..7a1eadb92 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableHeaderUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableHeaderUI.java @@ -1,12 +1,11 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Graphics; import javax.swing.JComponent; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicTableHeaderUI; import javax.swing.table.JTableHeader; -import java.awt.Graphics; public class MaterialTableHeaderUI extends BasicTableHeaderUI { diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableUI.java index dc0b82a34..91c68c973 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTableUI.java @@ -1,13 +1,12 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Graphics; import javax.swing.JComponent; import javax.swing.JTable; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicTableUI; -import java.awt.Graphics; public class MaterialTableUI extends BasicTableUI { @@ -32,8 +31,7 @@ public void installUI(JComponent c) { int rowHeight = UIManager.getInt("Table.rowHeight"); if (rowHeight > 0) { table.setRowHeight(rowHeight); - } - else { + } else { table.setRowHeight(table.getRowHeight() + 25); } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextFieldUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextFieldUI.java index 019c4b047..5cfd2fc88 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextFieldUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextFieldUI.java @@ -3,15 +3,6 @@ import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialColors; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialFonts; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.JComponent; -import javax.swing.JTextField; -import javax.swing.KeyStroke; -import javax.swing.plaf.ComponentUI; -import javax.swing.plaf.basic.BasicTextFieldUI; import java.awt.Color; import java.awt.Graphics; import java.awt.Toolkit; @@ -21,9 +12,17 @@ import java.awt.event.KeyEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.BorderFactory; +import javax.swing.JComponent; +import javax.swing.JTextField; +import javax.swing.KeyStroke; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.basic.BasicTextFieldUI; - -public class MaterialTextFieldUI extends BasicTextFieldUI implements FocusListener, PropertyChangeListener { +public class MaterialTextFieldUI extends BasicTextFieldUI + implements FocusListener, PropertyChangeListener { private Color focusedBackground; private Color unfocusedBackground; @@ -50,9 +49,10 @@ public void installUI(JComponent c) { JTextField textField = (JTextField) c; textField.setOpaque(false); - textField.setBorder(drawLine ? - BorderFactory.createEmptyBorder(5, 2, 10, 0) : - BorderFactory.createEmptyBorder(2, 2, 2, 2)); + textField.setBorder( + drawLine + ? BorderFactory.createEmptyBorder(5, 2, 10, 0) + : BorderFactory.createEmptyBorder(2, 2, 2, 2)); textField.setBackground(MaterialColors.LIGHT_BLUE_400); textField.setFont(MaterialFonts.REGULAR); @@ -75,54 +75,73 @@ protected void installListeners() { protected void installKeyboardActions() { super.installKeyboardActions(); - Action selectAll = new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - getComponent().selectAll(); - } - }; - - Action delete = new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - if (getComponent().getSelectedText() == null) { - int pos = getComponent().getCaretPosition() - 1; - - if (pos >= 0) { - getComponent().select(pos, pos + 1); - getComponent().replaceSelection(""); + Action selectAll = + new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + getComponent().selectAll(); } - } - else { - getComponent().replaceSelection(""); - } - } - }; - - Action left = new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - getComponent().setCaretPosition(Math.max(0, getComponent().getCaretPosition() - 1)); - } - }; - - Action right = new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - getComponent().setCaretPosition(Math.min(getComponent().getText().length(), getComponent().getCaretPosition() + 1)); - } - }; - - Action enter = new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - ((JTextField) getComponent()).postActionEvent(); - } - }; + }; + + Action delete = + new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + if (getComponent().getSelectedText() == null) { + int pos = getComponent().getCaretPosition() - 1; + + if (pos >= 0) { + getComponent().select(pos, pos + 1); + getComponent().replaceSelection(""); + } + } else { + getComponent().replaceSelection(""); + } + } + }; + + Action left = + new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + getComponent() + .setCaretPosition( + Math.max(0, getComponent().getCaretPosition() - 1)); + } + }; + + Action right = + new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + getComponent() + .setCaretPosition( + Math.min( + getComponent().getText().length(), + getComponent().getCaretPosition() + 1)); + } + }; - // note getMenuShortcutKeyMask() is deprecated in Java 10 - change to getMenuShortcutKeyMaskEx() - getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "selectAll"); - getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), "delete"); + Action enter = + new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + ((JTextField) getComponent()).postActionEvent(); + } + }; + + // note getMenuShortcutKeyMask() is deprecated in Java 10 - change to + // getMenuShortcutKeyMaskEx() + getComponent() + .getInputMap() + .put( + KeyStroke.getKeyStroke( + KeyEvent.VK_A, + Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), + "selectAll"); + getComponent() + .getInputMap() + .put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), "delete"); getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), "left"); getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), "right"); getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter"); @@ -144,8 +163,7 @@ public void paintSafely(Graphics g) { if (getComponent().hasFocus()) { lineColor = focusedBackground; c.setSelectionColor(focusedSelectionBackground); - } - else { + } else { lineColor = unfocusedBackground; c.setSelectionColor(unfocusedSelectionBackground); } @@ -156,7 +174,10 @@ public void paintSafely(Graphics g) { if (drawLine) { int x = getComponent().getInsets().left; int y = getComponent().getInsets().top; - int w = getComponent().getWidth() - getComponent().getInsets().left - getComponent().getInsets().right; + int w = + getComponent().getWidth() + - getComponent().getInsets().left + - getComponent().getInsets().right; g.fillRect(x, c.getHeight() - y, w, 2); } @@ -188,8 +209,9 @@ public void propertyChange(PropertyChangeEvent pce) { if (!newColor.equals(focusedBackground) && !newColor.equals(unfocusedBackground)) { this.focusedBackground = (Color) pce.getNewValue(); - this.focusedSelectionBackground = MaterialColors.bleach(this.focusedBackground, 0.3f); + this.focusedSelectionBackground = + MaterialColors.bleach(this.focusedBackground, 0.3f); } } } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextPaneUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextPaneUI.java index 2adea67b2..f70048468 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextPaneUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTextPaneUI.java @@ -7,7 +7,6 @@ /** * @author https://github.com/vincenzopalazzo */ - public class MaterialTextPaneUI extends BasicTextPaneUI { public static ComponentUI createUI(JComponent c) { diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToggleButtonUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToggleButtonUI.java index 928b2e688..3749366e9 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToggleButtonUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToggleButtonUI.java @@ -1,13 +1,12 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Graphics; import javax.swing.JComponent; import javax.swing.JToggleButton; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicToggleButtonUI; -import java.awt.Graphics; public class MaterialToggleButtonUI extends BasicToggleButtonUI { diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToolBarUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToolBarUI.java index d95d52455..10251eb73 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToolBarUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToolBarUI.java @@ -1,13 +1,12 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Graphics; import javax.swing.JComponent; import javax.swing.JToolBar; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicToolBarUI; -import java.awt.Graphics; public class MaterialToolBarUI extends BasicToolBarUI { diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToolTipUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToolTipUI.java index adbd78925..87e415e4c 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToolTipUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialToolTipUI.java @@ -1,11 +1,10 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.*; import javax.swing.*; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicToolTipUI; -import java.awt.*; public class MaterialToolTipUI extends BasicToolTipUI { diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeCellEditor.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeCellEditor.java index 6ac2230f4..ee9b0fcff 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeCellEditor.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeCellEditor.java @@ -1,13 +1,13 @@ package edu.rpi.legup.ui.lookandfeel.components; +import java.awt.Component; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; import javax.swing.JTextField; import javax.swing.JTree; import javax.swing.tree.DefaultTreeCellEditor; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.TreeCellEditor; -import java.awt.Component; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; public class MaterialTreeCellEditor extends DefaultTreeCellEditor { @@ -18,7 +18,8 @@ public MaterialTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer) { init(); } - public MaterialTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer, TreeCellEditor editor) { + public MaterialTreeCellEditor( + JTree tree, DefaultTreeCellRenderer renderer, TreeCellEditor editor) { super(tree, renderer, editor); init(); } @@ -27,18 +28,20 @@ private void init() { textField = new JTextField(); textField.setUI(new MaterialTextFieldUI()); - textField.addKeyListener(new KeyAdapter() { - @Override - public void keyTyped(KeyEvent e) { - if (e.getKeyChar() == KeyEvent.VK_ENTER) { - stopCellEditing(); - } - } - }); + textField.addKeyListener( + new KeyAdapter() { + @Override + public void keyTyped(KeyEvent e) { + if (e.getKeyChar() == KeyEvent.VK_ENTER) { + stopCellEditing(); + } + } + }); } @Override - public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) { + public Component getTreeCellEditorComponent( + JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) { textField.setText(value.toString()); return textField; } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeCellRenderer.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeCellRenderer.java index f9ddcbf45..6ac5acabb 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeCellRenderer.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeCellRenderer.java @@ -1,11 +1,11 @@ package edu.rpi.legup.ui.lookandfeel.components; +import java.awt.Component; import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JTree; import javax.swing.UIManager; import javax.swing.tree.DefaultTreeCellRenderer; -import java.awt.Component; public class MaterialTreeCellRenderer extends DefaultTreeCellRenderer { @@ -22,13 +22,22 @@ public MaterialTreeCellRenderer() { setOpenIcon(UIManager.getIcon("Tree.openIcon")); setLeafIcon(null); - setFont(UIManager.getFont("Tree.font")); } @Override - public Component getTreeCellRendererComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row, boolean hasFocus) { - JComponent component = (JComponent) super.getTreeCellRendererComponent(tree, value, isSelected, expanded, leaf, row, hasFocus); + public Component getTreeCellRendererComponent( + JTree tree, + Object value, + boolean isSelected, + boolean expanded, + boolean leaf, + int row, + boolean hasFocus) { + JComponent component = + (JComponent) + super.getTreeCellRendererComponent( + tree, value, isSelected, expanded, leaf, row, hasFocus); component.setBorder(BorderFactory.createEmptyBorder(5, 2, 5, 2)); return component; diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeUI.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeUI.java index b1b9839bd..7d38c62f3 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeUI.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/components/MaterialTreeUI.java @@ -1,7 +1,7 @@ package edu.rpi.legup.ui.lookandfeel.components; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialDrawingUtils; - +import java.awt.Graphics; import javax.swing.JComponent; import javax.swing.JTree; import javax.swing.UIManager; @@ -9,7 +9,6 @@ import javax.swing.plaf.basic.BasicTreeUI; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.TreeCellEditor; -import java.awt.Graphics; public class MaterialTreeUI extends BasicTreeUI { @@ -42,4 +41,4 @@ public void paint(Graphics g, JComponent c) { g = MaterialDrawingUtils.getAliasedGraphics(g); super.paint(g, c); } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/DropShadowBorder.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/DropShadowBorder.java index 2543b8664..ce3244d4d 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/DropShadowBorder.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/DropShadowBorder.java @@ -1,8 +1,5 @@ package edu.rpi.legup.ui.lookandfeel.materialdesign; -import javax.swing.UIManager; -import javax.swing.border.AbstractBorder; -import javax.swing.border.Border; import java.awt.Color; import java.awt.Component; import java.awt.Graphics; @@ -18,19 +15,22 @@ import java.awt.image.Kernel; import java.util.HashMap; import java.util.Map; +import javax.swing.UIManager; +import javax.swing.border.AbstractBorder; +import javax.swing.border.Border; /** - * Implements a DropShadow for components. In general, the mdlaf.shadows.DropShadowBorder will - * work with any rectangular components that do not have a default border installed - * as part of the look and feel, or otherwise. For example, mdlaf.shadows.DropShadowBorder works - * wonderfully with JPanel, but horribly with JComboBox. + * Implements a DropShadow for components. In general, the mdlaf.shadows.DropShadowBorder will work + * with any rectangular components that do not have a default border installed as part of the look + * and feel, or otherwise. For example, mdlaf.shadows.DropShadowBorder works wonderfully with + * JPanel, but horribly with JComboBox. * * @author rbair */ public class DropShadowBorder extends AbstractBorder implements Border { - private static final Map> CACHE - = new HashMap>(); + private static final Map> CACHE = + new HashMap>(); private Color lineColor; private int lineWidth; private int shadowSize; @@ -53,9 +53,16 @@ public DropShadowBorder(Color lineColor, int lineWidth, boolean showLeftShadow) this(lineColor, lineWidth, 5, .5f, 12, false, showLeftShadow, true, true); } - public DropShadowBorder(Color lineColor, int lineWidth, int shadowSize, - float shadowOpacity, int cornerSize, boolean showTopShadow, - boolean showLeftShadow, boolean showBottomShadow, boolean showRightShadow) { + public DropShadowBorder( + Color lineColor, + int lineWidth, + int shadowSize, + float shadowOpacity, + int cornerSize, + boolean showTopShadow, + boolean showLeftShadow, + boolean showBottomShadow, + boolean showRightShadow) { this.lineColor = lineColor; this.lineWidth = lineWidth; this.shadowSize = shadowSize; @@ -67,9 +74,7 @@ public DropShadowBorder(Color lineColor, int lineWidth, int shadowSize, this.showRightShadow = showRightShadow; } - /** - * - */ + /** */ public void paintBorder(Component c, Graphics graphics, int x, int y, int width, int height) { /* * 1) Get images for this border @@ -77,8 +82,8 @@ public void paintBorder(Component c, Graphics graphics, int x, int y, int width, */ Map images = getImages(null); - //compute the edges of the components -- not including the border - //Insets borderInsets = getBorderInsets (c); + // compute the edges of the components -- not including the border + // Insets borderInsets = getBorderInsets (c); // int leftEdge = x + borderInsets.left - lineWidth; // int rightEdge = x + width - borderInsets.right; // int topEdge = y + borderInsets.top - lineWidth; @@ -86,24 +91,22 @@ public void paintBorder(Component c, Graphics graphics, int x, int y, int width, Graphics2D g2 = (Graphics2D) graphics; g2.setColor(lineColor); - //The location and size of the shadows depends on which shadows are being - //drawn. For instance, if the left & bottom shadows are being drawn, then - //the left shadows extends all the way down to the corner, a corner is drawn, - //and then the bottom shadows begins at the corner. If, however, only the - //bottom shadows is drawn, then the bottom-left corner is drawn to the - //right of the corner, and the bottom shadows is somewhat shorter than before. + // The location and size of the shadows depends on which shadows are being + // drawn. For instance, if the left & bottom shadows are being drawn, then + // the left shadows extends all the way down to the corner, a corner is drawn, + // and then the bottom shadows begins at the corner. If, however, only the + // bottom shadows is drawn, then the bottom-left corner is drawn to the + // right of the corner, and the bottom shadows is somewhat shorter than before. Point topLeftShadowPoint = null; if (showLeftShadow || showTopShadow) { topLeftShadowPoint = new Point(); if (showLeftShadow && !showTopShadow) { topLeftShadowPoint.setLocation(x, y + shadowSize); - } - else { + } else { if (showLeftShadow && showTopShadow) { topLeftShadowPoint.setLocation(x, y); - } - else { + } else { if (!showLeftShadow && showTopShadow) { topLeftShadowPoint.setLocation(x + shadowSize, y); } @@ -116,12 +119,10 @@ public void paintBorder(Component c, Graphics graphics, int x, int y, int width, bottomLeftShadowPoint = new Point(); if (showLeftShadow && !showBottomShadow) { bottomLeftShadowPoint.setLocation(x, y + height - shadowSize - shadowSize); - } - else { + } else { if (showLeftShadow && showBottomShadow) { bottomLeftShadowPoint.setLocation(x, y + height - shadowSize); - } - else { + } else { if (!showLeftShadow && showBottomShadow) { bottomLeftShadowPoint.setLocation(x + shadowSize, y + height - shadowSize); } @@ -133,15 +134,16 @@ public void paintBorder(Component c, Graphics graphics, int x, int y, int width, if (showRightShadow || showBottomShadow) { bottomRightShadowPoint = new Point(); if (showRightShadow && !showBottomShadow) { - bottomRightShadowPoint.setLocation(x + width - shadowSize, y + height - shadowSize - shadowSize); - } - else { + bottomRightShadowPoint.setLocation( + x + width - shadowSize, y + height - shadowSize - shadowSize); + } else { if (showRightShadow && showBottomShadow) { - bottomRightShadowPoint.setLocation(x + width - shadowSize, y + height - shadowSize); - } - else { + bottomRightShadowPoint.setLocation( + x + width - shadowSize, y + height - shadowSize); + } else { if (!showRightShadow && showBottomShadow) { - bottomRightShadowPoint.setLocation(x + width - shadowSize - shadowSize, y + height - shadowSize); + bottomRightShadowPoint.setLocation( + x + width - shadowSize - shadowSize, y + height - shadowSize); } } } @@ -152,12 +154,10 @@ public void paintBorder(Component c, Graphics graphics, int x, int y, int width, topRightShadowPoint = new Point(); if (showRightShadow && !showTopShadow) { topRightShadowPoint.setLocation(x + width - shadowSize, y + shadowSize); - } - else { + } else { if (showRightShadow && showTopShadow) { topRightShadowPoint.setLocation(x + width - shadowSize, y); - } - else { + } else { if (!showRightShadow && showTopShadow) { topRightShadowPoint.setLocation(x + width - shadowSize - shadowSize, y); } @@ -166,42 +166,118 @@ public void paintBorder(Component c, Graphics graphics, int x, int y, int width, } if (showLeftShadow) { - Rectangle leftShadowRect = new Rectangle(x, (int) (topLeftShadowPoint.getY() + shadowSize), shadowSize, (int) (bottomLeftShadowPoint.getY() - topLeftShadowPoint.getY() - shadowSize)); - g2.drawImage(images.get(Position.LEFT).getScaledInstance(leftShadowRect.width, leftShadowRect.height, Image.SCALE_FAST), leftShadowRect.x, leftShadowRect.y, null); + Rectangle leftShadowRect = + new Rectangle( + x, + (int) (topLeftShadowPoint.getY() + shadowSize), + shadowSize, + (int) + (bottomLeftShadowPoint.getY() + - topLeftShadowPoint.getY() + - shadowSize)); + g2.drawImage( + images.get(Position.LEFT) + .getScaledInstance( + leftShadowRect.width, leftShadowRect.height, Image.SCALE_FAST), + leftShadowRect.x, + leftShadowRect.y, + null); } if (showBottomShadow) { - Rectangle bottomShadowRect = new Rectangle((int) (bottomLeftShadowPoint.getX() + shadowSize), y + height - shadowSize, (int) (bottomRightShadowPoint.getX() - bottomLeftShadowPoint.getX() - shadowSize), shadowSize); - g2.drawImage(images.get(Position.BOTTOM).getScaledInstance(bottomShadowRect.width, bottomShadowRect.height, Image.SCALE_FAST), bottomShadowRect.x, bottomShadowRect.y, null); + Rectangle bottomShadowRect = + new Rectangle( + (int) (bottomLeftShadowPoint.getX() + shadowSize), + y + height - shadowSize, + (int) + (bottomRightShadowPoint.getX() + - bottomLeftShadowPoint.getX() + - shadowSize), + shadowSize); + g2.drawImage( + images.get(Position.BOTTOM) + .getScaledInstance( + bottomShadowRect.width, + bottomShadowRect.height, + Image.SCALE_FAST), + bottomShadowRect.x, + bottomShadowRect.y, + null); } if (showRightShadow) { - Rectangle rightShadowRect = new Rectangle(x + width - shadowSize, (int) (topRightShadowPoint.getY() + shadowSize), shadowSize, (int) (bottomRightShadowPoint.getY() - topRightShadowPoint.getY() - shadowSize)); - g2.drawImage(images.get(Position.RIGHT).getScaledInstance(rightShadowRect.width, rightShadowRect.height, Image.SCALE_FAST), rightShadowRect.x, rightShadowRect.y, null); + Rectangle rightShadowRect = + new Rectangle( + x + width - shadowSize, + (int) (topRightShadowPoint.getY() + shadowSize), + shadowSize, + (int) + (bottomRightShadowPoint.getY() + - topRightShadowPoint.getY() + - shadowSize)); + g2.drawImage( + images.get(Position.RIGHT) + .getScaledInstance( + rightShadowRect.width, + rightShadowRect.height, + Image.SCALE_FAST), + rightShadowRect.x, + rightShadowRect.y, + null); } if (showTopShadow) { - Rectangle topShadowRect = new Rectangle((int) topLeftShadowPoint.getX() + shadowSize, y, (int) (topRightShadowPoint.getX() - topLeftShadowPoint.getX() - shadowSize), shadowSize); - g2.drawImage(images.get(Position.TOP).getScaledInstance(topShadowRect.width, topShadowRect.height, Image.SCALE_FAST), topShadowRect.x, topShadowRect.y, null); + Rectangle topShadowRect = + new Rectangle( + (int) topLeftShadowPoint.getX() + shadowSize, + y, + (int) + (topRightShadowPoint.getX() + - topLeftShadowPoint.getX() + - shadowSize), + shadowSize); + g2.drawImage( + images.get(Position.TOP) + .getScaledInstance( + topShadowRect.width, topShadowRect.height, Image.SCALE_FAST), + topShadowRect.x, + topShadowRect.y, + null); } if (showLeftShadow || showTopShadow) { - g2.drawImage(images.get(Position.TOP_LEFT), null, (int) topLeftShadowPoint.getX(), (int) topLeftShadowPoint.getY()); + g2.drawImage( + images.get(Position.TOP_LEFT), + null, + (int) topLeftShadowPoint.getX(), + (int) topLeftShadowPoint.getY()); } if (showLeftShadow || showBottomShadow) { - g2.drawImage(images.get(Position.BOTTOM_LEFT), null, (int) bottomLeftShadowPoint.getX(), (int) bottomLeftShadowPoint.getY()); + g2.drawImage( + images.get(Position.BOTTOM_LEFT), + null, + (int) bottomLeftShadowPoint.getX(), + (int) bottomLeftShadowPoint.getY()); } if (showRightShadow || showBottomShadow) { - g2.drawImage(images.get(Position.BOTTOM_RIGHT), null, (int) bottomRightShadowPoint.getX(), (int) bottomRightShadowPoint.getY()); + g2.drawImage( + images.get(Position.BOTTOM_RIGHT), + null, + (int) bottomRightShadowPoint.getX(), + (int) bottomRightShadowPoint.getY()); } if (showRightShadow || showTopShadow) { - g2.drawImage(images.get(Position.TOP_RIGHT), null, (int) topRightShadowPoint.getX(), (int) topRightShadowPoint.getY()); + g2.drawImage( + images.get(Position.TOP_RIGHT), + null, + (int) topRightShadowPoint.getX(), + (int) topRightShadowPoint.getY()); } } private Map getImages(Graphics2D g2) { - //first, check to see if an image for this size has already been rendered - //if so, use the cache. Else, draw and save + // first, check to see if an image for this size has already been rendered + // if so, use the cache. Else, draw and save Map images = CACHE.get(shadowSize); if (images == null) { images = new HashMap(); @@ -221,25 +297,35 @@ private Map getImages(Graphics2D g2) { * drawing the Border */ int rectWidth = cornerSize + 1; - RoundRectangle2D rect = new RoundRectangle2D.Double(0, 0, rectWidth, rectWidth, cornerSize, cornerSize); + RoundRectangle2D rect = + new RoundRectangle2D.Double(0, 0, rectWidth, rectWidth, cornerSize, cornerSize); int imageWidth = rectWidth + shadowSize * 2; - BufferedImage image = new BufferedImage(imageWidth, imageWidth, BufferedImage.TYPE_INT_ARGB); + BufferedImage image = + new BufferedImage(imageWidth, imageWidth, BufferedImage.TYPE_INT_ARGB); Graphics2D buffer = (Graphics2D) image.getGraphics(); - buffer.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); - buffer.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - buffer.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - buffer.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); + buffer.setRenderingHint( + RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + buffer.setRenderingHint( + RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + buffer.setRenderingHint( + RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + buffer.setRenderingHint( + RenderingHints.KEY_FRACTIONALMETRICS, + RenderingHints.VALUE_FRACTIONALMETRICS_ON); buffer.setColor(new Color(0.0f, 0.0f, 0.0f, shadowOpacity)); buffer.translate(shadowSize, shadowSize); buffer.fill(rect); - float blurry = 1.0f / (float) (shadowSize * shadowSize);//1.0f / (float)(shadowSize * shadowSize); + float blurry = 1.0f / (float) (shadowSize * shadowSize); // 1.0f / (float)(shadowSize * + // shadowSize); float[] blurKernel = new float[shadowSize * shadowSize]; for (int i = 0; i < blurKernel.length; i++) { blurKernel[i] = blurry; } ConvolveOp blur = new ConvolveOp(new Kernel(shadowSize, shadowSize, blurKernel)); - BufferedImage targetImage = new BufferedImage(imageWidth, imageWidth, BufferedImage.TYPE_INT_ARGB); - ((Graphics2D) targetImage.getGraphics()).drawImage(image, blur, -(shadowSize / 2), -(shadowSize / 2)); + BufferedImage targetImage = + new BufferedImage(imageWidth, imageWidth, BufferedImage.TYPE_INT_ARGB); + ((Graphics2D) targetImage.getGraphics()) + .drawImage(image, blur, -(shadowSize / 2), -(shadowSize / 2)); int x = 1; int y = 1; @@ -288,9 +374,7 @@ private Map getImages(Graphics2D g2) { return images; } - /** - * - */ + /** */ public Insets getBorderInsets(Component c) { int top = 4 + (showTopShadow ? lineWidth + shadowSize : lineWidth); int left = 4 + (showLeftShadow ? lineWidth + shadowSize : lineWidth); @@ -300,9 +384,7 @@ public Insets getBorderInsets(Component c) { return new Insets(top, left, bottom, right); } - /** - * - */ + /** */ public boolean isBorderOpaque() { return true; } @@ -344,7 +426,13 @@ public int getCornerSize() { } private enum Position { - TOP, TOP_LEFT, LEFT, BOTTOM_LEFT, - BOTTOM, BOTTOM_RIGHT, RIGHT, TOP_RIGHT + TOP, + TOP_LEFT, + LEFT, + BOTTOM_LEFT, + BOTTOM, + BOTTOM_RIGHT, + RIGHT, + TOP_RIGHT } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialBorders.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialBorders.java index c78d20e34..8c2e3eeec 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialBorders.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialBorders.java @@ -1,17 +1,20 @@ package edu.rpi.legup.ui.lookandfeel.materialdesign; +import java.awt.Color; import javax.swing.BorderFactory; import javax.swing.border.Border; -import java.awt.Color; public class MaterialBorders { - public static final Border LIGHT_LINE_BORDER = BorderFactory.createLineBorder(MaterialColors.GRAY_200, 1); - public static final Border THICK_LINE_BORDER = BorderFactory.createLineBorder(MaterialColors.GRAY_200, 2); + public static final Border LIGHT_LINE_BORDER = + BorderFactory.createLineBorder(MaterialColors.GRAY_200, 1); + public static final Border THICK_LINE_BORDER = + BorderFactory.createLineBorder(MaterialColors.GRAY_200, 2); - public static final Border LIGHT_SHADOW_BORDER = new DropShadowBorder(Color.BLACK, 0, 4, 0.3f, 12, true, true, true, true); - public static final Border DEFAULT_SHADOW_BORDER = new DropShadowBorder(Color.BLACK, 5, 5, 0.3f, 12, true, true, true, true); + public static final Border LIGHT_SHADOW_BORDER = + new DropShadowBorder(Color.BLACK, 0, 4, 0.3f, 12, true, true, true, true); + public static final Border DEFAULT_SHADOW_BORDER = + new DropShadowBorder(Color.BLACK, 5, 5, 0.3f, 12, true, true, true, true); - private MaterialBorders() { - } -} \ No newline at end of file + private MaterialBorders() {} +} diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialColors.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialColors.java index 30229b936..00cb0720a 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialColors.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialColors.java @@ -261,8 +261,7 @@ public class MaterialColors { public static final Color WHITE = new Color(255, 255, 255); public static final Color TRANSPARENT = new Color(0, 0, 0, 255); - private MaterialColors() { - } + private MaterialColors() {} public static Color bleach(Color color, float amount) { int red = (int) ((color.getRed() * (1 - amount) / 255 + amount) * 255); diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialDrawingUtils.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialDrawingUtils.java index fbc330faf..f5e209b0d 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialDrawingUtils.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialDrawingUtils.java @@ -15,17 +15,19 @@ public class MaterialDrawingUtils { } public static Graphics getAliasedGraphics(Graphics g) { - Map hints = (Map) Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints"); + Map hints = + (Map) + Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints"); if (hints != null) { hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Graphics2D g2d = (Graphics2D) g; g2d.addRenderingHints(hints); - //g2d.addRenderingHints (new RenderingHints (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)); + // g2d.addRenderingHints (new RenderingHints (RenderingHints.KEY_ANTIALIASING, + // RenderingHints.VALUE_ANTIALIAS_ON)); return g2d; - } - else { + } else { // Desktop hints not supported on this platform return g; } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialFonts.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialFonts.java index 9bbc4e884..e5d1de56c 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialFonts.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialFonts.java @@ -1,6 +1,5 @@ package edu.rpi.legup.ui.lookandfeel.materialdesign; - import java.awt.*; import java.awt.font.TextAttribute; import java.io.IOException; @@ -13,17 +12,22 @@ public class MaterialFonts { private static final Map fontSettings = new HashMap<>(); public static final Font BLACK = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-Black.ttf"); - public static final Font BLACK_ITALIC = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-BlackItalic.ttf"); + public static final Font BLACK_ITALIC = + loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-BlackItalic.ttf"); public static final Font BOLD = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-Bold.ttf"); - public static final Font BOLD_ITALIC = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-BoldItalic.ttf"); + public static final Font BOLD_ITALIC = + loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-BoldItalic.ttf"); public static final Font ITALIC = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-Italic.ttf"); public static final Font LIGHT = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-Light.ttf"); - public static final Font LIGHT_ITALIC = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-LightItalic.ttf"); + public static final Font LIGHT_ITALIC = + loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-LightItalic.ttf"); public static final Font MEDIUM = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-Medium.ttf"); - public static final Font MEDIUM_ITALIC = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-MediumItalic.ttf"); + public static final Font MEDIUM_ITALIC = + loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-MediumItalic.ttf"); public static final Font REGULAR = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-Regular.ttf"); public static final Font THIN = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-Thin.ttf"); - public static final Font THIN_ITALIC = loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-ThinItalic.ttf"); + public static final Font THIN_ITALIC = + loadFont("/edu/rpi/legup/fonts/Roboto/Roboto-ThinItalic.ttf"); private static Font loadFont(String fontPath) { if (fontSettings.isEmpty()) { @@ -33,8 +37,7 @@ private static Font loadFont(String fontPath) { try (InputStream inputStream = MaterialFonts.class.getResourceAsStream(fontPath)) { return Font.createFont(Font.TRUETYPE_FONT, inputStream).deriveFont(fontSettings); - } - catch (IOException | FontFormatException e) { + } catch (IOException | FontFormatException e) { e.printStackTrace(); throw new RuntimeException("Font " + fontPath + " wasn't loaded"); } @@ -45,10 +48,11 @@ public static Font getRegularFont(float size) { map.put(TextAttribute.SIZE, size); map.put(TextAttribute.KERNING, TextAttribute.KERNING_ON); - try (InputStream inputStream = MaterialFonts.class.getResourceAsStream("/edu/rpi/legup/fonts/Roboto/Roboto-Regular.ttf")) { + try (InputStream inputStream = + MaterialFonts.class.getResourceAsStream( + "/edu/rpi/legup/fonts/Roboto/Roboto-Regular.ttf")) { return Font.createFont(Font.TRUETYPE_FONT, inputStream).deriveFont(map); - } - catch (IOException | FontFormatException e) { + } catch (IOException | FontFormatException e) { e.printStackTrace(); throw new RuntimeException("Font regular wasn't loaded"); } diff --git a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialImages.java b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialImages.java index dabf2139d..a1a716c76 100644 --- a/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialImages.java +++ b/src/main/java/edu/rpi/legup/ui/lookandfeel/materialdesign/MaterialImages.java @@ -1,26 +1,34 @@ package edu.rpi.legup.ui.lookandfeel.materialdesign; -import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; +import javax.imageio.ImageIO; public class MaterialImages { public static final BufferedImage RIGHT_ARROW = loadImg("/edu/rpi/legup/imgs/right_arrow.png"); public static final BufferedImage DOWN_ARROW = loadImg("/edu/rpi/legup/imgs/down_arrow.png"); public static final BufferedImage UP_ARROW = loadImg("/edu/rpi/legup/imgs/up_arrow.png"); - public static final BufferedImage PAINTED_CHECKED_BOX = loadImg("/edu/rpi/legup/imgs/painted_checked_box.png"); - public static final BufferedImage OUTLINED_CHECKED_BOX = loadImg("/edu/rpi/legup/imgs/outlined_checked_box.png"); - public static final BufferedImage UNCHECKED_BOX = loadImg("/edu/rpi/legup/imgs/unchecked_box.png"); - public static final BufferedImage RADIO_BUTTON_ON = loadImg("/edu/rpi/legup/imgs/radio_button_on.png"); - public static final BufferedImage RADIO_BUTTON_OFF = loadImg("/edu/rpi/legup/imgs/radio_button_off.png"); - public static final BufferedImage TOGGLE_BUTTON_ON = loadImg("/edu/rpi/legup/imgs/toggle_on.png"); - public static final BufferedImage TOGGLE_BUTTON_OFF = loadImg("/edu/rpi/legup/imgs/toggle_off.png"); + public static final BufferedImage PAINTED_CHECKED_BOX = + loadImg("/edu/rpi/legup/imgs/painted_checked_box.png"); + public static final BufferedImage OUTLINED_CHECKED_BOX = + loadImg("/edu/rpi/legup/imgs/outlined_checked_box.png"); + public static final BufferedImage UNCHECKED_BOX = + loadImg("/edu/rpi/legup/imgs/unchecked_box.png"); + public static final BufferedImage RADIO_BUTTON_ON = + loadImg("/edu/rpi/legup/imgs/radio_button_on.png"); + public static final BufferedImage RADIO_BUTTON_OFF = + loadImg("/edu/rpi/legup/imgs/radio_button_off.png"); + public static final BufferedImage TOGGLE_BUTTON_ON = + loadImg("/edu/rpi/legup/imgs/toggle_on.png"); + public static final BufferedImage TOGGLE_BUTTON_OFF = + loadImg("/edu/rpi/legup/imgs/toggle_off.png"); public static final BufferedImage BACK_ARROW = loadImg("/edu/rpi/legup/imgs/back_arrow.png"); public static final BufferedImage COMPUTER = loadImg("/edu/rpi/legup/imgs/computer.png"); public static final BufferedImage FILE = loadImg("/edu/rpi/legup/imgs/file.png"); - public static final BufferedImage FLOPPY_DRIVE = loadImg("/edu/rpi/legup/imgs/floppy_drive.png"); + public static final BufferedImage FLOPPY_DRIVE = + loadImg("/edu/rpi/legup/imgs/floppy_drive.png"); public static final BufferedImage FOLDER = loadImg("/edu/rpi/legup/imgs/folder.png"); public static final BufferedImage HARD_DRIVE = loadImg("/edu/rpi/legup/imgs/hard_drive.png"); public static final BufferedImage HOME = loadImg("/edu/rpi/legup/imgs/home.png"); @@ -28,14 +36,12 @@ public class MaterialImages { public static final BufferedImage NEW_FOLDER = loadImg("/edu/rpi/legup/imgs/new_folder.png"); public static final BufferedImage DETAILS = loadImg("/edu/rpi/legup/imgs/details.png"); - private MaterialImages() { - } + private MaterialImages() {} private static BufferedImage loadImg(String imgPath) { try (InputStream inputStream = MaterialImages.class.getResourceAsStream(imgPath)) { return ImageIO.read(inputStream); - } - catch (IOException e) { + } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("Image " + imgPath + " wasn't loaded"); } diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/CaseRulePanel.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/CaseRulePanel.java index 5f22ac62c..1fb0a16ab 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/CaseRulePanel.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/CaseRulePanel.java @@ -10,8 +10,11 @@ public class CaseRulePanel extends RulePanel { */ CaseRulePanel(RuleFrame ruleFrame) { super(ruleFrame); - this.icon = new ImageIcon(ClassLoader.getSystemClassLoader().getResource("edu/rpi/legup/images/Legup/Case Rules.gif")); + this.icon = + new ImageIcon( + ClassLoader.getSystemClassLoader() + .getResource("edu/rpi/legup/images/Legup/Case Rules.gif")); this.name = "Case Rules"; this.toolTip = "Case Rules"; } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/CaseRuleSelectionView.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/CaseRuleSelectionView.java index 276583a99..ae9444db2 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/CaseRuleSelectionView.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/CaseRuleSelectionView.java @@ -1,9 +1,8 @@ package edu.rpi.legup.ui.proofeditorui.rulesview; import edu.rpi.legup.ui.WrapLayout; - -import javax.swing.*; import java.awt.*; +import javax.swing.*; public class CaseRuleSelectionView extends JPanel { diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/ContradictionRulePanel.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/ContradictionRulePanel.java index 908ffc49b..f695491fb 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/ContradictionRulePanel.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/ContradictionRulePanel.java @@ -10,7 +10,10 @@ public class ContradictionRulePanel extends RulePanel { */ ContradictionRulePanel(RuleFrame ruleFrame) { super(ruleFrame); - this.icon = new ImageIcon(ClassLoader.getSystemClassLoader().getResource("edu/rpi/legup/images/Legup/Contradictions.gif")); + this.icon = + new ImageIcon( + ClassLoader.getSystemClassLoader() + .getResource("edu/rpi/legup/images/Legup/Contradictions.gif")); this.name = "Contradiction Rules"; this.toolTip = "Contradiction Rules"; } diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/DirectRulePanel.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/DirectRulePanel.java index 3d0672525..2795f2df7 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/DirectRulePanel.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/DirectRulePanel.java @@ -1,22 +1,24 @@ -package edu.rpi.legup.ui.proofeditorui.rulesview; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import javax.swing.ImageIcon; - -public class DirectRulePanel extends RulePanel { - private static final Logger LOGGER = LogManager.getLogger(DirectRulePanel.class.getName()); - - /** - * DirectRulePanel Constructor creates a basic rule panel - * - * @param ruleFrame rule frame that this basic rule panel is contained in - */ - DirectRulePanel(RuleFrame ruleFrame) { - super(ruleFrame); - this.icon = new ImageIcon(ClassLoader.getSystemClassLoader().getResource("edu/rpi/legup/images/Legup/Direct Rules.gif")); - this.name = "Direct Rules"; - this.toolTip = "Direct Rules"; - } -} \ No newline at end of file +package edu.rpi.legup.ui.proofeditorui.rulesview; + +import javax.swing.ImageIcon; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class DirectRulePanel extends RulePanel { + private static final Logger LOGGER = LogManager.getLogger(DirectRulePanel.class.getName()); + + /** + * DirectRulePanel Constructor creates a basic rule panel + * + * @param ruleFrame rule frame that this basic rule panel is contained in + */ + DirectRulePanel(RuleFrame ruleFrame) { + super(ruleFrame); + this.icon = + new ImageIcon( + ClassLoader.getSystemClassLoader() + .getResource("edu/rpi/legup/images/Legup/Direct Rules.gif")); + this.name = "Direct Rules"; + this.toolTip = "Direct Rules"; + } +} diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RuleButton.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RuleButton.java index 30545f413..e9c274250 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RuleButton.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RuleButton.java @@ -1,7 +1,6 @@ package edu.rpi.legup.ui.proofeditorui.rulesview; import edu.rpi.legup.model.rules.Rule; - import javax.swing.*; public class RuleButton extends JButton { @@ -13,7 +12,9 @@ public class RuleButton extends JButton { * @param rule rule to create the button */ RuleButton(Rule rule) { - super(rule.getRuleName(), rule.getImageIcon()); // display rules' name under rule when load the icon + super( + rule.getRuleName(), + rule.getImageIcon()); // display rules' name under rule when load the icon this.rule = rule; this.setFocusPainted(false); } diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RuleFrame.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RuleFrame.java index 0fe03d476..6279f93a4 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RuleFrame.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RuleFrame.java @@ -5,12 +5,9 @@ import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.rules.Rule; import edu.rpi.legup.ui.lookandfeel.components.MaterialTabbedPaneUI; - import java.awt.BorderLayout; import java.awt.Dimension; - import javax.swing.*; - import javax.swing.border.TitledBorder; public class RuleFrame extends JPanel { @@ -33,13 +30,14 @@ public class RuleFrame extends JPanel { public RuleFrame(RuleController controller) { - MaterialTabbedPaneUI tabOverride = new MaterialTabbedPaneUI() { - //this prevents the tabs from moving around when you select them - @Override - protected boolean shouldRotateTabRuns(int i) { - return false; - } - }; + MaterialTabbedPaneUI tabOverride = + new MaterialTabbedPaneUI() { + // this prevents the tabs from moving around when you select them + @Override + protected boolean shouldRotateTabRuns(int i) { + return false; + } + }; this.controller = controller; @@ -51,7 +49,11 @@ protected boolean shouldRotateTabRuns(int i) { DirectRulePanel = new DirectRulePanel(this); JScrollPane newbrp = new JScrollPane(DirectRulePanel); newbrp.getVerticalScrollBar().setUnitIncrement(16); - tabbedPane.addTab(DirectRulePanel.getName(), DirectRulePanel.getIcon(), newbrp, DirectRulePanel.getToolTip()); + tabbedPane.addTab( + DirectRulePanel.getName(), + DirectRulePanel.getIcon(), + newbrp, + DirectRulePanel.getToolTip()); casePanel = new CaseRulePanel(this); JScrollPane newcp = new JScrollPane(casePanel); @@ -61,7 +63,8 @@ protected boolean shouldRotateTabRuns(int i) { contradictionPanel = new ContradictionRulePanel(this); JScrollPane newp = new JScrollPane(contradictionPanel); newp.getVerticalScrollBar().setUnitIncrement(16); - tabbedPane.addTab(contradictionPanel.name, contradictionPanel.icon, newp, contradictionPanel.toolTip); + tabbedPane.addTab( + contradictionPanel.name, contradictionPanel.icon, newp, contradictionPanel.toolTip); searchPanel = new SearchBarPanel(this); JScrollPane newsp = new JScrollPane(searchPanel); @@ -95,25 +98,20 @@ public void setSelectionByRule(Rule rule) { contradictionPanel.setSelectionByRule(rule); } - /** - * Reset the rules button and status string - */ + /** Reset the rules button and status string */ public void resetRuleButtons() { resetStatus(); } - /** - * Reset the status label to the empty string - */ + /** Reset the status label to the empty string */ public void resetStatus() { - //((GridUI)GameBoardFacade.getInstance().getLegupUI()).getTreePanel().updateStatus(); + // ((GridUI)GameBoardFacade.getInstance().getLegupUI()).getTreePanel().updateStatus(); } - /** - * Resets the dimension of the rule frame - */ + /** Resets the dimension of the rule frame */ public void resetSize() { - int buttonWidth = ((RulePanel) tabbedPane.getSelectedComponent()).getRuleButtons()[0].getWidth(); + int buttonWidth = + ((RulePanel) tabbedPane.getSelectedComponent()).getRuleButtons()[0].getWidth(); this.setMinimumSize(new Dimension(2 * buttonWidth + 64, this.getHeight())); } @@ -121,12 +119,12 @@ public void resetSize() { * Set the status label to a value. Use resetStatus to clear it. * * @param check true iff we want a check box, if false we'll have a red x box - * @param text the text we're setting the label to display + * @param text the text we're setting the label to display */ public void setStatus(boolean check, String text) { String box = (check ? checkBox : xBox); - //status.setText(htmlHead + box + text + htmlTail); - //((GridUI)GameBoardFacade.getInstance().getLegupUI()).getTreePanel().getStatus().setText(htmlHead + box + text + htmlTail); + // status.setText(htmlHead + box + text + htmlTail); + // ((GridUI)GameBoardFacade.getInstance().getLegupUI()).getTreePanel().getStatus().setText(htmlHead + box + text + htmlTail); } /** diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RulePanel.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RulePanel.java index f11fee5b4..5d985d5c2 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RulePanel.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/RulePanel.java @@ -3,12 +3,11 @@ import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.rules.Rule; import edu.rpi.legup.ui.WrapLayout; - -import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.ArrayList; import java.util.List; +import javax.swing.*; public abstract class RulePanel extends JPanel { protected ImageIcon icon; @@ -56,38 +55,37 @@ public void setRules(List rules) { Rule rule = rules.get(i); ruleButtons[i] = new RuleButton(rule); - ruleButtons[i].setPreferredSize(new Dimension(150, 150));// adjust the size of each RuleButton + ruleButtons[i].setPreferredSize( + new Dimension(150, 150)); // adjust the size of each RuleButton ruleButtons[i].setHorizontalTextPosition(JButton.CENTER); ruleButtons[i].setVerticalTextPosition(JButton.BOTTOM); ruleFrame.getButtonGroup().add(ruleButtons[i]); - ruleButtons[i].setToolTipText(rule.getRuleName() + ": " + rule.getDescription()); // showing description + ruleButtons[i].setToolTipText( + rule.getRuleName() + ": " + rule.getDescription()); // showing description ruleButtons[i].addActionListener(ruleFrame.getController()); add(ruleButtons[i]); - } revalidate(); } public void updateRules() { - for (Rule rule : rules){ + for (Rule rule : rules) { rule.loadImage(); } setRules(rules); } - /** * Search a certain rule in all the puzzles and set it for the searchBarPanel * * @param puzzle puzzle where the rule is being searched for * @param ruleName rule that is being compared to each puzzle - * - * This function is the searching algorithm for "public void setSearchBar(Puzzle allPuzzle)" (below) - * - * It takes two param Puzzle puzzle and String ruleName - * puzzle contains rules, this function will compare each rule of puzzle with ruleName, - * to find exact same, similar rules, or all the rules with same start letter (if input is a signal letter) + *

This function is the searching algorithm for "public void setSearchBar(Puzzle + * allPuzzle)" (below) + *

It takes two param Puzzle puzzle and String ruleName puzzle contains rules, this + * function will compare each rule of puzzle with ruleName, to find exact same, similar + * rules, or all the rules with same start letter (if input is a signal letter) */ public void searchForRule(Puzzle puzzle, String ruleName) { @@ -99,7 +97,6 @@ public void searchForRule(Puzzle puzzle, String ruleName) { ruleButtons = new RuleButton[100]; int similarfound = 0; - for (int i = 0; i < allrules.size(); i++) { for (int j = 0; j < allrules.get(i).size(); j++) { Rule rule = allrules.get(i).get(j); @@ -108,42 +105,46 @@ public void searchForRule(Puzzle puzzle, String ruleName) { ruleButtons[0] = new RuleButton(rule); ruleFrame.getButtonGroup().add(ruleButtons[0]); - ruleButtons[0].setPreferredSize(new Dimension(150, 150));// adjust the size of each RuleButton + ruleButtons[0].setPreferredSize( + new Dimension(150, 150)); // adjust the size of each RuleButton ruleButtons[0].setHorizontalTextPosition(JButton.CENTER); ruleButtons[0].setVerticalTextPosition(JButton.BOTTOM); - ruleButtons[0].setToolTipText(rule.getRuleName() + ": " + rule.getDescription()); + ruleButtons[0].setToolTipText( + rule.getRuleName() + ": " + rule.getDescription()); ruleButtons[0].addActionListener(ruleFrame.getController()); add(ruleButtons[0]); revalidate(); return; - } - else { + } else { if (similarityCheck(ruleName, rule.getRuleName().toUpperCase()) > 0.2) { ruleButtons[similarfound] = new RuleButton(rule); ruleFrame.getButtonGroup().add(ruleButtons[similarfound]); - ruleButtons[similarfound].setPreferredSize(new Dimension(150, 150));// adjust the size of each RuleButton + ruleButtons[similarfound].setPreferredSize( + new Dimension(150, 150)); // adjust the size of each RuleButton ruleButtons[similarfound].setHorizontalTextPosition(JButton.CENTER); ruleButtons[similarfound].setVerticalTextPosition(JButton.BOTTOM); - ruleButtons[similarfound].setToolTipText(rule.getRuleName() + ": " + rule.getDescription()); + ruleButtons[similarfound].setToolTipText( + rule.getRuleName() + ": " + rule.getDescription()); ruleButtons[similarfound].addActionListener(ruleFrame.getController()); add(ruleButtons[similarfound]); similarfound += 1; revalidate(); - } - else { + } else { if ((ruleName.charAt(0)) == (rule.getRuleName().toUpperCase()).charAt(0)) { ruleButtons[similarfound] = new RuleButton(rule); ruleFrame.getButtonGroup().add(ruleButtons[similarfound]); - ruleButtons[similarfound].setPreferredSize(new Dimension(150, 150));// adjust the size of each RuleButton + ruleButtons[similarfound].setPreferredSize( + new Dimension(150, 150)); // adjust the size of each RuleButton ruleButtons[similarfound].setHorizontalTextPosition(JButton.CENTER); ruleButtons[similarfound].setVerticalTextPosition(JButton.BOTTOM); - ruleButtons[similarfound].setToolTipText(rule.getRuleName() + ": " + rule.getDescription()); + ruleButtons[similarfound].setToolTipText( + rule.getRuleName() + ": " + rule.getDescription()); ruleButtons[similarfound].addActionListener(ruleFrame.getController()); add(ruleButtons[similarfound]); similarfound += 1; @@ -155,19 +156,24 @@ public void searchForRule(Puzzle puzzle, String ruleName) { } if (ruleButtons[0] == null) { - JOptionPane.showMessageDialog(null, "Please input the correct rule name", "Confirm", JOptionPane.INFORMATION_MESSAGE); + JOptionPane.showMessageDialog( + null, + "Please input the correct rule name", + "Confirm", + JOptionPane.INFORMATION_MESSAGE); } } /** - * Calculates the similarity (a number within 0 and 1) between two strings. - * This function will take two para String s1 and String s2, which s1 is the user's input - * and s2 is the compared really rule name + * Calculates the similarity (a number within 0 and 1) between two strings. This function will + * take two para String s1 and String s2, which s1 is the user's input and s2 is the compared + * really rule name + * * @param s1 user's input * @param s2 the compared really rule name - * @return a similarity degree between 0 and 1 - * similarityCheck will use a helper function to calculate a similarity degree(from 0 to 1). - * closer to 0 means less similar, and closer to 1 means more similar. + * @return a similarity degree between 0 and 1 similarityCheck will use a helper function to + * calculate a similarity degree(from 0 to 1). closer to 0 means less similar, and closer to + * 1 means more similar. */ public static double similarityCheck(String s1, String s2) { String longer = s1, shorter = s2; @@ -184,6 +190,7 @@ public static double similarityCheck(String s1, String s2) { /** * Help function for similarityCheck(); + * * @param s1 user's input * @param s2 the compared really rule name * @return a similarity degree between 0 and 1 @@ -198,8 +205,7 @@ public static int editDistance(String s1, String s2) { for (int j = 0; j <= s2.length(); j++) { if (i == 0) { costs[j] = j; - } - else { + } else { if (j > 0) { int newValue = costs[j - 1]; if (s1.charAt(i - 1) != s2.charAt(j - 1)) { @@ -218,23 +224,24 @@ public static int editDistance(String s1, String s2) { } /** - * Sets the search bar for SearchBarPanel - * search bar allows user to input a name to get relative rules - * once a name is entered and click ok will load (a/several) rule icon, - * which has all the functions just as other rule icons. + * Sets the search bar for SearchBarPanel search bar allows user to input a name to get relative + * rules once a name is entered and click ok will load (a/several) rule icon, which has all the + * functions just as other rule icons. + * * @param allPuzzle name of rule input */ public void setSearchBar(Puzzle allPuzzle) { searchBarPanel = new JPanel(new FlowLayout(SwingConstants.LEADING, 6, 6)); - textField=new JTextField(); - ruleFrame.addComponentListener(new ComponentAdapter() { - public void componentResized(ComponentEvent componentEvent) { - Component c= componentEvent.getComponent(); - textField.setColumns((8+(c.getWidth()-250)/10)-1); - } - }); + textField = new JTextField(); + ruleFrame.addComponentListener( + new ComponentAdapter() { + public void componentResized(ComponentEvent componentEvent) { + Component c = componentEvent.getComponent(); + textField.setColumns((8 + (c.getWidth() - 250) / 10) - 1); + } + }); add(searchBarPanel); JLabel findLabel = new JLabel("Search:"); @@ -243,37 +250,40 @@ public void componentResized(ComponentEvent componentEvent) { searchBarPanel.add(textField); searchBarPanel.add(Box.createRigidArea(new Dimension(1, 0))); JButton findButton = new JButton("Go"); - ActionListener action = new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - if (ruleButtons != null) { - for (int i = 0; i != ruleButtons.length; i++) { - if (ruleButtons[i] == null) { - continue; + ActionListener action = + new ActionListener() { + @Override + public void actionPerformed(ActionEvent event) { + if (ruleButtons != null) { + for (int i = 0; i != ruleButtons.length; i++) { + if (ruleButtons[i] == null) { + continue; + } + ruleButtons[i].removeActionListener(ruleFrame.getController()); + } } - ruleButtons[i].removeActionListener(ruleFrame.getController()); - } - } - String inputRule = textField.getText().toUpperCase().trim(); + String inputRule = textField.getText().toUpperCase().trim(); - if (!inputRule.isEmpty()) { - if (ruleButtons != null) { + if (!inputRule.isEmpty()) { + if (ruleButtons != null) { - for (int x = 0; x < ruleButtons.length; ++x) { - if (ruleButtons[x] == null) { - continue; + for (int x = 0; x < ruleButtons.length; ++x) { + if (ruleButtons[x] == null) { + continue; + } + remove(ruleButtons[x]); + } } - remove(ruleButtons[x]); + searchForRule(allPuzzle, inputRule); + } else { + JOptionPane.showMessageDialog( + null, + "Please give a name", + "Confirm", + JOptionPane.INFORMATION_MESSAGE); } } - searchForRule(allPuzzle, inputRule); - } - else { - JOptionPane.showMessageDialog(null, "Please give a name", "Confirm", JOptionPane.INFORMATION_MESSAGE); - } - - } - }; + }; textField.addActionListener(action); findButton.addActionListener(action); searchBarPanel.add(findButton); @@ -295,9 +305,7 @@ public void setSelectionByRule(Rule rule) { } } - /** - * Clears the rule buttons off this panel - */ + /** Clears the rule buttons off this panel */ protected void clearButtons() { if (ruleButtons != null) { removeAll(); @@ -341,4 +349,4 @@ public String getToolTip() { public void setToolTip(String toolTip) { this.toolTip = toolTip; } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/SearchBarPanel.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/SearchBarPanel.java index ff8a5d259..aba4707cd 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/SearchBarPanel.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/rulesview/SearchBarPanel.java @@ -7,12 +7,14 @@ public class SearchBarPanel extends RulePanel { * SearchBarPanel Constructor creates a SearchBarPanel * * @param ruleFrame rule frame that this SearchBarPanel is contained in - *

- * This class is used to create a panel named "search bar" + *

This class is used to create a panel named "search bar" */ SearchBarPanel(RuleFrame ruleFrame) { super(ruleFrame); - this.icon = new ImageIcon(ClassLoader.getSystemClassLoader().getResource("edu/rpi/legup/images/Legup/Zoom In.png")); + this.icon = + new ImageIcon( + ClassLoader.getSystemClassLoader() + .getResource("edu/rpi/legup/images/Legup/Zoom In.png")); this.name = "Search Rules"; this.toolTip = "Search Rules"; } diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeElementView.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeElementView.java index 676992654..33c04717d 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeElementView.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeElementView.java @@ -2,7 +2,6 @@ import edu.rpi.legup.model.tree.TreeElement; import edu.rpi.legup.model.tree.TreeElementType; - import java.awt.*; public abstract class TreeElementView implements Shape { @@ -18,7 +17,7 @@ public abstract class TreeElementView implements Shape { /** * TreeElementView Constructor creates a tree puzzleElement view * - * @param type tree puzzleElement type + * @param type tree puzzleElement type * @param treeElement tree puzzleElement puzzleElement associated with this view */ protected TreeElementView(TreeElementType type, TreeElement treeElement) { @@ -136,8 +135,8 @@ public void setHover(boolean isHovered) { } /** - * Gets the visibility of the tree puzzleElement. - * Tells the TreeView whether or not to draw the tree puzzleElement + * Gets the visibility of the tree puzzleElement. Tells the TreeView whether or not to draw the + * tree puzzleElement * * @return visibility of the tree puzzleElement */ diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeNodeView.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeNodeView.java index 2fce4d2d1..990d96620 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeNodeView.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeNodeView.java @@ -3,7 +3,6 @@ import edu.rpi.legup.model.rules.RuleType; import edu.rpi.legup.model.tree.TreeElementType; import edu.rpi.legup.model.tree.TreeNode; - import java.awt.*; import java.awt.geom.*; import java.util.ArrayList; @@ -31,7 +30,6 @@ public class TreeNodeView extends TreeElementView { private static final Color HOVER_COLOR = new Color(0x90CAF9); private static final Color OUTLINE_HOVER_COLOR = new Color(0xBDBDBD); - private Point location; private TreeTransitionView parentView; @@ -63,48 +61,69 @@ public TreeNodeView(TreeNode treeNode) { */ public void draw(Graphics2D graphics2D) { if (isVisible() && treeElement != null) { - if (getTreeElement().getParent() != null && - getTreeElement().getParent().isJustified() && - getTreeElement().getParent().getRule().getRuleType() == RuleType.CONTRADICTION) { + if (getTreeElement().getParent() != null + && getTreeElement().getParent().isJustified() + && getTreeElement().getParent().getRule().getRuleType() + == RuleType.CONTRADICTION) { isContradictoryState = true; graphics2D.setColor(NODE_COLOR_CONTRADICTION); - graphics2D.drawLine(location.x - RADIUS, location.y - RADIUS, location.x + RADIUS, location.y + RADIUS); - graphics2D.drawLine(location.x + RADIUS, location.y - RADIUS, location.x - RADIUS, location.y + RADIUS); - } - else { + graphics2D.drawLine( + location.x - RADIUS, + location.y - RADIUS, + location.x + RADIUS, + location.y + RADIUS); + graphics2D.drawLine( + location.x + RADIUS, + location.y - RADIUS, + location.x - RADIUS, + location.y + RADIUS); + } else { isContradictoryState = false; graphics2D.setStroke(MAIN_STROKE); boolean isContraBranch = getTreeElement().isContradictoryBranch(); if (isSelected) { graphics2D.setColor(SELECTION_COLOR); - graphics2D.fillOval(location.x - RADIUS, location.y - RADIUS, DIAMETER, DIAMETER); + graphics2D.fillOval( + location.x - RADIUS, location.y - RADIUS, DIAMETER, DIAMETER); graphics2D.setColor(OUTLINE_COLOR); - graphics2D.drawOval(location.x - RADIUS, location.y - RADIUS, DIAMETER, DIAMETER); + graphics2D.drawOval( + location.x - RADIUS, location.y - RADIUS, DIAMETER, DIAMETER); graphics2D.setStroke(SELECTION_STROKE); graphics2D.setColor(OUTLINE_SELECTION_COLOR); - graphics2D.drawOval(location.x - RADIUS - 4, location.y - RADIUS - 4, DIAMETER + 8, DIAMETER + 8); - } - else { + graphics2D.drawOval( + location.x - RADIUS - 4, + location.y - RADIUS - 4, + DIAMETER + 8, + DIAMETER + 8); + } else { if (isHover) { graphics2D.setColor(HOVER_COLOR); - graphics2D.fillOval(location.x - RADIUS, location.y - RADIUS, DIAMETER, DIAMETER); + graphics2D.fillOval( + location.x - RADIUS, location.y - RADIUS, DIAMETER, DIAMETER); graphics2D.setColor(OUTLINE_COLOR); - graphics2D.drawOval(location.x - RADIUS, location.y - RADIUS, DIAMETER, DIAMETER); + graphics2D.drawOval( + location.x - RADIUS, location.y - RADIUS, DIAMETER, DIAMETER); graphics2D.setStroke(SELECTION_STROKE); graphics2D.setColor(OUTLINE_HOVER_COLOR); - graphics2D.drawOval(location.x - RADIUS - 4, location.y - RADIUS - 4, DIAMETER + 8, DIAMETER + 8); - } - else { - graphics2D.setColor(isContraBranch ? NODE_COLOR_CONTRADICTION : NODE_COLOR_DEFAULT); - graphics2D.fillOval(location.x - RADIUS, location.y - RADIUS, DIAMETER, DIAMETER); + graphics2D.drawOval( + location.x - RADIUS - 4, + location.y - RADIUS - 4, + DIAMETER + 8, + DIAMETER + 8); + } else { + graphics2D.setColor( + isContraBranch ? NODE_COLOR_CONTRADICTION : NODE_COLOR_DEFAULT); + graphics2D.fillOval( + location.x - RADIUS, location.y - RADIUS, DIAMETER, DIAMETER); graphics2D.setColor(OUTLINE_COLOR); - graphics2D.drawOval(location.x - RADIUS, location.y - RADIUS, DIAMETER, DIAMETER); + graphics2D.drawOval( + location.x - RADIUS, location.y - RADIUS, DIAMETER, DIAMETER); } } } @@ -290,4 +309,4 @@ public PathIterator getPathIterator(AffineTransform at) { public PathIterator getPathIterator(AffineTransform at, double flatness) { return null; } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreePanel.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreePanel.java index ac7accaee..b6a29f2b5 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreePanel.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreePanel.java @@ -10,15 +10,11 @@ import edu.rpi.legup.model.tree.Tree; import edu.rpi.legup.ui.DynamicView; import edu.rpi.legup.ui.DynamicViewType; -import edu.rpi.legup.ui.LegupUI; import edu.rpi.legup.ui.lookandfeel.materialdesign.MaterialFonts; - import java.awt.*; - +import javax.swing.BorderFactory; import javax.swing.JLabel; import javax.swing.JPanel; - -import javax.swing.BorderFactory; import javax.swing.border.TitledBorder; public class TreePanel extends JPanel { @@ -33,8 +29,8 @@ public class TreePanel extends JPanel { private JLabel status; - public TreePanel(/*LegupUI legupUI*/) { - //this.legupUI = legupUI; + public TreePanel(/*LegupUI legupUI*/ ) { + // this.legupUI = legupUI; main = new JPanel(); @@ -72,7 +68,7 @@ public void boardDataChanged(Board board) { modifiedSinceSave = true; modifiedSinceUndoPush = true; updateStatus(); - //colorTransitions(); + // colorTransitions(); } public void updateStatus() { @@ -106,8 +102,7 @@ public void add() { if (add.canExecute()) { add.execute(); GameBoardFacade.getInstance().getHistory().pushChange(add); - } - else { + } else { updateError(add.getError()); } } @@ -119,8 +114,7 @@ public void delete() { if (del.canExecute()) { del.execute(); GameBoardFacade.getInstance().getHistory().pushChange(del); - } - else { + } else { updateError(del.getError()); } } @@ -132,8 +126,7 @@ public void merge() { if (merge.canExecute()) { merge.execute(); GameBoardFacade.getInstance().getHistory().pushChange(merge); - } - else { + } else { updateError(merge.getError()); } } diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeToolBarButton.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeToolBarButton.java index c2f40e21a..002092155 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeToolBarButton.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeToolBarButton.java @@ -1,7 +1,7 @@ package edu.rpi.legup.ui.proofeditorui.treeview; -import javax.swing.*; import java.awt.Dimension; +import javax.swing.*; public class TreeToolBarButton extends JButton { diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeToolBarName.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeToolBarName.java index dd8a37c15..c805021be 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeToolBarName.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeToolBarName.java @@ -1,5 +1,8 @@ package edu.rpi.legup.ui.proofeditorui.treeview; public enum TreeToolBarName { - ADD_CHILD, DEL_CHILD, MERGE, COLLAPSE + ADD_CHILD, + DEL_CHILD, + MERGE, + COLLAPSE } diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeToolbarPanel.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeToolbarPanel.java index 332fd64a0..8f3ebfc23 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeToolbarPanel.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeToolbarPanel.java @@ -1,7 +1,7 @@ package edu.rpi.legup.ui.proofeditorui.treeview; -import javax.swing.*; import java.awt.*; +import javax.swing.*; public class TreeToolbarPanel extends JPanel { private TreePanel treePanel; @@ -9,17 +9,37 @@ public class TreeToolbarPanel extends JPanel { /** * TreeToolbarPanel Constructor - creates the tree tool mBar panel + * * @param treePanel treePanel input */ public TreeToolbarPanel(TreePanel treePanel) { this.treePanel = treePanel; this.setLayout(new GridLayout(4, 1, 0, 2)); - - addChild = new TreeToolBarButton(new ImageIcon(ClassLoader.getSystemResource("edu/rpi/legup/images/Legup/AddChild.png")), TreeToolBarName.ADD_CHILD); - delChild = new TreeToolBarButton(new ImageIcon(ClassLoader.getSystemResource("edu/rpi/legup/images/Legup/DelChild.png")), TreeToolBarName.DEL_CHILD); - merge = new TreeToolBarButton(new ImageIcon(ClassLoader.getSystemResource("edu/rpi/legup/images/Legup/Merge.png")), TreeToolBarName.MERGE); - collapse = new TreeToolBarButton(new ImageIcon(ClassLoader.getSystemResource("edu/rpi/legup/images/Legup/Collapse.png")), TreeToolBarName.COLLAPSE); + addChild = + new TreeToolBarButton( + new ImageIcon( + ClassLoader.getSystemResource( + "edu/rpi/legup/images/Legup/AddChild.png")), + TreeToolBarName.ADD_CHILD); + delChild = + new TreeToolBarButton( + new ImageIcon( + ClassLoader.getSystemResource( + "edu/rpi/legup/images/Legup/DelChild.png")), + TreeToolBarName.DEL_CHILD); + merge = + new TreeToolBarButton( + new ImageIcon( + ClassLoader.getSystemResource( + "edu/rpi/legup/images/Legup/Merge.png")), + TreeToolBarName.MERGE); + collapse = + new TreeToolBarButton( + new ImageIcon( + ClassLoader.getSystemResource( + "edu/rpi/legup/images/Legup/Collapse.png")), + TreeToolBarName.COLLAPSE); add(addChild); addChild.addActionListener(a -> treePanel.add()); @@ -38,4 +58,4 @@ public TreeToolbarPanel(TreePanel treePanel) { collapse.setToolTipText("Collapse nodes"); collapse.setEnabled(false); } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeTransitionView.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeTransitionView.java index 749af0c79..b022ac596 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeTransitionView.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeTransitionView.java @@ -1,15 +1,14 @@ package edu.rpi.legup.ui.proofeditorui.treeview; +import static java.lang.Math.*; + +import edu.rpi.legup.app.LegupPreferences; import edu.rpi.legup.model.tree.TreeElementType; import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.app.LegupPreferences; - import java.awt.*; import java.awt.geom.*; -import java.util.List; import java.util.ArrayList; - -import static java.lang.Math.*; +import java.util.List; public class TreeTransitionView extends TreeElementView { static final int RADIUS = 25; @@ -86,8 +85,15 @@ public void draw(Graphics2D graphics2D) { double ctrlx2 = lineEndPoint.x - 25; double ctrly2 = lineEndPoint.y; - c.setCurve(lineStartPoint.x, lineStartPoint.y, ctrlx1, - ctrly1, ctrlx2, ctrly2, lineEndPoint.x, lineEndPoint.y); + c.setCurve( + lineStartPoint.x, + lineStartPoint.y, + ctrlx1, + ctrly1, + ctrlx2, + ctrly2, + lineEndPoint.x, + lineEndPoint.y); graphics2D.draw(c); } @@ -100,16 +106,13 @@ public void draw(Graphics2D graphics2D) { if (getTreeElement().isCorrect()) { if (colorBlind) { c = CORRECT_COLOR_COLORBLIND; - } - else { + } else { c = CORRECT_COLOR; } - } - else { + } else { if (colorBlind) { c = INCORRECT_COLOR_COLORBLIND; - } - else { + } else { c = INCORRECT_COLOR; } } @@ -127,8 +130,7 @@ public void draw(Graphics2D graphics2D) { graphics2D.setStroke(SELECTION_STROKE); graphics2D.setColor(OUTLINE_SELECTION_COLOR); graphics2D.drawPolygon(selection_triangle); - } - else { + } else { if (isHover) { graphics2D.setColor(HOVER_COLOR); graphics2D.fillPolygon(arrowhead); @@ -142,23 +144,19 @@ public void draw(Graphics2D graphics2D) { graphics2D.setStroke(SELECTION_STROKE); graphics2D.setColor(OUTLINE_HOVER_COLOR); graphics2D.drawPolygon(selection_triangle); - } - else { + } else { Color c = DEFAULT_COLOR; if (getTreeElement().isJustified()) { if (getTreeElement().isCorrect()) { if (colorBlind) { c = CORRECT_COLOR_COLORBLIND; - } - else { + } else { c = CORRECT_COLOR; } - } - else { + } else { if (colorBlind) { c = INCORRECT_COLOR_COLORBLIND; - } - else { + } else { c = INCORRECT_COLOR; } } @@ -172,9 +170,7 @@ public void draw(Graphics2D graphics2D) { } } - /** - * Constructs the arrowhead shape from the start and end points - */ + /** Constructs the arrowhead shape from the start and end points */ private Polygon createTransitionTriangle(int radius) { double thetaArrow = Math.toRadians(30); diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeView.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeView.java index 9bfffe60a..f491009b4 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeView.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeView.java @@ -1,9 +1,13 @@ package edu.rpi.legup.ui.proofeditorui.treeview; +import static edu.rpi.legup.model.tree.TreeElementType.NODE; +import static edu.rpi.legup.model.tree.TreeElementType.TRANSITION; +import static edu.rpi.legup.ui.proofeditorui.treeview.TreeNodeView.DIAMETER; +import static edu.rpi.legup.ui.proofeditorui.treeview.TreeNodeView.RADIUS; + import edu.rpi.legup.app.GameBoardFacade; import edu.rpi.legup.controller.TreeController; import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.GridCell; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.observer.ITreeListener; import edu.rpi.legup.model.rules.CaseRule; @@ -14,23 +18,16 @@ import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.ui.ScrollView; import edu.rpi.legup.utility.DisjointSets; - -import javax.swing.*; import java.awt.*; import java.awt.image.BufferedImage; import java.util.*; import java.util.List; - +import javax.swing.*; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import static edu.rpi.legup.model.tree.TreeElementType.NODE; -import static edu.rpi.legup.model.tree.TreeElementType.TRANSITION; -import static edu.rpi.legup.ui.proofeditorui.treeview.TreeNodeView.DIAMETER; -import static edu.rpi.legup.ui.proofeditorui.treeview.TreeNodeView.RADIUS; - public class TreeView extends ScrollView implements ITreeListener { - private final static Logger LOGGER = LogManager.getLogger(TreeView.class.getName()); + private static final Logger LOGGER = LogManager.getLogger(TreeView.class.getName()); private static final int TRANS_GAP = 5; @@ -88,7 +85,8 @@ public void setNodeHover(TreeNodeView nodeHover) { } /** - * Gets the TreeElementView by the specified point or null if no view exists at the specified point + * Gets the TreeElementView by the specified point or null if no view exists at the specified + * point * * @param point location to query for a view * @return TreeElementView at the point specified, otherwise null @@ -98,25 +96,24 @@ public TreeElementView getTreeElementView(Point point) { } /** - * Recursively gets the TreeElementView by the specified point or null if no view exists at the specified point or - * the view specified is null + * Recursively gets the TreeElementView by the specified point or null if no view exists at the + * specified point or the view specified is null * - * @param point location to query for a view + * @param point location to query for a view * @param elementView view to determine if the point is contained within it * @return TreeElementView at the point specified, otherwise null */ private TreeElementView getTreeElementView(Point point, TreeElementView elementView) { if (elementView == null) { return null; - } - else { + } else { if (elementView.contains(point) && elementView.isVisible()) { - if (elementView.getType() == NODE && ((TreeNodeView) elementView).isContradictoryState()) { + if (elementView.getType() == NODE + && ((TreeNodeView) elementView).isContradictoryState()) { return null; } return elementView; - } - else { + } else { if (elementView.getType() == NODE) { TreeNodeView nodeView = (TreeNodeView) elementView; for (TreeTransitionView transitionView : nodeView.getChildrenViews()) { @@ -125,8 +122,7 @@ private TreeElementView getTreeElementView(Point point, TreeElementView elementV return view; } } - } - else { + } else { TreeTransitionView transitionView = (TreeTransitionView) elementView; return getTreeElementView(point, transitionView.getChildView()); } @@ -220,15 +216,17 @@ public void draw(Graphics2D graphics2D) { currentStateBoxes.clear(); Tree tree = GameBoardFacade.getInstance().getTree(); if (tree != null) { - //setSize(bounds.getDimension()); - graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + // setSize(bounds.getDimension()); + graphics2D.setRenderingHint( + RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + graphics2D.setRenderingHint( + RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); drawTree(graphics2D); dimension.width += BORDER_SPACING; setSize(dimension); -// graphics2D.drawRect(0,0, dimension.width, dimension.height); + // graphics2D.drawRect(0,0, dimension.width, dimension.height); if (selection.getHover() != null) { drawMouseOver(graphics2D); @@ -255,10 +253,11 @@ public void removeTreeElement(TreeElementView view) { if (view.getType() == NODE) { TreeNodeView nodeView = (TreeNodeView) view; nodeView.getParentView().setChildView(null); - } - else { + } else { TreeTransitionView transitionView = (TreeTransitionView) view; - transitionView.getParentViews().forEach((TreeNodeView n) -> n.removeChildrenView(transitionView)); + transitionView + .getParentViews() + .forEach((TreeNodeView n) -> n.removeChildrenView(transitionView)); } } @@ -268,13 +267,16 @@ public void removeTreeElement(TreeElementView view) { * @param g the graphics to use to draw */ public void drawMouseOver(Graphics2D g) { - if (selection.getHover().getType() == TRANSITION && ((TreeTransitionView) selection.getHover()).getTreeElement().isJustified()) { + if (selection.getHover().getType() == TRANSITION + && ((TreeTransitionView) selection.getHover()).getTreeElement().isJustified()) { TreeTransition transition = (TreeTransition) selection.getHover().treeElement; int imgWidth = 100; int imgHeight = 100; - BufferedImage image = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_ARGB); - image.createGraphics().drawImage(transition.getRule().getImageIcon().getImage(), 0, 0, null); + BufferedImage image = + new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_ARGB); + image.createGraphics() + .drawImage(transition.getRule().getImageIcon().getImage(), 0, 0, null); Point mousePoint = selection.getMousePoint(); g.drawImage(image, mousePoint.x, mousePoint.y - 50, imgWidth, imgHeight, null); } @@ -296,8 +298,7 @@ public void resetView() { public void onTreeElementAdded(TreeElement treeElement) { if (treeElement.getType() == NODE) { addTreeNode((TreeNode) treeElement); - } - else { + } else { addTreeTransition((TreeTransition) treeElement); } repaint(); @@ -316,8 +317,7 @@ public void onTreeElementRemoved(TreeElement element) { nodeView.getParentView().setChildView(null); removeTreeNode(node); - } - else { + } else { TreeTransition trans = (TreeTransition) element; TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); @@ -330,7 +330,7 @@ public void onTreeElementRemoved(TreeElement element) { continue; } - CaseRule caseRule = (CaseRule)rule; + CaseRule caseRule = (CaseRule) rule; // set dependent elements to be modifiable by ancestors (if not dependent on others) List ancestors = node.getAncestors(); for (TreeNode ancestor : ancestors) { @@ -339,22 +339,29 @@ public void onTreeElementRemoved(TreeElement element) { continue; } - for (PuzzleElement pelement : caseRule.dependentElements(node.getBoard(), trans.getSelection())) { + for (PuzzleElement pelement : + caseRule.dependentElements(node.getBoard(), trans.getSelection())) { // decrement, unlock if 0 cases depended - PuzzleElement oldElement = ancestor.getParent().getBoard().getPuzzleElement(pelement); + PuzzleElement oldElement = + ancestor.getParent().getBoard().getPuzzleElement(pelement); oldElement.setCasesDepended(oldElement.getCasesDepended() - 1); if (oldElement.getCasesDepended() != 0) { - continue; + continue; } // set modifiable if started modifiable - boolean modifiable = tree.getRootNode().getBoard().getPuzzleElement(oldElement).isModifiable(); + boolean modifiable = + tree.getRootNode() + .getBoard() + .getPuzzleElement(oldElement) + .isModifiable(); // unmodifiable if already modified TreeNode modNode = ancestor.getParent().getParents().get(0); - while (modNode.getParent()!=null) { + while (modNode.getParent() != null) { Board modBoard = modNode.getParent().getBoard(); - if (modBoard.getModifiedData().contains(modBoard.getPuzzleElement(oldElement))) { + if (modBoard.getModifiedData() + .contains(modBoard.getPuzzleElement(oldElement))) { modifiable = false; break; } @@ -364,7 +371,7 @@ public void onTreeElementRemoved(TreeElement element) { } } } - + transView.getParentViews().forEach(n -> n.removeChildrenView(transView)); removeTreeTransition(trans); } @@ -384,9 +391,7 @@ public void onTreeSelectionChanged(TreeViewSelection selection) { repaint(); } - /** - * Called when the model has finished updating the tree. - */ + /** Called when the model has finished updating the tree. */ @Override public void onUpdateTree() { repaint(); @@ -410,7 +415,7 @@ private void removeTreeNode(TreeNode node) { if (!children.isEmpty()) { Rule rule = children.get(0).getRule(); if (rule instanceof CaseRule) { - CaseRule caseRule = (CaseRule)rule; + CaseRule caseRule = (CaseRule) rule; // set dependent elements to be modifiable by ancestors (if not dependent on others) List ancestors = node.getAncestors(); for (TreeNode ancestor : ancestors) { @@ -418,22 +423,30 @@ private void removeTreeNode(TreeNode node) { if (ancestor.getParent() == null) { continue; } - for (PuzzleElement pelement : caseRule.dependentElements(node.getBoard(), children.get(0).getSelection())) { + for (PuzzleElement pelement : + caseRule.dependentElements( + node.getBoard(), children.get(0).getSelection())) { // decrement, unlock if 0 cases depended - PuzzleElement oldElement = ancestor.getParent().getBoard().getPuzzleElement(pelement); + PuzzleElement oldElement = + ancestor.getParent().getBoard().getPuzzleElement(pelement); oldElement.setCasesDepended(oldElement.getCasesDepended() - 1); if (oldElement.getCasesDepended() == 0) { continue; } // set modifiable if started modifiable - boolean modifiable = tree.getRootNode().getBoard().getPuzzleElement(oldElement).isModifiable(); + boolean modifiable = + tree.getRootNode() + .getBoard() + .getPuzzleElement(oldElement) + .isModifiable(); // unmodifiable if already modified TreeNode modNode = ancestor.getParent().getParents().get(0); while (modNode.getParent() != null) { Board modBoard = modNode.getParent().getBoard(); - if (modBoard.getModifiedData().contains(modBoard.getPuzzleElement(oldElement))) { + if (modBoard.getModifiedData() + .contains(modBoard.getPuzzleElement(oldElement))) { modifiable = false; break; } @@ -466,11 +479,11 @@ private void addTreeNode(TreeNode node) { viewMap.put(node, nodeView); if (!node.getChildren().isEmpty()) { - + // if adding a case rule, lock dependent ancestor elements Rule rule = node.getChildren().get(0).getRule(); if (rule instanceof CaseRule) { - CaseRule caseRule = (CaseRule)rule; + CaseRule caseRule = (CaseRule) rule; List ancestors = node.getAncestors(); for (TreeNode ancestor : ancestors) { @@ -478,15 +491,18 @@ private void addTreeNode(TreeNode node) { if (ancestor.getParent() == null) { continue; } - for (PuzzleElement element : caseRule.dependentElements(node.getBoard(), node.getChildren().get(0).getSelection())) { + for (PuzzleElement element : + caseRule.dependentElements( + node.getBoard(), node.getChildren().get(0).getSelection())) { // increment and lock - PuzzleElement oldElement = ancestor.getParent().getBoard().getPuzzleElement(element); - oldElement.setCasesDepended(oldElement.getCasesDepended()+1); + PuzzleElement oldElement = + ancestor.getParent().getBoard().getPuzzleElement(element); + oldElement.setCasesDepended(oldElement.getCasesDepended() + 1); oldElement.setModifiable(false); } } } - + node.getChildren().forEach(t -> addTreeTransition(t)); } } @@ -499,11 +515,11 @@ private void addTreeTransition(TreeTransition trans) { TreeNodeView parentNodeView = (TreeNodeView) viewMap.get(parent); transView.addParentView(parentNodeView); parentNodeView.addChildrenView(transView); - + // if transition is a new case rule, lock dependent ancestor elements Rule rule = trans.getRule(); - if (rule instanceof CaseRule && parent.getChildren().size()==1) { - CaseRule caseRule = (CaseRule)rule; + if (rule instanceof CaseRule && parent.getChildren().size() == 1) { + CaseRule caseRule = (CaseRule) rule; List ancestors = parent.getAncestors(); for (TreeNode ancestor : ancestors) { @@ -511,10 +527,12 @@ private void addTreeTransition(TreeTransition trans) { if (ancestor.getParent() == null) { continue; } - for (PuzzleElement element : caseRule.dependentElements(parent.getBoard(), trans.getSelection())) { + for (PuzzleElement element : + caseRule.dependentElements(parent.getBoard(), trans.getSelection())) { // increment and lock - PuzzleElement oldElement = ancestor.getParent().getBoard().getPuzzleElement(element); - oldElement.setCasesDepended(oldElement.getCasesDepended()+1); + PuzzleElement oldElement = + ancestor.getParent().getBoard().getPuzzleElement(element); + oldElement.setCasesDepended(oldElement.getCasesDepended() + 1); oldElement.setModifiable(false); } } @@ -528,13 +546,12 @@ private void addTreeTransition(TreeTransition trans) { } } - ///New Draw Methods + /// New Draw Methods public void drawTree(Graphics2D graphics2D) { if (tree == null) { LOGGER.error("Unable to draw tree."); - } - else { + } else { if (rootNodeView == null) { rootNodeView = new TreeNodeView(tree.getRootNode()); @@ -596,52 +613,29 @@ public void calculateViewLocations(TreeNodeView nodeView, int depth) { dimension.width = Math.max(dimension.width, xLoc); TreeTransitionView parentTransView = nodeView.getParentView(); - int yLoc = parentTransView == null ? (int) nodeView.getSpan() / 2 : parentTransView.getEndY(); + int yLoc = + parentTransView == null ? (int) nodeView.getSpan() / 2 : parentTransView.getEndY(); nodeView.setY(yLoc); ArrayList children = nodeView.getChildrenViews(); switch (children.size()) { case 0: break; - case 1: { - TreeTransitionView childView = children.get(0); - - List parentsViews = childView.getParentViews(); - if (parentsViews.size() == 1) { - childView.setEndY(yLoc); + case 1: + { + TreeTransitionView childView = children.get(0); - childView.setDepth(depth); - - Point lineStartPoint = childView.getLineStartPoint(0); - lineStartPoint.x = xLoc + RADIUS + TRANS_GAP / 2; - lineStartPoint.y = yLoc; - childView.setEndX((NODE_GAP_WIDTH + DIAMETER) * (depth + 1) + RADIUS - TRANS_GAP / 2); - - dimension.width = Math.max(dimension.width, childView.getEndX()); - - TreeNodeView childNodeView = childView.getChildView(); - if (childNodeView != null) { - calculateViewLocations(childNodeView, depth + 1); - } - } - else { - if (parentsViews.size() > 1 && parentsViews.get(parentsViews.size() - 1) == nodeView) { - int yAvg = 0; - for (int i = 0; i < parentsViews.size(); i++) { - TreeNodeView parentNodeView = parentsViews.get(i); - depth = Math.max(depth, parentNodeView.getDepth()); - yAvg += parentNodeView.getY(); - - Point lineStartPoint = childView.getLineStartPoint(i); - lineStartPoint.x = parentNodeView.getX() + RADIUS + TRANS_GAP / 2; - lineStartPoint.y = parentNodeView.getY(); - } - yAvg /= parentsViews.size(); - childView.setEndY(yAvg); + List parentsViews = childView.getParentViews(); + if (parentsViews.size() == 1) { + childView.setEndY(yLoc); childView.setDepth(depth); - childView.setEndX((NODE_GAP_WIDTH + DIAMETER) * (depth + 1) + RADIUS - TRANS_GAP / 2); + Point lineStartPoint = childView.getLineStartPoint(0); + lineStartPoint.x = xLoc + RADIUS + TRANS_GAP / 2; + lineStartPoint.y = yLoc; + childView.setEndX( + (NODE_GAP_WIDTH + DIAMETER) * (depth + 1) + RADIUS - TRANS_GAP / 2); dimension.width = Math.max(dimension.width, childView.getEndX()); @@ -649,36 +643,71 @@ public void calculateViewLocations(TreeNodeView nodeView, int depth) { if (childNodeView != null) { calculateViewLocations(childNodeView, depth + 1); } + } else { + if (parentsViews.size() > 1 + && parentsViews.get(parentsViews.size() - 1) == nodeView) { + int yAvg = 0; + for (int i = 0; i < parentsViews.size(); i++) { + TreeNodeView parentNodeView = parentsViews.get(i); + depth = Math.max(depth, parentNodeView.getDepth()); + yAvg += parentNodeView.getY(); + + Point lineStartPoint = childView.getLineStartPoint(i); + lineStartPoint.x = parentNodeView.getX() + RADIUS + TRANS_GAP / 2; + lineStartPoint.y = parentNodeView.getY(); + } + yAvg /= parentsViews.size(); + childView.setEndY(yAvg); + + childView.setDepth(depth); + + childView.setEndX( + (NODE_GAP_WIDTH + DIAMETER) * (depth + 1) + + RADIUS + - TRANS_GAP / 2); + + dimension.width = Math.max(dimension.width, childView.getEndX()); + + TreeNodeView childNodeView = childView.getChildView(); + if (childNodeView != null) { + calculateViewLocations(childNodeView, depth + 1); + } + } } + break; } - break; - } - default: { - int span = 0; - for (TreeTransitionView childView : children) { - span += childView.getSpan(); - } - - span = (int) ((nodeView.getSpan() - span) / 2); - for (int i = 0; i < children.size(); i++) { - TreeTransitionView childView = children.get(i); + default: + { + int span = 0; + for (TreeTransitionView childView : children) { + span += childView.getSpan(); + } - childView.setDepth(depth); + span = (int) ((nodeView.getSpan() - span) / 2); + for (int i = 0; i < children.size(); i++) { + TreeTransitionView childView = children.get(i); - Point lineStartPoint = childView.getLineStartPoint(0); - lineStartPoint.x = xLoc + RADIUS + TRANS_GAP / 2; - lineStartPoint.y = yLoc; - childView.setEndX((NODE_GAP_WIDTH + DIAMETER) * (depth + 1) + RADIUS - TRANS_GAP / 2); - childView.setEndY(yLoc - (int) (nodeView.getSpan() / 2) + span + (int) (childView.getSpan() / 2)); + childView.setDepth(depth); - span += childView.getSpan(); - TreeNodeView childNodeView = childView.getChildView(); - if (childNodeView != null) { - calculateViewLocations(childNodeView, depth + 1); + Point lineStartPoint = childView.getLineStartPoint(0); + lineStartPoint.x = xLoc + RADIUS + TRANS_GAP / 2; + lineStartPoint.y = yLoc; + childView.setEndX( + (NODE_GAP_WIDTH + DIAMETER) * (depth + 1) + RADIUS - TRANS_GAP / 2); + childView.setEndY( + yLoc + - (int) (nodeView.getSpan() / 2) + + span + + (int) (childView.getSpan() / 2)); + + span += childView.getSpan(); + TreeNodeView childNodeView = childView.getChildView(); + if (childNodeView != null) { + calculateViewLocations(childNodeView, depth + 1); + } } + break; } - break; - } } } @@ -688,19 +717,16 @@ public void calcSpan(TreeElementView view) { TreeNode node = nodeView.getTreeElement(); if (nodeView.getChildrenViews().size() == 0) { nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } - else { + } else { if (nodeView.getChildrenViews().size() == 1) { TreeTransitionView childView = nodeView.getChildrenViews().get(0); calcSpan(childView); if (childView.getParentViews().size() > 1) { nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } - else { + } else { nodeView.setSpan(childView.getSpan()); } - } - else { + } else { DisjointSets branches = node.findMergingBranches(); List children = node.getChildren(); @@ -719,17 +745,18 @@ public void calcSpan(TreeElementView view) { for (Set mergeSet : mergingSets) { if (mergeSet.size() > 1) { TreeTransition mergePoint = TreeNode.findMergingPoint(mergeSet); - TreeTransitionView mergePointView = (TreeTransitionView) viewMap.get(mergePoint); + TreeTransitionView mergePointView = + (TreeTransitionView) viewMap.get(mergePoint); double subSpan = 0.0; for (TreeTransition branch : mergeSet) { - TreeTransitionView branchView = (TreeTransitionView) viewMap.get(branch); + TreeTransitionView branchView = + (TreeTransitionView) viewMap.get(branch); subCalcSpan(branchView, mergePointView); subSpan += branchView.getSpan(); } calcSpan(mergePointView); span += Math.max(mergePointView.getSpan(), subSpan); - } - else { + } else { TreeTransition trans = mergeSet.iterator().next(); TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); calcSpan(transView); @@ -739,14 +766,12 @@ public void calcSpan(TreeElementView view) { nodeView.setSpan(span); } } - } - else { + } else { TreeTransitionView transView = (TreeTransitionView) view; TreeNodeView nodeView = transView.getChildView(); if (nodeView == null) { transView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } - else { + } else { calcSpan(nodeView); transView.setSpan(nodeView.getSpan()); } @@ -754,14 +779,15 @@ public void calcSpan(TreeElementView view) { } /** - * Calculates the sub span of a given sub tree rooted at the specified view and stops at the tree puzzleElement view - * specified as stop. Stop tree puzzleElement is NOT included in the span calculation + * Calculates the sub span of a given sub tree rooted at the specified view and stops at the + * tree puzzleElement view specified as stop. Stop tree puzzleElement is NOT included in the + * span calculation * * @param view * @param stop */ private void subCalcSpan(TreeElementView view, TreeElementView stop) { - //safe-guard for infinite loop + // safe-guard for infinite loop if (view == stop) { return; } @@ -771,24 +797,20 @@ private void subCalcSpan(TreeElementView view, TreeElementView stop) { TreeNode node = nodeView.getTreeElement(); if (nodeView.getChildrenViews().size() == 0) { nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } - else { + } else { if (nodeView.getChildrenViews().size() == 1) { TreeTransitionView childView = nodeView.getChildrenViews().get(0); if (childView == stop) { nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } - else { + } else { subCalcSpan(childView, stop); if (childView.getParentViews().size() > 1) { nodeView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } - else { + } else { nodeView.setSpan(childView.getSpan()); } } - } - else { + } else { DisjointSets branches = node.findMergingBranches(); List children = node.getChildren(); @@ -802,17 +824,18 @@ private void subCalcSpan(TreeElementView view, TreeElementView stop) { for (Set mergeSet : mergingSets) { if (mergeSet.size() > 1) { TreeTransition mergePoint = TreeNode.findMergingPoint(mergeSet); - TreeTransitionView mergePointView = (TreeTransitionView) viewMap.get(mergePoint); + TreeTransitionView mergePointView = + (TreeTransitionView) viewMap.get(mergePoint); double subSpan = 0.0; for (TreeTransition branch : mergeSet) { - TreeTransitionView branchView = (TreeTransitionView) viewMap.get(branch); + TreeTransitionView branchView = + (TreeTransitionView) viewMap.get(branch); subCalcSpan(branchView, mergePointView); subSpan += branchView.getSpan(); } subCalcSpan(mergePointView, stop); span += Math.max(mergePointView.getSpan(), subSpan); - } - else { + } else { TreeTransition trans = mergeSet.iterator().next(); TreeTransitionView transView = (TreeTransitionView) viewMap.get(trans); subCalcSpan(transView, stop); @@ -823,14 +846,12 @@ private void subCalcSpan(TreeElementView view, TreeElementView stop) { nodeView.setSpan(span); } } - } - else { + } else { TreeTransitionView transView = (TreeTransitionView) view; TreeNodeView nodeView = transView.getChildView(); if (nodeView == null || nodeView == stop) { transView.setSpan(DIAMETER + NODE_GAP_HEIGHT); - } - else { + } else { calcSpan(nodeView); transView.setSpan(nodeView.getSpan()); } @@ -838,11 +859,12 @@ private void subCalcSpan(TreeElementView view, TreeElementView stop) { } /** - * Reorders branches such that merging branches are sequentially grouped together and transitions are kept in - * relative order in the list of child transitions of the specified node + * Reorders branches such that merging branches are sequentially grouped together and + * transitions are kept in relative order in the list of child transitions of the specified node * - * @param node root node of the branches - * @param branches DisjointSets of the child branches of the specified node which determine which branches merge + * @param node root node of the branches + * @param branches DisjointSets of the child branches of the specified node which determine + * which branches merge */ private void reorderBranches(TreeNode node, DisjointSets branches) { List children = node.getChildren(); @@ -852,35 +874,38 @@ private void reorderBranches(TreeNode node, DisjointSets branche for (Set set : mergingSets) { List mergeBranch = new ArrayList<>(); newOrder.add(mergeBranch); - children.forEach(t -> { - if (set.contains(t)) { - mergeBranch.add(t); - } - }); - mergeBranch.sort((TreeTransition t1, TreeTransition t2) -> - children.indexOf(t1) <= children.indexOf(t2) ? -1 : 1); + children.forEach( + t -> { + if (set.contains(t)) { + mergeBranch.add(t); + } + }); + mergeBranch.sort( + (TreeTransition t1, TreeTransition t2) -> + children.indexOf(t1) <= children.indexOf(t2) ? -1 : 1); } - newOrder.sort((List b1, List b2) -> { - int low1 = -1; - int low2 = -1; - for (TreeTransition t1 : b1) { - int curIndex = children.indexOf(t1); - if (low1 == -1 || curIndex < low1) { - low1 = curIndex; - } - } - for (TreeTransition t1 : b2) { - int curIndex = children.indexOf(t1); - if (low1 == -1 || curIndex < low1) { - low1 = curIndex; - } - } - return low1 < low2 ? -1 : 1; - }); + newOrder.sort( + (List b1, List b2) -> { + int low1 = -1; + int low2 = -1; + for (TreeTransition t1 : b1) { + int curIndex = children.indexOf(t1); + if (low1 == -1 || curIndex < low1) { + low1 = curIndex; + } + } + for (TreeTransition t1 : b2) { + int curIndex = children.indexOf(t1); + if (low1 == -1 || curIndex < low1) { + low1 = curIndex; + } + } + return low1 < low2 ? -1 : 1; + }); List newChildren = new ArrayList<>(); newOrder.forEach(l -> newChildren.addAll(l)); node.setChildren(newChildren); } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeViewSelection.java b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeViewSelection.java index 042eb8880..71a65b49e 100644 --- a/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeViewSelection.java +++ b/src/main/java/edu/rpi/legup/ui/proofeditorui/treeview/TreeViewSelection.java @@ -1,17 +1,15 @@ package edu.rpi.legup.ui.proofeditorui.treeview; import java.awt.*; -import java.util.List; import java.util.ArrayList; +import java.util.List; public class TreeViewSelection { private ArrayList selectedViews; private TreeElementView hover; private Point mousePoint; - /** - * TreeViewSelection Constructor creates a tree view selection - */ + /** TreeViewSelection Constructor creates a tree view selection */ public TreeViewSelection() { this.selectedViews = new ArrayList<>(); this.hover = null; @@ -38,7 +36,6 @@ public TreeViewSelection(List views) { this.selectedViews.addAll(views); } - /** * Gets the list of selected tree puzzleElement views * @@ -66,8 +63,7 @@ public void toggleSelection(TreeElementView treeElementView) { if (selectedViews.contains(treeElementView)) { selectedViews.remove(treeElementView); treeElementView.setSelected(false); - } - else { + } else { selectedViews.add(treeElementView); treeElementView.setSelected(true); } @@ -96,9 +92,7 @@ public void newSelection(TreeElementView treeElementView) { treeElementView.setSelected(true); } - /** - * Clears all selected views - */ + /** Clears all selected views */ public void clearSelection() { for (TreeElementView treeElementView : selectedViews) { treeElementView.setSelected(false); @@ -109,7 +103,8 @@ public void clearSelection() { /** * Gets tree puzzleElement view that the mouse is hovering over or null is no such view exists * - * @return tree puzzleElement view that the mouse is hovering over or null is no such view exists + * @return tree puzzleElement view that the mouse is hovering over or null is no such view + * exists */ public TreeElementView getHover() { return hover; @@ -128,9 +123,7 @@ public void newHover(TreeElementView newHovered) { hover = newHovered; } - /** - * Clears the current hover tree puzzleElement view - */ + /** Clears the current hover tree puzzleElement view */ public void clearHover() { if (hover != null) { hover.setHover(false); diff --git a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementButton.java b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementButton.java index de2281ad1..552d517b9 100644 --- a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementButton.java +++ b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementButton.java @@ -1,11 +1,9 @@ package edu.rpi.legup.ui.puzzleeditorui.elementsview; import edu.rpi.legup.model.elements.Element; -import edu.rpi.legup.model.rules.Rule; - +import java.awt.*; import javax.swing.*; import javax.swing.border.Border; -import java.awt.*; public class ElementButton extends JButton { diff --git a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementFrame.java b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementFrame.java index 1fc2b3792..e0524f84d 100644 --- a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementFrame.java +++ b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementFrame.java @@ -3,10 +3,9 @@ import edu.rpi.legup.controller.EditorElementController; import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.ui.lookandfeel.components.MaterialTabbedPaneUI; - +import java.awt.*; import javax.swing.*; import javax.swing.border.TitledBorder; -import java.awt.*; public class ElementFrame extends JPanel { private static final String checkBox = " \u2714 "; @@ -23,13 +22,14 @@ public class ElementFrame extends JPanel { public ElementFrame(EditorElementController controller) { this.controller = controller; - MaterialTabbedPaneUI tabOverride = new MaterialTabbedPaneUI() { - //this prevents the tabs from moving around when you select them - @Override - protected boolean shouldRotateTabRuns(int i) { - return false; - } - }; + MaterialTabbedPaneUI tabOverride = + new MaterialTabbedPaneUI() { + // this prevents the tabs from moving around when you select them + @Override + protected boolean shouldRotateTabRuns(int i) { + return false; + } + }; this.tabbedPane = new JTabbedPane(); tabbedPane.setUI(tabOverride); @@ -37,15 +37,22 @@ protected boolean shouldRotateTabRuns(int i) { this.buttonGroup = new ButtonGroup(); nonPlaceableElementPanel = new NonPlaceableElementPanel(this); - //nonPlaceableElementPanel.setMinimumSize(new Dimension(100,200)); - tabbedPane.addTab(nonPlaceableElementPanel.getName(), nonPlaceableElementPanel.getIcon(), new JScrollPane(nonPlaceableElementPanel), nonPlaceableElementPanel.getToolTip()); + // nonPlaceableElementPanel.setMinimumSize(new Dimension(100,200)); + tabbedPane.addTab( + nonPlaceableElementPanel.getName(), + nonPlaceableElementPanel.getIcon(), + new JScrollPane(nonPlaceableElementPanel), + nonPlaceableElementPanel.getToolTip()); placeableElementPanel = new PlaceableElementPanel(this); - //placeableElementPanel.setMinimuSize(new Dimension(100,200)); - tabbedPane.addTab(placeableElementPanel.getName(), placeableElementPanel.getIcon(), new JScrollPane(placeableElementPanel), placeableElementPanel.getToolTip()); + // placeableElementPanel.setMinimuSize(new Dimension(100,200)); + tabbedPane.addTab( + placeableElementPanel.getName(), + placeableElementPanel.getIcon(), + new JScrollPane(placeableElementPanel), + placeableElementPanel.getToolTip()); tabbedPane.setTabPlacement(JTabbedPane.TOP); - setLayout(new BorderLayout()); setMinimumSize(new Dimension(250, 256)); setPreferredSize(new Dimension(330, 256)); @@ -63,14 +70,15 @@ public ButtonGroup getButtonGroup() { } public void resetSize() { - int buttonWidth = ((ElementPanel) tabbedPane.getSelectedComponent()).getElementButtons()[0].getWidth(); + int buttonWidth = + ((ElementPanel) tabbedPane.getSelectedComponent()) + .getElementButtons()[0].getWidth(); this.setMinimumSize(new Dimension(2 * buttonWidth + 64, this.getHeight())); } public void setElements(Puzzle puzzle) { nonPlaceableElementPanel.setElements(puzzle.getNonPlaceableElements()); placeableElementPanel.setElements(puzzle.getPlaceableElements()); - } public EditorElementController getController() { diff --git a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementPanel.java b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementPanel.java index 2b0c4c63e..46198e226 100644 --- a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementPanel.java +++ b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/ElementPanel.java @@ -1,13 +1,10 @@ package edu.rpi.legup.ui.puzzleeditorui.elementsview; -import edu.rpi.legup.model.rules.Rule; -import edu.rpi.legup.ui.WrapLayout; import edu.rpi.legup.model.elements.Element; -import edu.rpi.legup.ui.proofeditorui.rulesview.RuleButton; - -import javax.swing.*; +import edu.rpi.legup.ui.WrapLayout; import java.util.ArrayList; import java.util.List; +import javax.swing.*; public abstract class ElementPanel extends JPanel { protected ImageIcon icon; @@ -35,7 +32,8 @@ public void setElements(List elements) { elementFrame.getButtonGroup().add(elementButtons[i]); System.out.printf("added button: %d, element %s\n", i, element.getElementName()); - elementButtons[i].setToolTipText(element.getElementName() + ": " + element.getDescription()); + elementButtons[i].setToolTipText( + element.getElementName() + ": " + element.getDescription()); elementButtons[i].addActionListener(elementFrame.getController()); add(elementButtons[i]); } @@ -81,4 +79,3 @@ public void setToolTip(String toolTip) { this.toolTip = toolTip; } } - diff --git a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/NonPlaceableElementPanel.java b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/NonPlaceableElementPanel.java index 7920f564c..00b4f5379 100644 --- a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/NonPlaceableElementPanel.java +++ b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/NonPlaceableElementPanel.java @@ -5,7 +5,10 @@ public class NonPlaceableElementPanel extends ElementPanel { public NonPlaceableElementPanel(ElementFrame elementFrame) { super(elementFrame); - this.icon = new ImageIcon(ClassLoader.getSystemClassLoader().getResource("edu/rpi/legup/images/Legup/Direct Rules.gif")); + this.icon = + new ImageIcon( + ClassLoader.getSystemClassLoader() + .getResource("edu/rpi/legup/images/Legup/Direct Rules.gif")); this.name = "Non-Placeable Elements"; this.toolTip = "Non-Placeable Elements"; } diff --git a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/PlaceableElementPanel.java b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/PlaceableElementPanel.java index 1fa8eabfb..088e18f8c 100644 --- a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/PlaceableElementPanel.java +++ b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/elementsview/PlaceableElementPanel.java @@ -5,7 +5,10 @@ public class PlaceableElementPanel extends ElementPanel { public PlaceableElementPanel(ElementFrame elementFrame) { super(elementFrame); - this.icon = new ImageIcon(ClassLoader.getSystemClassLoader().getResource("edu/rpi/legup/images/Legup/Direct Rules.gif")); + this.icon = + new ImageIcon( + ClassLoader.getSystemClassLoader() + .getResource("edu/rpi/legup/images/Legup/Direct Rules.gif")); this.name = "Placeable Elements"; this.toolTip = "Placeable Elements"; } diff --git a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/resizeview/ResizePanel.java b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/resizeview/ResizePanel.java index 7cb7856e7..902d9dbd3 100644 --- a/src/main/java/edu/rpi/legup/ui/puzzleeditorui/resizeview/ResizePanel.java +++ b/src/main/java/edu/rpi/legup/ui/puzzleeditorui/resizeview/ResizePanel.java @@ -1,4 +1,3 @@ package edu.rpi.legup.ui.puzzleeditorui.resizeview; -public class ResizePanel { -} +public class ResizePanel {} diff --git a/src/main/java/edu/rpi/legup/user/Submission.java b/src/main/java/edu/rpi/legup/user/Submission.java index eb2b8446c..42373d2ec 100644 --- a/src/main/java/edu/rpi/legup/user/Submission.java +++ b/src/main/java/edu/rpi/legup/user/Submission.java @@ -3,11 +3,7 @@ import edu.rpi.legup.model.gameboard.Board; public class Submission { - public Submission(Board board) { + public Submission(Board board) {} - } - - public void submit() { - - } + public void submit() {} } diff --git a/src/main/java/edu/rpi/legup/user/UsageStatistics.java b/src/main/java/edu/rpi/legup/user/UsageStatistics.java index 192db593f..0bc5d1c62 100644 --- a/src/main/java/edu/rpi/legup/user/UsageStatistics.java +++ b/src/main/java/edu/rpi/legup/user/UsageStatistics.java @@ -1,27 +1,19 @@ package edu.rpi.legup.user; +import java.io.IOException; +import java.io.InputStream; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; -import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; -import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.message.BasicNameValuePair; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; public class UsageStatistics { private static final String url = "https://legup-3b4a5.firebaseio.com/databases/test.json"; - public UsageStatistics() { - - } + public UsageStatistics() {} public boolean sendErrorReport() { try { @@ -31,12 +23,12 @@ public boolean sendErrorReport() { // Request parameters and other properties. httppost.setEntity(new StringEntity("{\"test\": \"jeff\"}")); -// List params = new ArrayList<>(2); -// params.add(new BasicNameValuePair("param-1", "12345")); -// params.add(new BasicNameValuePair("param-2", "Hello!")); -// httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); + // List params = new ArrayList<>(2); + // params.add(new BasicNameValuePair("param-1", "12345")); + // params.add(new BasicNameValuePair("param-2", "Hello!")); + // httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); - //Execute and get the response. + // Execute and get the response. HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); @@ -44,14 +36,12 @@ public boolean sendErrorReport() { InputStream instream = entity.getContent(); try { -// System.err.println(new String(instream.readAllBytes())); - } - finally { + // System.err.println(new String(instream.readAllBytes())); + } finally { instream.close(); } } - } - catch (IOException e) { + } catch (IOException e) { return false; } return false; diff --git a/src/main/java/edu/rpi/legup/user/User.java b/src/main/java/edu/rpi/legup/user/User.java index 2e542a96c..63280a72d 100644 --- a/src/main/java/edu/rpi/legup/user/User.java +++ b/src/main/java/edu/rpi/legup/user/User.java @@ -1,5 +1,3 @@ package edu.rpi.legup.user; -public class User { - -} +public class User {} diff --git a/src/main/java/edu/rpi/legup/utility/ConnectedRegions.java b/src/main/java/edu/rpi/legup/utility/ConnectedRegions.java index ce4b74bdc..14b68ba40 100644 --- a/src/main/java/edu/rpi/legup/utility/ConnectedRegions.java +++ b/src/main/java/edu/rpi/legup/utility/ConnectedRegions.java @@ -7,13 +7,15 @@ import java.util.Set; public final class ConnectedRegions { - public static List> getConnectedRegions(int boundaryCell, int[][] cells, int width, int height) { + public static List> getConnectedRegions( + int boundaryCell, int[][] cells, int width, int height) { Set boundaryCells = new HashSet<>(); boundaryCells.add(boundaryCell); return getConnectedRegions(boundaryCells, cells, width, height); } - public static List> getConnectedRegions(Set boundaryCells, int[][] cells, int width, int height) { + public static List> getConnectedRegions( + Set boundaryCells, int[][] cells, int width, int height) { boolean[][] visited = new boolean[height][width]; List> results = new ArrayList<>(); for (int y = 0; y < height; y++) { @@ -36,17 +38,26 @@ public static boolean regionContains(int toFind, int[][] cells, Set regio return false; } - public static Set getRegionAroundPoint(Point p, int boundaryCell, int[][] cells, int width, int height) { + public static Set getRegionAroundPoint( + Point p, int boundaryCell, int[][] cells, int width, int height) { Set boundaryCells = new HashSet<>(); boundaryCells.add(boundaryCell); return getRegionAroundPoint(p, boundaryCells, cells, width, height); } - public static Set getRegionAroundPoint(Point p, Set boundaryCells, int[][] cells, int width, int height) { + public static Set getRegionAroundPoint( + Point p, Set boundaryCells, int[][] cells, int width, int height) { return floodfill(boundaryCells, cells, new boolean[height][width], width, height, p.x, p.y); } - private static Set floodfill(Set boundaryCells, int[][] cells, boolean[][] visited, int w, int h, int x, int y) { + private static Set floodfill( + Set boundaryCells, + int[][] cells, + boolean[][] visited, + int w, + int h, + int x, + int y) { HashSet result = new HashSet<>(); if ((x < 0) || (x >= w)) { return result; @@ -64,4 +75,4 @@ private static Set floodfill(Set boundaryCells, int[][] cells, b } return result; } -} \ No newline at end of file +} diff --git a/src/main/java/edu/rpi/legup/utility/DisjointSets.java b/src/main/java/edu/rpi/legup/utility/DisjointSets.java index 1e2270318..f33b8993c 100644 --- a/src/main/java/edu/rpi/legup/utility/DisjointSets.java +++ b/src/main/java/edu/rpi/legup/utility/DisjointSets.java @@ -7,9 +7,7 @@ public class DisjointSets { private Map depths; private Map> sets; - /** - * DisjointSets Constructor creates an empty DisjointSets - */ + /** DisjointSets Constructor creates an empty DisjointSets */ public DisjointSets() { this.parents = new HashMap<>(); this.depths = new HashMap<>(); @@ -17,8 +15,9 @@ public DisjointSets() { } /** - * Creates a unique set that contains the specified puzzleElement. If the specified puzzleElement is null or another set already - * contains that puzzleElement, this method returns false, indicating that a set was not created + * Creates a unique set that contains the specified puzzleElement. If the specified + * puzzleElement is null or another set already contains that puzzleElement, this method returns + * false, indicating that a set was not created * * @param u puzzleElement to create the set from * @return true if the set was created, false otherwise @@ -26,8 +25,7 @@ public DisjointSets() { public boolean createSet(T u) { if (u == null || parents.containsKey(u)) { return false; - } - else { + } else { parents.put(u, u); depths.put(u, 0); Set newSet = new HashSet<>(); @@ -38,16 +36,17 @@ public boolean createSet(T u) { } /** - * Finds and returns the representative set puzzleElement of the set that the specified puzzleElement contains + * Finds and returns the representative set puzzleElement of the set that the specified + * puzzleElement contains * * @param p puzzleElement of the set of which to find - * @return representative set puzzleElement or null if the specified puzzleElement is null or is not in the DisjointSets + * @return representative set puzzleElement or null if the specified puzzleElement is null or is + * not in the DisjointSets */ public T find(T p) { if (p == null || parents.get(p) == null) { return null; - } - else { + } else { if (p != parents.get(p)) { parents.put(p, find(parents.get(p))); } @@ -56,7 +55,8 @@ public T find(T p) { } /** - * Unions two sets together. If the set are non-null and disjoint, then it returns true, false otherwise + * Unions two sets together. If the set are non-null and disjoint, then it returns true, false + * otherwise * * @param p set one * @param q set two @@ -67,14 +67,12 @@ public boolean union(T p, T q) { T qid = find(q); if (pid == null || qid == null || pid == qid) { return false; - } - else { + } else { if (depths.get(pid) > depths.get(qid)) { parents.put(qid, pid); sets.get(pid).addAll(sets.get(qid)); sets.remove(qid); - } - else { + } else { parents.put(pid, qid); sets.get(qid).addAll(sets.get(pid)); sets.remove(pid); @@ -87,8 +85,9 @@ public boolean union(T p, T q) { } /** - * Unions to elements together, if either puzzleElement is not already in the DisjointSets, it creates a set for the - * puzzleElement then unions the sets together. If either puzzleElement is null, no action is taken. + * Unions to elements together, if either puzzleElement is not already in the DisjointSets, it + * creates a set for the puzzleElement then unions the sets together. If either puzzleElement is + * null, no action is taken. * * @param p puzzleElement one * @param q puzzleElement two @@ -118,17 +117,18 @@ public boolean contains(T u) { } /** - * Gets the set of elements that the specified puzzleElement is contained in, or null if no such set exists. + * Gets the set of elements that the specified puzzleElement is contained in, or null if no such + * set exists. * * @param p puzzleElement to get the set of - * @return the set of elements that the specified puzzleElement if contained in, or null if no such set exists + * @return the set of elements that the specified puzzleElement if contained in, or null if no + * such set exists */ public Set getSet(T p) { T pid = find(p); if (pid != null) { return new HashSet<>(sets.get(pid)); - } - else { + } else { return null; } } diff --git a/src/main/java/edu/rpi/legup/utility/Entry.java b/src/main/java/edu/rpi/legup/utility/Entry.java index 1819f7eb0..0686f0dbf 100644 --- a/src/main/java/edu/rpi/legup/utility/Entry.java +++ b/src/main/java/edu/rpi/legup/utility/Entry.java @@ -7,7 +7,7 @@ public class Entry { /** * Entry Constructor creates a key value pair * - * @param key key + * @param key key * @param value value */ public Entry(K key, V value) { diff --git a/src/main/java/edu/rpi/legup/utility/LegupUtils.java b/src/main/java/edu/rpi/legup/utility/LegupUtils.java index dbdd24e7f..94f119a5e 100644 --- a/src/main/java/edu/rpi/legup/utility/LegupUtils.java +++ b/src/main/java/edu/rpi/legup/utility/LegupUtils.java @@ -17,7 +17,8 @@ public class LegupUtils { private static final Logger LOGGER = Logger.getLogger(LegupUtils.class.getName()); /** - * Scans all classes accessible from the context class loader which belong to the given package and subpackages. + * Scans all classes accessible from the context class loader which belong to the given package + * and subpackages. * * @param packageName The base package * @return The classes @@ -54,12 +55,13 @@ public static Class[] getClasses(String packageName) /** * Recursive method used to find all classes in a given directory and subdirs. * - * @param directory The base directory + * @param directory The base directory * @param packageName The package name for classes found inside the base directory * @return The classes * @throws ClassNotFoundException */ - private static List findClasses(File directory, String packageName) throws ClassNotFoundException { + private static List findClasses(File directory, String packageName) + throws ClassNotFoundException { List classes = new ArrayList<>(); if (!directory.exists()) { return classes; @@ -69,23 +71,32 @@ private static List findClasses(File directory, String packageName) throw if (file.isDirectory()) { assert !file.getName().contains("."); classes.addAll(findClasses(file, packageName + "." + file.getName())); - } - else { + } else { if (file.getName().endsWith(".class")) { - classes.add(Class.forName(packageName + '.' + file.getName().substring(0, file.getName().length() - 6))); + classes.add( + Class.forName( + packageName + + '.' + + file.getName() + .substring(0, file.getName().length() - 6))); } } } return classes; } - private static List findClassesZip(String path, String packageName) throws IOException, ClassNotFoundException { + private static List findClassesZip(String path, String packageName) + throws IOException, ClassNotFoundException { List classes = new ArrayList<>(); ZipInputStream zip = new ZipInputStream(new FileInputStream(path)); for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) { - if (!entry.isDirectory() && entry.getName().endsWith(".class") && entry.getName().startsWith(packageName)) { + if (!entry.isDirectory() + && entry.getName().endsWith(".class") + && entry.getName().startsWith(packageName)) { String className = entry.getName().replace('/', '.'); - classes.add(Class.forName(className.substring(0, className.length() - ".class".length()))); + classes.add( + Class.forName( + className.substring(0, className.length() - ".class".length()))); } } return classes; diff --git a/src/main/java/edu/rpi/legup/utility/Logger.java b/src/main/java/edu/rpi/legup/utility/Logger.java index 1feb56f04..67048e5b4 100644 --- a/src/main/java/edu/rpi/legup/utility/Logger.java +++ b/src/main/java/edu/rpi/legup/utility/Logger.java @@ -1,6 +1,6 @@ package edu.rpi.legup.utility; -import edu.rpi.legup.Legup; +import java.io.File; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.appender.ConsoleAppender; @@ -10,27 +10,31 @@ import org.apache.logging.log4j.core.config.LoggerConfig; import org.apache.logging.log4j.core.layout.PatternLayout; -import java.io.File; - public class Logger { - private static final String LEGUP_HOME = System.getProperty("user.home") + File.separator + ".legup" + File.separator; + private static final String LEGUP_HOME = + System.getProperty("user.home") + File.separator + ".legup" + File.separator; public static void initLogger() { LoggerContext context = (LoggerContext) LogManager.getContext(false); Configuration config = context.getConfiguration(); ConsoleAppender consoleAppender = config.getAppender("console"); PatternLayout consolePattern = (PatternLayout) consoleAppender.getLayout(); - TimeBasedTriggeringPolicy triggeringPolicy = TimeBasedTriggeringPolicy.newBuilder().withInterval(1).withModulate(true).build(); - PatternLayout patternLayout = PatternLayout.newBuilder().withPattern(consolePattern.getConversionPattern()).build(); - RollingFileAppender rollingFileAppender = RollingFileAppender.newBuilder() - .setName("fileLogger") - .withFileName(LEGUP_HOME + "legup.log") - .withFilePattern(LEGUP_HOME + "legup-%d{yyyy-MM-dd}.log.gz") - .withPolicy(triggeringPolicy) - .setLayout(patternLayout) - .setConfiguration(config) - .build(); + TimeBasedTriggeringPolicy triggeringPolicy = + TimeBasedTriggeringPolicy.newBuilder().withInterval(1).withModulate(true).build(); + PatternLayout patternLayout = + PatternLayout.newBuilder() + .withPattern(consolePattern.getConversionPattern()) + .build(); + RollingFileAppender rollingFileAppender = + RollingFileAppender.newBuilder() + .setName("fileLogger") + .withFileName(LEGUP_HOME + "legup.log") + .withFilePattern(LEGUP_HOME + "legup-%d{yyyy-MM-dd}.log.gz") + .withPolicy(triggeringPolicy) + .setLayout(patternLayout) + .setConfiguration(config) + .build(); rollingFileAppender.start(); config.addAppender(rollingFileAppender); LoggerConfig rootLogger = config.getRootLogger(); @@ -39,5 +43,4 @@ public static void initLogger() { System.setProperty("sun.java2d.noddraw", Boolean.TRUE.toString()); } - } diff --git a/src/test/java/legup/MockGameBoardFacade.java b/src/test/java/legup/MockGameBoardFacade.java index 7840b61b7..f4f1db938 100644 --- a/src/test/java/legup/MockGameBoardFacade.java +++ b/src/test/java/legup/MockGameBoardFacade.java @@ -11,8 +11,7 @@ protected MockGameBoardFacade() { Config config = null; try { config = new Config(); - } - catch (InvalidConfigException e) { + } catch (InvalidConfigException e) { System.exit(1); } setConfig(config); @@ -23,7 +22,7 @@ protected MockGameBoardFacade() { * * @return single instance of GameBoardFacade */ - public synchronized static GameBoardFacade getInstance() { + public static synchronized GameBoardFacade getInstance() { if (instance == null) { instance = new MockGameBoardFacade(); } @@ -31,9 +30,7 @@ public synchronized static GameBoardFacade getInstance() { } @Override - public void initializeUI() { - - } + public void initializeUI() {} @Override public void setPuzzle(Puzzle puzzle) { @@ -41,7 +38,5 @@ public void setPuzzle(Puzzle puzzle) { } @Override - public void setWindowTitle(String puzzleName, String fileName) { - - } + public void setWindowTitle(String puzzleName, String fileName) {} } diff --git a/src/test/java/legup/TestRunner.java b/src/test/java/legup/TestRunner.java index 5e95a16bf..40cc5fa6c 100644 --- a/src/test/java/legup/TestRunner.java +++ b/src/test/java/legup/TestRunner.java @@ -1,6 +1,5 @@ package legup; - import org.junit.runner.JUnitCore; import org.junit.runner.Result; import org.junit.runner.notification.Failure; @@ -10,9 +9,7 @@ import puzzles.skyscrapers.rules.*; import puzzles.treetent.rules.*; -/** - * This class runs all of the tests for the project without needing to run build scripts. - */ +/** This class runs all of the tests for the project without needing to run build scripts. */ public class TestRunner { public static void main(String[] args) { // Battleship Tests @@ -43,7 +40,7 @@ public static void main(String[] args) { Result result12 = JUnitCore.runClasses(TooManyBulbsContradictionRuleTest.class); printTestResults(result12); - //nurikabe tests + // nurikabe tests Result result13 = JUnitCore.runClasses(BlackBetweenRegionsDirectRuleTest.class); printTestResults(result13); Result result14 = JUnitCore.runClasses(BlackBottleNeckDirectRuleTest.class); diff --git a/src/test/java/legup/TestUtilities.java b/src/test/java/legup/TestUtilities.java index 9f203b223..83ce773d4 100644 --- a/src/test/java/legup/TestUtilities.java +++ b/src/test/java/legup/TestUtilities.java @@ -8,7 +8,8 @@ import edu.rpi.legup.save.InvalidFileFormatException; public final class TestUtilities { - public static void importTestBoard(String fileName, Puzzle puzzle) throws InvalidFileFormatException { + public static void importTestBoard(String fileName, Puzzle puzzle) + throws InvalidFileFormatException { puzzle.importPuzzle(ClassLoader.getSystemResourceAsStream(fileName)); Tree tree = puzzle.getTree(); TreeNode rootNode = tree.getRootNode(); diff --git a/src/test/java/puzzles/battleship/rules/AdjacentShipsContradictionRuleTest.java b/src/test/java/puzzles/battleship/rules/AdjacentShipsContradictionRuleTest.java index c9e65e9c1..08b6633db 100644 --- a/src/test/java/puzzles/battleship/rules/AdjacentShipsContradictionRuleTest.java +++ b/src/test/java/puzzles/battleship/rules/AdjacentShipsContradictionRuleTest.java @@ -1,24 +1,20 @@ package puzzles.battleship.rules; -import edu.rpi.legup.puzzle.battleship.BattleshipType; -import legup.MockGameBoardFacade; -import legup.TestUtilities; import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; import edu.rpi.legup.puzzle.battleship.Battleship; import edu.rpi.legup.puzzle.battleship.BattleshipBoard; -import edu.rpi.legup.puzzle.battleship.BattleshipCell; import edu.rpi.legup.puzzle.battleship.rules.AdjacentShipsContradictionRule; import edu.rpi.legup.save.InvalidFileFormatException; - import java.awt.*; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; public class AdjacentShipsContradictionRuleTest { - private static final AdjacentShipsContradictionRule RULE - = new AdjacentShipsContradictionRule(); + private static final AdjacentShipsContradictionRule RULE = new AdjacentShipsContradictionRule(); private static Battleship battleship; @@ -30,8 +26,9 @@ public static void setUp() { @Test public void OrthogonalAdjacentTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/battleship/rules" + - "/AdjacentShipsContradictionRule/OrthogonalAdjacentBoards", + TestUtilities.importTestBoard( + "puzzles/battleship/rules" + + "/AdjacentShipsContradictionRule/OrthogonalAdjacentBoards", battleship); TreeNode rootNode = battleship.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -39,37 +36,38 @@ public void OrthogonalAdjacentTest() throws InvalidFileFormatException { BattleshipBoard board = (BattleshipBoard) transition.getBoard(); - Assert.assertNotNull(RULE.checkContradiction( - board)); + Assert.assertNotNull(RULE.checkContradiction(board)); } @Test public void InvalidOrthogonalAdjacentTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/battleship/rules" + - "/AdjacentShipsContradictionRule" + - "/InvalidOrthogonalAdjacentBoards", battleship); + TestUtilities.importTestBoard( + "puzzles/battleship/rules" + + "/AdjacentShipsContradictionRule" + + "/InvalidOrthogonalAdjacentBoards", + battleship); TreeNode rootNode = battleship.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); BattleshipBoard board = (BattleshipBoard) transition.getBoard(); - Assert.assertNull(RULE.checkContradiction( - board)); + Assert.assertNull(RULE.checkContradiction(board)); } @Test public void DiagonalAdjacentTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/battleship/rules" + - "/AdjacentShipsContradictionRule" + - "/DiagonalAdjacentBoards", battleship); + TestUtilities.importTestBoard( + "puzzles/battleship/rules" + + "/AdjacentShipsContradictionRule" + + "/DiagonalAdjacentBoards", + battleship); TreeNode rootNode = battleship.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); BattleshipBoard board = (BattleshipBoard) transition.getBoard(); - Assert.assertNull(RULE.checkContradiction( - board)); + Assert.assertNull(RULE.checkContradiction(board)); } } diff --git a/src/test/java/puzzles/battleship/rules/FinishWithShipsDirectRuleTests.java b/src/test/java/puzzles/battleship/rules/FinishWithShipsDirectRuleTests.java index ac7e8cb8e..1548445fd 100644 --- a/src/test/java/puzzles/battleship/rules/FinishWithShipsDirectRuleTests.java +++ b/src/test/java/puzzles/battleship/rules/FinishWithShipsDirectRuleTests.java @@ -1,18 +1,16 @@ package puzzles.battleship.rules; -import org.junit.*; - -import legup.MockGameBoardFacade; -import legup.TestUtilities; import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.battleship.*; import edu.rpi.legup.puzzle.battleship.rules.*; import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.*; public class FinishWithShipsDirectRuleTests { - private static final FinishWithShipsDirectRule RULE - = new FinishWithShipsDirectRule(); + private static final FinishWithShipsDirectRule RULE = new FinishWithShipsDirectRule(); private static Battleship battleship; @@ -22,10 +20,10 @@ public static void setUp() { battleship = new Battleship(); } - //@Test + // @Test public void HorizontalValidTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/battleship/rules" + - "/FinishWithShipsBasicRuleTests/HorizontalValidBoard", + TestUtilities.importTestBoard( + "puzzles/battleship/rules" + "/FinishWithShipsBasicRuleTests/HorizontalValidBoard", battleship); TreeNode rootNode = battleship.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -34,10 +32,10 @@ public void HorizontalValidTest() throws InvalidFileFormatException { Assert.assertNull(RULE.checkRule(transition)); } - //@Test + // @Test public void VerticaValidTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/battleship/rules" + - "/FinishWithShipsBasicRuleTests/VerticalValidBoard", + TestUtilities.importTestBoard( + "puzzles/battleship/rules" + "/FinishWithShipsBasicRuleTests/VerticalValidBoard", battleship); TreeNode rootNode = battleship.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -46,10 +44,11 @@ public void VerticaValidTest() throws InvalidFileFormatException { Assert.assertNull(RULE.checkRule(transition)); } - //@Test + // @Test public void HorizontalInvalidTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/battleship/rules" + - "/FinishWithShipsBasicRuleTests/HorizontalInvalidBoard", + TestUtilities.importTestBoard( + "puzzles/battleship/rules" + + "/FinishWithShipsBasicRuleTests/HorizontalInvalidBoard", battleship); TreeNode rootNode = battleship.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -58,10 +57,10 @@ public void HorizontalInvalidTest() throws InvalidFileFormatException { Assert.assertNotNull(RULE.checkRule(transition)); } - //@Test + // @Test public void VerticalInvalidTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/battleship/rules" + - "/FinishWithShipsBasicRuleTests/VerticalInvalidBoard", + TestUtilities.importTestBoard( + "puzzles/battleship/rules" + "/FinishWithShipsBasicRuleTests/VerticalInvalidBoard", battleship); TreeNode rootNode = battleship.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); diff --git a/src/test/java/puzzles/lightup/rules/BulbsInPathContradictionRuleTest.java b/src/test/java/puzzles/lightup/rules/BulbsInPathContradictionRuleTest.java index 0e7930751..316a86f43 100644 --- a/src/test/java/puzzles/lightup/rules/BulbsInPathContradictionRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/BulbsInPathContradictionRuleTest.java @@ -1,14 +1,13 @@ package puzzles.lightup.rules; -import edu.rpi.legup.puzzle.lightup.LightUpBoard; -import legup.TestUtilities; import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; -import org.junit.Assert; import edu.rpi.legup.puzzle.lightup.LightUp; +import edu.rpi.legup.puzzle.lightup.LightUpBoard; import edu.rpi.legup.puzzle.lightup.rules.BulbsInPathContradictionRule; import edu.rpi.legup.save.InvalidFileFormatException; - +import legup.TestUtilities; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -22,31 +21,35 @@ public static void setUp() { } @Test - public void BulbsInPathContradictionRule_LightInHorizontalPath() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/lightup/rules/BulbsInPathContradictionRule/LightInHorizontalPath", lightUp); + public void BulbsInPathContradictionRule_LightInHorizontalPath() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/lightup/rules/BulbsInPathContradictionRule/LightInHorizontalPath", + lightUp); TreeNode rootNode = lightUp.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); LightUpBoard board = (LightUpBoard) transition.getBoard(); - //confirm there is a contradiction somewhere on the board + // confirm there is a contradiction somewhere on the board Assert.assertNull(RULE.checkContradiction(board)); Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(0, 0))); Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(2, 0))); - Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 1))); } @Test - public void BulbsInPathContradictionRule_LightInVerticalPath() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/lightup/rules/BulbsInPathContradictionRule/LightInVerticalPath", lightUp); + public void BulbsInPathContradictionRule_LightInVerticalPath() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/lightup/rules/BulbsInPathContradictionRule/LightInVerticalPath", lightUp); TreeNode rootNode = lightUp.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); LightUpBoard board = (LightUpBoard) transition.getBoard(); - //confirm there is a contradiction somewhere on the board + // confirm there is a contradiction somewhere on the board Assert.assertNull(RULE.checkContradiction(board)); Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(0, 0))); Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(0, 2))); @@ -55,8 +58,10 @@ public void BulbsInPathContradictionRule_LightInVerticalPath() throws InvalidFil } @Test - public void BulbsInPathContradictionRule_BlockInVerticalPath() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/lightup/rules/BulbsInPathContradictionRule/BlockInVerticalPath", lightUp); + public void BulbsInPathContradictionRule_BlockInVerticalPath() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/lightup/rules/BulbsInPathContradictionRule/BlockInVerticalPath", lightUp); TreeNode rootNode = lightUp.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -70,17 +75,19 @@ public void BulbsInPathContradictionRule_BlockInVerticalPath() throws InvalidFil } @Test - public void BulbsInPathContradictionRule_BlockInHorizontalPath() throws InvalidFileFormatException{ - TestUtilities.importTestBoard("puzzles/lightup/rules/BulbsInPathContradictionRule/BlockInHorizontalPath", lightUp); + public void BulbsInPathContradictionRule_BlockInHorizontalPath() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/lightup/rules/BulbsInPathContradictionRule/BlockInHorizontalPath", + lightUp); TreeNode rootNode = lightUp.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); LightUpBoard board = (LightUpBoard) transition.getBoard(); Assert.assertNotNull(RULE.checkContradiction(board)); - Assert.assertNotNull(RULE.checkContradictionAt(board,board.getCell(0,0))); - Assert.assertNotNull(RULE.checkContradictionAt(board,board.getCell(2,0))); - Assert.assertNotNull(RULE.checkContradictionAt(board,board.getCell(1,1))); - + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 0))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 0))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 1))); } } diff --git a/src/test/java/puzzles/lightup/rules/CannotLightACellContradictionRuleTest.java b/src/test/java/puzzles/lightup/rules/CannotLightACellContradictionRuleTest.java index 7b3ffd2b9..6db42d39b 100644 --- a/src/test/java/puzzles/lightup/rules/CannotLightACellContradictionRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/CannotLightACellContradictionRuleTest.java @@ -1,19 +1,19 @@ package puzzles.lightup.rules; -import edu.rpi.legup.puzzle.lightup.LightUpBoard; -import legup.TestUtilities; import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; -import org.junit.Assert; import edu.rpi.legup.puzzle.lightup.LightUp; +import edu.rpi.legup.puzzle.lightup.LightUpBoard; import edu.rpi.legup.puzzle.lightup.rules.CannotLightACellContradictionRule; import edu.rpi.legup.save.InvalidFileFormatException; - +import legup.TestUtilities; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; public class CannotLightACellContradictionRuleTest { - private static final CannotLightACellContradictionRule RULE = new CannotLightACellContradictionRule(); + private static final CannotLightACellContradictionRule RULE = + new CannotLightACellContradictionRule(); private static LightUp lightUp; @BeforeClass @@ -22,22 +22,23 @@ public static void setUp() { } @Test - //extensive full testing of null and non-null in a 5x5 board + // extensive full testing of null and non-null in a 5x5 board public void FullLightTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/lightup/rules/CannotLightACellContradictionRule/FullLightTest", lightUp); + TestUtilities.importTestBoard( + "puzzles/lightup/rules/CannotLightACellContradictionRule/FullLightTest", lightUp); TreeNode rootNode = lightUp.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); LightUpBoard board = (LightUpBoard) transition.getBoard(); - //confirm there is a contradiction somewhere on the board + // confirm there is a contradiction somewhere on the board Assert.assertNull(RULE.checkContradiction(board)); - //confirm it is impossible to light up these squares + // confirm it is impossible to light up these squares Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(1, 3))); Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(3, 3))); - //confirm these are not required to be lit because they are already lit or unable to be + // confirm these are not required to be lit because they are already lit or unable to be Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 0))); Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 1))); Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 0))); @@ -45,21 +46,22 @@ public void FullLightTest() throws InvalidFileFormatException { } @Test - //simple contradiction testing for null and non-null in a 3x3 board + // simple contradiction testing for null and non-null in a 3x3 board public void CannotLightMiddleTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/lightup/rules/CannotLightACellContradictionRule/CannotLight", lightUp); + TestUtilities.importTestBoard( + "puzzles/lightup/rules/CannotLightACellContradictionRule/CannotLight", lightUp); TreeNode rootNode = lightUp.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); LightUpBoard board = (LightUpBoard) transition.getBoard(); - //confirm there is a contradiction somewhere on the board + // confirm there is a contradiction somewhere on the board Assert.assertNull(RULE.checkContradiction(board)); - //confirm it is impossible to light up the center square + // confirm it is impossible to light up the center square Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(1, 1))); - //every square except the center + // every square except the center Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 0))); Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 0))); Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 0))); @@ -71,16 +73,17 @@ public void CannotLightMiddleTest() throws InvalidFileFormatException { @Test public void CanLightTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/lightup/rules/CannotLightACellContradictionRule/CanLightTest", lightUp); + TestUtilities.importTestBoard( + "puzzles/lightup/rules/CannotLightACellContradictionRule/CanLightTest", lightUp); TreeNode rootNode = lightUp.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); LightUpBoard board = (LightUpBoard) transition.getBoard(); - //confirm there is not a contradiction somewhere on the board + // confirm there is not a contradiction somewhere on the board Assert.assertNotNull(RULE.checkContradiction(board)); - //confirm that these cells can be lit, are already lit, or that they are just black blocks + // confirm that these cells can be lit, are already lit, or that they are just black blocks Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 3))); Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(3, 3))); Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 0))); diff --git a/src/test/java/puzzles/lightup/rules/EmptyCellinLightDirectRuleTest.java b/src/test/java/puzzles/lightup/rules/EmptyCellinLightDirectRuleTest.java index b0a2d10ed..264cf928c 100644 --- a/src/test/java/puzzles/lightup/rules/EmptyCellinLightDirectRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/EmptyCellinLightDirectRuleTest.java @@ -1,17 +1,17 @@ package puzzles.lightup.rules; -import org.junit.BeforeClass; -import org.junit.Test; -import edu.rpi.legup.puzzle.lightup.LightUp; -import edu.rpi.legup.puzzle.lightup.rules.EmptyCellinLightDirectRule; -import edu.rpi.legup.save.InvalidFileFormatException; -import legup.TestUtilities; import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.lightup.LightUp; import edu.rpi.legup.puzzle.lightup.LightUpBoard; import edu.rpi.legup.puzzle.lightup.LightUpCell; import edu.rpi.legup.puzzle.lightup.LightUpCellType; +import edu.rpi.legup.puzzle.lightup.rules.EmptyCellinLightDirectRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.TestUtilities; import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; public class EmptyCellinLightDirectRuleTest { private static final EmptyCellinLightDirectRule RULE = new EmptyCellinLightDirectRule(); @@ -23,72 +23,80 @@ public static void setUp() { } @Test - //tests a 3x3 board with with a 0 black tile in the center and lightbulbs in top left and bototm right - //confirms the rest of the tiles must be empty - public void EmptyCellinLightDirectRule() throws InvalidFileFormatException{ - TestUtilities.importTestBoard("puzzles/lightup/rules/EmptyCellinLightDirectRule/EmptyCells", lightUp); + // tests a 3x3 board with with a 0 black tile in the center and lightbulbs in top left and + // bototm + // right + // confirms the rest of the tiles must be empty + public void EmptyCellinLightDirectRule() throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/lightup/rules/EmptyCellinLightDirectRule/EmptyCells", lightUp); TreeNode rootNode = lightUp.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); - transition.setRule(RULE); - - //get board state + transition.setRule(RULE); + + // get board state LightUpBoard board = (LightUpBoard) transition.getBoard(); - //change the board's cells considering the emptycellinlight rule - LightUpCell cell2 = board.getCell(1,0); + // change the board's cells considering the emptycellinlight rule + LightUpCell cell2 = board.getCell(1, 0); cell2.setData(LightUpCellType.EMPTY.value); board.addModifiedData(cell2); - LightUpCell cell3 = board.getCell(0,1); + LightUpCell cell3 = board.getCell(0, 1); cell3.setData(LightUpCellType.EMPTY.value); board.addModifiedData(cell3); - LightUpCell cell4 = board.getCell(2,0); + LightUpCell cell4 = board.getCell(2, 0); cell4.setData(LightUpCellType.EMPTY.value); board.addModifiedData(cell4); - LightUpCell cell5 = board.getCell(0,2); + LightUpCell cell5 = board.getCell(0, 2); cell5.setData(LightUpCellType.EMPTY.value); board.addModifiedData(cell5); - LightUpCell cell6 = board.getCell(1,2); + LightUpCell cell6 = board.getCell(1, 2); cell6.setData(LightUpCellType.EMPTY.value); board.addModifiedData(cell6); - LightUpCell cell7 = board.getCell(2,1); + LightUpCell cell7 = board.getCell(2, 1); cell7.setData(LightUpCellType.EMPTY.value); board.addModifiedData(cell7); - LightUpCell cell8 = board.getCell(3,0); + LightUpCell cell8 = board.getCell(3, 0); cell8.setData(LightUpCellType.EMPTY.value); board.addModifiedData(cell8); - LightUpCell cell9 = board.getCell(3,2); + LightUpCell cell9 = board.getCell(3, 2); cell9.setData(LightUpCellType.EMPTY.value); board.addModifiedData(cell9); - LightUpCell cell10 = board.getCell(2,3); + LightUpCell cell10 = board.getCell(2, 3); cell10.setData(LightUpCellType.EMPTY.value); board.addModifiedData(cell10); - LightUpCell cell11 = board.getCell(0,3); + LightUpCell cell11 = board.getCell(0, 3); cell11.setData(LightUpCellType.EMPTY.value); board.addModifiedData(cell11); - //confirm there is a logical following of the EmptyCellinLight rule + // confirm there is a logical following of the EmptyCellinLight rule Assert.assertNull(RULE.checkRule(transition)); - //cells (0,0) and (2,2) are not empty because they have lightbulbs, (1,1) - //because it is a black tile, and (1,3),(3,1),(3,3) because they are not lit. Confirm the rest are empty + // cells (0,0) and (2,2) are not empty because they have lightbulbs, (1,1) + // because it is a black tile, and (1,3),(3,1),(3,3) because they are not lit. Confirm the + // rest + // are empty LightUpCell c; for (int i = 0; i < board.getHeight(); i++) { for (int j = 0; j < board.getWidth(); j++) { c = board.getCell(j, i); - if ((i == 0 && j == 0) || (i == 2 && j == 2) || (i == 1 && j == 1) || (i == 1 && j == 3) || (i == 3 && j == 1) - || (i==3 && j==3)){ + if ((i == 0 && j == 0) + || (i == 2 && j == 2) + || (i == 1 && j == 1) + || (i == 1 && j == 3) + || (i == 3 && j == 1) + || (i == 3 && j == 3)) { Assert.assertNotNull(RULE.checkRuleAt(transition, c)); - } - else { + } else { Assert.assertNull(RULE.checkRuleAt(transition, c)); } } diff --git a/src/test/java/puzzles/lightup/rules/EmptyCornersDirectRuleTest.java b/src/test/java/puzzles/lightup/rules/EmptyCornersDirectRuleTest.java index bea69b95f..a4f958860 100644 --- a/src/test/java/puzzles/lightup/rules/EmptyCornersDirectRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/EmptyCornersDirectRuleTest.java @@ -1,23 +1,22 @@ package puzzles.lightup.rules; -import org.junit.BeforeClass; -import org.junit.Test; -import edu.rpi.legup.puzzle.lightup.LightUp; -import edu.rpi.legup.puzzle.lightup.rules.EmptyCornersDirectRule; -import edu.rpi.legup.save.InvalidFileFormatException; -import legup.TestUtilities; import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.lightup.LightUp; import edu.rpi.legup.puzzle.lightup.LightUpBoard; import edu.rpi.legup.puzzle.lightup.LightUpCell; import edu.rpi.legup.puzzle.lightup.LightUpCellType; +import edu.rpi.legup.puzzle.lightup.rules.EmptyCornersDirectRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.TestUtilities; import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; public class EmptyCornersDirectRuleTest { private static final EmptyCornersDirectRule RULE = new EmptyCornersDirectRule(); private static LightUp lightUp; - @BeforeClass public static void setUp() { lightUp = new LightUp(); @@ -25,55 +24,55 @@ public static void setUp() { @Test public void EmptyCornersTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/lightup/rules/EmptyCornersDirectRule/EmptyCorners", lightUp); + TestUtilities.importTestBoard( + "puzzles/lightup/rules/EmptyCornersDirectRule/EmptyCorners", lightUp); TreeNode rootNode = lightUp.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - //get board state + // get board state LightUpBoard board = (LightUpBoard) transition.getBoard(); - //change the board's cells considering the EmptyCorners rule to empty - LightUpCell cell1 = board.getCell(2,2); + // change the board's cells considering the EmptyCorners rule to empty + LightUpCell cell1 = board.getCell(2, 2); cell1.setData(LightUpCellType.EMPTY.value); board.addModifiedData(cell1); - LightUpCell cell2 = board.getCell(0,2); + LightUpCell cell2 = board.getCell(0, 2); cell2.setData(LightUpCellType.EMPTY.value); board.addModifiedData(cell2); - LightUpCell cell3 = board.getCell(4,3); + LightUpCell cell3 = board.getCell(4, 3); cell3.setData(LightUpCellType.EMPTY.value); board.addModifiedData(cell3); - //confirm there is a logical following of the EmptyCorners rule + // confirm there is a logical following of the EmptyCorners rule Assert.assertNull(RULE.checkRule(transition)); - //this should not be accepted, the cell should remain unknown - LightUpCell cell4 = board.getCell(4,5); + // this should not be accepted, the cell should remain unknown + LightUpCell cell4 = board.getCell(4, 5); cell4.setData(LightUpCellType.EMPTY.value); board.addModifiedData(cell4); - //this should not be accepted, the cell should be empty but not because of this rule - LightUpCell cell5 = board.getCell(4,1); + // this should not be accepted, the cell should be empty but not because of this rule + LightUpCell cell5 = board.getCell(4, 1); cell5.setData(LightUpCellType.EMPTY.value); board.addModifiedData(cell5); Assert.assertNotNull(RULE.checkRule(transition)); - //confirm the two expected cells are emptied USING THE RULE + // confirm the two expected cells are emptied USING THE RULE // and none of the rest are (others can be empty just not by the same rule) LightUpCell c; for (int i = 0; i < board.getHeight(); i++) { for (int j = 0; j < board.getWidth(); j++) { c = board.getCell(j, i); - if ((i == 2 && j == 0) || (i == 2 && j == 2) || (i==3 && j==4)){ + if ((i == 2 && j == 0) || (i == 2 && j == 2) || (i == 3 && j == 4)) { Assert.assertNull(RULE.checkRuleAt(transition, c)); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, c)); } } } } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/lightup/rules/FinishWithBulbsDirectRuleTest.java b/src/test/java/puzzles/lightup/rules/FinishWithBulbsDirectRuleTest.java index f98a48303..59cbfdbf9 100644 --- a/src/test/java/puzzles/lightup/rules/FinishWithBulbsDirectRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/FinishWithBulbsDirectRuleTest.java @@ -1,17 +1,17 @@ package puzzles.lightup.rules; -import org.junit.BeforeClass; -import org.junit.Test; -import edu.rpi.legup.puzzle.lightup.LightUp; -import edu.rpi.legup.puzzle.lightup.rules.FinishWithBulbsDirectRule; -import edu.rpi.legup.save.InvalidFileFormatException; -import legup.TestUtilities; import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.lightup.LightUp; import edu.rpi.legup.puzzle.lightup.LightUpBoard; import edu.rpi.legup.puzzle.lightup.LightUpCell; import edu.rpi.legup.puzzle.lightup.LightUpCellType; +import edu.rpi.legup.puzzle.lightup.rules.FinishWithBulbsDirectRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.TestUtilities; import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; public class FinishWithBulbsDirectRuleTest { private static final FinishWithBulbsDirectRule RULE = new FinishWithBulbsDirectRule(); @@ -24,77 +24,79 @@ public static void setUp() { @Test public void FinishBulbTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/lightup/rules/FinishWithBulbsDirectRule/FinishWithBulbs", lightUp); + TestUtilities.importTestBoard( + "puzzles/lightup/rules/FinishWithBulbsDirectRule/FinishWithBulbs", lightUp); TreeNode rootNode = lightUp.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); - transition.setRule(RULE); - - //get board state + transition.setRule(RULE); + + // get board state LightUpBoard board = (LightUpBoard) transition.getBoard(); - //change the board's cells considering the FinishWithBulbs rule to empty - LightUpCell cell1 = board.getCell(1,0); + // change the board's cells considering the FinishWithBulbs rule to empty + LightUpCell cell1 = board.getCell(1, 0); cell1.setData(LightUpCellType.BULB.value); board.addModifiedData(cell1); - //confirm there is a logical following of the FinishWithBulbs rule + // confirm there is a logical following of the FinishWithBulbs rule Assert.assertNull(RULE.checkRule(transition)); - //check every square except the top center (2,0) + // check every square except the top center (2,0) LightUpCell c; for (int i = 0; i < board.getHeight(); i++) { for (int j = 0; j < board.getWidth(); j++) { c = board.getCell(j, i); - if (i == 0 && j == 1){ - //logically follows + if (i == 0 && j == 1) { + // logically follows Assert.assertNull(RULE.checkRuleAt(transition, c)); - } - else { - //does not use the rule to logically follow + } else { + // does not use the rule to logically follow Assert.assertNotNull(RULE.checkRuleAt(transition, c)); } } } } - //even though this test isnt a completely filled board because it is unsolveable, it tests FinishBulbs properly + // even though this test isnt a completely filled board because it is unsolveable, it tests + // FinishBulbs properly @Test public void FinishBulbTestWithThree() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/lightup/rules/FinishWithBulbsDirectRule/FinishWithBulbsWithThree", lightUp); + TestUtilities.importTestBoard( + "puzzles/lightup/rules/FinishWithBulbsDirectRule/FinishWithBulbsWithThree", + lightUp); TreeNode rootNode = lightUp.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); - transition.setRule(RULE); - - //get board state + transition.setRule(RULE); + + // get board state LightUpBoard board = (LightUpBoard) transition.getBoard(); - //change the board's cells considering the FinishWithBulbs rule to empty - LightUpCell cell1 = board.getCell(1,2); + // change the board's cells considering the FinishWithBulbs rule to empty + LightUpCell cell1 = board.getCell(1, 2); cell1.setData(LightUpCellType.BULB.value); board.addModifiedData(cell1); - LightUpCell cell2 = board.getCell(0,1); + LightUpCell cell2 = board.getCell(0, 1); cell2.setData(LightUpCellType.BULB.value); board.addModifiedData(cell2); - LightUpCell cell3 = board.getCell(2,1); + LightUpCell cell3 = board.getCell(2, 1); cell3.setData(LightUpCellType.BULB.value); board.addModifiedData(cell3); - //confirm there is a logical following of the FinishWithBulbs rule + // confirm there is a logical following of the FinishWithBulbs rule Assert.assertNull(RULE.checkRule(transition)); - //check every square for logical following + // check every square for logical following LightUpCell c; for (int i = 0; i < board.getHeight(); i++) { for (int j = 0; j < board.getWidth(); j++) { c = board.getCell(j, i); - if ((i == 1 && j == 2) || (i == 2 && j == 1) || (i == 1 && j == 0)){ - //logically follows + if ((i == 1 && j == 2) || (i == 2 && j == 1) || (i == 1 && j == 0)) { + // logically follows Assert.assertNull(RULE.checkRuleAt(transition, c)); - } - else { - //does not use the rule to logically follow + } else { + // does not use the rule to logically follow Assert.assertNotNull(RULE.checkRuleAt(transition, c)); } } diff --git a/src/test/java/puzzles/lightup/rules/LightOrEmptyCaseRuleTest.java b/src/test/java/puzzles/lightup/rules/LightOrEmptyCaseRuleTest.java index 2e6a1e879..fa0698edb 100644 --- a/src/test/java/puzzles/lightup/rules/LightOrEmptyCaseRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/LightOrEmptyCaseRuleTest.java @@ -1,19 +1,19 @@ package puzzles.lightup.rules; -import org.junit.BeforeClass; -import org.junit.Test; -import edu.rpi.legup.puzzle.lightup.LightUp; -import edu.rpi.legup.puzzle.lightup.rules.LightOrEmptyCaseRule; -import edu.rpi.legup.save.InvalidFileFormatException; -import legup.TestUtilities; +import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.lightup.LightUp; import edu.rpi.legup.puzzle.lightup.LightUpBoard; -import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.puzzle.lightup.LightUpCell; import edu.rpi.legup.puzzle.lightup.LightUpCellType; -import org.junit.Assert; +import edu.rpi.legup.puzzle.lightup.rules.LightOrEmptyCaseRule; +import edu.rpi.legup.save.InvalidFileFormatException; import java.util.ArrayList; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; public class LightOrEmptyCaseRuleTest { private static final LightOrEmptyCaseRule RULE = new LightOrEmptyCaseRule(); @@ -24,49 +24,52 @@ public static void setUp() { lightUp = new LightUp(); } - //creates boards for what is expected output, and checks that the getcases function produces the correct boards - //IT FAILS BECAUSE THE EXISTING GETCASES FUNCTION IS BUGGY/NOT COMPLETED (not my fault :| ) + // creates boards for what is expected output, and checks that the getcases function produces + // the + // correct boards + // IT FAILS BECAUSE THE EXISTING GETCASES FUNCTION IS BUGGY/NOT COMPLETED (not my fault :| ) @Test public void LightOrEmptyTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/lightup/rules/LightOrEmptyCaseRule/LightOrEmpty", lightUp); + TestUtilities.importTestBoard( + "puzzles/lightup/rules/LightOrEmptyCaseRule/LightOrEmpty", lightUp); TreeNode rootNode = lightUp.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); - transition.setRule(RULE); + transition.setRule(RULE); - //get all new board states using caserule builtin function + // get all new board states using caserule builtin function LightUpBoard b = (LightUpBoard) transition.getBoard(); - LightUpCell numbered_cell = b.getCell(0,0); //the focus cell + LightUpCell numbered_cell = b.getCell(0, 0); // the focus cell ArrayList cases = RULE.getCases(b, numbered_cell); - //assert correct number of cases + // assert correct number of cases Assert.assertEquals(2, cases.size()); - //make a list of boards that I expect + // make a list of boards that I expect LightUpCell change_cell; LightUpBoard case1 = ((LightUpBoard) transition.getBoard()).copy(); LightUpBoard case2 = ((LightUpBoard) transition.getBoard()).copy(); - //change the cells of the first new case board - change_cell = case1.getCell(0,0); + // change the cells of the first new case board + change_cell = case1.getCell(0, 0); change_cell.setData(LightUpCellType.BULB.value); - //case1.addModifiedData(change_cell); + // case1.addModifiedData(change_cell); - change_cell = case1.getCell(1,1); + change_cell = case1.getCell(1, 1); change_cell.setData(LightUpCellType.BULB.value); - //case1.addModifiedData(change_cell); + // case1.addModifiedData(change_cell); - //change the cells of the second new case board - change_cell = case2.getCell(0,1); + // change the cells of the second new case board + change_cell = case2.getCell(0, 1); change_cell.setData(LightUpCellType.BULB.value); - //case2.addModifiedData(change_cell); + // case2.addModifiedData(change_cell); - change_cell = case2.getCell(1,0); + change_cell = case2.getCell(1, 0); change_cell.setData(LightUpCellType.BULB.value); - //case2.addModifiedData(change_cell); + // case2.addModifiedData(change_cell); - //check each board I expect and make sure it exists in returned board list - //currently cases is not made correctly, so the getCases function is flawed. - //Assert.assertTrue(cases.contains((Board) case1)); - //Assert.assertTrue(cases.contains((Board) case2)); + // check each board I expect and make sure it exists in returned board list + // currently cases is not made correctly, so the getCases function is flawed. + // Assert.assertTrue(cases.contains((Board) case1)); + // Assert.assertTrue(cases.contains((Board) case2)); } } diff --git a/src/test/java/puzzles/lightup/rules/MustLightDirectRuleTest.java b/src/test/java/puzzles/lightup/rules/MustLightDirectRuleTest.java index 07958895b..e0e1434c3 100644 --- a/src/test/java/puzzles/lightup/rules/MustLightDirectRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/MustLightDirectRuleTest.java @@ -1,17 +1,17 @@ package puzzles.lightup.rules; -import org.junit.BeforeClass; -import org.junit.Test; -import edu.rpi.legup.puzzle.lightup.LightUp; -import edu.rpi.legup.puzzle.lightup.rules.MustLightDirectRule; -import edu.rpi.legup.save.InvalidFileFormatException; -import legup.TestUtilities; import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.lightup.LightUp; import edu.rpi.legup.puzzle.lightup.LightUpBoard; import edu.rpi.legup.puzzle.lightup.LightUpCell; import edu.rpi.legup.puzzle.lightup.LightUpCellType; +import edu.rpi.legup.puzzle.lightup.rules.MustLightDirectRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.TestUtilities; import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; public class MustLightDirectRuleTest { private static final MustLightDirectRule RULE = new MustLightDirectRule(); @@ -24,33 +24,33 @@ public static void setUp() { @Test public void MustLightTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/lightup/rules/MustLightDirectRule/MustLight", lightUp); + TestUtilities.importTestBoard( + "puzzles/lightup/rules/MustLightDirectRule/MustLight", lightUp); TreeNode rootNode = lightUp.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); - transition.setRule(RULE); - - //get board state + transition.setRule(RULE); + + // get board state LightUpBoard board = (LightUpBoard) transition.getBoard(); - //change the board's cells considering the MustLight rule - LightUpCell cell1 = board.getCell(1,2); + // change the board's cells considering the MustLight rule + LightUpCell cell1 = board.getCell(1, 2); cell1.setData(LightUpCellType.BULB.value); board.addModifiedData(cell1); - //confirm there is a logical following of the FinishWithBulbs rule + // confirm there is a logical following of the FinishWithBulbs rule Assert.assertNull(RULE.checkRule(transition)); - //only the cell above should change following the rule + // only the cell above should change following the rule LightUpCell c; for (int i = 0; i < board.getHeight(); i++) { for (int j = 0; j < board.getWidth(); j++) { c = board.getCell(j, i); - if (i == 2 && j == 1){ - //logically follows + if (i == 2 && j == 1) { + // logically follows Assert.assertNull(RULE.checkRuleAt(transition, c)); - } - else { - //does not use the rule to logically follow + } else { + // does not use the rule to logically follow Assert.assertNotNull(RULE.checkRuleAt(transition, c)); } } diff --git a/src/test/java/puzzles/lightup/rules/SatisfyNumberCaseRuleTest.java b/src/test/java/puzzles/lightup/rules/SatisfyNumberCaseRuleTest.java index de3551778..a04f1c520 100644 --- a/src/test/java/puzzles/lightup/rules/SatisfyNumberCaseRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/SatisfyNumberCaseRuleTest.java @@ -1,19 +1,19 @@ package puzzles.lightup.rules; -import org.junit.BeforeClass; -import org.junit.Test; -import edu.rpi.legup.puzzle.lightup.LightUp; -import edu.rpi.legup.puzzle.lightup.rules.SatisfyNumberCaseRule; -import edu.rpi.legup.save.InvalidFileFormatException; -import legup.TestUtilities; +import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.lightup.LightUp; import edu.rpi.legup.puzzle.lightup.LightUpBoard; -import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.puzzle.lightup.LightUpCell; import edu.rpi.legup.puzzle.lightup.LightUpCellType; -import org.junit.Assert; +import edu.rpi.legup.puzzle.lightup.rules.SatisfyNumberCaseRule; +import edu.rpi.legup.save.InvalidFileFormatException; import java.util.ArrayList; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; public class SatisfyNumberCaseRuleTest { private static final SatisfyNumberCaseRule RULE = new SatisfyNumberCaseRule(); @@ -23,69 +23,77 @@ public class SatisfyNumberCaseRuleTest { public static void setUp() { lightUp = new LightUp(); } - - //creates two boards for what is expected output, and checks that the getcases function produces the correct boards - //IT FAILS BECAUSE THE EXISTING GETCASES FUNCTION IS BUGGY/NOT COMPLETED (not my fault :| ) + + // creates two boards for what is expected output, and checks that the getcases function + // produces + // the correct boards + // IT FAILS BECAUSE THE EXISTING GETCASES FUNCTION IS BUGGY/NOT COMPLETED (not my fault :| ) @Test public void SatisfyNumberTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/lightup/rules/SatisfyNumberCaseRule/SatisfyNumber", lightUp); + TestUtilities.importTestBoard( + "puzzles/lightup/rules/SatisfyNumberCaseRule/SatisfyNumber", lightUp); TreeNode rootNode = lightUp.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); - transition.setRule(RULE); + transition.setRule(RULE); - //get all new board states using caserule builtin function + // get all new board states using caserule builtin function LightUpBoard b = (LightUpBoard) transition.getBoard(); - LightUpCell numbered_cell = b.getCell(1,0); //the tile cell - ArrayList cases = RULE.getCases(b, numbered_cell);//C MUST BE THE NUMBERED TILE, NOT ANY RANDOM EMPTY ONE + LightUpCell numbered_cell = b.getCell(1, 0); // the tile cell + ArrayList cases = + RULE.getCases( + b, numbered_cell); // C MUST BE THE NUMBERED TILE, NOT ANY RANDOM EMPTY ONE - //assert correct number of cases + // assert correct number of cases Assert.assertEquals(2, cases.size()); - //make a list of boards that I expect + // make a list of boards that I expect LightUpCell change_cell; LightUpBoard case1 = ((LightUpBoard) transition.getBoard()).copy(); LightUpBoard case2 = ((LightUpBoard) transition.getBoard()).copy(); - //change the cells of the first new case board - change_cell = case1.getCell(0,0); + // change the cells of the first new case board + change_cell = case1.getCell(0, 0); change_cell.setData(LightUpCellType.BULB.value); - //case1.addModifiedData(change_cell); + // case1.addModifiedData(change_cell); - change_cell = case1.getCell(1,1); + change_cell = case1.getCell(1, 1); change_cell.setData(LightUpCellType.EMPTY.value); - //case1.addModifiedData(change_cell); + // case1.addModifiedData(change_cell); - //change the cells of the second new case board - change_cell = case2.getCell(0,0); + // change the cells of the second new case board + change_cell = case2.getCell(0, 0); change_cell.setData(LightUpCellType.EMPTY.value); - //case2.addModifiedData(change_cell); + // case2.addModifiedData(change_cell); - change_cell = case2.getCell(1,1); + change_cell = case2.getCell(1, 1); change_cell.setData(LightUpCellType.BULB.value); - //case2.addModifiedData(change_cell); + // case2.addModifiedData(change_cell); - //check each board I expect and make sure it exists in returned board list - //currently cases is not made correctly, so the getCases function is flawed. - //Assert.assertTrue(cases.contains((Board) case1)); - //Assert.assertTrue(cases.contains((Board) case2)); + // check each board I expect and make sure it exists in returned board list + // currently cases is not made correctly, so the getCases function is flawed. + // Assert.assertTrue(cases.contains((Board) case1)); + // Assert.assertTrue(cases.contains((Board) case2)); } @Test public void SatisfyNumberTestTwo() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/lightup/rules/SatisfyNumberCaseRule/SatisfyNumberTwo", lightUp); + TestUtilities.importTestBoard( + "puzzles/lightup/rules/SatisfyNumberCaseRule/SatisfyNumberTwo", lightUp); TreeNode rootNode = lightUp.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); - transition.setRule(RULE); + transition.setRule(RULE); - //get all new board states using caserule builtin function + // get all new board states using caserule builtin function LightUpBoard b = (LightUpBoard) transition.getBoard(); - LightUpCell numbered_cell = b.getCell(1,1); //the tile cell - ArrayList cases = RULE.getCases(b, numbered_cell);//C MUST BE THE NUMBERED TILE, NOT ANY RANDOM EMPTY ONE + LightUpCell numbered_cell = b.getCell(1, 1); // the tile cell + ArrayList cases = + RULE.getCases( + b, numbered_cell); // C MUST BE THE NUMBERED TILE, NOT ANY RANDOM EMPTY ONE - //assert correct number of cases + // assert correct number of cases Assert.assertEquals(6, cases.size()); - //make a list of boards that I expect + // make a list of boards that I expect LightUpCell change_cell1; LightUpCell change_cell2; LightUpBoard case1 = ((LightUpBoard) transition.getBoard()).copy(); @@ -95,61 +103,61 @@ public void SatisfyNumberTestTwo() throws InvalidFileFormatException { LightUpBoard case5 = ((LightUpBoard) transition.getBoard()).copy(); LightUpBoard case6 = ((LightUpBoard) transition.getBoard()).copy(); - //case 1: lights in (1,0) and (0,1) - change_cell1 = case1.getCell(1,0); - change_cell2 = case1.getCell(0,1); + // case 1: lights in (1,0) and (0,1) + change_cell1 = case1.getCell(1, 0); + change_cell2 = case1.getCell(0, 1); change_cell1.setData(LightUpCellType.BULB.value); change_cell2.setData(LightUpCellType.BULB.value); case1.addModifiedData(change_cell1); case1.addModifiedData(change_cell2); - //case 2: lights in (1,0) and (1,2) - change_cell1 = case2.getCell(1,0); - change_cell2 = case2.getCell(1,2); + // case 2: lights in (1,0) and (1,2) + change_cell1 = case2.getCell(1, 0); + change_cell2 = case2.getCell(1, 2); change_cell1.setData(LightUpCellType.BULB.value); change_cell2.setData(LightUpCellType.BULB.value); case2.addModifiedData(change_cell1); case2.addModifiedData(change_cell2); - //case 3: lights in (1,0) and (2,1) - change_cell1 = case3.getCell(1,0); - change_cell2 = case3.getCell(2,1); + // case 3: lights in (1,0) and (2,1) + change_cell1 = case3.getCell(1, 0); + change_cell2 = case3.getCell(2, 1); change_cell1.setData(LightUpCellType.BULB.value); change_cell2.setData(LightUpCellType.BULB.value); case3.addModifiedData(change_cell1); case3.addModifiedData(change_cell2); - //case 4: lights in (0,1) and (2,1) - change_cell1 = case4.getCell(0,1); - change_cell2 = case4.getCell(2,1); + // case 4: lights in (0,1) and (2,1) + change_cell1 = case4.getCell(0, 1); + change_cell2 = case4.getCell(2, 1); change_cell1.setData(LightUpCellType.BULB.value); change_cell2.setData(LightUpCellType.BULB.value); case4.addModifiedData(change_cell1); case4.addModifiedData(change_cell2); - //case 5: lights in (0,1) and (1,2) - change_cell1 = case5.getCell(0,1); - change_cell2 = case5.getCell(1,2); + // case 5: lights in (0,1) and (1,2) + change_cell1 = case5.getCell(0, 1); + change_cell2 = case5.getCell(1, 2); change_cell1.setData(LightUpCellType.BULB.value); change_cell2.setData(LightUpCellType.BULB.value); case5.addModifiedData(change_cell1); case5.addModifiedData(change_cell2); - //case 6: lights in (1,2) and (2,1) - change_cell1 = case6.getCell(1,2); - change_cell2 = case6.getCell(2,1); + // case 6: lights in (1,2) and (2,1) + change_cell1 = case6.getCell(1, 2); + change_cell2 = case6.getCell(2, 1); change_cell1.setData(LightUpCellType.BULB.value); change_cell2.setData(LightUpCellType.BULB.value); case6.addModifiedData(change_cell1); case6.addModifiedData(change_cell2); - //check each board I expect and make sure it exists in returned board list - //currently the cases list is not made correctly, so the getCases function is flawed. - //Assert.assertTrue(cases.contains((Board) case1)); - //Assert.assertTrue(cases.contains((Board) case2)); - //Assert.assertTrue(cases.contains((Board) case3)); - //Assert.assertTrue(cases.contains((Board) case4)); - //Assert.assertTrue(cases.contains((Board) case5)); - //Assert.assertTrue(cases.contains((Board) case6)); + // check each board I expect and make sure it exists in returned board list + // currently the cases list is not made correctly, so the getCases function is flawed. + // Assert.assertTrue(cases.contains((Board) case1)); + // Assert.assertTrue(cases.contains((Board) case2)); + // Assert.assertTrue(cases.contains((Board) case3)); + // Assert.assertTrue(cases.contains((Board) case4)); + // Assert.assertTrue(cases.contains((Board) case5)); + // Assert.assertTrue(cases.contains((Board) case6)); } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/lightup/rules/TooFewBulbsContradictionRuleTest.java b/src/test/java/puzzles/lightup/rules/TooFewBulbsContradictionRuleTest.java index bab616198..fe994baa6 100644 --- a/src/test/java/puzzles/lightup/rules/TooFewBulbsContradictionRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/TooFewBulbsContradictionRuleTest.java @@ -1,15 +1,15 @@ package puzzles.lightup.rules; -import org.junit.BeforeClass; -import org.junit.Test; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.lightup.LightUp; +import edu.rpi.legup.puzzle.lightup.LightUpBoard; import edu.rpi.legup.puzzle.lightup.rules.TooFewBulbsContradictionRule; import edu.rpi.legup.save.InvalidFileFormatException; import legup.TestUtilities; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.lightup.LightUpBoard; import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; public class TooFewBulbsContradictionRuleTest { private static final TooFewBulbsContradictionRule RULE = new TooFewBulbsContradictionRule(); @@ -22,21 +22,22 @@ public static void setUp() { @Test public void TooFewBulbsContradictionRule() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/lightup/rules/TooFewBulbsContradictionRule/FullTooFewTest", lightUp); + TestUtilities.importTestBoard( + "puzzles/lightup/rules/TooFewBulbsContradictionRule/FullTooFewTest", lightUp); TreeNode rootNode = lightUp.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); - transition.setRule(RULE); + transition.setRule(RULE); LightUpBoard board = (LightUpBoard) transition.getBoard(); - //confirm there is a contradiction somewhere on the board + // confirm there is a contradiction somewhere on the board Assert.assertNull(RULE.checkContradiction(board)); - //confirm that there arent enough bulbs around the black tiles + // confirm that there arent enough bulbs around the black tiles Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(1, 1))); Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(4, 1))); Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(1, 4))); - //confirm there are no requirements for number of bulbs around non-black tiles or 0 tiles + // confirm there are no requirements for number of bulbs around non-black tiles or 0 tiles Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 0))); Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(4, 4))); Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(5, 5))); @@ -44,17 +45,18 @@ public void TooFewBulbsContradictionRule() throws InvalidFileFormatException { @Test public void TooFewSimpleTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/lightup/rules/TooFewBulbsContradictionRule/TooFew", lightUp); + TestUtilities.importTestBoard( + "puzzles/lightup/rules/TooFewBulbsContradictionRule/TooFew", lightUp); TreeNode rootNode = lightUp.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); - transition.setRule(RULE); + transition.setRule(RULE); LightUpBoard board = (LightUpBoard) transition.getBoard(); - //confirm it is impossible to satisfy up the center square + // confirm it is impossible to satisfy up the center square Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(1, 1))); - //every square except the center + // every square except the center Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 0))); Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 0))); Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 0))); diff --git a/src/test/java/puzzles/lightup/rules/TooManyBulbsContradictionRuleTest.java b/src/test/java/puzzles/lightup/rules/TooManyBulbsContradictionRuleTest.java index fe3dad2e0..e27fa3323 100644 --- a/src/test/java/puzzles/lightup/rules/TooManyBulbsContradictionRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/TooManyBulbsContradictionRuleTest.java @@ -1,15 +1,15 @@ package puzzles.lightup.rules; -import org.junit.BeforeClass; -import org.junit.Test; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.lightup.LightUp; +import edu.rpi.legup.puzzle.lightup.LightUpBoard; import edu.rpi.legup.puzzle.lightup.rules.TooManyBulbsContradictionRule; import edu.rpi.legup.save.InvalidFileFormatException; import legup.TestUtilities; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.lightup.LightUpBoard; import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; public class TooManyBulbsContradictionRuleTest { private static final TooManyBulbsContradictionRule RULE = new TooManyBulbsContradictionRule(); @@ -19,41 +19,44 @@ public class TooManyBulbsContradictionRuleTest { public static void setUp() { lightUp = new LightUp(); } + @Test - //complex extensive toofew test + // complex extensive toofew test public void TooFewBulbsContradictionRule() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/lightup/rules/TooManyBulbsContradictionRule/FullTooManyTest", lightUp); + TestUtilities.importTestBoard( + "puzzles/lightup/rules/TooManyBulbsContradictionRule/FullTooManyTest", lightUp); TreeNode rootNode = lightUp.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); - transition.setRule(RULE); + transition.setRule(RULE); LightUpBoard board = (LightUpBoard) transition.getBoard(); - //confirm there is a contradiction somewhere on the board + // confirm there is a contradiction somewhere on the board Assert.assertNull(RULE.checkContradiction(board)); - //confirm that there are too many bulbs around the black tiles + // confirm that there are too many bulbs around the black tiles Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(1, 1))); Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(1, 4))); - //confirm there are no requirements for number of bulbs around non-black tiles or 0 tiles + // confirm there are no requirements for number of bulbs around non-black tiles or 0 tiles Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 0))); Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(5, 5))); } @Test - //tests a 3x3 board with a 3 in the center and 4 surrounding lightbulbs + // tests a 3x3 board with a 3 in the center and 4 surrounding lightbulbs public void TooManySimpleTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/lightup/rules/TooManyBulbsContradictionRule/TooMany", lightUp); + TestUtilities.importTestBoard( + "puzzles/lightup/rules/TooManyBulbsContradictionRule/TooMany", lightUp); TreeNode rootNode = lightUp.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); - transition.setRule(RULE); + transition.setRule(RULE); LightUpBoard board = (LightUpBoard) transition.getBoard(); - //confirm it is impossible to satisfy up the center square + // confirm it is impossible to satisfy up the center square Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(1, 1))); - //every square except the center + // every square except the center Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 0))); Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 0))); Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 0))); diff --git a/src/test/java/puzzles/nurikabe/rules/BlackBetweenRegionsDirectRuleTest.java b/src/test/java/puzzles/nurikabe/rules/BlackBetweenRegionsDirectRuleTest.java index 7e8b5eb83..d87398303 100644 --- a/src/test/java/puzzles/nurikabe/rules/BlackBetweenRegionsDirectRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/BlackBetweenRegionsDirectRuleTest.java @@ -1,190 +1,204 @@ -package puzzles.nurikabe.rules; - -//import javafx.scene.layout.Pane; - -import legup.MockGameBoardFacade; -import legup.TestUtilities; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -import edu.rpi.legup.puzzle.nurikabe.Nurikabe; -import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; -import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; -import edu.rpi.legup.puzzle.nurikabe.NurikabeType; -import edu.rpi.legup.puzzle.nurikabe.rules.BlackBetweenRegionsDirectRule; -import edu.rpi.legup.save.InvalidFileFormatException; - -import java.awt.*; - -public class BlackBetweenRegionsDirectRuleTest { - - private static final BlackBetweenRegionsDirectRule RULE = new BlackBetweenRegionsDirectRule(); - private static Nurikabe nurikabe; - - @BeforeClass - public static void setUp() { - MockGameBoardFacade.getInstance(); - nurikabe = new Nurikabe(); - } - - /** - * Tests the Black Between Regions direct rule for regions that are diagonal to each other (diagonal going from top left to bottom right) - */ - @Test - public void BlackBetweenRegionsDirectRule_DiagonalBlackBetweenRegions1Test() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsDirectRule/DiagonalBlackBetweenRegions1", nurikabe); - TreeNode rootNode = nurikabe.getTree().getRootNode(); - TreeTransition transition = rootNode.getChildren().get(0); - transition.setRule(RULE); - - NurikabeBoard board = (NurikabeBoard) transition.getBoard(); - - NurikabeCell cell1 = board.getCell(2, 1); - cell1.setData(NurikabeType.BLACK.toValue()); - NurikabeCell cell2 = board.getCell(1, 2); - cell2.setData(NurikabeType.BLACK.toValue()); - - board.addModifiedData(cell1); - board.addModifiedData(cell2); - - Assert.assertNull(RULE.checkRule(transition)); - - for (int i = 0; i < board.getHeight(); i++) { - for (int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { - Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { - Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - } - } - } - - /** - * Tests the Black Between Regions direct rule for regions that are diagonal to each other (diagonal going from bottom left to top right) - */ - @Test - public void BlackBetweenRegionsDirectRule_DiagonalBlackBetweenRegions2Test() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsDirectRule/DiagonalBlackBetweenRegions2", nurikabe); - TreeNode rootNode = nurikabe.getTree().getRootNode(); - TreeTransition transition = rootNode.getChildren().get(0); - transition.setRule(RULE); - - NurikabeBoard board = (NurikabeBoard) transition.getBoard(); - - NurikabeCell cell1 = board.getCell(1, 1); - cell1.setData(NurikabeType.BLACK.toValue()); - NurikabeCell cell2 = board.getCell(2, 2); - cell2.setData(NurikabeType.BLACK.toValue()); - - board.addModifiedData(cell1); - board.addModifiedData(cell2); - - Assert.assertNull(RULE.checkRule(transition)); - - for (int i = 0; i < board.getHeight(); i++) { - for (int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { - Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { - Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - } - } - } - - /** - * Tests the Black Between Regions direct rule for regions that are horizontally opposite each other - */ - @Test - public void BlackBetweenRegionsDirectRule_HorizontalBlackBetweenRegionsTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsDirectRule/HorizontalBlackBetweenRegions", nurikabe); - TreeNode rootNode = nurikabe.getTree().getRootNode(); - TreeTransition transition = rootNode.getChildren().get(0); - transition.setRule(RULE); - - NurikabeBoard board = (NurikabeBoard) transition.getBoard(); - - NurikabeCell cell = board.getCell(1, 1); - cell.setData(NurikabeType.BLACK.toValue()); - - board.addModifiedData(cell); - - Assert.assertNull(RULE.checkRule(transition)); - - for (int i = 0; i < board.getHeight(); i++) { - for (int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if (point.equals(cell.getLocation())) { - Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { - Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - } - } - } - - /** - * Tests the Black Between Regions direct rule for regions that are vertically opposite each other - */ - @Test - public void BlackBetweenRegionsDirectRule_VerticalBlackBetweenRegionsTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsDirectRule/VerticalBlackBetweenRegions", nurikabe); - TreeNode rootNode = nurikabe.getTree().getRootNode(); - TreeTransition transition = rootNode.getChildren().get(0); - transition.setRule(RULE); - - NurikabeBoard board = (NurikabeBoard) transition.getBoard(); - - NurikabeCell cell = board.getCell(1, 1); - cell.setData(NurikabeType.BLACK.toValue()); - - board.addModifiedData(cell); - - Assert.assertNull(RULE.checkRule(transition)); - - for (int i = 0; i < board.getHeight(); i++) { - for (int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if (point.equals(cell.getLocation())) { - Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { - Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - } - } - } - - /** - * Tests the Black Between Regions direct rule for a false application of the rule, where a black tile is enclosed by one region - */ - @Test - public void BlackBetweenRegionsDirectRule_FalseBlackBetweenRegionsTest() throws InvalidFileFormatException{ - TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsDirectRule/FalseBlackBetweenRegions",nurikabe); - TreeNode rootNode = nurikabe.getTree().getRootNode(); - TreeTransition transition = rootNode.getChildren().get(0); - transition.setRule(RULE); - - NurikabeBoard board = (NurikabeBoard) transition.getBoard(); - NurikabeCell cell = board.getCell(1,1); - cell.setData(NurikabeType.BLACK.toValue()); - board.addModifiedData(cell); - - Assert.assertNotNull(RULE.checkRule(transition)); - - for(int i=0; i cases = RULE.getCases(board,cell); + NurikabeCell cell = board.getCell(0, 0); + ArrayList cases = RULE.getCases(board, cell); - Assert.assertEquals(2,cases.size()); + Assert.assertEquals(2, cases.size()); NurikabeBoard caseBoard = (NurikabeBoard) cases.get(0); NurikabeBoard caseBoard2 = (NurikabeBoard) cases.get(1); - NurikabeType board1Type = caseBoard.getCell(0,0).getType(); - NurikabeType board2Type = caseBoard2.getCell(0,0).getType(); + NurikabeType board1Type = caseBoard.getCell(0, 0).getType(); + NurikabeType board2Type = caseBoard2.getCell(0, 0).getType(); - Assert.assertTrue((board1Type.equals(NurikabeType.BLACK) || board1Type.equals(NurikabeType.WHITE)) && - (board2Type.equals(NurikabeType.BLACK) || board2Type.equals(NurikabeType.WHITE))); + Assert.assertTrue( + (board1Type.equals(NurikabeType.BLACK) || board1Type.equals(NurikabeType.WHITE)) + && (board2Type.equals(NurikabeType.BLACK) + || board2Type.equals(NurikabeType.WHITE))); Assert.assertFalse(board1Type.equals(board2Type)); - Assert.assertEquals(caseBoard.getHeight(),caseBoard2.getHeight(), board.getHeight()); - Assert.assertEquals(caseBoard.getWidth(),caseBoard2.getWidth(), board.getWidth()); + Assert.assertEquals(caseBoard.getHeight(), caseBoard2.getHeight(), board.getHeight()); + Assert.assertEquals(caseBoard.getWidth(), caseBoard2.getWidth(), board.getWidth()); - for(int i=0; i cases = RULE.getCases(board, cell); // Make sure that the rule checks out @@ -63,60 +60,64 @@ private void falseAndTest(String fileName, // First assert the two cells are not equal, then verify that they are either // unknown or false. Assert.assertNotEquals(board1A, board1B); - Assert.assertTrue(board1A.equals(ShortTruthTableCellType.UNKNOWN) || board1A.equals(ShortTruthTableCellType.FALSE)); - Assert.assertTrue(board1B.equals(ShortTruthTableCellType.UNKNOWN) || board1B.equals(ShortTruthTableCellType.FALSE)); + Assert.assertTrue( + board1A.equals(ShortTruthTableCellType.UNKNOWN) + || board1A.equals(ShortTruthTableCellType.FALSE)); + Assert.assertTrue( + board1B.equals(ShortTruthTableCellType.UNKNOWN) + || board1B.equals(ShortTruthTableCellType.FALSE)); Assert.assertNotEquals(board2A, board2B); - Assert.assertTrue(board2A.equals(ShortTruthTableCellType.UNKNOWN) || board1A.equals(ShortTruthTableCellType.FALSE)); - Assert.assertTrue(board2B.equals(ShortTruthTableCellType.UNKNOWN) || board2B.equals(ShortTruthTableCellType.FALSE)); + Assert.assertTrue( + board2A.equals(ShortTruthTableCellType.UNKNOWN) + || board1A.equals(ShortTruthTableCellType.FALSE)); + Assert.assertTrue( + board2B.equals(ShortTruthTableCellType.UNKNOWN) + || board2B.equals(ShortTruthTableCellType.FALSE)); // Verify the board dimensions are unchanged Assert.assertEquals(caseBoard1.getHeight(), caseBoard2.getHeight(), board.getHeight()); Assert.assertEquals(caseBoard1.getWidth(), caseBoard2.getWidth(), board.getWidth()); // Verify that everywhere else on the board is unchanged - for (int i = 0; i< caseBoard1.getWidth(); i++) { + for (int i = 0; i < caseBoard1.getWidth(); i++) { for (int j = 0; j < caseBoard1.getHeight(); j++) { // Make sure not to check the two cells that should be different if (!((i == aX && j == aY) || (i == bX && j == bY))) { - Assert.assertEquals(caseBoard1.getCell(i, j).getType(), caseBoard2.getCell(i, j).getType()); + Assert.assertEquals( + caseBoard1.getCell(i, j).getType(), caseBoard2.getCell(i, j).getType()); } } } } /** - * Given a statement A ^ B where ^ is false, tests this case rule by ensuring that - * two branches are created: one where A is false and one where B is false. + * Given a statement A ^ B where ^ is false, tests this case rule by ensuring that two branches + * are created: one where A is false and one where B is false. */ @Test public void SimpleStatement1FalseTest() throws InvalidFileFormatException { - falseAndTest("SimpleStatement1_False", 1, 0, 0, 0, - 2, 0); + falseAndTest("SimpleStatement1_False", 1, 0, 0, 0, 2, 0); } /** - * Given a statement ~(A|B)^(C^D) where the first ^ is false, tests this case rule - * by ensuring that two branches are created: one where ~ is false and one where - * the second ^ is false. + * Given a statement ~(A|B)^(C^D) where the first ^ is false, tests this case rule by ensuring + * that two branches are created: one where ~ is false and one where the second ^ is false. */ @Test public void ComplexStatement1FalseTest() throws InvalidFileFormatException { - falseAndTest("ComplexStatement1_False", 6, 0, 0, 0, - 9, 0); + falseAndTest("ComplexStatement1_False", 6, 0, 0, 0, 9, 0); } - private void trueAndTest(String fileName, - int andX, int andY, - int aX, int aY, - int bX, int bY) throws InvalidFileFormatException { + private void trueAndTest(String fileName, int andX, int andY, int aX, int aY, int bX, int bY) + throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/AndCaseRule/" + fileName, stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); - ShortTruthTableCell cell = board.getCell(andX,andY); + ShortTruthTableCell cell = board.getCell(andX, andY); ArrayList cases = RULE.getCases(board, cell); // Make sure that the rule checks out @@ -139,22 +140,20 @@ private void trueAndTest(String fileName, } /** - * Given a statement A ^ B where ^ is false, tests this case rule by ensuring that - * one branch is created where A and B are both true. + * Given a statement A ^ B where ^ is false, tests this case rule by ensuring that one branch is + * created where A and B are both true. */ @Test public void SimpleStatement1AndTest() throws InvalidFileFormatException { - trueAndTest("SimpleStatement1_True", 1, 0, 0, 0, - 2, 0); + trueAndTest("SimpleStatement1_True", 1, 0, 0, 0, 2, 0); } /** - * Given a statement ~(A|B)^(C^D) where the first ^ is true, tests this case rule - * by ensuring that one branch is created where both ~ and the second ^ are true. + * Given a statement ~(A|B)^(C^D) where the first ^ is true, tests this case rule by ensuring + * that one branch is created where both ~ and the second ^ are true. */ @Test public void ComplexStatement1TrueTest() throws InvalidFileFormatException { - trueAndTest("ComplexStatement1_True", 6, 0, 0, 0, - 9, 0); + trueAndTest("ComplexStatement1_True", 6, 0, 0, 0, 9, 0); } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/shorttruthtable/rules/AndEliminationDirectRuleTest.java b/src/test/java/puzzles/shorttruthtable/rules/AndEliminationDirectRuleTest.java index 0d94eb672..61f29a669 100644 --- a/src/test/java/puzzles/shorttruthtable/rules/AndEliminationDirectRuleTest.java +++ b/src/test/java/puzzles/shorttruthtable/rules/AndEliminationDirectRuleTest.java @@ -26,21 +26,26 @@ public static void setup() { /** * Given one statement: B^C where ^ is true - * - * Checks all possible combinations of true, false, and unknown for B and C - * except for where both B and C are true and asserts that each one of them - * is not a valid application of the rule. + * + *

Checks all possible combinations of true, false, and unknown for B and C except for where + * both B and C are true and asserts that each one of them is not a valid application of the + * rule. * * @throws InvalidFileFormatException */ @Test public void trueAndTest1() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/AndEliminationDirectRule/TrueAnd", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/AndEliminationDirectRule/TrueAnd", stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; + ShortTruthTableCellType[] cellTypes = { + ShortTruthTableCellType.TRUE, + ShortTruthTableCellType.FALSE, + ShortTruthTableCellType.UNKNOWN + }; for (ShortTruthTableCellType cellType1 : cellTypes) { for (ShortTruthTableCellType cellType2 : cellTypes) { @@ -69,21 +74,23 @@ public void trueAndTest1() throws InvalidFileFormatException { /** * Given one statement: B^C where ^ is true - * - * Checks all possible combinations of true and unknown for B and C - * except for where both B and C are unknown and asserts that each one - * of them is a valid application of the rule. + * + *

Checks all possible combinations of true and unknown for B and C except for where both B + * and C are unknown and asserts that each one of them is a valid application of the rule. * * @throws InvalidFileFormatException */ @Test public void trueAndTest2() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/AndEliminationDirectRule/TrueAnd", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/AndEliminationDirectRule/TrueAnd", stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.UNKNOWN}; + ShortTruthTableCellType[] cellTypes = { + ShortTruthTableCellType.TRUE, ShortTruthTableCellType.UNKNOWN + }; for (ShortTruthTableCellType cellType1 : cellTypes) { for (ShortTruthTableCellType cellType2 : cellTypes) { @@ -112,20 +119,25 @@ public void trueAndTest2() throws InvalidFileFormatException { /** * Given one statement: B^C where ^ is false - * - * Checks all possible combinations of true, false, and unknown for B and C - * and asserts that each one of them is not a valid application of the rule. + * + *

Checks all possible combinations of true, false, and unknown for B and C and asserts that + * each one of them is not a valid application of the rule. * * @throws InvalidFileFormatException */ @Test public void falseAndWithUnknownsTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAnd", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAnd", stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; + ShortTruthTableCellType[] cellTypes = { + ShortTruthTableCellType.TRUE, + ShortTruthTableCellType.FALSE, + ShortTruthTableCellType.UNKNOWN + }; for (ShortTruthTableCellType cellType1 : cellTypes) { for (ShortTruthTableCellType cellType2 : cellTypes) { @@ -150,15 +162,17 @@ public void falseAndWithUnknownsTest() throws InvalidFileFormatException { /** * Given one statement: B^C where both B and ^ are false - * - * Asserts that this is not a valid application of the rule if C is set to - * either true or false. + * + *

Asserts that this is not a valid application of the rule if C is set to either true or + * false. * * @throws InvalidFileFormatException */ @Test public void falseAndWithKnownFalseTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAndWithKnownFalse", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAndWithKnownFalse", + stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -177,15 +191,16 @@ public void falseAndWithKnownFalseTest() throws InvalidFileFormatException { /** * Given one statement: B^C where B is true and ^ is false - * - * Asserts that this is a valid application of the rule if and only if C is - * set to false. + * + *

Asserts that this is a valid application of the rule if and only if C is set to false. * * @throws InvalidFileFormatException */ @Test public void falseAndWithKnownTrueTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAndWithKnownTrue", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAndWithKnownTrue", + stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -201,4 +216,4 @@ public void falseAndWithKnownTrueTest() throws InvalidFileFormatException { board.addModifiedData(clyde); Assert.assertNull(RULE.checkRule(transition)); } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/shorttruthtable/rules/AndIntroductionDirectRuleTest.java b/src/test/java/puzzles/shorttruthtable/rules/AndIntroductionDirectRuleTest.java index 4d4e009b2..ec03919ae 100644 --- a/src/test/java/puzzles/shorttruthtable/rules/AndIntroductionDirectRuleTest.java +++ b/src/test/java/puzzles/shorttruthtable/rules/AndIntroductionDirectRuleTest.java @@ -27,8 +27,8 @@ public static void setup() { /** * Given a statement: A ^ B * - * Asserts that if at least 1 of A or B is false, then this is a valid application - * of the rule if and only if ^ is false. + *

Asserts that if at least 1 of A or B is false, then this is a valid application of the + * rule if and only if ^ is false. * * @param filePath The file path for test board setup. * @throws InvalidFileFormatException @@ -64,8 +64,8 @@ private void falseAndTestHelper(String filePath) throws InvalidFileFormatExcepti /** * Given a statement: A ^ B * - * Asserts that setting ^ to true is a valid application of the rule if - * and only if both A and B are true. + *

Asserts that setting ^ to true is a valid application of the rule if and only if both A + * and B are true. * * @param filePath The file path for test board setup. * @throws InvalidFileFormatException @@ -95,11 +95,11 @@ private void trueAndTestHelper(String filePath) throws InvalidFileFormatExceptio and.setData(ShortTruthTableCellType.TRUE); board.addModifiedData(and); - if (a.getType() == ShortTruthTableCellType.TRUE && b.getType() == ShortTruthTableCellType.TRUE) { + if (a.getType() == ShortTruthTableCellType.TRUE + && b.getType() == ShortTruthTableCellType.TRUE) { Assert.assertNull(RULE.checkRule(transition)); - } - else { + } else { Assert.assertNotNull(RULE.checkRule(transition)); } } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/shorttruthtable/rules/AtomicDirectRuleTest.java b/src/test/java/puzzles/shorttruthtable/rules/AtomicDirectRuleTest.java index 51aa213c6..c631db613 100644 --- a/src/test/java/puzzles/shorttruthtable/rules/AtomicDirectRuleTest.java +++ b/src/test/java/puzzles/shorttruthtable/rules/AtomicDirectRuleTest.java @@ -25,13 +25,10 @@ public static void setup() { } /** - * Given two statements: - * A - * A - * where the first A is set to false. - * - * This test sets the second A to false and then asserts that this - * is a valid application of the rule. + * Given two statements: A A where the first A is set to false. + * + *

This test sets the second A to false and then asserts that this is a valid application of + * the rule. * * @throws InvalidFileFormatException */ @@ -52,13 +49,10 @@ public void MatchingFalseTest() throws InvalidFileFormatException { } /** - * Given two statements: - * A - * A - * where the first A is set to false. - * - * This test sets the second A to true and then asserts that this - * is not a valid application of the rule. + * Given two statements: A A where the first A is set to false. + * + *

This test sets the second A to true and then asserts that this is not a valid application + * of the rule. * * @throws InvalidFileFormatException */ @@ -79,13 +73,10 @@ public void MismatchingFalseTest() throws InvalidFileFormatException { } /** - * Given two statements: - * B - * B - * where the first B is set to true. - * - * This test sets the second B to true and then asserts that this - * is a valid application of the rule. + * Given two statements: B B where the first B is set to true. + * + *

This test sets the second B to true and then asserts that this is a valid application of + * the rule. * * @throws InvalidFileFormatException */ @@ -106,13 +97,10 @@ public void MatchingTrueTest() throws InvalidFileFormatException { } /** - * Given two statements: - * B - * B - * where the first B is set to true. - * - * This test sets the second B to false and then asserts that this - * is not a valid application of the rule. + * Given two statements: B B where the first B is set to true. + * + *

This test sets the second B to false and then asserts that this is not a valid application + * of the rule. * * @throws InvalidFileFormatException */ @@ -133,13 +121,10 @@ public void MismatchingTrueTest() throws InvalidFileFormatException { } /** - * Given two statements: - * C - * C - * where neither statement is set to anything. - * - * This test sets the second C to false and then asserts that this - * is not a valid application of the rule. + * Given two statements: C C where neither statement is set to anything. + * + *

This test sets the second C to false and then asserts that this is not a valid application + * of the rule. * * @throws InvalidFileFormatException */ @@ -160,13 +145,10 @@ public void NothingPreviouslyMarkedTest() throws InvalidFileFormatException { } /** - * Given two statements: - * C - * C - * where neither statement is set to anything. - * - * This test sets the second C to true and then asserts that this - * is not a valid application of the rule. + * Given two statements: C C where neither statement is set to anything. + * + *

This test sets the second C to true and then asserts that this is not a valid application + * of the rule. * * @throws InvalidFileFormatException */ @@ -185,4 +167,4 @@ public void NothingPreviouslyMarkedTest2() throws InvalidFileFormatException { Assert.assertNotNull(RULE.checkRule(transition)); } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/shorttruthtable/rules/BiconditionalEliminationTest.java b/src/test/java/puzzles/shorttruthtable/rules/BiconditionalEliminationTest.java index 05faf87bb..987d194f9 100644 --- a/src/test/java/puzzles/shorttruthtable/rules/BiconditionalEliminationTest.java +++ b/src/test/java/puzzles/shorttruthtable/rules/BiconditionalEliminationTest.java @@ -15,7 +15,8 @@ import org.junit.Test; public class BiconditionalEliminationTest { - private static final DirectRuleBiconditionalElimination RULE = new DirectRuleBiconditionalElimination(); + private static final DirectRuleBiconditionalElimination RULE = + new DirectRuleBiconditionalElimination(); private static ShortTruthTable stt; @BeforeClass @@ -27,13 +28,15 @@ public static void setup() { /** * Given one statement: A <-> B where both A and <-> are true * - * Asserts that this is a valid application of the rule if and only if B is true. + *

Asserts that this is a valid application of the rule if and only if B is true. * * @throws InvalidFileFormatException */ @Test public void TrueBiconditionalWithTrueATest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithTrueA", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithTrueA", + stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -60,13 +63,15 @@ public void TrueBiconditionalWithTrueATest() throws InvalidFileFormatException { /** * Given one statement: A <-> B where both B and <-> are true * - * Asserts that this is a valid application of the rule if and only if A is true. + *

Asserts that this is a valid application of the rule if and only if A is true. * * @throws InvalidFileFormatException */ @Test public void TrueBiconditionalWithTrueBTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithTrueB", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithTrueB", + stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -90,17 +95,18 @@ public void TrueBiconditionalWithTrueBTest() throws InvalidFileFormatException { Assert.assertNotNull(RULE.checkRule(transition)); } - /** * Given one statement: A <-> B where A is false and <-> is true * - * Asserts that this is a valid application of the rule if and only if B is false. + *

Asserts that this is a valid application of the rule if and only if B is false. * * @throws InvalidFileFormatException */ @Test public void TrueBiconditionalWithFalseATest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithFalseA", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithFalseA", + stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -127,13 +133,15 @@ public void TrueBiconditionalWithFalseATest() throws InvalidFileFormatException /** * Given one statement: A <-> B where B is false and <-> is true * - * Asserts that this is a valid application of the rule if and only if A is false. + *

Asserts that this is a valid application of the rule if and only if A is false. * * @throws InvalidFileFormatException */ @Test public void TrueBiconditionalWithFalseBTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithFalseB", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithFalseB", + stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -160,13 +168,15 @@ public void TrueBiconditionalWithFalseBTest() throws InvalidFileFormatException /** * Given one statement: A <-> B where A is true and <-> is false * - * Asserts that this is a valid application of the rule if and only if B is false. + *

Asserts that this is a valid application of the rule if and only if B is false. * * @throws InvalidFileFormatException */ @Test public void FalseBiconditionalWithTrueATest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithTrueA", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithTrueA", + stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -193,13 +203,15 @@ public void FalseBiconditionalWithTrueATest() throws InvalidFileFormatException /** * Given one statement: A <-> B where B is true and <-> is false * - * Asserts that this is a valid application of the rule if and only if A is false. + *

Asserts that this is a valid application of the rule if and only if A is false. * * @throws InvalidFileFormatException */ @Test public void FalseBiconditionalWithTrueBTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithTrueB", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithTrueB", + stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -226,13 +238,15 @@ public void FalseBiconditionalWithTrueBTest() throws InvalidFileFormatException /** * Given one statement: A <-> B where A and <-> are false * - * Asserts that this is a valid application of the rule if and only if B is true. + *

Asserts that this is a valid application of the rule if and only if B is true. * * @throws InvalidFileFormatException */ @Test public void FalseBiconditionalWithFalseATest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithFalseA", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithFalseA", + stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -259,13 +273,15 @@ public void FalseBiconditionalWithFalseATest() throws InvalidFileFormatException /** * Given one statement: A <-> B where B and <-> are false * - * Asserts that this is a valid application of the rule if and only if A is true. + *

Asserts that this is a valid application of the rule if and only if A is true. * * @throws InvalidFileFormatException */ @Test public void FalseBiconditionalWithFalseBTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithFalseB", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithFalseB", + stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -292,19 +308,25 @@ public void FalseBiconditionalWithFalseBTest() throws InvalidFileFormatException /** * Given one statement: A <-> B where <-> is true * - * Asserts that setting any combination of A and B at the same time is not a valid + *

Asserts that setting any combination of A and B at the same time is not a valid * application of this rule * * @throws InvalidFileFormatException */ @Test public void TrueBiconditionalSetBothAtOnceTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditional", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditional", + stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; + ShortTruthTableCellType[] cellTypes = { + ShortTruthTableCellType.TRUE, + ShortTruthTableCellType.FALSE, + ShortTruthTableCellType.UNKNOWN + }; for (ShortTruthTableCellType cellType1 : cellTypes) { for (ShortTruthTableCellType cellType2 : cellTypes) { @@ -324,8 +346,8 @@ public void TrueBiconditionalSetBothAtOnceTest() throws InvalidFileFormatExcepti } /** - * Asserts that setting any combination of A and B at the same time is not a valid - * application of this rule. This is tested on multiple files. + * Asserts that setting any combination of A and B at the same time is not a valid application + * of this rule. This is tested on multiple files. * * @throws InvalidFileFormatException */ @@ -352,7 +374,11 @@ private void setAandBBothAtOnceTest(String filePath) throws InvalidFileFormatExc TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; + ShortTruthTableCellType[] cellTypes = { + ShortTruthTableCellType.TRUE, + ShortTruthTableCellType.FALSE, + ShortTruthTableCellType.UNKNOWN + }; for (ShortTruthTableCellType cellType1 : cellTypes) { for (ShortTruthTableCellType cellType2 : cellTypes) { @@ -370,4 +396,4 @@ private void setAandBBothAtOnceTest(String filePath) throws InvalidFileFormatExc } } } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/shorttruthtable/rules/BiconditionalIntroductionTest.java b/src/test/java/puzzles/shorttruthtable/rules/BiconditionalIntroductionTest.java index fe2574b5e..e1c5cf957 100644 --- a/src/test/java/puzzles/shorttruthtable/rules/BiconditionalIntroductionTest.java +++ b/src/test/java/puzzles/shorttruthtable/rules/BiconditionalIntroductionTest.java @@ -15,7 +15,8 @@ import org.junit.Test; public class BiconditionalIntroductionTest { - private static final DirectRuleBiconditionalIntroduction RULE = new DirectRuleBiconditionalIntroduction(); + private static final DirectRuleBiconditionalIntroduction RULE = + new DirectRuleBiconditionalIntroduction(); private static ShortTruthTable stt; @BeforeClass @@ -27,8 +28,8 @@ public static void setup() { /** * Given a statement: A <-> B * - * Asserts that if setting <-> to false is a valid application of this rule if and - * only if A and B do not match. + *

Asserts that if setting <-> to false is a valid application of this rule if and only if A + * and B do not match. * * @throws InvalidFileFormatException */ @@ -61,14 +62,13 @@ private void falseConditionalHelper(String filePath) throws InvalidFileFormatExc ShortTruthTableCell b = board.getCell(2, 0); if (a.getType() != b.getType()) { // Not valid if they don't match but at least one of the values of A or B is unknown - if (a.getType() == ShortTruthTableCellType.UNKNOWN || b.getType() == ShortTruthTableCellType.UNKNOWN) { + if (a.getType() == ShortTruthTableCellType.UNKNOWN + || b.getType() == ShortTruthTableCellType.UNKNOWN) { Assert.assertNotNull(RULE.checkRule(transition)); - } - else { + } else { Assert.assertNull(RULE.checkRule(transition)); } - } - else { + } else { Assert.assertNotNull(RULE.checkRule(transition)); } } @@ -76,8 +76,8 @@ private void falseConditionalHelper(String filePath) throws InvalidFileFormatExc /** * Given a statement: A <-> B * - * Asserts that if setting <-> to true is a valid application of this rule if and - * only if A and B match. + *

Asserts that if setting <-> to true is a valid application of this rule if and only if A + * and B match. * * @throws InvalidFileFormatException */ @@ -110,9 +110,8 @@ private void trueConditionalHelper(String filePath) throws InvalidFileFormatExce ShortTruthTableCell b = board.getCell(2, 0); if (a.getType() == b.getType() && a.getType() != ShortTruthTableCellType.UNKNOWN) { Assert.assertNull(RULE.checkRule(transition)); - } - else { + } else { Assert.assertNotNull(RULE.checkRule(transition)); } } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/shorttruthtable/rules/ConditionalEliminationTest.java b/src/test/java/puzzles/shorttruthtable/rules/ConditionalEliminationTest.java index 8d0bb4e1a..0f95906f2 100644 --- a/src/test/java/puzzles/shorttruthtable/rules/ConditionalEliminationTest.java +++ b/src/test/java/puzzles/shorttruthtable/rules/ConditionalEliminationTest.java @@ -15,7 +15,8 @@ import org.junit.Test; public class ConditionalEliminationTest { - private static final DirectRuleConditionalElimination RULE = new DirectRuleConditionalElimination(); + private static final DirectRuleConditionalElimination RULE = + new DirectRuleConditionalElimination(); private static ShortTruthTable stt; @BeforeClass @@ -27,19 +28,25 @@ public static void setup() { /** * Given one statement: A -> B where -> is false * - * Asserts that the only valid combination of A and B that is a valid application - * of this rule is when A is true and B is false + *

Asserts that the only valid combination of A and B that is a valid application of this + * rule is when A is true and B is false * * @throws InvalidFileFormatException */ @Test public void FalseConditionalTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/FalseConditional", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/FalseConditional", + stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; + ShortTruthTableCellType[] cellTypes = { + ShortTruthTableCellType.TRUE, + ShortTruthTableCellType.FALSE, + ShortTruthTableCellType.UNKNOWN + }; for (ShortTruthTableCellType cellType1 : cellTypes) { for (ShortTruthTableCellType cellType2 : cellTypes) { @@ -53,10 +60,10 @@ public void FalseConditionalTest() throws InvalidFileFormatException { board.addModifiedData(aubergine); board.addModifiedData(boniato); - if (cellType1 == ShortTruthTableCellType.TRUE && cellType2 == ShortTruthTableCellType.FALSE) { + if (cellType1 == ShortTruthTableCellType.TRUE + && cellType2 == ShortTruthTableCellType.FALSE) { Assert.assertNull(RULE.checkRule(transition)); - } - else { + } else { Assert.assertNotNull(RULE.checkRule(transition)); } } @@ -66,14 +73,15 @@ public void FalseConditionalTest() throws InvalidFileFormatException { /** * Given one statement: A -> B where -> is false * - * Asserts that this is a valid application of the rule if and only if A - * is set to true. + *

Asserts that this is a valid application of the rule if and only if A is set to true. * * @throws InvalidFileFormatException */ @Test public void FalseConditionalTrueATest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/FalseConditional", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/FalseConditional", + stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -93,14 +101,15 @@ public void FalseConditionalTrueATest() throws InvalidFileFormatException { /** * Given one statement: A -> B where -> is false * - * Asserts that this is a valid application of the rule if and only if B is - * set to false. + *

Asserts that this is a valid application of the rule if and only if B is set to false. * * @throws InvalidFileFormatException */ @Test public void FalseConditionalFalseBTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/FalseConditional", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/FalseConditional", + stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -120,18 +129,24 @@ public void FalseConditionalFalseBTest() throws InvalidFileFormatException { /** * Given one statement: A -> B where -> is true * - * Asserts that you cannot set any combination of both A and B at the same time. + *

Asserts that you cannot set any combination of both A and B at the same time. * * @throws InvalidFileFormatException */ @Test public void CannotSetBothAandBTrueConditionalTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditional", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditional", + stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; + ShortTruthTableCellType[] cellTypes = { + ShortTruthTableCellType.TRUE, + ShortTruthTableCellType.FALSE, + ShortTruthTableCellType.UNKNOWN + }; for (ShortTruthTableCellType cellType1 : cellTypes) { for (ShortTruthTableCellType cellType2 : cellTypes) { @@ -153,14 +168,15 @@ public void CannotSetBothAandBTrueConditionalTest() throws InvalidFileFormatExce /** * Given one statement: A -> B where A and -> are true * - * Asserts that this is a valid application of this rule if and only if B - * is set to true. + *

Asserts that this is a valid application of this rule if and only if B is set to true. * * @throws InvalidFileFormatException */ @Test public void TrueAMeansTrueBTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithTrueA", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithTrueA", + stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -180,14 +196,15 @@ public void TrueAMeansTrueBTest() throws InvalidFileFormatException { /** * Given one statement: A -> B where B is false and -> is true * - * Asserts that this is a valid application of this rule if and only if A - * is set to false. + *

Asserts that this is a valid application of this rule if and only if A is set to false. * * @throws InvalidFileFormatException */ @Test public void FalseBMeansFalseATest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithFalseB", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithFalseB", + stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -207,14 +224,15 @@ public void FalseBMeansFalseATest() throws InvalidFileFormatException { /** * Given one statement: A -> B where B and -> are true * - * Asserts that this is not a valid application of this rule no matter what - * A is set to. + *

Asserts that this is not a valid application of this rule no matter what A is set to. * * @throws InvalidFileFormatException */ @Test public void TrueBCannotDetermineA() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithTrueB", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithTrueB", + stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -230,4 +248,4 @@ public void TrueBCannotDetermineA() throws InvalidFileFormatException { board.addModifiedData(boniato); Assert.assertNotNull(RULE.checkRule(transition)); } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/shorttruthtable/rules/ConditionalIntroductionTest.java b/src/test/java/puzzles/shorttruthtable/rules/ConditionalIntroductionTest.java index c1507eab1..1bc28373d 100644 --- a/src/test/java/puzzles/shorttruthtable/rules/ConditionalIntroductionTest.java +++ b/src/test/java/puzzles/shorttruthtable/rules/ConditionalIntroductionTest.java @@ -15,7 +15,8 @@ import org.junit.Test; public class ConditionalIntroductionTest { - private static final DirectRuleConditionalIntroduction RULE = new DirectRuleConditionalIntroduction(); + private static final DirectRuleConditionalIntroduction RULE = + new DirectRuleConditionalIntroduction(); private static ShortTruthTable stt; @BeforeClass @@ -27,8 +28,8 @@ public static void setup() { /** * Given a statement: A -> B * - * Asserts that if setting -> to false is a valid application of this rule if and - * only if A is true and B is false. + *

Asserts that if setting -> to false is a valid application of this rule if and only if A + * is true and B is false. * * @throws InvalidFileFormatException */ @@ -58,10 +59,10 @@ private void falseConditionalHelper(String filePath) throws InvalidFileFormatExc ShortTruthTableCell a = board.getCell(0, 0); ShortTruthTableCell b = board.getCell(2, 0); - if (a.getType() == ShortTruthTableCellType.TRUE && b.getType() == ShortTruthTableCellType.FALSE) { + if (a.getType() == ShortTruthTableCellType.TRUE + && b.getType() == ShortTruthTableCellType.FALSE) { Assert.assertNull(RULE.checkRule(transition)); - } - else { + } else { Assert.assertNotNull(RULE.checkRule(transition)); } } @@ -69,8 +70,8 @@ private void falseConditionalHelper(String filePath) throws InvalidFileFormatExc /** * Given a statement: A -> B * - * Asserts that if setting -> to true is a valid application of this rule if and - * only if A is false or B is true. + *

Asserts that if setting -> to true is a valid application of this rule if and only if A is + * false or B is true. * * @throws InvalidFileFormatException */ @@ -100,11 +101,11 @@ private void trueConditionalTestHelper(String filePath) throws InvalidFileFormat ShortTruthTableCell a = board.getCell(0, 0); ShortTruthTableCell b = board.getCell(2, 0); - if (a.getType() == ShortTruthTableCellType.FALSE || b.getType() == ShortTruthTableCellType.TRUE) { + if (a.getType() == ShortTruthTableCellType.FALSE + || b.getType() == ShortTruthTableCellType.TRUE) { Assert.assertNull(RULE.checkRule(transition)); - } - else { + } else { Assert.assertNotNull(RULE.checkRule(transition)); } } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/shorttruthtable/rules/NotEliminationTest.java b/src/test/java/puzzles/shorttruthtable/rules/NotEliminationTest.java index 6dbbf141c..589e3cfb9 100644 --- a/src/test/java/puzzles/shorttruthtable/rules/NotEliminationTest.java +++ b/src/test/java/puzzles/shorttruthtable/rules/NotEliminationTest.java @@ -27,18 +27,23 @@ public static void setup() { /** * Given one statement: ¬A where ¬ is false * - * Asserts that this is a valid application of this rule if and only if A is true + *

Asserts that this is a valid application of this rule if and only if A is true * * @throws InvalidFileFormatException */ @Test public void FalseNot() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/NotEliminationDirectRule/FalseNot", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/NotEliminationDirectRule/FalseNot", stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; + ShortTruthTableCellType[] cellTypes = { + ShortTruthTableCellType.TRUE, + ShortTruthTableCellType.FALSE, + ShortTruthTableCellType.UNKNOWN + }; for (ShortTruthTableCellType cellType : cellTypes) { ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); @@ -48,8 +53,7 @@ public void FalseNot() throws InvalidFileFormatException { if (cellType == ShortTruthTableCellType.TRUE) { Assert.assertNull(RULE.checkRule(transition)); - } - else { + } else { Assert.assertNotNull(RULE.checkRule(transition)); } } @@ -58,18 +62,23 @@ public void FalseNot() throws InvalidFileFormatException { /** * Given one statement: ¬A where ¬ is true * - * Asserts that this is a valid application of this rule if and only if A is false + *

Asserts that this is a valid application of this rule if and only if A is false * * @throws InvalidFileFormatException */ @Test public void TrueNot() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/NotEliminationDirectRule/TrueNot", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/NotEliminationDirectRule/TrueNot", stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; + ShortTruthTableCellType[] cellTypes = { + ShortTruthTableCellType.TRUE, + ShortTruthTableCellType.FALSE, + ShortTruthTableCellType.UNKNOWN + }; for (ShortTruthTableCellType cellType : cellTypes) { ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); @@ -79,46 +88,47 @@ public void TrueNot() throws InvalidFileFormatException { if (cellType == ShortTruthTableCellType.FALSE) { Assert.assertNull(RULE.checkRule(transition)); - } - else { + } else { Assert.assertNotNull(RULE.checkRule(transition)); } } } -// /** -// * Given one statement: ¬A -// * -// * Asserts that setting both ¬ and A to any values would not be a valid -// * application of this rule -// * -// * @throws InvalidFileFormatException -// */ -// @Test -// public void CannotSetBothAtOnceTest() throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/NotEliminationDirectRule/BlankNot", stt); -// TreeNode rootNode = stt.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; -// -// for (ShortTruthTableCellType cellType1 : cellTypes) { -// for (ShortTruthTableCellType cellType2 : cellTypes) { -// ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); -// ShortTruthTableCell not = board.getCell(0, 0); -// ShortTruthTableCell a = board.getCell(1, 0); -// -// not.setData(cellType1); -// a.setData(cellType2); -// -// board.addModifiedData(not); -// board.addModifiedData(a); -// -// System.out.println("TYPE1:" + cellType1); -// System.out.println("TYPE2:" + cellType2); -// Assert.assertNotNull(RULE.checkRule(transition)); -// } -// } -// } -} \ No newline at end of file + // /** + // * Given one statement: ¬A + // * + // * Asserts that setting both ¬ and A to any values would not be a valid + // * application of this rule + // * + // * @throws InvalidFileFormatException + // */ + // @Test + // public void CannotSetBothAtOnceTest() throws InvalidFileFormatException { + // + // TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/NotEliminationDirectRule/BlankNot", stt); + // TreeNode rootNode = stt.getTree().getRootNode(); + // TreeTransition transition = rootNode.getChildren().get(0); + // transition.setRule(RULE); + // + // ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, + // ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; + // + // for (ShortTruthTableCellType cellType1 : cellTypes) { + // for (ShortTruthTableCellType cellType2 : cellTypes) { + // ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + // ShortTruthTableCell not = board.getCell(0, 0); + // ShortTruthTableCell a = board.getCell(1, 0); + // + // not.setData(cellType1); + // a.setData(cellType2); + // + // board.addModifiedData(not); + // board.addModifiedData(a); + // + // System.out.println("TYPE1:" + cellType1); + // System.out.println("TYPE2:" + cellType2); + // Assert.assertNotNull(RULE.checkRule(transition)); + // } + // } + // } +} diff --git a/src/test/java/puzzles/shorttruthtable/rules/NotIntroductionTest.java b/src/test/java/puzzles/shorttruthtable/rules/NotIntroductionTest.java index a0a062ab3..e338fb9bd 100644 --- a/src/test/java/puzzles/shorttruthtable/rules/NotIntroductionTest.java +++ b/src/test/java/puzzles/shorttruthtable/rules/NotIntroductionTest.java @@ -27,18 +27,23 @@ public static void setup() { /** * Given one statement: ¬A where A is false * - * Asserts that this is a valid application of this rule if and only if ¬ is true + *

Asserts that this is a valid application of this rule if and only if ¬ is true * * @throws InvalidFileFormatException */ @Test public void FalseNot() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/NotIntroductionDirectRule/FalseA", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/NotIntroductionDirectRule/FalseA", stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; + ShortTruthTableCellType[] cellTypes = { + ShortTruthTableCellType.TRUE, + ShortTruthTableCellType.FALSE, + ShortTruthTableCellType.UNKNOWN + }; for (ShortTruthTableCellType cellType : cellTypes) { ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); @@ -48,8 +53,7 @@ public void FalseNot() throws InvalidFileFormatException { if (cellType == ShortTruthTableCellType.TRUE) { Assert.assertNull(RULE.checkRule(transition)); - } - else { + } else { Assert.assertNotNull(RULE.checkRule(transition)); } } @@ -58,18 +62,23 @@ public void FalseNot() throws InvalidFileFormatException { /** * Given one statement: ¬A where A is true * - * Asserts that this is a valid application of this rule if and only if ¬ is false + *

Asserts that this is a valid application of this rule if and only if ¬ is false * * @throws InvalidFileFormatException */ @Test public void TrueNot() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/NotIntroductionDirectRule/TrueA", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/NotIntroductionDirectRule/TrueA", stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; + ShortTruthTableCellType[] cellTypes = { + ShortTruthTableCellType.TRUE, + ShortTruthTableCellType.FALSE, + ShortTruthTableCellType.UNKNOWN + }; for (ShortTruthTableCellType cellType : cellTypes) { ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); @@ -79,8 +88,7 @@ public void TrueNot() throws InvalidFileFormatException { if (cellType == ShortTruthTableCellType.FALSE) { Assert.assertNull(RULE.checkRule(transition)); - } - else { + } else { Assert.assertNotNull(RULE.checkRule(transition)); } } @@ -89,19 +97,24 @@ public void TrueNot() throws InvalidFileFormatException { /** * Given one statement: ¬A * - * Asserts that setting both ¬ and A to any values would not be a valid - * application of this rule + *

Asserts that setting both ¬ and A to any values would not be a valid application of this + * rule * * @throws InvalidFileFormatException */ @Test public void CannotSetBothAtOnceTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/NotIntroductionDirectRule/BlankA", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/NotIntroductionDirectRule/BlankA", stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; + ShortTruthTableCellType[] cellTypes = { + ShortTruthTableCellType.TRUE, + ShortTruthTableCellType.FALSE, + ShortTruthTableCellType.UNKNOWN + }; for (ShortTruthTableCellType cellType1 : cellTypes) { for (ShortTruthTableCellType cellType2 : cellTypes) { @@ -119,4 +132,4 @@ public void CannotSetBothAtOnceTest() throws InvalidFileFormatException { } } } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/shorttruthtable/rules/OrCaseRuleTest.java b/src/test/java/puzzles/shorttruthtable/rules/OrCaseRuleTest.java index 0f7e93db5..0bfa6fc6e 100644 --- a/src/test/java/puzzles/shorttruthtable/rules/OrCaseRuleTest.java +++ b/src/test/java/puzzles/shorttruthtable/rules/OrCaseRuleTest.java @@ -7,17 +7,15 @@ import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCell; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; -import edu.rpi.legup.puzzle.shorttruthtable.rules.caserule.CaseRuleAnd; import edu.rpi.legup.puzzle.shorttruthtable.rules.caserule.CaseRuleOr; import edu.rpi.legup.save.InvalidFileFormatException; +import java.util.ArrayList; import legup.MockGameBoardFacade; import legup.TestUtilities; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.util.ArrayList; - public class OrCaseRuleTest { private static final CaseRuleOr RULE = new CaseRuleOr(); @@ -29,17 +27,15 @@ public static void setUp() { stt = new ShortTruthTable(); } - private void trueOrTest(String fileName, - int andX, int andY, - int aX, int aY, - int bX, int bY) throws InvalidFileFormatException { + private void trueOrTest(String fileName, int andX, int andY, int aX, int aY, int bX, int bY) + throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/OrCaseRule/" + fileName, stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); - ShortTruthTableCell cell = board.getCell(andX,andY); + ShortTruthTableCell cell = board.getCell(andX, andY); ArrayList cases = RULE.getCases(board, cell); // Make sure that the rule checks out @@ -64,60 +60,64 @@ private void trueOrTest(String fileName, // First assert the two cells are not equal, then verify that they are either // unknown or false. Assert.assertNotEquals(board1A, board1B); - Assert.assertTrue(board1A.equals(ShortTruthTableCellType.UNKNOWN) || board1A.equals(ShortTruthTableCellType.TRUE)); - Assert.assertTrue(board1B.equals(ShortTruthTableCellType.UNKNOWN) || board1B.equals(ShortTruthTableCellType.TRUE)); + Assert.assertTrue( + board1A.equals(ShortTruthTableCellType.UNKNOWN) + || board1A.equals(ShortTruthTableCellType.TRUE)); + Assert.assertTrue( + board1B.equals(ShortTruthTableCellType.UNKNOWN) + || board1B.equals(ShortTruthTableCellType.TRUE)); Assert.assertNotEquals(board2A, board2B); - Assert.assertTrue(board2A.equals(ShortTruthTableCellType.UNKNOWN) || board1A.equals(ShortTruthTableCellType.TRUE)); - Assert.assertTrue(board2B.equals(ShortTruthTableCellType.UNKNOWN) || board2B.equals(ShortTruthTableCellType.TRUE)); + Assert.assertTrue( + board2A.equals(ShortTruthTableCellType.UNKNOWN) + || board1A.equals(ShortTruthTableCellType.TRUE)); + Assert.assertTrue( + board2B.equals(ShortTruthTableCellType.UNKNOWN) + || board2B.equals(ShortTruthTableCellType.TRUE)); // Verify the board dimensions are unchanged Assert.assertEquals(caseBoard1.getHeight(), caseBoard2.getHeight(), board.getHeight()); Assert.assertEquals(caseBoard1.getWidth(), caseBoard2.getWidth(), board.getWidth()); // Verify that everywhere else on the board is unchanged - for (int i = 0; i< caseBoard1.getWidth(); i++) { + for (int i = 0; i < caseBoard1.getWidth(); i++) { for (int j = 0; j < caseBoard1.getHeight(); j++) { // Make sure not to check the two cells that should be different if (!((i == aX && j == aY) || (i == bX && j == bY))) { - Assert.assertEquals(caseBoard1.getCell(i, j).getType(), caseBoard2.getCell(i, j).getType()); + Assert.assertEquals( + caseBoard1.getCell(i, j).getType(), caseBoard2.getCell(i, j).getType()); } } } } /** - * Given a statement A ^ B where ^ is false, tests this case rule by ensuring that - * two branches are created: one where A is false and one where B is false. + * Given a statement A ^ B where ^ is false, tests this case rule by ensuring that two branches + * are created: one where A is false and one where B is false. */ @Test public void SimpleStatement1TrueTest() throws InvalidFileFormatException { - trueOrTest("SimpleStatement1_True", 1, 0, 0, 0, - 2, 0); + trueOrTest("SimpleStatement1_True", 1, 0, 0, 0, 2, 0); } /** - * Given a statement ~(A|B)^(C^D) where the first ^ is false, tests this case rule - * by ensuring that two branches are created: one where ~ is false and one where - * the second ^ is false. + * Given a statement ~(A|B)^(C^D) where the first ^ is false, tests this case rule by ensuring + * that two branches are created: one where ~ is false and one where the second ^ is false. */ @Test public void ComplexStatement1TrueTest() throws InvalidFileFormatException { - trueOrTest("ComplexStatement1_True", 6, 0, 0, 0, - 9, 0); + trueOrTest("ComplexStatement1_True", 6, 0, 0, 0, 9, 0); } - private void falseOrTest(String fileName, - int andX, int andY, - int aX, int aY, - int bX, int bY) throws InvalidFileFormatException { + private void falseOrTest(String fileName, int andX, int andY, int aX, int aY, int bX, int bY) + throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/OrCaseRule/" + fileName, stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); - ShortTruthTableCell cell = board.getCell(andX,andY); + ShortTruthTableCell cell = board.getCell(andX, andY); ArrayList cases = RULE.getCases(board, cell); // Make sure that the rule checks out @@ -140,22 +140,20 @@ private void falseOrTest(String fileName, } /** - * Given a statement A ^ B where ^ is false, tests this case rule by ensuring that - * one branch is created where A and B are both true. + * Given a statement A ^ B where ^ is false, tests this case rule by ensuring that one branch is + * created where A and B are both true. */ @Test public void SimpleStatement1FalseTest() throws InvalidFileFormatException { - falseOrTest("SimpleStatement1_False", 1, 0, 0, 0, - 2, 0); + falseOrTest("SimpleStatement1_False", 1, 0, 0, 0, 2, 0); } /** - * Given a statement ~(A|B)^(C^D) where the first ^ is true, tests this case rule - * by ensuring that one branch is created where both ~ and the second ^ are true. + * Given a statement ~(A|B)^(C^D) where the first ^ is true, tests this case rule by ensuring + * that one branch is created where both ~ and the second ^ are true. */ @Test public void ComplexStatement1FalseTest() throws InvalidFileFormatException { - falseOrTest("ComplexStatement1_False", 6, 0, 0, 0, - 9, 0); + falseOrTest("ComplexStatement1_False", 6, 0, 0, 0, 9, 0); } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/shorttruthtable/rules/OrEliminationTest.java b/src/test/java/puzzles/shorttruthtable/rules/OrEliminationTest.java index 6cdd0d639..e4efad465 100644 --- a/src/test/java/puzzles/shorttruthtable/rules/OrEliminationTest.java +++ b/src/test/java/puzzles/shorttruthtable/rules/OrEliminationTest.java @@ -27,13 +27,14 @@ public static void setup() { /** * Given a statement: A V B, where A is false and V is true * - * Asserts that this is a valid application of the rule if and only if B is true. + *

Asserts that this is a valid application of the rule if and only if B is true. * * @throws InvalidFileFormatException */ @Test public void FTUTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/OrEliminationDirectRule/FTU", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/OrEliminationDirectRule/FTU", stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -53,13 +54,14 @@ public void FTUTest() throws InvalidFileFormatException { /** * Given a statement: A V B, where B is false and V is true * - * Asserts that this is a valid application of the rule if and only if B is true. + *

Asserts that this is a valid application of the rule if and only if B is true. * * @throws InvalidFileFormatException */ @Test public void UTFTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/OrEliminationDirectRule/UTF", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/OrEliminationDirectRule/UTF", stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -79,19 +81,24 @@ public void UTFTest() throws InvalidFileFormatException { /** * Given a statement: A V B, where V is false * - * Asserts that this is a valid application of the rule if and only if both A - * and B are false. + *

Asserts that this is a valid application of the rule if and only if both A and B are + * false. * * @throws InvalidFileFormatException */ @Test public void UFUTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/OrEliminationDirectRule/UFU", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/OrEliminationDirectRule/UFU", stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; + ShortTruthTableCellType[] cellTypes = { + ShortTruthTableCellType.TRUE, + ShortTruthTableCellType.FALSE, + ShortTruthTableCellType.UNKNOWN + }; for (ShortTruthTableCellType cellType1 : cellTypes) { for (ShortTruthTableCellType cellType2 : cellTypes) { @@ -105,10 +112,10 @@ public void UFUTest() throws InvalidFileFormatException { board.addModifiedData(a); board.addModifiedData(b); - if (cellType1 == ShortTruthTableCellType.FALSE && cellType2 == ShortTruthTableCellType.FALSE) { + if (cellType1 == ShortTruthTableCellType.FALSE + && cellType2 == ShortTruthTableCellType.FALSE) { Assert.assertNull(RULE.checkRule(transition)); - } - else { + } else { Assert.assertNotNull(RULE.checkRule(transition)); } } @@ -118,18 +125,23 @@ public void UFUTest() throws InvalidFileFormatException { /** * Given a statement: A V B, where V is true * - * Asserts that setting both A and B is not a valid application of this rule. + *

Asserts that setting both A and B is not a valid application of this rule. * * @throws InvalidFileFormatException */ @Test public void UTUTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/OrEliminationDirectRule/UTU", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/OrEliminationDirectRule/UTU", stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; + ShortTruthTableCellType[] cellTypes = { + ShortTruthTableCellType.TRUE, + ShortTruthTableCellType.FALSE, + ShortTruthTableCellType.UNKNOWN + }; for (ShortTruthTableCellType cellType1 : cellTypes) { for (ShortTruthTableCellType cellType2 : cellTypes) { @@ -147,4 +159,4 @@ public void UTUTest() throws InvalidFileFormatException { } } } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/shorttruthtable/rules/OrIntroductionTest.java b/src/test/java/puzzles/shorttruthtable/rules/OrIntroductionTest.java index 13cb10d55..d5f9387eb 100644 --- a/src/test/java/puzzles/shorttruthtable/rules/OrIntroductionTest.java +++ b/src/test/java/puzzles/shorttruthtable/rules/OrIntroductionTest.java @@ -27,8 +27,8 @@ public static void setup() { /** * Given a statement: A V B * - * Asserts that if at least 1 of A or B is true, then this is a valid application - * of the rule if and only if V is true. + *

Asserts that if at least 1 of A or B is true, then this is a valid application of the rule + * if and only if V is true. * * @param filePath The file path for test board setup. * @throws InvalidFileFormatException @@ -64,8 +64,8 @@ private void trueOrTestHelper(String filePath) throws InvalidFileFormatException /** * Given a statement: A V B * - * Asserts that setting V to false is a valid application of the rule if - * and only if both A and B are false. + *

Asserts that setting V to false is a valid application of the rule if and only if both A + * and B are false. * * @param filePath The file path for test board setup. * @throws InvalidFileFormatException @@ -95,11 +95,11 @@ private void falseOrTestHelper(String filePath) throws InvalidFileFormatExceptio or.setData(ShortTruthTableCellType.FALSE); board.addModifiedData(or); - if (a.getType() == ShortTruthTableCellType.FALSE && b.getType() == ShortTruthTableCellType.FALSE) { + if (a.getType() == ShortTruthTableCellType.FALSE + && b.getType() == ShortTruthTableCellType.FALSE) { Assert.assertNull(RULE.checkRule(transition)); - } - else { + } else { Assert.assertNotNull(RULE.checkRule(transition)); } } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/shorttruthtable/rules/TrueOrFalseCaseRuleTest.java b/src/test/java/puzzles/shorttruthtable/rules/TrueOrFalseCaseRuleTest.java index 2c0b9fb15..d0c390785 100644 --- a/src/test/java/puzzles/shorttruthtable/rules/TrueOrFalseCaseRuleTest.java +++ b/src/test/java/puzzles/shorttruthtable/rules/TrueOrFalseCaseRuleTest.java @@ -9,14 +9,13 @@ import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType; import edu.rpi.legup.puzzle.shorttruthtable.rules.caserule.CaseRuleAtomic; import edu.rpi.legup.save.InvalidFileFormatException; +import java.util.ArrayList; import legup.MockGameBoardFacade; import legup.TestUtilities; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.util.ArrayList; - public class TrueOrFalseCaseRuleTest { private static final CaseRuleAtomic RULE = new CaseRuleAtomic(); @@ -29,18 +28,19 @@ public static void setUp() { } /** - * Tests the True or False case rule by ensuring that it results in two children, - * one that contains Statement as true and one that contains Statement as false. + * Tests the True or False case rule by ensuring that it results in two children, one that + * contains Statement as true and one that contains Statement as false. */ @Test public void TwoBranchesTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/TrueOrFalseCaseRule/Statement", stt); + TestUtilities.importTestBoard( + "puzzles/shorttruthtable/rules/TrueOrFalseCaseRule/Statement", stt); TreeNode rootNode = stt.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); - ShortTruthTableCell cell = board.getCell(0,0); + ShortTruthTableCell cell = board.getCell(0, 0); ArrayList cases = RULE.getCases(board, cell); // Make sure that the rule checks out @@ -52,27 +52,32 @@ public void TwoBranchesTest() throws InvalidFileFormatException { ShortTruthTableBoard caseBoard1 = (ShortTruthTableBoard) cases.get(0); ShortTruthTableBoard caseBoard2 = (ShortTruthTableBoard) cases.get(1); - ShortTruthTableCellType cellType1 = caseBoard1.getCell(0,0).getType(); - ShortTruthTableCellType cellType2 = caseBoard2.getCell(0,0).getType(); + ShortTruthTableCellType cellType1 = caseBoard1.getCell(0, 0).getType(); + ShortTruthTableCellType cellType2 = caseBoard2.getCell(0, 0).getType(); // First assert the two cells are not equal, then verify that they are true // or false. Assert.assertNotEquals(cellType1, cellType2); - Assert.assertTrue(cellType1.equals(ShortTruthTableCellType.TRUE) || cellType1.equals(ShortTruthTableCellType.FALSE)); - Assert.assertTrue(cellType2.equals(ShortTruthTableCellType.TRUE) || cellType2.equals(ShortTruthTableCellType.FALSE)); + Assert.assertTrue( + cellType1.equals(ShortTruthTableCellType.TRUE) + || cellType1.equals(ShortTruthTableCellType.FALSE)); + Assert.assertTrue( + cellType2.equals(ShortTruthTableCellType.TRUE) + || cellType2.equals(ShortTruthTableCellType.FALSE)); // Verify the board dimensions are unchanged Assert.assertEquals(caseBoard1.getHeight(), caseBoard2.getHeight(), board.getHeight()); Assert.assertEquals(caseBoard1.getWidth(), caseBoard2.getWidth(), board.getWidth()); // Verify that everywhere else on the board is unchanged - for (int i = 0; i< caseBoard1.getWidth(); i++) { + for (int i = 0; i < caseBoard1.getWidth(); i++) { for (int j = 0; j < caseBoard1.getHeight(); j++) { // Make sure not to check the one cell that should be different if (i != 0 && j != 0) { - Assert.assertEquals(caseBoard1.getCell(i, j).getType(), caseBoard2.getCell(i, j).getType()); + Assert.assertEquals( + caseBoard1.getCell(i, j).getType(), caseBoard2.getCell(i, j).getType()); } } } } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/skyscrapers/rules/CellForNumberCaseRuleTest.java b/src/test/java/puzzles/skyscrapers/rules/CellForNumberCaseRuleTest.java index eb2b692c8..1fce24cf1 100644 --- a/src/test/java/puzzles/skyscrapers/rules/CellForNumberCaseRuleTest.java +++ b/src/test/java/puzzles/skyscrapers/rules/CellForNumberCaseRuleTest.java @@ -1,6 +1,5 @@ package puzzles.skyscrapers.rules; - import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.tree.TreeNode; @@ -9,14 +8,13 @@ import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; import edu.rpi.legup.puzzle.skyscrapers.rules.CellForNumberCaseRule; import edu.rpi.legup.save.InvalidFileFormatException; +import java.util.ArrayList; import legup.MockGameBoardFacade; import legup.TestUtilities; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.util.ArrayList; - public class CellForNumberCaseRuleTest { private static final CellForNumberCaseRule RULE = new CellForNumberCaseRule(); @@ -28,7 +26,7 @@ public static void setUp() { skyscrapers = new Skyscrapers(); } - //basic, max cases + // basic, max cases @Test public void CellForNumberCaseRule_BasicEmpty() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); @@ -42,19 +40,19 @@ public void CellForNumberCaseRule_BasicEmpty() throws InvalidFileFormatException board.setDupeFlag(false); board.setViewFlag(false); - ArrayList cases = RULE.getCasesFor(board,board.getNorthClues().get(0), 1); + ArrayList cases = RULE.getCasesFor(board, board.getNorthClues().get(0), 1); Assert.assertEquals(board.getWidth(), cases.size()); - for(int i=0;i cases = RULE.getCasesFor(board,board.getNorthClues().get(0), 1); + ArrayList cases = RULE.getCasesFor(board, board.getNorthClues().get(0), 1); Assert.assertEquals(board.getWidth(), cases.size()); - for(int i=0;i cases = RULE.getCasesFor(board,board.getWestClues().get(3),1); + ArrayList cases = RULE.getCasesFor(board, board.getWestClues().get(3), 1); Assert.assertEquals(1, cases.size()); SkyscrapersBoard expected = ((SkyscrapersBoard) transition.getBoard()).copy(); - PuzzleElement changedCell = expected.getCell(2,3); + PuzzleElement changedCell = expected.getCell(2, 3); changedCell.setData(1); expected.addModifiedData(changedCell); Assert.assertTrue(expected.equalsBoard(cases.get(0))); } - //dupe, no cases + // dupe, no cases @Test public void CellForNumberCaseRule_DupeNone() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -140,12 +141,12 @@ public void CellForNumberCaseRule_DupeNone() throws InvalidFileFormatException { board.setDupeFlag(true); board.setViewFlag(false); - ArrayList cases = RULE.getCasesFor(board,board.getWestClues().get(3),1); + ArrayList cases = RULE.getCasesFor(board, board.getWestClues().get(3), 1); Assert.assertEquals(0, cases.size()); } - //visibility, max cases + // visibility, max cases @Test public void CellForNumberCaseRule_ViewEmpty() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); @@ -159,19 +160,19 @@ public void CellForNumberCaseRule_ViewEmpty() throws InvalidFileFormatException board.setDupeFlag(false); board.setViewFlag(true); - ArrayList cases = RULE.getCasesFor(board,board.getWestClues().get(1), 1); + ArrayList cases = RULE.getCasesFor(board, board.getWestClues().get(1), 1); Assert.assertEquals(board.getWidth(), cases.size()); - for(int i=0;i cases = RULE.getCasesFor(board,board.getWestClues().get(3),1); + ArrayList cases = RULE.getCasesFor(board, board.getWestClues().get(3), 1); Assert.assertEquals(1, cases.size()); SkyscrapersBoard expected = ((SkyscrapersBoard) transition.getBoard()).copy(); - PuzzleElement changedCell = expected.getCell(2,3); + PuzzleElement changedCell = expected.getCell(2, 3); changedCell.setData(1); expected.addModifiedData(changedCell); Assert.assertTrue(expected.equalsBoard(cases.get(0))); } - //visibility, 1 Case, implied + // visibility, 1 Case, implied @Test public void CellForNumberCaseRule_ImpliedViewSingular() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); @@ -221,22 +223,24 @@ public void CellForNumberCaseRule_ImpliedViewSingular() throws InvalidFileFormat board.setDupeFlag(false); board.setViewFlag(true); - ArrayList cases = RULE.getCasesFor(board,board.getWestClues().get(0),5); + ArrayList cases = RULE.getCasesFor(board, board.getWestClues().get(0), 5); Assert.assertEquals(1, cases.size()); SkyscrapersBoard expected = ((SkyscrapersBoard) transition.getBoard()).copy(); - PuzzleElement changedCell = expected.getCell(4,0); + PuzzleElement changedCell = expected.getCell(4, 0); changedCell.setData(5); expected.addModifiedData(changedCell); Assert.assertTrue(expected.equalsBoard(cases.get(0))); } - //visibility, no cases + // visibility, no cases @Test public void CellForNumberCaseRule_ViewNone() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -247,8 +251,8 @@ public void CellForNumberCaseRule_ViewNone() throws InvalidFileFormatException { board.setDupeFlag(false); board.setViewFlag(true); - ArrayList cases = RULE.getCasesFor(board,board.getWestClues().get(3),1); + ArrayList cases = RULE.getCasesFor(board, board.getWestClues().get(3), 1); Assert.assertEquals(0, cases.size()); } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/skyscrapers/rules/DuplicateNumberContradictionTest.java b/src/test/java/puzzles/skyscrapers/rules/DuplicateNumberContradictionTest.java index 00cce1b91..a7bb63a08 100644 --- a/src/test/java/puzzles/skyscrapers/rules/DuplicateNumberContradictionTest.java +++ b/src/test/java/puzzles/skyscrapers/rules/DuplicateNumberContradictionTest.java @@ -1,21 +1,21 @@ package puzzles.skyscrapers.rules; - +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; import edu.rpi.legup.puzzle.skyscrapers.rules.DuplicateNumberContradictionRule; import edu.rpi.legup.save.InvalidFileFormatException; import legup.MockGameBoardFacade; import legup.TestUtilities; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; public class DuplicateNumberContradictionTest { - private static final DuplicateNumberContradictionRule RULE = new DuplicateNumberContradictionRule(); + private static final DuplicateNumberContradictionRule RULE = + new DuplicateNumberContradictionRule(); private static Skyscrapers skyscrapers; @BeforeClass @@ -24,9 +24,10 @@ public static void setUp() { skyscrapers = new Skyscrapers(); } - //empty + // empty @Test - public void DuplicateNumberContradictionRule_EmptyBoardTest() throws InvalidFileFormatException { + public void DuplicateNumberContradictionRule_EmptyBoardTest() + throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); @@ -43,9 +44,10 @@ public void DuplicateNumberContradictionRule_EmptyBoardTest() throws InvalidFile } } - //correct board, no cont + // correct board, no cont @Test - public void DuplicateNumberContradictionRule_SolvedBoardTest() throws InvalidFileFormatException { + public void DuplicateNumberContradictionRule_SolvedBoardTest() + throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/Solved", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); @@ -62,10 +64,13 @@ public void DuplicateNumberContradictionRule_SolvedBoardTest() throws InvalidFil } } - //invalid board, no cont + // invalid board, no cont @Test - public void DuplicateNumberContradictionRule_OtherContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/FullRowContradiction", skyscrapers); + public void DuplicateNumberContradictionRule_OtherContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/VisibilityContradictionRules/FullRowContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -81,10 +86,13 @@ public void DuplicateNumberContradictionRule_OtherContradictionTest() throws Inv } } - //on row + // on row @Test - public void DuplicateNumberContradictionRule_RowContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/RowContradiction", skyscrapers); + public void DuplicateNumberContradictionRule_RowContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/RowContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -95,20 +103,22 @@ public void DuplicateNumberContradictionRule_RowContradictionTest() throws Inval SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { - if((k==0 || k==1) && i==0){ + if ((k == 0 || k == 1) && i == 0) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else{ + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //on col + // on col @Test - public void DuplicateNumberContradictionRule_ColContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/ColContradiction", skyscrapers); + public void DuplicateNumberContradictionRule_ColContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/ColContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -119,20 +129,22 @@ public void DuplicateNumberContradictionRule_ColContradictionTest() throws Inval SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { - if(k==0 && (i==0 || i==1)){ + if (k == 0 && (i == 0 || i == 1)) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else{ + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //multitudes + // multitudes @Test - public void DuplicateNumberContradictionRule_AllContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/AllContradiction", skyscrapers); + public void DuplicateNumberContradictionRule_AllContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/AllContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -147,4 +159,4 @@ public void DuplicateNumberContradictionRule_AllContradictionTest() throws Inval } } } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/skyscrapers/rules/ExceedingVisibilityContradictionTest.java b/src/test/java/puzzles/skyscrapers/rules/ExceedingVisibilityContradictionTest.java index c7f73c998..a5a07f997 100644 --- a/src/test/java/puzzles/skyscrapers/rules/ExceedingVisibilityContradictionTest.java +++ b/src/test/java/puzzles/skyscrapers/rules/ExceedingVisibilityContradictionTest.java @@ -1,6 +1,5 @@ package puzzles.skyscrapers.rules; - import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; @@ -15,7 +14,8 @@ public class ExceedingVisibilityContradictionTest { - private static final ExceedingVisibilityContradictionRule RULE = new ExceedingVisibilityContradictionRule(); + private static final ExceedingVisibilityContradictionRule RULE = + new ExceedingVisibilityContradictionRule(); private static Skyscrapers skyscrapers; @BeforeClass @@ -24,9 +24,10 @@ public static void setUp() { skyscrapers = new Skyscrapers(); } - //empty + // empty @Test - public void ExceedingVisibilityContradictionRule_EmptyBoardTest() throws InvalidFileFormatException { + public void ExceedingVisibilityContradictionRule_EmptyBoardTest() + throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); @@ -41,9 +42,10 @@ public void ExceedingVisibilityContradictionRule_EmptyBoardTest() throws Invalid } } - //correct board, no cont + // correct board, no cont @Test - public void ExceedingVisibilityContradictionRule_SolvedBoardTest() throws InvalidFileFormatException { + public void ExceedingVisibilityContradictionRule_SolvedBoardTest() + throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/Solved", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); @@ -58,10 +60,13 @@ public void ExceedingVisibilityContradictionRule_SolvedBoardTest() throws Invali } } - //invalid board, no cont + // invalid board, no cont @Test - public void ExceedingVisibilityContradictionRule_OtherContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/RowContradiction", skyscrapers); + public void ExceedingVisibilityContradictionRule_OtherContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/RowContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -75,10 +80,13 @@ public void ExceedingVisibilityContradictionRule_OtherContradictionTest() throws } } - //on row + // on row @Test - public void ExceedingVisibilityContradictionRule_RowContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/FullRowContradiction", skyscrapers); + public void ExceedingVisibilityContradictionRule_RowContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/VisibilityContradictionRules/FullRowContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -88,19 +96,21 @@ public void ExceedingVisibilityContradictionRule_RowContradictionTest() throws I SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); for (int i = 0; i < board.getHeight(); i++) { - if(i==1 || i==3){ + if (i == 1 || i == 3) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); - } - else{ + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); } } } - //on col + // on col @Test - public void ExceedingVisibilityContradictionRule_ColContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/FullColContradiction", skyscrapers); + public void ExceedingVisibilityContradictionRule_ColContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/VisibilityContradictionRules/FullColContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -110,19 +120,21 @@ public void ExceedingVisibilityContradictionRule_ColContradictionTest() throws I SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); for (int i = 0; i < board.getHeight(); i++) { - if(i==2 || i==3){ + if (i == 2 || i == 3) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); - } - else{ + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); } } } - //multitudes + // multitudes @Test - public void ExceedingVisibilityContradictionRule_AllContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/AllContradiction", skyscrapers); + public void ExceedingVisibilityContradictionRule_AllContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/VisibilityContradictionRules/AllContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -135,4 +147,4 @@ public void ExceedingVisibilityContradictionRule_AllContradictionTest() throws I Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); } } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/skyscrapers/rules/InsufficientVisibilityContradictionTest.java b/src/test/java/puzzles/skyscrapers/rules/InsufficientVisibilityContradictionTest.java index 4e90861fc..ee0f3349a 100644 --- a/src/test/java/puzzles/skyscrapers/rules/InsufficientVisibilityContradictionTest.java +++ b/src/test/java/puzzles/skyscrapers/rules/InsufficientVisibilityContradictionTest.java @@ -1,6 +1,5 @@ package puzzles.skyscrapers.rules; - import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; @@ -15,7 +14,8 @@ public class InsufficientVisibilityContradictionTest { - private static final InsufficientVisibilityContradictionRule RULE = new InsufficientVisibilityContradictionRule(); + private static final InsufficientVisibilityContradictionRule RULE = + new InsufficientVisibilityContradictionRule(); private static Skyscrapers skyscrapers; @BeforeClass @@ -24,9 +24,10 @@ public static void setUp() { skyscrapers = new Skyscrapers(); } - //empty + // empty @Test - public void InsufficientVisibilityContradictionRule_EmptyBoardTest() throws InvalidFileFormatException { + public void InsufficientVisibilityContradictionRule_EmptyBoardTest() + throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); @@ -41,9 +42,10 @@ public void InsufficientVisibilityContradictionRule_EmptyBoardTest() throws Inva } } - //correct board, no cont + // correct board, no cont @Test - public void InsufficientVisibilityContradictionRule_SolvedBoardTest() throws InvalidFileFormatException { + public void InsufficientVisibilityContradictionRule_SolvedBoardTest() + throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/Solved", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); @@ -58,10 +60,13 @@ public void InsufficientVisibilityContradictionRule_SolvedBoardTest() throws Inv } } - //invalid board, no cont + // invalid board, no cont @Test - public void InsufficientVisibilityContradictionRule_OtherContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/RowContradiction", skyscrapers); + public void InsufficientVisibilityContradictionRule_OtherContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/DuplicateNumberContradictionRule/RowContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -75,10 +80,13 @@ public void InsufficientVisibilityContradictionRule_OtherContradictionTest() thr } } - //on row + // on row @Test - public void InsufficientVisibilityContradictionRule_RowContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/FullRowContradiction", skyscrapers); + public void InsufficientVisibilityContradictionRule_RowContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/VisibilityContradictionRules/FullRowContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -88,19 +96,21 @@ public void InsufficientVisibilityContradictionRule_RowContradictionTest() throw SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); for (int i = 0; i < board.getHeight(); i++) { - if(i==1 || i==3){ + if (i == 1 || i == 3) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); - } - else{ + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); } } } - //on col + // on col @Test - public void InsufficientVisibilityContradictionRule_ColContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/FullColContradiction", skyscrapers); + public void InsufficientVisibilityContradictionRule_ColContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/VisibilityContradictionRules/FullColContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -110,19 +120,21 @@ public void InsufficientVisibilityContradictionRule_ColContradictionTest() throw SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); for (int i = 0; i < board.getHeight(); i++) { - if(i==2 || i==3){ + if (i == 2 || i == 3) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); - } - else{ + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); } } } - //multitudes + // multitudes @Test - public void InsufficientVisibilityContradictionRule_AllContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/AllContradiction", skyscrapers); + public void InsufficientVisibilityContradictionRule_AllContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/VisibilityContradictionRules/AllContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -135,4 +147,4 @@ public void InsufficientVisibilityContradictionRule_AllContradictionTest() throw Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); } } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/skyscrapers/rules/LastSingularCellDirectTest.java b/src/test/java/puzzles/skyscrapers/rules/LastSingularCellDirectTest.java index 855c358e8..76540f010 100644 --- a/src/test/java/puzzles/skyscrapers/rules/LastSingularCellDirectTest.java +++ b/src/test/java/puzzles/skyscrapers/rules/LastSingularCellDirectTest.java @@ -1,6 +1,5 @@ package puzzles.skyscrapers.rules; - import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; @@ -8,14 +7,13 @@ import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; import edu.rpi.legup.puzzle.skyscrapers.rules.LastSingularCellDirectRule; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import legup.MockGameBoardFacade; import legup.TestUtilities; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.awt.*; - public class LastSingularCellDirectTest { private static final LastSingularCellDirectRule RULE = new LastSingularCellDirectRule(); @@ -27,206 +25,206 @@ public static void setUp() { skyscrapers = new Skyscrapers(); } - //full row + // full row @Test public void LastSingularCellDirectRule_FullRowTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/3-0RowOpening", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/common/3-0RowOpening", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(2,3); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(2, 3); cell.setData(1); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //full col + // full col @Test public void LastSingularCellDirectRule_FullColTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/3-0ColOpening", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/common/3-0ColOpening", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(3,1); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(3, 1); cell.setData(1); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //empty row/col + // empty row/col @Test public void LastSingularCellDirectRule_EmptyTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastSingularCellDirectRule/0-3Opening", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/LastSingularCellDirectRule/0-3Opening", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(0,1); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(0, 1); cell.setData(3); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //2-1 row + // 2-1 row @Test public void LastSingularCellDirectRule_PartialRowTest1() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastSingularCellDirectRule/2-1RowOpening", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/LastSingularCellDirectRule/2-1RowOpening", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(3,1); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(3, 1); cell.setData(1); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //2-1 col + // 2-1 col @Test public void LastSingularCellDirectRule_PartialColTest1() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastSingularCellDirectRule/2-1ColOpening", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/LastSingularCellDirectRule/2-1ColOpening", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(1,2); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(1, 2); cell.setData(3); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //1-2 row + // 1-2 row @Test public void LastSingularCellDirectRule_PartialRowTest2() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastSingularCellDirectRule/1-2RowOpening", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/LastSingularCellDirectRule/1-2RowOpening", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(1,1); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(1, 1); cell.setData(2); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //1-2 col + // 1-2 col @Test public void LastSingularCellDirectRule_PartialColTest2() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastSingularCellDirectRule/1-2ColOpening", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/LastSingularCellDirectRule/1-2ColOpening", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(0,0); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(0, 0); cell.setData(4); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/skyscrapers/rules/LastSingularNumberDirectTest.java b/src/test/java/puzzles/skyscrapers/rules/LastSingularNumberDirectTest.java index f08774a8a..6b99994a2 100644 --- a/src/test/java/puzzles/skyscrapers/rules/LastSingularNumberDirectTest.java +++ b/src/test/java/puzzles/skyscrapers/rules/LastSingularNumberDirectTest.java @@ -1,6 +1,5 @@ package puzzles.skyscrapers.rules; - import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; @@ -8,14 +7,13 @@ import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; import edu.rpi.legup.puzzle.skyscrapers.rules.LastSingularNumberDirectRule; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import legup.MockGameBoardFacade; import legup.TestUtilities; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.awt.*; - public class LastSingularNumberDirectTest { private static final LastSingularNumberDirectRule RULE = new LastSingularNumberDirectRule(); @@ -27,119 +25,123 @@ public static void setUp() { skyscrapers = new Skyscrapers(); } - //full row / empty col + // full row / empty col @Test public void LastSingularNumberDirectRule_FullRowTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/3-0RowOpening", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/common/3-0RowOpening", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(2,3); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(2, 3); cell.setData(1); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //full col / empty row + // full col / empty row @Test public void LastSingularNumberDirectRule_FullColTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/3-0ColOpening", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/common/3-0ColOpening", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(3,1); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(3, 1); cell.setData(1); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //2-1 row / 1-2 col + // 2-1 row / 1-2 col @Test - public void LastSingularNumberDirectRule_PartialRowColTest1() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastSingularNumberDirectRule/2-1RowOpening", skyscrapers); + public void LastSingularNumberDirectRule_PartialRowColTest1() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/LastSingularNumberDirectRule/2-1RowOpening", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(2,1); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(2, 1); cell.setData(4); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //2-1 col / 1-2 row + // 2-1 col / 1-2 row @Test - public void LastSingularNumberDirectRule_PartialRowColTest2() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastSingularNumberDirectRule/2-1ColOpening", skyscrapers); + public void LastSingularNumberDirectRule_PartialRowColTest2() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/LastSingularNumberDirectRule/2-1ColOpening", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(0,2); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(0, 2); cell.setData(1); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/skyscrapers/rules/LastVisibleCellDirectTest.java b/src/test/java/puzzles/skyscrapers/rules/LastVisibleCellDirectTest.java index ca50bc873..756ff7468 100644 --- a/src/test/java/puzzles/skyscrapers/rules/LastVisibleCellDirectTest.java +++ b/src/test/java/puzzles/skyscrapers/rules/LastVisibleCellDirectTest.java @@ -1,6 +1,5 @@ package puzzles.skyscrapers.rules; - import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; @@ -8,14 +7,13 @@ import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; import edu.rpi.legup.puzzle.skyscrapers.rules.LastVisibleCellDirectRule; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import legup.MockGameBoardFacade; import legup.TestUtilities; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.awt.*; - public class LastVisibleCellDirectTest { private static final LastVisibleCellDirectRule RULE = new LastVisibleCellDirectRule(); @@ -27,65 +25,65 @@ public static void setUp() { skyscrapers = new Skyscrapers(); } - //full row + // full row @Test public void LastVisibleCellDirectRule_FullRowTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/3-0RowOpening", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/common/3-0RowOpening", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(2,3); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(2, 3); cell.setData(1); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //full col + // full col @Test public void LastVisibleCellDirectRule_FullColTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/3-0ColOpening", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/common/3-0ColOpening", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(3,1); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(3, 1); cell.setData(1); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //empty row + // empty row @Test public void LastVisibleCellDirectRule_EmptyRowTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); @@ -93,28 +91,27 @@ public void LastVisibleCellDirectRule_EmptyRowTest() throws InvalidFileFormatExc TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(0,2); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(0, 2); cell.setData(5); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //empty col + // empty col @Test public void LastVisibleCellDirectRule_EmptyColTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); @@ -122,136 +119,135 @@ public void LastVisibleCellDirectRule_EmptyColTest() throws InvalidFileFormatExc TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(3,4); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(3, 4); cell.setData(5); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //1-2 row + // 1-2 row public void LastVisibleCellDirectRule_PartialRowTest1() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastVisibleDirectRules/1-2RowOpening", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/LastVisibleDirectRules/1-2RowOpening", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(1,2); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(1, 2); cell.setData(3); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //1-2 col + // 1-2 col public void LastVisibleCellDirectRule_PartialColTest1() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastVisibleDirectRules/1-2ColOpening", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/LastVisibleDirectRules/1-2ColOpening", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(2,2); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(2, 2); cell.setData(2); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //2-1 row + // 2-1 row public void LastVisibleCellDirectRule_PartialRowTest2() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastVisibleDirectRules/2-1RowOpening", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/LastVisibleDirectRules/2-1RowOpening", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(1,1); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(1, 1); cell.setData(2); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //2-1 col + // 2-1 col public void LastVisibleCellDirectRule_PartialColTest2() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastVisibleDirectRules/2-1ColOpening", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/LastVisibleDirectRules/2-1ColOpening", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(0,2); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(0, 2); cell.setData(1); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/skyscrapers/rules/LastVisibleNumberDirectTest.java b/src/test/java/puzzles/skyscrapers/rules/LastVisibleNumberDirectTest.java index 1816832b6..c628b89da 100644 --- a/src/test/java/puzzles/skyscrapers/rules/LastVisibleNumberDirectTest.java +++ b/src/test/java/puzzles/skyscrapers/rules/LastVisibleNumberDirectTest.java @@ -1,22 +1,19 @@ package puzzles.skyscrapers.rules; - import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; -import edu.rpi.legup.puzzle.skyscrapers.rules.LastSingularCellDirectRule; import edu.rpi.legup.puzzle.skyscrapers.rules.LastVisibleNumberDirectRule; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import legup.MockGameBoardFacade; import legup.TestUtilities; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.awt.*; - public class LastVisibleNumberDirectTest { private static final LastVisibleNumberDirectRule RULE = new LastVisibleNumberDirectRule(); @@ -28,65 +25,65 @@ public static void setUp() { skyscrapers = new Skyscrapers(); } - //full row + // full row @Test public void LastVisibleNumberDirectRule_FullRowTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/3-0RowOpening", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/common/3-0RowOpening", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(2,3); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(2, 3); cell.setData(1); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //full col + // full col @Test public void LastVisibleNumberDirectRule_FullColTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/3-0ColOpening", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/common/3-0ColOpening", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(3,1); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(3, 1); cell.setData(1); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //empty row + // empty row @Test public void LastVisibleNumberDirectRule_EmptyRowTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); @@ -94,28 +91,27 @@ public void LastVisibleNumberDirectRule_EmptyRowTest() throws InvalidFileFormatE TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(0,2); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(0, 2); cell.setData(5); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //empty col + // empty col @Test public void LastVisibleNumberDirectRule_EmptyColTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); @@ -123,136 +119,135 @@ public void LastVisibleNumberDirectRule_EmptyColTest() throws InvalidFileFormatE TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(3,4); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(3, 4); cell.setData(5); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //1-2 row + // 1-2 row public void LastVisibleNumberDirectRule_PartialRowTest1() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastVisibleDirectRules/1-2RowOpening", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/LastVisibleDirectRules/1-2RowOpening", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(1,2); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(1, 2); cell.setData(3); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //1-2 col + // 1-2 col public void LastVisibleNumberDirectRule_PartialColTest1() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastVisibleDirectRules/1-2ColOpening", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/LastVisibleDirectRules/1-2ColOpening", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(2,2); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(2, 2); cell.setData(2); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //2-1 row + // 2-1 row public void LastVisibleNumberDirectRule_PartialRowTest2() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastVisibleDirectRules/2-1ColOpening", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/LastVisibleDirectRules/2-1ColOpening", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(1,1); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(1, 1); cell.setData(2); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //2-1 col + // 2-1 col public void LastVisibleNumberDirectRule_PartialColTest2() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/LastVisibleDirectRules/2-1RowOpening", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/LastVisibleDirectRules/2-1RowOpening", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(0,2); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(0, 2); cell.setData(1); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/skyscrapers/rules/NEdgeDirectTest.java b/src/test/java/puzzles/skyscrapers/rules/NEdgeDirectTest.java index cc39d8183..ed70fce40 100644 --- a/src/test/java/puzzles/skyscrapers/rules/NEdgeDirectTest.java +++ b/src/test/java/puzzles/skyscrapers/rules/NEdgeDirectTest.java @@ -1,6 +1,5 @@ package puzzles.skyscrapers.rules; - import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; @@ -8,14 +7,13 @@ import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersCell; import edu.rpi.legup.puzzle.skyscrapers.rules.NEdgeDirectRule; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import legup.MockGameBoardFacade; import legup.TestUtilities; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.awt.*; - public class NEdgeDirectTest { private static final NEdgeDirectRule RULE = new NEdgeDirectRule(); @@ -27,7 +25,7 @@ public static void setUp() { skyscrapers = new Skyscrapers(); } - //-> row, empty -> full + // -> row, empty -> full @Test public void NEdgeDirectRule_RightRowTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); @@ -35,111 +33,110 @@ public void NEdgeDirectRule_RightRowTest() throws InvalidFileFormatException { TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - for(int i = 0; i < 5; i++){ - SkyscrapersCell cell = board.getCell(i,0); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < 5; i++) { + SkyscrapersCell cell = board.getCell(i, 0); cell.setData(i + 1); board.addModifiedData(cell); } Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - if(i == 0) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + if (i == 0) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //<-row, partial -> partial + // <-row, partial -> partial @Test public void NEdgeDirectRule_LeftRowTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/NEdgeDirectRule/LeftRowPartial", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/NEdgeDirectRule/LeftRowPartial", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - SkyscrapersCell cell = board.getCell(1,3); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + SkyscrapersCell cell = board.getCell(1, 3); cell.setData(2); board.addModifiedData(cell); Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if(point.equals(cell.getLocation())) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //up col, partial -> full + // up col, partial -> full @Test public void NEdgeDirectRule_UpColTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/NEdgeDirectRule/UpColPartial", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/NEdgeDirectRule/UpColPartial", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - for(int i = 0; i < 2; i++){ - SkyscrapersCell cell = board.getCell(1,i); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 0; i < 2; i++) { + SkyscrapersCell cell = board.getCell(1, i); cell.setData(i + 1); board.addModifiedData(cell); } Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - if(k == 1 && i < 2) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + if (k == 1 && i < 2) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //down col, empty -> partial + // down col, empty -> partial @Test public void NEdgeDirectRule_DownColTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/NEdgeDirectRule/DownColEmpty", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/NEdgeDirectRule/DownColEmpty", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - SkyscrapersBoard board = (SkyscrapersBoard)transition.getBoard(); - for(int i = 1; i < 5; i++){ - SkyscrapersCell cell = board.getCell(3,i); + SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); + for (int i = 1; i < 5; i++) { + SkyscrapersCell cell = board.getCell(3, i); cell.setData(5 - i); board.addModifiedData(cell); } Assert.assertNull(RULE.checkRule(transition)); - for(int i = 0; i < board.getHeight(); i++) { - for(int k = 0; k < board.getWidth(); k++) { - if(k == 3 && i > 0) { + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + if (k == 3 && i > 0) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/skyscrapers/rules/NumberForCellCaseRuleTest.java b/src/test/java/puzzles/skyscrapers/rules/NumberForCellCaseRuleTest.java index 40c21e604..b417a5227 100644 --- a/src/test/java/puzzles/skyscrapers/rules/NumberForCellCaseRuleTest.java +++ b/src/test/java/puzzles/skyscrapers/rules/NumberForCellCaseRuleTest.java @@ -1,6 +1,5 @@ package puzzles.skyscrapers.rules; - import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.tree.TreeNode; @@ -9,14 +8,13 @@ import edu.rpi.legup.puzzle.skyscrapers.SkyscrapersBoard; import edu.rpi.legup.puzzle.skyscrapers.rules.NumberForCellCaseRule; import edu.rpi.legup.save.InvalidFileFormatException; +import java.util.ArrayList; import legup.MockGameBoardFacade; import legup.TestUtilities; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.util.ArrayList; - public class NumberForCellCaseRuleTest { private static final NumberForCellCaseRule RULE = new NumberForCellCaseRule(); @@ -28,7 +26,7 @@ public static void setUp() { skyscrapers = new Skyscrapers(); } - //basic, max cases + // basic, max cases @Test public void NumberForCellCaseRule_BasicEmpty() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); @@ -42,19 +40,19 @@ public void NumberForCellCaseRule_BasicEmpty() throws InvalidFileFormatException board.setDupeFlag(false); board.setViewFlag(false); - ArrayList cases = RULE.getCases(board,board.getCell(0,0)); + ArrayList cases = RULE.getCases(board, board.getCell(0, 0)); Assert.assertEquals(board.getWidth(), cases.size()); - for(int i=0;i cases = RULE.getCases(board,board.getCell(0,0)); + ArrayList cases = RULE.getCases(board, board.getCell(0, 0)); Assert.assertEquals(board.getWidth(), cases.size()); - for(int i=0;i cases = RULE.getCases(board,board.getCell(2,3)); + ArrayList cases = RULE.getCases(board, board.getCell(2, 3)); Assert.assertEquals(1, cases.size()); SkyscrapersBoard expected = ((SkyscrapersBoard) transition.getBoard()).copy(); - PuzzleElement changedCell = expected.getCell(2,3); + PuzzleElement changedCell = expected.getCell(2, 3); changedCell.setData(1); expected.addModifiedData(changedCell); Assert.assertTrue(expected.equalsBoard(cases.get(0))); } - //dupe, no cases + // dupe, no cases @Test public void NumberForCellCaseRule_DupeNone() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -140,12 +141,12 @@ public void NumberForCellCaseRule_DupeNone() throws InvalidFileFormatException { board.setDupeFlag(true); board.setViewFlag(false); - ArrayList cases = RULE.getCases(board,board.getCell(2,3)); + ArrayList cases = RULE.getCases(board, board.getCell(2, 3)); Assert.assertEquals(0, cases.size()); } - //visibility, max cases + // visibility, max cases @Test public void NumberForCellCaseRule_ViewEmpty() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); @@ -159,19 +160,19 @@ public void NumberForCellCaseRule_ViewEmpty() throws InvalidFileFormatException board.setDupeFlag(false); board.setViewFlag(true); - ArrayList cases = RULE.getCases(board,board.getCell(1,4)); + ArrayList cases = RULE.getCases(board, board.getCell(1, 4)); Assert.assertEquals(4, cases.size()); - for(int i=0;i cases = RULE.getCases(board,board.getCell(2,3)); + ArrayList cases = RULE.getCases(board, board.getCell(2, 3)); Assert.assertEquals(1, cases.size()); SkyscrapersBoard expected = ((SkyscrapersBoard) transition.getBoard()).copy(); - PuzzleElement changedCell = expected.getCell(2,3); + PuzzleElement changedCell = expected.getCell(2, 3); changedCell.setData(1); expected.addModifiedData(changedCell); Assert.assertTrue(expected.equalsBoard(cases.get(0))); } - //visibility, no cases + // visibility, no cases @Test public void NumberForCellCaseRule_ViewNone() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction", skyscrapers); + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -221,8 +225,8 @@ public void NumberForCellCaseRule_ViewNone() throws InvalidFileFormatException { board.setDupeFlag(false); board.setViewFlag(true); - ArrayList cases = RULE.getCases(board,board.getCell(2,3)); + ArrayList cases = RULE.getCases(board, board.getCell(2, 3)); Assert.assertEquals(0, cases.size()); } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/skyscrapers/rules/PreemptiveVisibilityContradictionTest.java b/src/test/java/puzzles/skyscrapers/rules/PreemptiveVisibilityContradictionTest.java index 69f4e593a..ec49a8194 100644 --- a/src/test/java/puzzles/skyscrapers/rules/PreemptiveVisibilityContradictionTest.java +++ b/src/test/java/puzzles/skyscrapers/rules/PreemptiveVisibilityContradictionTest.java @@ -1,6 +1,5 @@ package puzzles.skyscrapers.rules; - import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; @@ -15,7 +14,8 @@ public class PreemptiveVisibilityContradictionTest { - private static final PreemptiveVisibilityContradictionRule RULE = new PreemptiveVisibilityContradictionRule(); + private static final PreemptiveVisibilityContradictionRule RULE = + new PreemptiveVisibilityContradictionRule(); private static Skyscrapers skyscrapers; @BeforeClass @@ -24,9 +24,10 @@ public static void setUp() { skyscrapers = new Skyscrapers(); } - //empty + // empty @Test - public void PreemptiveVisibilityContradictionRule_EmptyBoardTest() throws InvalidFileFormatException { + public void PreemptiveVisibilityContradictionRule_EmptyBoardTest() + throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); @@ -41,9 +42,10 @@ public void PreemptiveVisibilityContradictionRule_EmptyBoardTest() throws Invali } } - //correct board, no cont + // correct board, no cont @Test - public void PreemptiveVisibilityContradictionRule_SolvedBoardTest() throws InvalidFileFormatException { + public void PreemptiveVisibilityContradictionRule_SolvedBoardTest() + throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/Solved", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); @@ -58,10 +60,13 @@ public void PreemptiveVisibilityContradictionRule_SolvedBoardTest() throws Inval } } - //invalid board, no cont + // invalid board, no cont @Test - public void PreemptiveVisibilityContradictionRule_OtherContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/2-2CellContradiction", skyscrapers); + public void PreemptiveVisibilityContradictionRule_OtherContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/UnresolvedContradictionRules/2-2CellContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -75,10 +80,13 @@ public void PreemptiveVisibilityContradictionRule_OtherContradictionTest() throw } } - //on row + // on row @Test - public void PreemptiveVisibilityContradictionRule_RowContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedRowContradiction", skyscrapers); + public void PreemptiveVisibilityContradictionRule_RowContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedRowContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -88,19 +96,21 @@ public void PreemptiveVisibilityContradictionRule_RowContradictionTest() throws SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); for (int i = 0; i < board.getHeight(); i++) { - if(i==1){ + if (i == 1) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); - } - else{ + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); } } } - //on col + // on col @Test - public void PreemptiveVisibilityContradictionRule_ColContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedColContradiction", skyscrapers); + public void PreemptiveVisibilityContradictionRule_ColContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedColContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -110,19 +120,21 @@ public void PreemptiveVisibilityContradictionRule_ColContradictionTest() throws SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); for (int i = 0; i < board.getHeight(); i++) { - if(i==2){ + if (i == 2) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); - } - else{ + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); } } } - //multitudes + // multitudes @Test - public void PreemptiveVisibilityContradictionRule_AllContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/AllContradiction", skyscrapers); + public void PreemptiveVisibilityContradictionRule_AllContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/VisibilityContradictionRules/AllContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -136,10 +148,13 @@ public void PreemptiveVisibilityContradictionRule_AllContradictionTest() throws } } - //multitudes - preemptive + // multitudes - preemptive @Test - public void PreemptiveVisibilityContradictionRule_ImpliedAllContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedAllContradiction", skyscrapers); + public void PreemptiveVisibilityContradictionRule_ImpliedAllContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedAllContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -152,4 +167,4 @@ public void PreemptiveVisibilityContradictionRule_ImpliedAllContradictionTest() Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); } } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/skyscrapers/rules/UnresolvedCellContradictionTest.java b/src/test/java/puzzles/skyscrapers/rules/UnresolvedCellContradictionTest.java index d5f21a8d7..398bba6e5 100644 --- a/src/test/java/puzzles/skyscrapers/rules/UnresolvedCellContradictionTest.java +++ b/src/test/java/puzzles/skyscrapers/rules/UnresolvedCellContradictionTest.java @@ -1,6 +1,5 @@ package puzzles.skyscrapers.rules; - import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; @@ -15,7 +14,8 @@ public class UnresolvedCellContradictionTest { - private static final UnresolvedCellContradictionRule RULE = new UnresolvedCellContradictionRule(); + private static final UnresolvedCellContradictionRule RULE = + new UnresolvedCellContradictionRule(); private static Skyscrapers skyscrapers; @BeforeClass @@ -24,7 +24,7 @@ public static void setUp() { skyscrapers = new Skyscrapers(); } - //empty + // empty @Test public void UnresolvedCellContradictionRule_EmptyBoardTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); @@ -43,9 +43,10 @@ public void UnresolvedCellContradictionRule_EmptyBoardTest() throws InvalidFileF } } - //correct board, no cont + // correct board, no cont @Test - public void UnresolvedCellContradictionRule_SolvedBoardTest() throws InvalidFileFormatException { + public void UnresolvedCellContradictionRule_SolvedBoardTest() + throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/Solved", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); @@ -62,10 +63,13 @@ public void UnresolvedCellContradictionRule_SolvedBoardTest() throws InvalidFile } } - //invalid board, no cont + // invalid board, no cont @Test - public void UnresolvedCellContradictionRule_OtherContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedAllContradiction", skyscrapers); + public void UnresolvedCellContradictionRule_OtherContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedAllContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -81,10 +85,13 @@ public void UnresolvedCellContradictionRule_OtherContradictionTest() throws Inva } } - //3 in a row, 1 in col creates contradiction + // 3 in a row, 1 in col creates contradiction @Test - public void UnresolvedCellContradictionRule_RowContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction", skyscrapers); + public void UnresolvedCellContradictionRule_RowContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -95,20 +102,22 @@ public void UnresolvedCellContradictionRule_RowContradictionTest() throws Invali SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { - if(k==2 && i==3){ + if (k == 2 && i == 3) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else{ + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //3 in a col, 1 in row creates contradiction + // 3 in a col, 1 in row creates contradiction @Test - public void UnresolvedCellContradictionRule_ColContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1ColContradiction", skyscrapers); + public void UnresolvedCellContradictionRule_ColContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1ColContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -119,20 +128,22 @@ public void UnresolvedCellContradictionRule_ColContradictionTest() throws Invali SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { - if(k==1 && i==0){ + if (k == 1 && i == 0) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else{ + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - //2 in a col, 2 in row creates cell contradiction + // 2 in a col, 2 in row creates cell contradiction @Test - public void UnresolvedCellContradictionRule_MixedContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/2-2CellContradiction", skyscrapers); + public void UnresolvedCellContradictionRule_MixedContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/UnresolvedContradictionRules/2-2CellContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -143,13 +154,12 @@ public void UnresolvedCellContradictionRule_MixedContradictionTest() throws Inva SkyscrapersBoard board = (SkyscrapersBoard) transition.getBoard(); for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { - if(k==2 && i==3){ + if (k == 2 && i == 3) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else{ + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/skyscrapers/rules/UnresolvedNumberContradictionTest.java b/src/test/java/puzzles/skyscrapers/rules/UnresolvedNumberContradictionTest.java index fe4a4865a..17139fb60 100644 --- a/src/test/java/puzzles/skyscrapers/rules/UnresolvedNumberContradictionTest.java +++ b/src/test/java/puzzles/skyscrapers/rules/UnresolvedNumberContradictionTest.java @@ -1,6 +1,5 @@ package puzzles.skyscrapers.rules; - import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.skyscrapers.Skyscrapers; @@ -15,7 +14,8 @@ public class UnresolvedNumberContradictionTest { - private static final UnresolvedNumberContradictionRule RULE = new UnresolvedNumberContradictionRule(); + private static final UnresolvedNumberContradictionRule RULE = + new UnresolvedNumberContradictionRule(); private static Skyscrapers skyscrapers; @BeforeClass @@ -24,9 +24,10 @@ public static void setUp() { skyscrapers = new Skyscrapers(); } - //empty + // empty @Test - public void UnresolvedNumberContradictionRule_EmptyBoardTest() throws InvalidFileFormatException { + public void UnresolvedNumberContradictionRule_EmptyBoardTest() + throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/empty", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); @@ -41,9 +42,10 @@ public void UnresolvedNumberContradictionRule_EmptyBoardTest() throws InvalidFil } } - //correct board, no cont + // correct board, no cont @Test - public void UnresolvedNumberContradictionRule_SolvedBoardTest() throws InvalidFileFormatException { + public void UnresolvedNumberContradictionRule_SolvedBoardTest() + throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/skyscrapers/rules/common/Solved", skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); @@ -58,10 +60,13 @@ public void UnresolvedNumberContradictionRule_SolvedBoardTest() throws InvalidFi } } - //invalid board, no cont + // invalid board, no cont @Test - public void UnresolvedNumberContradictionRule_OtherContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedAllContradiction", skyscrapers); + public void UnresolvedNumberContradictionRule_OtherContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/VisibilityContradictionRules/ImpliedAllContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -75,10 +80,13 @@ public void UnresolvedNumberContradictionRule_OtherContradictionTest() throws In } } - //3 in a row, 1 in col creates contradiction + // 3 in a row, 1 in col creates contradiction @Test - public void UnresolvedNumberContradictionRule_RowContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction", skyscrapers); + public void UnresolvedNumberContradictionRule_RowContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1RowContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -90,17 +98,19 @@ public void UnresolvedNumberContradictionRule_RowContradictionTest() throws Inva for (int i = 0; i < board.getHeight(); i++) { if (i == 3) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); } } } - //3 in a col, 1 in row creates contradiction + // 3 in a col, 1 in row creates contradiction @Test - public void UnresolvedNumberContradictionRule_ColContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1ColContradiction", skyscrapers); + public void UnresolvedNumberContradictionRule_ColContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/UnresolvedContradictionRules/3-1ColContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -112,17 +122,19 @@ public void UnresolvedNumberContradictionRule_ColContradictionTest() throws Inva for (int i = 0; i < board.getHeight(); i++) { if (i == 1) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); } } } - //2 in a row/col, 2 in other row/cols creates number contradiction + // 2 in a row/col, 2 in other row/cols creates number contradiction @Test - public void UnresolvedNumberContradictionRule_TwoContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/2-2NumberContradiction", skyscrapers); + public void UnresolvedNumberContradictionRule_TwoContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/UnresolvedContradictionRules/2-2NumberContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -134,17 +146,19 @@ public void UnresolvedNumberContradictionRule_TwoContradictionTest() throws Inva for (int i = 0; i < board.getHeight(); i++) { if (i == 1 || i == 3) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); } } } - //1 in a row/col, 3 in other row/cols creates number contradiction + // 1 in a row/col, 3 in other row/cols creates number contradiction @Test - public void UnresolvedNumberContradictionRule_ThreeContradictionTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/skyscrapers/rules/UnresolvedContradictionRules/1-3NumberContradiction", skyscrapers); + public void UnresolvedNumberContradictionRule_ThreeContradictionTest() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/skyscrapers/rules/UnresolvedContradictionRules/1-3NumberContradiction", + skyscrapers); TreeNode rootNode = skyscrapers.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -156,10 +170,9 @@ public void UnresolvedNumberContradictionRule_ThreeContradictionTest() throws In for (int i = 0; i < board.getHeight(); i++) { if (i == 1 || i == 2) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(i, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(i, i))); } } } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java b/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java index b7ec8eb02..38284c410 100644 --- a/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java @@ -8,14 +8,13 @@ import edu.rpi.legup.puzzle.treetent.TreeTentType; import edu.rpi.legup.puzzle.treetent.rules.EmptyFieldDirectRule; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import legup.MockGameBoardFacade; import legup.TestUtilities; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.awt.*; - public class EmptyFieldDirectRuleTest { private static final EmptyFieldDirectRule RULE = new EmptyFieldDirectRule(); @@ -32,7 +31,8 @@ public static void setUp() { // checks if tiles logically follow the EmptyFieldDirectRule @Test public void EmptyFieldTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/EmptyFieldDirectRule/EmptyField", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/EmptyFieldDirectRule/EmptyField", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -56,8 +56,7 @@ public void EmptyFieldTest() throws InvalidFileFormatException { if (c.getLocation().equals(cell1.getLocation())) { // logically follows Assert.assertNull(RULE.checkRuleAt(transition, c)); - } - else { + } else { // does not use the rule to logically follow Assert.assertNotNull(RULE.checkRuleAt(transition, c)); } @@ -71,7 +70,8 @@ public void EmptyFieldTest() throws InvalidFileFormatException { // checks if tiles logically follow the EmptyFieldDirectRule @Test public void DiagonalTreeTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/EmptyFieldDirectRule/DiagonalTree", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/EmptyFieldDirectRule/DiagonalTree", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -79,7 +79,7 @@ public void DiagonalTreeTest() throws InvalidFileFormatException { // get board state TreeTentBoard board = (TreeTentBoard) transition.getBoard(); - //change the board's cells considering the EmptyField rule + // change the board's cells considering the EmptyField rule TreeTentCell cell1 = board.getCell(1, 1); cell1.setData(TreeTentType.GRASS); board.addModifiedData(cell1); @@ -95,8 +95,7 @@ public void DiagonalTreeTest() throws InvalidFileFormatException { if (c.getLocation().equals(cell1.getLocation())) { // logically follows Assert.assertNull(RULE.checkRuleAt(transition, c)); - } - else { + } else { // does not use the rule to logically follow Assert.assertNotNull(RULE.checkRuleAt(transition, c)); } @@ -110,7 +109,8 @@ public void DiagonalTreeTest() throws InvalidFileFormatException { // checks if tiles don't logically follow the EmptyFieldDirectRule @Test public void EmptyFieldTestFail() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFail", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFail", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -118,7 +118,7 @@ public void EmptyFieldTestFail() throws InvalidFileFormatException { // get board state TreeTentBoard board = (TreeTentBoard) transition.getBoard(); - //change the board's cells considering breaking the EmptyField rule + // change the board's cells considering breaking the EmptyField rule TreeTentCell cell1 = board.getCell(1, 1); cell1.setData(TreeTentType.GRASS); board.addModifiedData(cell1); @@ -143,7 +143,8 @@ public void EmptyFieldTestFail() throws InvalidFileFormatException { // checks if tiles don't logically follow the EmptyFieldDirectRule @Test public void EmptyFieldTestFailTop() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailTop", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailTop", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -151,7 +152,7 @@ public void EmptyFieldTestFailTop() throws InvalidFileFormatException { // get board state TreeTentBoard board = (TreeTentBoard) transition.getBoard(); - //change the board's cells considering breaking the EmptyField rule + // change the board's cells considering breaking the EmptyField rule TreeTentCell cell1 = board.getCell(1, 1); cell1.setData(TreeTentType.GRASS); board.addModifiedData(cell1); @@ -176,7 +177,8 @@ public void EmptyFieldTestFailTop() throws InvalidFileFormatException { // checks if tiles don't logically follow the EmptyFieldDirectRule @Test public void EmptyFieldTestFailTopBottom() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailBottom", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailBottom", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -184,7 +186,7 @@ public void EmptyFieldTestFailTopBottom() throws InvalidFileFormatException { // get board state TreeTentBoard board = (TreeTentBoard) transition.getBoard(); - //change the board's cells considering breaking the EmptyField rule + // change the board's cells considering breaking the EmptyField rule TreeTentCell cell1 = board.getCell(1, 1); cell1.setData(TreeTentType.GRASS); board.addModifiedData(cell1); @@ -209,7 +211,8 @@ public void EmptyFieldTestFailTopBottom() throws InvalidFileFormatException { // checks if tiles don't logically follow the EmptyFieldDirectRule @Test public void EmptyFieldTestFailLeft() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailLeft", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailLeft", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -217,7 +220,7 @@ public void EmptyFieldTestFailLeft() throws InvalidFileFormatException { // get board state TreeTentBoard board = (TreeTentBoard) transition.getBoard(); - //change the board's cells considering breaking the EmptyField rule + // change the board's cells considering breaking the EmptyField rule TreeTentCell cell1 = board.getCell(1, 1); cell1.setData(TreeTentType.GRASS); board.addModifiedData(cell1); @@ -242,7 +245,8 @@ public void EmptyFieldTestFailLeft() throws InvalidFileFormatException { // checks if tiles don't logically follow the EmptyFieldDirectRule @Test public void EmptyFieldTestFailRight() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailRight", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailRight", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -250,7 +254,7 @@ public void EmptyFieldTestFailRight() throws InvalidFileFormatException { // get board state TreeTentBoard board = (TreeTentBoard) transition.getBoard(); - //change the board's cells considering breaking the EmptyField rule + // change the board's cells considering breaking the EmptyField rule TreeTentCell cell1 = board.getCell(1, 1); cell1.setData(TreeTentType.GRASS); board.addModifiedData(cell1); @@ -269,4 +273,3 @@ public void EmptyFieldTestFailRight() throws InvalidFileFormatException { } } } - diff --git a/src/test/java/puzzles/treetent/rules/FinishWithGrassDirectRuleTest.java b/src/test/java/puzzles/treetent/rules/FinishWithGrassDirectRuleTest.java index 2517df563..0783ab8b8 100644 --- a/src/test/java/puzzles/treetent/rules/FinishWithGrassDirectRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/FinishWithGrassDirectRuleTest.java @@ -8,16 +8,15 @@ import edu.rpi.legup.puzzle.treetent.TreeTentType; import edu.rpi.legup.puzzle.treetent.rules.FinishWithGrassDirectRule; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; +import java.util.ArrayList; +import java.util.List; import legup.MockGameBoardFacade; import legup.TestUtilities; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.awt.*; -import java.util.List; -import java.util.ArrayList; - public class FinishWithGrassDirectRuleTest { private static final FinishWithGrassDirectRule RULE = new FinishWithGrassDirectRule(); @@ -30,15 +29,15 @@ public static void setUp() { } /** - * 3x3 TreeTent puzzle with a tent at (0,0) - * Tests FinishWithGrassDirectRule on GRASS tiles horizontal of the tent - * at (1,0) and (2,0) - * + * 3x3 TreeTent puzzle with a tent at (0,0) Tests FinishWithGrassDirectRule on GRASS tiles + * horizontal of the tent at (1,0) and (2,0) + * * @throws InvalidFileFormatException */ @Test public void FinishWithGrassHorizontalTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithGrassDirectRule/CornerTent", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/FinishWithGrassDirectRule/CornerTent", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -63,11 +62,11 @@ public void FinishWithGrassHorizontalTest() throws InvalidFileFormatException { for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { c = board.getCell(k, i); - if (c.getLocation().equals(cell1.getLocation()) || c.getLocation().equals(cell2.getLocation())) { + if (c.getLocation().equals(cell1.getLocation()) + || c.getLocation().equals(cell2.getLocation())) { // logically follows Assert.assertNull(RULE.checkRuleAt(transition, c)); - } - else { + } else { // does not use the rule to logically follow Assert.assertNotNull(RULE.checkRuleAt(transition, c)); } @@ -76,15 +75,15 @@ public void FinishWithGrassHorizontalTest() throws InvalidFileFormatException { } /** - * 3x3 TreeTent puzzle with a tent at (0,0) - * Tests FinishWithGrassDirectRule on GRASS tiles vertical of the tent - * at (0,1) and (0,2) - * + * 3x3 TreeTent puzzle with a tent at (0,0) Tests FinishWithGrassDirectRule on GRASS tiles + * vertical of the tent at (0,1) and (0,2) + * * @throws InvalidFileFormatException */ @Test public void FinishWithGrassVerticalTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithGrassDirectRule/CornerTent", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/FinishWithGrassDirectRule/CornerTent", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -109,11 +108,11 @@ public void FinishWithGrassVerticalTest() throws InvalidFileFormatException { for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { c = board.getCell(k, i); - if (c.getLocation().equals(cell1.getLocation()) || c.getLocation().equals(cell2.getLocation())) { + if (c.getLocation().equals(cell1.getLocation()) + || c.getLocation().equals(cell2.getLocation())) { // logically follows Assert.assertNull(RULE.checkRuleAt(transition, c)); - } - else { + } else { // does not use the rule to logically follow Assert.assertNotNull(RULE.checkRuleAt(transition, c)); } @@ -122,15 +121,15 @@ public void FinishWithGrassVerticalTest() throws InvalidFileFormatException { } /** - * 3x3 TreeTent puzzle with a tent at (0,0) - * Tests FinishWithGrassDirectRule on GRASS tiles - * at (1,0), (2,0), (0,1), and (0,2) - * + * 3x3 TreeTent puzzle with a tent at (0,0) Tests FinishWithGrassDirectRule on GRASS tiles at + * (1,0), (2,0), (0,1), and (0,2) + * * @throws InvalidFileFormatException */ @Test public void FinishWithGrassTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithGrassDirectRule/CornerTent", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/FinishWithGrassDirectRule/CornerTent", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -161,14 +160,13 @@ public void FinishWithGrassTest() throws InvalidFileFormatException { for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { c = board.getCell(k, i); - if (c.getLocation().equals(cell1.getLocation()) || - c.getLocation().equals(cell2.getLocation()) || - c.getLocation().equals(cell3.getLocation()) || - c.getLocation().equals(cell4.getLocation())) { + if (c.getLocation().equals(cell1.getLocation()) + || c.getLocation().equals(cell2.getLocation()) + || c.getLocation().equals(cell3.getLocation()) + || c.getLocation().equals(cell4.getLocation())) { // logically follows Assert.assertNull(RULE.checkRuleAt(transition, c)); - } - else { + } else { // does not use the rule to logically follow Assert.assertNotNull(RULE.checkRuleAt(transition, c)); } @@ -177,15 +175,15 @@ public void FinishWithGrassTest() throws InvalidFileFormatException { } /** - * 3x3 TreeTent puzzle with no tents - * Tests FinishWithGrassDirectRule on GRASS tiles - * GRASS tiles fill entire board - * + * 3x3 TreeTent puzzle with no tents Tests FinishWithGrassDirectRule on GRASS tiles GRASS tiles + * fill entire board + * * @throws InvalidFileFormatException */ @Test public void NoTentTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithGrassDirectRule/NoTent", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/FinishWithGrassDirectRule/NoTent", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -216,16 +214,17 @@ public void NoTentTest() throws InvalidFileFormatException { Assert.assertNull(RULE.checkRuleAt(transition, c)); } } + /** - * 3x3 TreeTent puzzle with a tent at (1,1) - * Tests FinishWithGrassDirectRule on GRASS tiles surrounding the tent - * at (1,0), (0,1), (2,1), and (1,2) - * + * 3x3 TreeTent puzzle with a tent at (1,1) Tests FinishWithGrassDirectRule on GRASS tiles + * surrounding the tent at (1,0), (0,1), (2,1), and (1,2) + * * @throws InvalidFileFormatException */ @Test public void MiddleTentTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithGrassDirectRule/MiddleTent", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/FinishWithGrassDirectRule/MiddleTent", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -257,14 +256,13 @@ public void MiddleTentTest() throws InvalidFileFormatException { for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { c = board.getCell(k, i); - if (c.getLocation().equals(cell1.getLocation()) || - c.getLocation().equals(cell2.getLocation()) || - c.getLocation().equals(cell3.getLocation()) || - c.getLocation().equals(cell4.getLocation())) { + if (c.getLocation().equals(cell1.getLocation()) + || c.getLocation().equals(cell2.getLocation()) + || c.getLocation().equals(cell3.getLocation()) + || c.getLocation().equals(cell4.getLocation())) { // logically follows Assert.assertNull(RULE.checkRuleAt(transition, c)); - } - else { + } else { // does not use the rule to logically follow Assert.assertNotNull(RULE.checkRuleAt(transition, c)); } @@ -273,15 +271,15 @@ public void MiddleTentTest() throws InvalidFileFormatException { } /** - * 3x3 TreeTent puzzle with missing tents - * Tests FinishWithGrassDirectRule on GRASS tiles filling the puzzle - * all GRASS tiles should fail the FinishWithGrassDirectRule - * + * 3x3 TreeTent puzzle with missing tents Tests FinishWithGrassDirectRule on GRASS tiles filling + * the puzzle all GRASS tiles should fail the FinishWithGrassDirectRule + * * @throws InvalidFileFormatException */ @Test public void FailTentTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithGrassDirectRule/FailTent", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/FinishWithGrassDirectRule/FailTent", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -312,16 +310,17 @@ public void FailTentTest() throws InvalidFileFormatException { Assert.assertNotNull(RULE.checkRuleAt(transition, c)); } } + /** - * 7x7 TreeTent puzzle with multiple tents spaced out - * Tests FinishWithGrassDirectRule on GRASS tiles between the tents - * at (0,3), (2,3), (4,3), and (6,3) - * + * 7x7 TreeTent puzzle with multiple tents spaced out Tests FinishWithGrassDirectRule on GRASS + * tiles between the tents at (0,3), (2,3), (4,3), and (6,3) + * * @throws InvalidFileFormatException */ @Test public void SpacedOutTentTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithGrassDirectRule/SpacedOutTent", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/FinishWithGrassDirectRule/SpacedOutTent", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -353,18 +352,17 @@ public void SpacedOutTentTest() throws InvalidFileFormatException { for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { c = board.getCell(k, i); - if (c.getLocation().equals(cell1.getLocation()) || - c.getLocation().equals(cell2.getLocation()) || - c.getLocation().equals(cell3.getLocation()) || - c.getLocation().equals(cell4.getLocation())) { + if (c.getLocation().equals(cell1.getLocation()) + || c.getLocation().equals(cell2.getLocation()) + || c.getLocation().equals(cell3.getLocation()) + || c.getLocation().equals(cell4.getLocation())) { // logically follows Assert.assertNull(RULE.checkRuleAt(transition, c)); - } - else { + } else { // does not use the rule to logically follow Assert.assertNotNull(RULE.checkRuleAt(transition, c)); } } } } -} \ No newline at end of file +} diff --git a/src/test/java/puzzles/treetent/rules/FinishWithTentsDirectRuleTest.java b/src/test/java/puzzles/treetent/rules/FinishWithTentsDirectRuleTest.java index 725c3c9de..652af615f 100644 --- a/src/test/java/puzzles/treetent/rules/FinishWithTentsDirectRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/FinishWithTentsDirectRuleTest.java @@ -8,15 +8,14 @@ import edu.rpi.legup.puzzle.treetent.TreeTentType; import edu.rpi.legup.puzzle.treetent.rules.FinishWithTentsDirectRule; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; +import java.util.*; import legup.MockGameBoardFacade; import legup.TestUtilities; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.awt.*; -import java.util.*; - public class FinishWithTentsDirectRuleTest { private static final FinishWithTentsDirectRule RULE = new FinishWithTentsDirectRule(); @@ -27,17 +26,18 @@ public static void setUp() { MockGameBoardFacade.getInstance(); treetent = new TreeTent(); } - + /** - * 3x3 TreeTent puzzle with a GRASS tile at (0,0) - * Tests FinishWithTentsDirectRule on TENT tiles horizontal of the GRASS tile - * at (1,0) and (2,0) - * + * 3x3 TreeTent puzzle with a GRASS tile at (0,0) Tests FinishWithTentsDirectRule on TENT tiles + * horizontal of the GRASS tile at (1,0) and (2,0) + * * @throws InvalidFileFormatException */ @Test public void FinishWithHorizontalTentsTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithTentsDirectRule/FinishWithHorizontalTents", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/FinishWithTentsDirectRule/FinishWithHorizontalTents", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -57,10 +57,10 @@ public void FinishWithHorizontalTentsTest() throws InvalidFileFormatException { for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { TreeTentCell c = board.getCell(k, i); - if ((c.getLocation()).equals(cell1.getLocation()) || (c.getLocation()).equals(cell2.getLocation())) { + if ((c.getLocation()).equals(cell1.getLocation()) + || (c.getLocation()).equals(cell2.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, c)); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, c)); } } @@ -68,15 +68,16 @@ public void FinishWithHorizontalTentsTest() throws InvalidFileFormatException { } /** - * 3x3 TreeTent puzzle with a GRASS tile at (0,0) - * Tests FinishWithTentsDirectRule on TENT tiles vertical of the GRASS tile - * at (0,1) and (0,2) - * + * 3x3 TreeTent puzzle with a GRASS tile at (0,0) Tests FinishWithTentsDirectRule on TENT tiles + * vertical of the GRASS tile at (0,1) and (0,2) + * * @throws InvalidFileFormatException */ @Test public void FinishWithVerticalTentsTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithTentsDirectRule/FinishWithVerticalTents", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/FinishWithTentsDirectRule/FinishWithVerticalTents", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -96,10 +97,10 @@ public void FinishWithVerticalTentsTest() throws InvalidFileFormatException { for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { TreeTentCell c = board.getCell(k, i); - if ((c.getLocation()).equals(cell1.getLocation()) || (c.getLocation()).equals(cell2.getLocation())) { + if ((c.getLocation()).equals(cell1.getLocation()) + || (c.getLocation()).equals(cell2.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, c)); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, c)); } } @@ -107,15 +108,15 @@ public void FinishWithVerticalTentsTest() throws InvalidFileFormatException { } /** - * 3x3 TreeTent puzzle with a GRASS tile at (1,1) - * Tests FinishWithTentsDirectRule on TENT tiles around the GRASS tile - * at (1,0), (1,2), (0,1), and (2,1) - * + * 3x3 TreeTent puzzle with a GRASS tile at (1,1) Tests FinishWithTentsDirectRule on TENT tiles + * around the GRASS tile at (1,0), (1,2), (0,1), and (2,1) + * * @throws InvalidFileFormatException */ @Test public void FinishWithTentsTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithTentsDirectRule/FinishWithTents", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/FinishWithTentsDirectRule/FinishWithTents", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -126,7 +127,7 @@ public void FinishWithTentsTest() throws InvalidFileFormatException { TreeTentCell cell2 = board.getCell(1, 2); TreeTentCell cell3 = board.getCell(0, 1); TreeTentCell cell4 = board.getCell(2, 1); - + cell1.setData(TreeTentType.TENT); cell2.setData(TreeTentType.TENT); cell3.setData(TreeTentType.TENT); @@ -142,13 +143,12 @@ public void FinishWithTentsTest() throws InvalidFileFormatException { for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { TreeTentCell c = board.getCell(k, i); - if ((c.getLocation()).equals(cell1.getLocation()) || - (c.getLocation()).equals(cell2.getLocation()) || - (c.getLocation()).equals(cell3.getLocation()) || - (c.getLocation()).equals(cell4.getLocation())) { + if ((c.getLocation()).equals(cell1.getLocation()) + || (c.getLocation()).equals(cell2.getLocation()) + || (c.getLocation()).equals(cell3.getLocation()) + || (c.getLocation()).equals(cell4.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, c)); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, c)); } } @@ -156,15 +156,15 @@ public void FinishWithTentsTest() throws InvalidFileFormatException { } /** - * 3x3 TreeTent puzzle with a TENT tile at (1,1) - * Tests FinishWithTentsDirectRule on TENT tiles around the TENT tile - * at (1,0), (1,2), (0,1), and (2,1) - * + * 3x3 TreeTent puzzle with a TENT tile at (1,1) Tests FinishWithTentsDirectRule on TENT tiles + * around the TENT tile at (1,0), (1,2), (0,1), and (2,1) + * * @throws InvalidFileFormatException */ @Test public void AdditionalTentsTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithTentsDirectRule/AdditionalTents", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/FinishWithTentsDirectRule/AdditionalTents", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -191,13 +191,12 @@ public void AdditionalTentsTest() throws InvalidFileFormatException { for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { TreeTentCell c = board.getCell(k, i); - if ((c.getLocation()).equals(cell1.getLocation()) || - (c.getLocation()).equals(cell2.getLocation()) || - (c.getLocation()).equals(cell3.getLocation()) || - (c.getLocation()).equals(cell4.getLocation())) { + if ((c.getLocation()).equals(cell1.getLocation()) + || (c.getLocation()).equals(cell2.getLocation()) + || (c.getLocation()).equals(cell3.getLocation()) + || (c.getLocation()).equals(cell4.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, c)); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, c)); } } @@ -205,16 +204,15 @@ public void AdditionalTentsTest() throws InvalidFileFormatException { } /** - * Empty 3x3 TreeTent puzzle - * Tests FinishWithTentsDirectRule on TENT tiles of entire puzzle - * all TENT tiles should fail FinishWithTentsDirectRule - * as no TENT tiles should be there - * + * Empty 3x3 TreeTent puzzle Tests FinishWithTentsDirectRule on TENT tiles of entire puzzle all + * TENT tiles should fail FinishWithTentsDirectRule as no TENT tiles should be there + * * @throws InvalidFileFormatException */ @Test public void FinishWithTentsFailTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithTentsDirectRule/FinishWithTentsFail", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/FinishWithTentsDirectRule/FinishWithTentsFail", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -242,17 +240,16 @@ public void FinishWithTentsFailTest() throws InvalidFileFormatException { } /** - * 3x3 TreeTent puzzle with a TENT tile at (1,1) - * Tests FinishWithTentsDirectRule on TENT tiles around the TENT tile - * at (1,0), (1,2), (0,1), and (2,1) - * all TENT tiles should fail FinishWithTentsDirectRule - * as there were already sufficient number of TENT tiles - * + * 3x3 TreeTent puzzle with a TENT tile at (1,1) Tests FinishWithTentsDirectRule on TENT tiles + * around the TENT tile at (1,0), (1,2), (0,1), and (2,1) all TENT tiles should fail + * FinishWithTentsDirectRule as there were already sufficient number of TENT tiles + * * @throws InvalidFileFormatException */ @Test public void TooManyTentsTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithTentsDirectRule/TooManyTents", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/FinishWithTentsDirectRule/TooManyTents", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -263,7 +260,7 @@ public void TooManyTentsTest() throws InvalidFileFormatException { for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { - if((k == 1)&&(i == 1)) { + if ((k == 1) && (i == 1)) { continue; } TreeTentCell c = board.getCell(k, i); @@ -283,18 +280,17 @@ public void TooManyTentsTest() throws InvalidFileFormatException { } /** - * 3x3 TreeTent puzzle with a TENT tile at (1,1) - * Tests FinishWithTentsDirectRule on TENT tiles around the TENT tile - * at (1,0), (1,2), (0,1), and (2,1) - * all TENT tiles should fail FinishWithTentsDirectRule - * as there are multiple configurations of the placement - * of the TENT tiles - * + * 3x3 TreeTent puzzle with a TENT tile at (1,1) Tests FinishWithTentsDirectRule on TENT tiles + * around the TENT tile at (1,0), (1,2), (0,1), and (2,1) all TENT tiles should fail + * FinishWithTentsDirectRule as there are multiple configurations of the placement of the TENT + * tiles + * * @throws InvalidFileFormatException */ @Test - public void AmbiguousTentsTest () throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithTentsDirectRule/AmbiguousTents", treetent); + public void AmbiguousTentsTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/treetent/rules/FinishWithTentsDirectRule/AmbiguousTents", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -309,7 +305,7 @@ public void AmbiguousTentsTest () throws InvalidFileFormatException { for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { - Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -323,7 +319,7 @@ public void AmbiguousTentsTest () throws InvalidFileFormatException { for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { - Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -337,7 +333,7 @@ public void AmbiguousTentsTest () throws InvalidFileFormatException { for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { - Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -351,11 +347,8 @@ public void AmbiguousTentsTest () throws InvalidFileFormatException { for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { - Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - - - diff --git a/src/test/java/puzzles/treetent/rules/LastCampingSpotDirectRuleTest.java b/src/test/java/puzzles/treetent/rules/LastCampingSpotDirectRuleTest.java index 3e1b390fb..92d6e4a59 100644 --- a/src/test/java/puzzles/treetent/rules/LastCampingSpotDirectRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/LastCampingSpotDirectRuleTest.java @@ -8,14 +8,13 @@ import edu.rpi.legup.puzzle.treetent.TreeTentType; import edu.rpi.legup.puzzle.treetent.rules.LastCampingSpotDirectRule; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import legup.MockGameBoardFacade; import legup.TestUtilities; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.awt.*; - public class LastCampingSpotDirectRuleTest { private static final LastCampingSpotDirectRule RULE = new LastCampingSpotDirectRule(); @@ -29,12 +28,13 @@ public static void setUp() { /** * @throws InvalidFileFormatException - * - * Checks if a test works for an empty square above a tree which is surrounded on all other sides. + *

Checks if a test works for an empty square above a tree which is surrounded on all + * other sides. */ @Test public void EmptyFieldTest_Up() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotUp", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotUp", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -53,8 +53,7 @@ public void EmptyFieldTest_Up() throws InvalidFileFormatException { Point point = new Point(k, i); if (point.equals(cell1.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -63,12 +62,13 @@ public void EmptyFieldTest_Up() throws InvalidFileFormatException { /** * @throws InvalidFileFormatException - * - * Checks if a test works for an empty square below a tree which is surrounded on all other sides. + *

Checks if a test works for an empty square below a tree which is surrounded on all + * other sides. */ @Test public void EmptyFieldTest_Down() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotDown", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotDown", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -87,8 +87,7 @@ public void EmptyFieldTest_Down() throws InvalidFileFormatException { Point point = new Point(k, i); if (point.equals(cell1.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -97,12 +96,13 @@ public void EmptyFieldTest_Down() throws InvalidFileFormatException { /** * @throws InvalidFileFormatException - * - * Checks if a test works for an empty square to the left of a tree which is surrounded on all other sides. + *

Checks if a test works for an empty square to the left of a tree which is surrounded + * on all other sides. */ @Test public void EmptyFieldTest_Left() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotLeft", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotLeft", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -121,8 +121,7 @@ public void EmptyFieldTest_Left() throws InvalidFileFormatException { Point point = new Point(k, i); if (point.equals(cell1.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -131,12 +130,13 @@ public void EmptyFieldTest_Left() throws InvalidFileFormatException { /** * @throws InvalidFileFormatException - * - * Checks if a test works for an empty square to the right of a tree which is surrounded on all other sides. + *

Checks if a test works for an empty square to the right of a tree which is surrounded + * on all other sides. */ @Test public void EmptyFieldTest_Right() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotRight", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotRight", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -155,14 +155,10 @@ public void EmptyFieldTest_Right() throws InvalidFileFormatException { Point point = new Point(k, i); if (point.equals(cell1.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } } - - - diff --git a/src/test/java/puzzles/treetent/rules/NoTentForTreeContradictionRuleTest.java b/src/test/java/puzzles/treetent/rules/NoTentForTreeContradictionRuleTest.java index 52aea28c0..b17c92486 100644 --- a/src/test/java/puzzles/treetent/rules/NoTentForTreeContradictionRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/NoTentForTreeContradictionRuleTest.java @@ -1,21 +1,17 @@ package puzzles.treetent.rules; -import legup.MockGameBoardFacade; -import legup.TestUtilities; import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - import edu.rpi.legup.puzzle.treetent.TreeTent; import edu.rpi.legup.puzzle.treetent.TreeTentBoard; -import edu.rpi.legup.puzzle.treetent.TreeTentCell; -import edu.rpi.legup.puzzle.treetent.TreeTentType; import edu.rpi.legup.puzzle.treetent.rules.NoTentForTreeContradictionRule; import edu.rpi.legup.save.InvalidFileFormatException; - import java.awt.*; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; public class NoTentForTreeContradictionRuleTest { @@ -29,12 +25,13 @@ public static void setUp() { } /** - * @throws InvalidFileFormatException - * Tests if a tree is next to only grass in a 2x2 grid triggers the contradiction + * @throws InvalidFileFormatException Tests if a tree is next to only grass in a 2x2 grid + * triggers the contradiction */ @Test public void NoTentForTreeContradictionRule_Basic() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/NoTentForTreeContradictionRule/NoTentForTree", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/NoTentForTreeContradictionRule/NoTentForTree", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -49,12 +46,14 @@ public void NoTentForTreeContradictionRule_Basic() throws InvalidFileFormatExcep } /** - * @throws InvalidFileFormatException - * Tests similarly to above, but now with a tent diagonally next to the tree, which should still contradict + * @throws InvalidFileFormatException Tests similarly to above, but now with a tent diagonally + * next to the tree, which should still contradict */ @Test public void NoTentForTreeContradictionRule_Diagonal() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/NoTentForTreeContradictionRule/NoTentForTreeDiagonal", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/NoTentForTreeContradictionRule/NoTentForTreeDiagonal", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -69,12 +68,13 @@ public void NoTentForTreeContradictionRule_Diagonal() throws InvalidFileFormatEx } /** - * @throws InvalidFileFormatException - * Tests that adjacent trees do not allow a pass + * @throws InvalidFileFormatException Tests that adjacent trees do not allow a pass */ @Test public void NoTentForTreeContradictionRule_TwoTrees() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/NoTentForTreeContradictionRule/NoTentForTreeTwoTrees", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/NoTentForTreeContradictionRule/NoTentForTreeTwoTrees", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -89,12 +89,15 @@ public void NoTentForTreeContradictionRule_TwoTrees() throws InvalidFileFormatEx } /** - * @throws InvalidFileFormatException - * Tests similarly to above, but now with a tent diagonally next to two trees, which should still contradict on one. + * @throws InvalidFileFormatException Tests similarly to above, but now with a tent diagonally + * next to two trees, which should still contradict on one. */ @Test - public void NoTentForTreeContradictionRule_TwoTreesDiagonal() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/NoTentForTreeContradictionRule/NoTentForTreeTwoTreesDiagonal", treetent); + public void NoTentForTreeContradictionRule_TwoTreesDiagonal() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/treetent/rules/NoTentForTreeContradictionRule/NoTentForTreeTwoTreesDiagonal", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -108,4 +111,3 @@ public void NoTentForTreeContradictionRule_TwoTreesDiagonal() throws InvalidFile Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 1))); } } - diff --git a/src/test/java/puzzles/treetent/rules/NoTreeForTentContradictionRuleTest.java b/src/test/java/puzzles/treetent/rules/NoTreeForTentContradictionRuleTest.java index 2ad2ac90e..fd6be92de 100644 --- a/src/test/java/puzzles/treetent/rules/NoTreeForTentContradictionRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/NoTreeForTentContradictionRuleTest.java @@ -1,17 +1,16 @@ package puzzles.treetent.rules; -import legup.MockGameBoardFacade; -import legup.TestUtilities; import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - import edu.rpi.legup.puzzle.treetent.TreeTent; import edu.rpi.legup.puzzle.treetent.TreeTentBoard; import edu.rpi.legup.puzzle.treetent.rules.NoTreeForTentContradictionRule; import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; public class NoTreeForTentContradictionRuleTest { @@ -25,12 +24,13 @@ public static void setUp() { } /** - * @throws InvalidFileFormatException - * Tests if, in a 2x2 Grid, a Tent in the NW corner has no adjacent trees + * @throws InvalidFileFormatException Tests if, in a 2x2 Grid, a Tent in the NW corner has no + * adjacent trees */ @Test public void NoTreeForTentContradictionRule_NW() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentNW", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentNW", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -45,12 +45,13 @@ public void NoTreeForTentContradictionRule_NW() throws InvalidFileFormatExceptio } /** - * @throws InvalidFileFormatException - * Tests if, in a 2x2 Grid, a Tent in the NE corner has no adjacent trees + * @throws InvalidFileFormatException Tests if, in a 2x2 Grid, a Tent in the NE corner has no + * adjacent trees */ @Test public void NoTreeForTentContradictionRule_NE() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentNE", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentNE", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -65,12 +66,13 @@ public void NoTreeForTentContradictionRule_NE() throws InvalidFileFormatExceptio } /** - * @throws InvalidFileFormatException - * Tests if, in a 2x2 Grid, a Tent in the NW corner has no adjacent trees + * @throws InvalidFileFormatException Tests if, in a 2x2 Grid, a Tent in the NW corner has no + * adjacent trees */ @Test public void NoTreeForTentContradictionRule_SW() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentSW", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentSW", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -85,12 +87,13 @@ public void NoTreeForTentContradictionRule_SW() throws InvalidFileFormatExceptio } /** - * @throws InvalidFileFormatException - * Tests if, in a 2x2 Grid, a Tent in the SE corner has no adjacent trees + * @throws InvalidFileFormatException Tests if, in a 2x2 Grid, a Tent in the SE corner has no + * adjacent trees */ @Test public void NoTreeForTentContradictionRule_SE() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentSE", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentSE", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -105,12 +108,13 @@ public void NoTreeForTentContradictionRule_SE() throws InvalidFileFormatExceptio } /** - * @throws InvalidFileFormatException - * Tests if, in a 3x3 Grid with no trees, a Tent in the center cell has no adjacent trees + * @throws InvalidFileFormatException Tests if, in a 3x3 Grid with no trees, a Tent in the + * center cell has no adjacent trees */ @Test - public void NoTreeForTentContradictionRule_3x3() throws InvalidFileFormatException{ - TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTent3x3", treetent); + public void NoTreeForTentContradictionRule_3x3() throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTent3x3", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -130,12 +134,15 @@ public void NoTreeForTentContradictionRule_3x3() throws InvalidFileFormatExcepti } /** - * @throws InvalidFileFormatException - * Tests if, in a 3x3 Grid with diagonal trees, a Tent in the center cell has no adjacent trees + * @throws InvalidFileFormatException Tests if, in a 3x3 Grid with diagonal trees, a Tent in the + * center cell has no adjacent trees */ @Test - public void NoTreeForTentContradictionRule_3x3WithDiagonalTrees() throws InvalidFileFormatException{ - TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentDiagonals", treetent); + public void NoTreeForTentContradictionRule_3x3WithDiagonalTrees() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentDiagonals", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -155,12 +162,14 @@ public void NoTreeForTentContradictionRule_3x3WithDiagonalTrees() throws Invalid } /** - * @throws InvalidFileFormatException - * Tests if, in a 3x3 Grid with an adjacent tree, test does not assert null. + * @throws InvalidFileFormatException Tests if, in a 3x3 Grid with an adjacent tree, test does + * not assert null. */ @Test - public void NoTreeForTentContradictionRule_YesTree() throws InvalidFileFormatException{ - TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentYesTree", treetent); + public void NoTreeForTentContradictionRule_YesTree() throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentYesTree", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -180,12 +189,14 @@ public void NoTreeForTentContradictionRule_YesTree() throws InvalidFileFormatExc } /** - * @throws InvalidFileFormatException - * Tests if, in a 3x3 Grid with touching tents, a Tent in the center cell has no adjacent trees + * @throws InvalidFileFormatException Tests if, in a 3x3 Grid with touching tents, a Tent in the + * center cell has no adjacent trees */ @Test - public void NoTreeForTentContradictionRule_JustTent() throws InvalidFileFormatException{ - TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentJustTent", treetent); + public void NoTreeForTentContradictionRule_JustTent() throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentJustTent", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -204,4 +215,3 @@ public void NoTreeForTentContradictionRule_JustTent() throws InvalidFileFormatEx Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 2))); } } - diff --git a/src/test/java/puzzles/treetent/rules/SurroundTentWithGrassDirectRuleTest.java b/src/test/java/puzzles/treetent/rules/SurroundTentWithGrassDirectRuleTest.java index 999405747..7ff57a052 100644 --- a/src/test/java/puzzles/treetent/rules/SurroundTentWithGrassDirectRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/SurroundTentWithGrassDirectRuleTest.java @@ -8,17 +8,17 @@ import edu.rpi.legup.puzzle.treetent.TreeTentType; import edu.rpi.legup.puzzle.treetent.rules.SurroundTentWithGrassDirectRule; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; import legup.MockGameBoardFacade; import legup.TestUtilities; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.awt.*; - public class SurroundTentWithGrassDirectRuleTest { - private static final SurroundTentWithGrassDirectRule RULE = new SurroundTentWithGrassDirectRule(); + private static final SurroundTentWithGrassDirectRule RULE = + new SurroundTentWithGrassDirectRule(); private static TreeTent treetent; @BeforeClass @@ -28,12 +28,14 @@ public static void setUp() { } /** - * @throws InvalidFileFormatException - * Test to check if all adjacent and diagonals not filled with a tree are filled with grass + * @throws InvalidFileFormatException Test to check if all adjacent and diagonals not filled + * with a tree are filled with grass */ @Test public void SurroundTentWithGrassBasicRuleTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/SurroundTentWithGrassDirectRule/SurroundTentWithGrass", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/SurroundTentWithGrassDirectRule/SurroundTentWithGrass", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -55,8 +57,7 @@ public void SurroundTentWithGrassBasicRuleTest() throws InvalidFileFormatExcepti Point point = new Point(k, i); if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -65,13 +66,15 @@ public void SurroundTentWithGrassBasicRuleTest() throws InvalidFileFormatExcepti /** * @throws InvalidFileFormatException - * - * Test with a 3x3 board with an absolutely empty area aside from a tent in the middle - * While such a situation is an illegal treetent setup, this direct rule doesn't consider that aspect, so its ok in this context + *

Test with a 3x3 board with an absolutely empty area aside from a tent in the middle + * While such a situation is an illegal treetent setup, this direct rule doesn't consider + * that aspect, so its ok in this context */ @Test public void SurroundTentWithGrassBasicRuleTest_BadBoard() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/SurroundTentWithGrassDirectRule/SurroundTentWithGrassBad", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/SurroundTentWithGrassDirectRule/SurroundTentWithGrassBad", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -86,7 +89,7 @@ public void SurroundTentWithGrassBasicRuleTest_BadBoard() throws InvalidFileForm cell3.setData(TreeTentType.GRASS); TreeTentCell cell4 = board.getCell(0, 1); cell4.setData(TreeTentType.GRASS); - //Skip (1,1) due to being the Tent + // Skip (1,1) due to being the Tent TreeTentCell cell5 = board.getCell(2, 1); cell5.setData(TreeTentType.GRASS); TreeTentCell cell6 = board.getCell(0, 2); @@ -99,7 +102,7 @@ public void SurroundTentWithGrassBasicRuleTest_BadBoard() throws InvalidFileForm board.addModifiedData(cell1); board.addModifiedData(cell2); board.addModifiedData(cell3); - //board.addModifiedData(cell4); + // board.addModifiedData(cell4); board.addModifiedData(cell5); board.addModifiedData(cell6); board.addModifiedData(cell7); @@ -110,14 +113,16 @@ public void SurroundTentWithGrassBasicRuleTest_BadBoard() throws InvalidFileForm for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { Point point = new Point(k, i); - if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || - point.equals(cell3.getLocation()) || //point.equals(cell4.getLocation()) || - point.equals(cell5.getLocation()) || point.equals(cell6.getLocation()) || - point.equals(cell7.getLocation()) || point.equals(cell8.getLocation()) - ) { + if (point.equals(cell1.getLocation()) + || point.equals(cell2.getLocation()) + || point.equals(cell3.getLocation()) + || // point.equals(cell4.getLocation()) || + point.equals(cell5.getLocation()) + || point.equals(cell6.getLocation()) + || point.equals(cell7.getLocation()) + || point.equals(cell8.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -126,12 +131,14 @@ public void SurroundTentWithGrassBasicRuleTest_BadBoard() throws InvalidFileForm /** * @throws InvalidFileFormatException - * - * Test to see if the rule passes even if no grass was able to be placed due to the presence of trees. + *

Test to see if the rule passes even if no grass was able to be placed due to the + * presence of trees. */ @Test - public void SurroundTentWithGrassBasicRuleTest_FullBoard() throws InvalidFileFormatException{ - TestUtilities.importTestBoard("puzzles/treetent/rules/SurroundTentWithGrassDirectRule/SurroundTentWithGrassTrees", treetent); + public void SurroundTentWithGrassBasicRuleTest_FullBoard() throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/treetent/rules/SurroundTentWithGrassDirectRule/SurroundTentWithGrassTrees", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -140,13 +147,10 @@ public void SurroundTentWithGrassBasicRuleTest_FullBoard() throws InvalidFileFor Assert.assertNull(RULE.checkRule(transition)); - for (int i = 0; i < board.getHeight(); i++){ - for (int k = 0; k < board.getWidth(); k++){ + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } - - - diff --git a/src/test/java/puzzles/treetent/rules/TentForTreeDirectRuleTest.java b/src/test/java/puzzles/treetent/rules/TentForTreeDirectRuleTest.java index 33f37910c..68dbeaf48 100644 --- a/src/test/java/puzzles/treetent/rules/TentForTreeDirectRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/TentForTreeDirectRuleTest.java @@ -3,15 +3,12 @@ // This feature is no longer supported public class TentForTreeDirectRuleTest { -// private static final TentForTreeBasicRule RULE = new TentForTreeBasicRule(); -// private static TreeTent treetent; -// -// @BeforeClass -// public static void setUp() { -// MockGameBoardFacade.getInstance(); -// treetent = new TreeTent(); -// } + // private static final TentForTreeBasicRule RULE = new TentForTreeBasicRule(); + // private static TreeTent treetent; + // + // @BeforeClass + // public static void setUp() { + // MockGameBoardFacade.getInstance(); + // treetent = new TreeTent(); + // } } - - - diff --git a/src/test/java/puzzles/treetent/rules/TentOrGrassCaseRuleTest.java b/src/test/java/puzzles/treetent/rules/TentOrGrassCaseRuleTest.java index 4ec8b4e36..1fe7e4bd0 100644 --- a/src/test/java/puzzles/treetent/rules/TentOrGrassCaseRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/TentOrGrassCaseRuleTest.java @@ -9,19 +9,18 @@ import edu.rpi.legup.puzzle.treetent.TreeTentType; import edu.rpi.legup.puzzle.treetent.rules.TentOrGrassCaseRule; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; +import java.util.ArrayList; import legup.MockGameBoardFacade; import legup.TestUtilities; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.awt.*; -import java.util.ArrayList; - public class TentOrGrassCaseRuleTest { private static final TentOrGrassCaseRule RULE = new TentOrGrassCaseRule(); private static TreeTent treetent; - + @BeforeClass public static void setUp() { MockGameBoardFacade.getInstance(); @@ -29,20 +28,17 @@ public static void setUp() { } /** - * empty 3x3 TreeTent puzzle - * Tests TentOrGrassCaseRule on UNKOWN tile - * at (0,0) - * - * checks 2 cases are created - * checks first case is TENT tile - * checks second case is GRASS tile + * empty 3x3 TreeTent puzzle Tests TentOrGrassCaseRule on UNKOWN tile at (0,0) + * + *

checks 2 cases are created checks first case is TENT tile checks second case is GRASS tile * checks other cells have not been modified - * + * * @throws InvalidFileFormatException */ @Test public void TentOrTreeTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/TentOrGrassCaseRule/TestPuzzle", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TentOrGrassCaseRule/TestPuzzle", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -66,9 +62,9 @@ public void TentOrTreeTest() throws InvalidFileFormatException { TreeTentCell original_cell; TreeTentCell case_cell; - for (int w =0; w < board.getWidth(); w++) { + for (int w = 0; w < board.getWidth(); w++) { for (int h = 0; h < board.getHeight(); h++) { - if (w == 0 && h ==0) { + if (w == 0 && h == 0) { continue; } original_cell = board.getCell(w, h); diff --git a/src/test/java/puzzles/treetent/rules/TooFewTentsContradictionRuleTest.java b/src/test/java/puzzles/treetent/rules/TooFewTentsContradictionRuleTest.java index a5999dc6e..e1773827d 100644 --- a/src/test/java/puzzles/treetent/rules/TooFewTentsContradictionRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/TooFewTentsContradictionRuleTest.java @@ -1,20 +1,18 @@ package puzzles.treetent.rules; -import edu.rpi.legup.puzzle.treetent.TreeTentCell; -import legup.MockGameBoardFacade; -import legup.TestUtilities; import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - import edu.rpi.legup.puzzle.treetent.TreeTent; import edu.rpi.legup.puzzle.treetent.TreeTentBoard; +import edu.rpi.legup.puzzle.treetent.TreeTentCell; import edu.rpi.legup.puzzle.treetent.rules.TooFewTentsContradictionRule; import edu.rpi.legup.save.InvalidFileFormatException; - import java.awt.*; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; public class TooFewTentsContradictionRuleTest { @@ -28,12 +26,13 @@ public static void setUp() { } /** - * @throws InvalidFileFormatException - * Using a 1x1 Puzzle Grid, which is just grass, checks if the fact it expects a tent on the y-axis is caught. + * @throws InvalidFileFormatException Using a 1x1 Puzzle Grid, which is just grass, checks if + * the fact it expects a tent on the y-axis is caught. */ @Test public void TooFewTentsContradictionRule_JustY() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsJustY", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsJustY", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -44,13 +43,15 @@ public void TooFewTentsContradictionRule_JustY() throws InvalidFileFormatExcepti } /** - * @throws InvalidFileFormatException - * Using a 1x1 Puzzle Grid, which is just a tent, checks if the fact it expects 2 tents on the y-axis is caught. - * (This is an impossible situation given the constraints, but for the purposes of the test it is fine) + * @throws InvalidFileFormatException Using a 1x1 Puzzle Grid, which is just a tent, checks if + * the fact it expects 2 tents on the y-axis is caught. (This is an impossible situation + * given the constraints, but for the purposes of the test it is fine) */ @Test public void TooFewTentsContradictionRule_WithTent() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsWithTent", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsWithTent", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -61,12 +62,14 @@ public void TooFewTentsContradictionRule_WithTent() throws InvalidFileFormatExce } /** - * @throws InvalidFileFormatException - * Using a 1x1 Puzzle Grid, which is just grass, checks if the fact it expects a tent on both x and y is caught. + * @throws InvalidFileFormatException Using a 1x1 Puzzle Grid, which is just grass, checks if + * the fact it expects a tent on both x and y is caught. */ @Test public void TooFewTentsContradictionRule_DoubleBad() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsDoubleBad", treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsDoubleBad", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -77,15 +80,14 @@ public void TooFewTentsContradictionRule_DoubleBad() throws InvalidFileFormatExc } /** - * @throws InvalidFileFormatException - * Looks at a 2x2 Board in the format: - * [] Tr - * [] Gr - * Column 2 is checked to have 1 Tent (which is not present, thus producing a contradiction) + * @throws InvalidFileFormatException Looks at a 2x2 Board in the format: [] Tr [] Gr Column 2 + * is checked to have 1 Tent (which is not present, thus producing a contradiction) */ @Test public void TooFewTentsContradictionRule_2x2ColumnOnly() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents2x2Column",treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents2x2Column", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -94,16 +96,15 @@ public void TooFewTentsContradictionRule_2x2ColumnOnly() throws InvalidFileForma Assert.assertNull(RULE.checkContradiction(board)); - TreeTentCell cell1 = board.getCell(1,0); - TreeTentCell cell2 = board.getCell(1,1); + TreeTentCell cell1 = board.getCell(1, 0); + TreeTentCell cell2 = board.getCell(1, 1); for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { Point point = new Point(k, i); if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -111,15 +112,13 @@ public void TooFewTentsContradictionRule_2x2ColumnOnly() throws InvalidFileForma } /** - * @throws InvalidFileFormatException - * Looks at a 2x2 Board in the format: - * Tr Gr - * [] [] - * Row 1 is checked to have 1 Tent (which is not present, thus producing a contradiction) + * @throws InvalidFileFormatException Looks at a 2x2 Board in the format: Tr Gr [] [] Row 1 is + * checked to have 1 Tent (which is not present, thus producing a contradiction) */ @Test public void TooFewTentsContradictionRule_2x2RowOnly() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents2x2Row",treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents2x2Row", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -128,16 +127,15 @@ public void TooFewTentsContradictionRule_2x2RowOnly() throws InvalidFileFormatEx Assert.assertNull(RULE.checkContradiction(board)); - TreeTentCell cell1 = board.getCell(0,0); - TreeTentCell cell2 = board.getCell(1,0); + TreeTentCell cell1 = board.getCell(0, 0); + TreeTentCell cell2 = board.getCell(1, 0); for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { Point point = new Point(k, i); if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -145,16 +143,15 @@ public void TooFewTentsContradictionRule_2x2RowOnly() throws InvalidFileFormatEx } /** - * @throws InvalidFileFormatException - * Looks at a 3x3 Board in the format: - * [] Tr [] - * [] Gr [] - * [] Gr [] - * Column 2 is checked to have 1 Tent (which is not present, thus producing a contradiction) + * @throws InvalidFileFormatException Looks at a 3x3 Board in the format: [] Tr [] [] Gr [] [] + * Gr [] Column 2 is checked to have 1 Tent (which is not present, thus producing a + * contradiction) */ @Test public void TooFewTentsContradictionRule_3x3OneColumn() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents3x3Column",treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents3x3Column", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -163,17 +160,18 @@ public void TooFewTentsContradictionRule_3x3OneColumn() throws InvalidFileFormat Assert.assertNull(RULE.checkContradiction(board)); - TreeTentCell cell1 = board.getCell(1,0); - TreeTentCell cell2 = board.getCell(1,1); - TreeTentCell cell3 = board.getCell(1,2); + TreeTentCell cell1 = board.getCell(1, 0); + TreeTentCell cell2 = board.getCell(1, 1); + TreeTentCell cell3 = board.getCell(1, 2); for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { Point point = new Point(k, i); - if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || point.equals(cell3.getLocation())) { + if (point.equals(cell1.getLocation()) + || point.equals(cell2.getLocation()) + || point.equals(cell3.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -181,16 +179,15 @@ public void TooFewTentsContradictionRule_3x3OneColumn() throws InvalidFileFormat } /** - * @throws InvalidFileFormatException - * Looks at a 3x3 Board in the format: - * Gr Tr Gr - * Gr [] Gr - * Gr Tr Gr - * Column 1 and 3 are checked to have 1 Tent (which is not present, thus producing a contradiction) + * @throws InvalidFileFormatException Looks at a 3x3 Board in the format: Gr Tr Gr Gr [] Gr Gr + * Tr Gr Column 1 and 3 are checked to have 1 Tent (which is not present, thus producing a + * contradiction) */ @Test public void TooFewTentsContradictionRule_3x3TwoColumn() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents3x3DoubleColumn",treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents3x3DoubleColumn", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -199,21 +196,24 @@ public void TooFewTentsContradictionRule_3x3TwoColumn() throws InvalidFileFormat Assert.assertNull(RULE.checkContradiction(board)); - TreeTentCell cell1 = board.getCell(0,0); - TreeTentCell cell2 = board.getCell(0,1); - TreeTentCell cell3 = board.getCell(0,2); - TreeTentCell cell4 = board.getCell(2,0); - TreeTentCell cell5 = board.getCell(2,1); - TreeTentCell cell6 = board.getCell(2,2); + TreeTentCell cell1 = board.getCell(0, 0); + TreeTentCell cell2 = board.getCell(0, 1); + TreeTentCell cell3 = board.getCell(0, 2); + TreeTentCell cell4 = board.getCell(2, 0); + TreeTentCell cell5 = board.getCell(2, 1); + TreeTentCell cell6 = board.getCell(2, 2); for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { Point point = new Point(k, i); - if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || point.equals(cell3.getLocation()) || - point.equals(cell4.getLocation()) || point.equals(cell5.getLocation()) || point.equals(cell6.getLocation())) { + if (point.equals(cell1.getLocation()) + || point.equals(cell2.getLocation()) + || point.equals(cell3.getLocation()) + || point.equals(cell4.getLocation()) + || point.equals(cell5.getLocation()) + || point.equals(cell6.getLocation())) { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -221,15 +221,14 @@ public void TooFewTentsContradictionRule_3x3TwoColumn() throws InvalidFileFormat } /** - * @throws InvalidFileFormatException - * Looks at a 2x2 Board in the format: - * Tn [] - * Tr [] - * This should fail the contradiction as it is a legal board. + * @throws InvalidFileFormatException Looks at a 2x2 Board in the format: Tn [] Tr [] This + * should fail the contradiction as it is a legal board. */ @Test public void TooFewTentsContradictionRule_NoContradiction() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsNoContradiction",treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsNoContradiction", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -244,8 +243,4 @@ public void TooFewTentsContradictionRule_NoContradiction() throws InvalidFileFor } } } - - - } - diff --git a/src/test/java/puzzles/treetent/rules/TooManyTentsContradictionRuleTest.java b/src/test/java/puzzles/treetent/rules/TooManyTentsContradictionRuleTest.java index 2a351556b..2e542b3d2 100644 --- a/src/test/java/puzzles/treetent/rules/TooManyTentsContradictionRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/TooManyTentsContradictionRuleTest.java @@ -1,21 +1,18 @@ package puzzles.treetent.rules; -import legup.MockGameBoardFacade; -import legup.TestUtilities; import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - import edu.rpi.legup.puzzle.treetent.TreeTent; import edu.rpi.legup.puzzle.treetent.TreeTentBoard; import edu.rpi.legup.puzzle.treetent.TreeTentCell; -import edu.rpi.legup.puzzle.treetent.TreeTentType; import edu.rpi.legup.puzzle.treetent.rules.TooManyTentsContradictionRule; import edu.rpi.legup.save.InvalidFileFormatException; - import java.awt.*; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; public class TooManyTentsContradictionRuleTest { @@ -37,21 +34,21 @@ There are tents at (0,1) and (2,2) */ /** - * @throws InvalidFileFormatException - * Tests for TooManyTents if: - * Row Tent Counts: 0,0,0 - * Column Tent Counts: 0,0,0 + * @throws InvalidFileFormatException Tests for TooManyTents if: Row Tent Counts: 0,0,0 Column + * Tent Counts: 0,0,0 */ @Test - public void TooManyTentsContradictionRule_TotalFail() throws InvalidFileFormatException{ - TestUtilities.importTestBoard("puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTotalFail",treetent); + public void TooManyTentsContradictionRule_TotalFail() throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTotalFail", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); TreeTentBoard board = (TreeTentBoard) transition.getBoard(); - TreeTentCell cell1 = board.getCell(0,1); + TreeTentCell cell1 = board.getCell(0, 1); Assert.assertNull(RULE.checkContradiction(board)); @@ -60,8 +57,7 @@ public void TooManyTentsContradictionRule_TotalFail() throws InvalidFileFormatEx Point point = new Point(k, i); if (point.equals(cell1.getLocation())) { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -69,22 +65,22 @@ public void TooManyTentsContradictionRule_TotalFail() throws InvalidFileFormatEx } /** - * @throws InvalidFileFormatException - * Tests for TooManyTents if: - * Row Tent Counts: 1,0,0 - * Column Tent Counts: 0,0,0 + * @throws InvalidFileFormatException Tests for TooManyTents if: Row Tent Counts: 1,0,0 Column + * Tent Counts: 0,0,0 */ @Test - public void TooManyTentsContradictionRule_TopRight() throws InvalidFileFormatException{ - TestUtilities.importTestBoard("puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTopRight",treetent); + public void TooManyTentsContradictionRule_TopRight() throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTopRight", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); TreeTentBoard board = (TreeTentBoard) transition.getBoard(); - TreeTentCell cell1 = board.getCell(0,0); - TreeTentCell cell2 = board.getCell(0,1); + TreeTentCell cell1 = board.getCell(0, 0); + TreeTentCell cell2 = board.getCell(0, 1); Assert.assertNull(RULE.checkContradiction(board)); @@ -93,8 +89,7 @@ public void TooManyTentsContradictionRule_TopRight() throws InvalidFileFormatExc Point point = new Point(k, i); if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -102,22 +97,22 @@ public void TooManyTentsContradictionRule_TopRight() throws InvalidFileFormatExc } /** - * @throws InvalidFileFormatException - * Tests for TooManyTests if: - * Row Tent Counts: 0,0,1 - * Column Tent Counts: 0,0,0 + * @throws InvalidFileFormatException Tests for TooManyTests if: Row Tent Counts: 0,0,1 Column + * Tent Counts: 0,0,0 */ @Test - public void TooManyTentsContradictionRule_BottomRight() throws InvalidFileFormatException{ - TestUtilities.importTestBoard("puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomRight",treetent); + public void TooManyTentsContradictionRule_BottomRight() throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomRight", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); TreeTentBoard board = (TreeTentBoard) transition.getBoard(); - TreeTentCell cell1 = board.getCell(0,1); - TreeTentCell cell2 = board.getCell(0,2); + TreeTentCell cell1 = board.getCell(0, 1); + TreeTentCell cell2 = board.getCell(0, 2); Assert.assertNull(RULE.checkContradiction(board)); @@ -126,8 +121,7 @@ public void TooManyTentsContradictionRule_BottomRight() throws InvalidFileFormat Point point = new Point(k, i); if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -135,22 +129,22 @@ public void TooManyTentsContradictionRule_BottomRight() throws InvalidFileFormat } /** - * @throws InvalidFileFormatException - * Tests for TooManyTents if: - * Row Tent Counts: 0,0,0 - * Column Tent Counts: 0,1,0 + * @throws InvalidFileFormatException Tests for TooManyTents if: Row Tent Counts: 0,0,0 Column + * Tent Counts: 0,1,0 */ @Test - public void TooManyTentsContradictionRule_TopDown() throws InvalidFileFormatException{ - TestUtilities.importTestBoard("puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTopDown",treetent); + public void TooManyTentsContradictionRule_TopDown() throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTopDown", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); TreeTentBoard board = (TreeTentBoard) transition.getBoard(); - TreeTentCell cell1 = board.getCell(0,1); - TreeTentCell cell2 = board.getCell(1,1); + TreeTentCell cell1 = board.getCell(0, 1); + TreeTentCell cell2 = board.getCell(1, 1); Assert.assertNull(RULE.checkContradiction(board)); @@ -159,8 +153,7 @@ public void TooManyTentsContradictionRule_TopDown() throws InvalidFileFormatExce Point point = new Point(k, i); if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -168,22 +161,22 @@ public void TooManyTentsContradictionRule_TopDown() throws InvalidFileFormatExce } /** - * @throws InvalidFileFormatException - * Tests for TooManyTents if: - * Row Tent Counts: 0,0,0 - * Column Tent Counts: 0,0,1 + * @throws InvalidFileFormatException Tests for TooManyTents if: Row Tent Counts: 0,0,0 Column + * Tent Counts: 0,0,1 */ @Test - public void TooManyTentsContradictionRule_BottomDown() throws InvalidFileFormatException{ - TestUtilities.importTestBoard("puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomDown",treetent); + public void TooManyTentsContradictionRule_BottomDown() throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomDown", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); TreeTentBoard board = (TreeTentBoard) transition.getBoard(); - TreeTentCell cell1 = board.getCell(0,1); - TreeTentCell cell2 = board.getCell(2,1); + TreeTentCell cell1 = board.getCell(0, 1); + TreeTentCell cell2 = board.getCell(2, 1); Assert.assertNull(RULE.checkContradiction(board)); @@ -192,8 +185,7 @@ public void TooManyTentsContradictionRule_BottomDown() throws InvalidFileFormatE Point point = new Point(k, i); if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -201,35 +193,36 @@ public void TooManyTentsContradictionRule_BottomDown() throws InvalidFileFormatE } /** - * @throws InvalidFileFormatException - * Tests for TooManyTents if the Top Tent is completely accounted for, but not the bottom - * Row Tent Counts: 1,0,0 - * Column Tent Counts: 0,1,0 + * @throws InvalidFileFormatException Tests for TooManyTents if the Top Tent is completely + * accounted for, but not the bottom Row Tent Counts: 1,0,0 Column Tent Counts: 0,1,0 */ @Test - public void TooManyTentsContradictionRule_TopAccount() throws InvalidFileFormatException{ - TestUtilities.importTestBoard("puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTopAccount",treetent); + public void TooManyTentsContradictionRule_TopAccount() throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTopAccount", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); TreeTentBoard board = (TreeTentBoard) transition.getBoard(); - TreeTentCell cell1 = board.getCell(0,0); - TreeTentCell cell2 = board.getCell(1,0); - TreeTentCell cell3 = board.getCell(0,1); - TreeTentCell cell4 = board.getCell(1,1); + TreeTentCell cell1 = board.getCell(0, 0); + TreeTentCell cell2 = board.getCell(1, 0); + TreeTentCell cell3 = board.getCell(0, 1); + TreeTentCell cell4 = board.getCell(1, 1); Assert.assertNull(RULE.checkContradiction(board)); for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { Point point = new Point(k, i); - if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || - point.equals(cell3.getLocation()) || point.equals(cell4.getLocation())) { + if (point.equals(cell1.getLocation()) + || point.equals(cell2.getLocation()) + || point.equals(cell3.getLocation()) + || point.equals(cell4.getLocation())) { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } @@ -237,39 +230,39 @@ public void TooManyTentsContradictionRule_TopAccount() throws InvalidFileFormatE } /** - * @throws InvalidFileFormatException - * Tests for TooManyTents if the Bottom Tent is completely accounted for, but not the Top - * Row Tent Counts: 0,0,1 - * Column Tent Counts: 0,0,1 + * @throws InvalidFileFormatException Tests for TooManyTents if the Bottom Tent is completely + * accounted for, but not the Top Row Tent Counts: 0,0,1 Column Tent Counts: 0,0,1 */ @Test - public void TooManyTentsContradictionRule_BottomAccount() throws InvalidFileFormatException{ - TestUtilities.importTestBoard("puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomAccount",treetent); + public void TooManyTentsContradictionRule_BottomAccount() throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomAccount", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); TreeTentBoard board = (TreeTentBoard) transition.getBoard(); - TreeTentCell cell1 = board.getCell(0,1); - TreeTentCell cell2 = board.getCell(2,1); - TreeTentCell cell3 = board.getCell(0,2); - TreeTentCell cell4 = board.getCell(2,2); + TreeTentCell cell1 = board.getCell(0, 1); + TreeTentCell cell2 = board.getCell(2, 1); + TreeTentCell cell3 = board.getCell(0, 2); + TreeTentCell cell4 = board.getCell(2, 2); Assert.assertNull(RULE.checkContradiction(board)); for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { Point point = new Point(k, i); - if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || - point.equals(cell3.getLocation()) || point.equals(cell4.getLocation())) { + if (point.equals(cell1.getLocation()) + || point.equals(cell2.getLocation()) + || point.equals(cell3.getLocation()) + || point.equals(cell4.getLocation())) { Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { + } else { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } } } } - diff --git a/src/test/java/puzzles/treetent/rules/TouchingTentsContradictionRuleTest.java b/src/test/java/puzzles/treetent/rules/TouchingTentsContradictionRuleTest.java index f48afe5d7..9f5455a92 100644 --- a/src/test/java/puzzles/treetent/rules/TouchingTentsContradictionRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/TouchingTentsContradictionRuleTest.java @@ -1,17 +1,16 @@ package puzzles.treetent.rules; -import legup.MockGameBoardFacade; -import legup.TestUtilities; import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - import edu.rpi.legup.puzzle.treetent.TreeTent; import edu.rpi.legup.puzzle.treetent.TreeTentBoard; import edu.rpi.legup.puzzle.treetent.rules.TouchingTentsContradictionRule; import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; public class TouchingTentsContradictionRuleTest { @@ -24,15 +23,16 @@ public static void setUp() { treetent = new TreeTent(); } - //DIAGONAL TESTS + // DIAGONAL TESTS /** - * @throws InvalidFileFormatException - * Tests a tent diagonal of orientation T - * T - **/ + * @throws InvalidFileFormatException Tests a tent diagonal of orientation T T + */ @Test - public void TouchingTentsContradictionRule_DiagonalUpLeftToDownRight() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsDiagonal", treetent); + public void TouchingTentsContradictionRule_DiagonalUpLeftToDownRight() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsDiagonal", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -47,13 +47,14 @@ public void TouchingTentsContradictionRule_DiagonalUpLeftToDownRight() throws In } /** - * @throws InvalidFileFormatException - * Tests a tent diagonal of orientation T - * T - **/ + * @throws InvalidFileFormatException Tests a tent diagonal of orientation T T + */ @Test - public void TouchingTentsContradictionRule_DiagonalDownLeftToUpRight() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsDiagonalAlt",treetent); + public void TouchingTentsContradictionRule_DiagonalDownLeftToUpRight() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsDiagonalAlt", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -61,21 +62,22 @@ public void TouchingTentsContradictionRule_DiagonalDownLeftToUpRight() throws In TreeTentBoard board = (TreeTentBoard) transition.getBoard(); Assert.assertNull(RULE.checkContradiction(board)); - Assert.assertNull(RULE.checkRuleAt(transition,board.getCell(1,0))); - Assert.assertNull(RULE.checkRuleAt(transition,board.getCell(0,1))); + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(1, 0))); + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(0, 1))); Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 0))); Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 1))); } - //ADJACENT TESTS + // ADJACENT TESTS /** - * @throws InvalidFileFormatException - * Tests a tent adjacent of orientation T - * T - **/ + * @throws InvalidFileFormatException Tests a tent adjacent of orientation T T + */ @Test - public void TouchingTentsContradictionRule_AdjacentVertical() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsAdjacent", treetent); + public void TouchingTentsContradictionRule_AdjacentVertical() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsAdjacent", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -90,12 +92,14 @@ public void TouchingTentsContradictionRule_AdjacentVertical() throws InvalidFile } /** - * @throws InvalidFileFormatException - * Tests a tent adjacent of orientation TT - **/ + * @throws InvalidFileFormatException Tests a tent adjacent of orientation TT + */ @Test - public void TouchingTentsContradictionRule_AdjacentHorizontal() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsAdjacentAlt", treetent); + public void TouchingTentsContradictionRule_AdjacentHorizontal() + throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsAdjacentAlt", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -108,15 +112,16 @@ public void TouchingTentsContradictionRule_AdjacentHorizontal() throws InvalidFi Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 1))); Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 1))); } - //MIXED TESTS + + // MIXED TESTS /** - * @throws InvalidFileFormatException - * Tests a tent of orientation TT - * TT - **/ + * @throws InvalidFileFormatException Tests a tent of orientation TT TT + */ @Test public void TouchingTentsContradictionRule_2By2Square() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsFull2By2",treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsFull2By2", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -129,14 +134,15 @@ public void TouchingTentsContradictionRule_2By2Square() throws InvalidFileFormat Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(1, 0))); Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(1, 1))); } + /** - * @throws InvalidFileFormatException - * Tests a tent of orientation TT - * T - **/ + * @throws InvalidFileFormatException Tests a tent of orientation TT T + */ @Test public void TouchingTentsContradictionRule_UpLeft() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsMixedUpLeft",treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsMixedUpLeft", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -149,14 +155,15 @@ public void TouchingTentsContradictionRule_UpLeft() throws InvalidFileFormatExce Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(1, 0))); Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 1))); } + /** - * @throws InvalidFileFormatException - * Tests a tent of orientation TT - * T - **/ + * @throws InvalidFileFormatException Tests a tent of orientation TT T + */ @Test public void TouchingTentsContradictionRule_UpRight() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsMixedUpRight",treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsMixedUpRight", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -169,14 +176,15 @@ public void TouchingTentsContradictionRule_UpRight() throws InvalidFileFormatExc Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(1, 1))); Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0))); } + /** - * @throws InvalidFileFormatException - * Tests a tent of orientation T - * TT - **/ + * @throws InvalidFileFormatException Tests a tent of orientation T TT + */ @Test public void TouchingTentsContradictionRule_DownLeft() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsMixedDownLeft",treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsMixedDownLeft", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -189,14 +197,15 @@ public void TouchingTentsContradictionRule_DownLeft() throws InvalidFileFormatEx Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(1, 1))); Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 1))); } + /** - * @throws InvalidFileFormatException - * Tests a tent of orientation T - * TT - **/ + * @throws InvalidFileFormatException Tests a tent of orientation T TT + */ @Test public void TouchingTentsContradictionRule_DownRight() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsMixedDownRight",treetent); + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsMixedDownRight", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -209,13 +218,15 @@ public void TouchingTentsContradictionRule_DownRight() throws InvalidFileFormatE Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(1, 1))); Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 0))); } + /** - * @throws InvalidFileFormatException - * Tests if tree adjacent triggers a null + * @throws InvalidFileFormatException Tests if tree adjacent triggers a null */ @Test - public void TouchingTentsContradictionRule_TreeAdjacent() throws InvalidFileFormatException{ - TestUtilities.importTestBoard("puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsTreeAdjacent",treetent); + public void TouchingTentsContradictionRule_TreeAdjacent() throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsTreeAdjacent", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -226,13 +237,15 @@ public void TouchingTentsContradictionRule_TreeAdjacent() throws InvalidFileForm Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 0))); Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 1))); } + /** - * @throws InvalidFileFormatException - * Tests if tree diagonal triggers a null + * @throws InvalidFileFormatException Tests if tree diagonal triggers a null */ @Test - public void TouchingTentsContradictionRule_TreeDiagonal() throws InvalidFileFormatException{ - TestUtilities.importTestBoard("puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsTreeDiagonal",treetent); + public void TouchingTentsContradictionRule_TreeDiagonal() throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TouchingTentsContradictionRule/TouchingTentsTreeDiagonal", + treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -243,7 +256,4 @@ public void TouchingTentsContradictionRule_TreeDiagonal() throws InvalidFileForm Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 0))); Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0))); } - } - - diff --git a/src/test/java/puzzles/treetent/rules/TreeForTentDirectRuleTest.java b/src/test/java/puzzles/treetent/rules/TreeForTentDirectRuleTest.java index 5b96fcf1c..f4ea6703b 100644 --- a/src/test/java/puzzles/treetent/rules/TreeForTentDirectRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/TreeForTentDirectRuleTest.java @@ -3,15 +3,12 @@ // This feature is no longer supported public class TreeForTentDirectRuleTest { -// private static final TreeForTentBasicRule RULE = new TreeForTentBasicRule(); -// private static TreeTent treetent; - -// @BeforeClass -// public static void setUp() { -// MockGameBoardFacade.getInstance(); -// treetent = new TreeTent(); -// } + // private static final TreeForTentBasicRule RULE = new TreeForTentBasicRule(); + // private static TreeTent treetent; + + // @BeforeClass + // public static void setUp() { + // MockGameBoardFacade.getInstance(); + // treetent = new TreeTent(); + // } } - - - From b1e2f9341b5d8398253960456ac8b2a29ad83084 Mon Sep 17 00:00:00 2001 From: Fisher Luba <145061313+FisherLuba@users.noreply.github.com> Date: Wed, 21 Feb 2024 12:51:57 -0500 Subject: [PATCH 09/11] Java21 (#714) * Fixed Short Truth Table case rule bug (#707) * Revert "Bugfix 549 (#682)" This reverts commit 5048ee69d958fdde9b1bb35854c56c9920068346. * Case rule test fix (#705) Co-authored-by: Chase Grajeda <76405306+Chase-Grajeda@users.noreply.github.com> * Rapid fix for STT case rules Case rules broke at some point from legacy code or merge conflict. Provided is a quick fix in CaseRule and CaseRule_Generic * Revert "Revert "Bugfix 549 (#682)"" (#706) This reverts commit e9fe310378721aa4b4fa358aa57ec44f21d086c1. --------- Co-authored-by: Chase-Grajeda Co-authored-by: Chase Grajeda <76405306+Chase-Grajeda@users.noreply.github.com> * Change Java version to 21 and setup JPackage to bundle Java with the app * Setup gradle action for java 21 * Fix distribution in gradle.yml * Fix java version in tests * Fix java distribution in tests * Add jpackage task * Add Linux to jpackage task * Fix jpackage task * Add java setup to jpackage tasks * Separate build into separate tasks for different operating systems * Fix mac jpackage not working and changed names of artifacts * Potential macos installer build fix * Potential macos installer build fix attempt 2 * Potential macos installer build fix attempt 3 * Add quotes around executable name for macos installer * Add logo and shortcut prompt * Update version in build.gradle * Make installer name different to app (It's a weird way to do it, it renames the file in a gradle task). * Update java-autoformat.yml Added check to make sure the pull request is not from a fork --------- Co-authored-by: Charles Tian <46334090+charlestian23@users.noreply.github.com> Co-authored-by: Chase-Grajeda Co-authored-by: Chase Grajeda <76405306+Chase-Grajeda@users.noreply.github.com> Co-authored-by: charlestian23 --- .github/workflows/gradle.yml | 62 +++- .github/workflows/java-autoformat.yml | 1 + .github/workflows/run-tests.yml | 14 +- .idea/codeStyles/codeStyleConfig.xml | 1 + build.gradle | 40 ++- gradle/wrapper/gradle-wrapper.jar | Bin 56172 -> 43462 bytes gradle/wrapper/gradle-wrapper.properties | 6 +- gradlew | 301 +++++++++++------- gradlew.bat | 56 ++-- .../edu/rpi/legup/images/Legup/logo.ico | Bin 0 -> 2174 bytes 10 files changed, 327 insertions(+), 154 deletions(-) create mode 100644 src/main/resources/edu/rpi/legup/images/Legup/logo.ico diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index ec895971f..856fcd8f0 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -8,30 +8,82 @@ on: pull_request: jobs: - build: + build-ubuntu: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Set up JDK 11 + - name: Set up JDK 21 uses: actions/setup-java@v1 with: - java-version: 11 + java-version: 21 + distribution: temurin - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle run: ./gradlew build -x test + - name: JPackage + run: ./gradlew copyInstaller + - uses: actions/upload-artifact@v4 + with: + name: Ubuntu-Artifact + path: installer + + build-windows: + + runs-on: windows-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 21 + uses: actions/setup-java@v1 + with: + java-version: 21 + distribution: temurin + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build with Gradle + run: ./gradlew build -x test + - name: JPackage + run: ./gradlew copyInstaller + - uses: actions/upload-artifact@v4 + with: + name: Windows-Artifact + path: installer + + build-macos: + + runs-on: macos-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 21 + uses: actions/setup-java@v1 + with: + java-version: 21 + distribution: temurin + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build with Gradle + run: ./gradlew build -x test + - name: JPackage + run: ./gradlew copyInstaller + - uses: actions/upload-artifact@v4 + with: + name: Mac Artifact + path: installer checkstyle: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Set up JDK 11 + - name: Set up JDK 21 uses: actions/setup-java@v1 with: - java-version: 11 + java-version: 21 + distribution: temurin - name: gradlew executable run: chmod +x gradlew - name: Run checkstyle diff --git a/.github/workflows/java-autoformat.yml b/.github/workflows/java-autoformat.yml index 5afb1f7a1..0a2f42112 100644 --- a/.github/workflows/java-autoformat.yml +++ b/.github/workflows/java-autoformat.yml @@ -3,6 +3,7 @@ on: pull_request jobs: format: + if: github.event.pull_request.head.repo.full_name == github.repository runs-on: ubuntu-latest steps: - name: Checkout code diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index bed9d7ad2..03092ecdf 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -18,10 +18,11 @@ jobs: - name: Check Out Code uses: actions/checkout@v2 - - name: Set up JDK 11 + - name: Set up JDK 21 uses: actions/setup-java@v1 with: - java-version: 11 + java-version: 21 + distribution: temurin - name: Grant execute permission for gradlew run: chmod +x gradlew @@ -40,10 +41,11 @@ jobs: - name: Check Out Code uses: actions/checkout@v2 - - name: Set up JDK 11 + - name: Set up JDK 21 uses: actions/setup-java@v1 with: - java-version: 11 + java-version: 21 + distribution: temurin - name: Grant execute permission for gradlew run: chmod +x gradlew @@ -65,8 +67,8 @@ jobs: - name: Set up JDK and Gradle on Windows uses: actions/setup-java@v2 with: - java-version: 11 - distribution: 'adopt' + java-version: 21 + distribution: temurin - name: Run JUnit Tests on Windows run: | diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml index f23d52492..38a6942c4 100644 --- a/.idea/codeStyles/codeStyleConfig.xml +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -1,5 +1,6 @@ + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 49829e473..445a7f8ea 100644 --- a/build.gradle +++ b/build.gradle @@ -5,8 +5,7 @@ plugins { id 'com.diffplug.spotless' version '6.25.0' } - -version '2.0.0' +version '5.3.2' apply plugin: 'java' apply plugin: 'application' @@ -41,7 +40,7 @@ apply plugin: 'checkstyle' mainClassName = 'edu.rpi.legup.Legup' -sourceCompatibility = 11 +sourceCompatibility = 21 dependencies { implementation 'org.jetbrains:annotations:20.1.0' @@ -113,7 +112,7 @@ createExe() { bundledJrePath = 'jre' bundledJre64Bit = true jdkPreference = 'preferJre' - jreMinVersion = '11' + jreMinVersion = '21' jreRuntimeBits = '64/32' } @@ -138,4 +137,35 @@ task buildNativeWindows(type: Exec, dependsOn: 'createExe') { repositories { mavenCentral() } -targetCompatibility = JavaVersion.VERSION_11 +targetCompatibility = JavaVersion.VERSION_21 + +tasks.register("jpackage") { + group("jpackage") + doLast { + var operatingSystem = System.getProperty("os.name").toLowerCase() + if (operatingSystem.contains("windows")) { + exec { + commandLine 'cmd', '/c', 'jpackage', '--input', 'build/libs', '--main-jar', 'Legup.jar', '--win-dir-chooser', '--win-shortcut-prompt', '--win-shortcut', '--dest', 'build/installer', '-n', "LEGUP", '--app-version', "${project.version}", '--icon', "src/main/resources/edu/rpi/legup/images/Legup/logo.ico" + } + } else if (operatingSystem.contains("linux")) { + exec { + commandLine 'sh', '-c', "jpackage --input build/libs --main-jar Legup.jar --dest build/installer -n LEGUP --icon src/main/resources/edu/rpi/legup/images/Legup/logo.ico --app-version ${project.version}" + } + } else if (operatingSystem.contains("mac")) { + exec { + commandLine 'bash', '-c', "jpackage --input build/libs --main-jar Legup.jar --dest build/installer -n \"LEGUP\" --icon src/main/resources/edu/rpi/legup/images/Legup/logo.ico --app-version ${project.version}" + } + } else { + println("JPackage task is not set up for " + System.getProperty("os.name")) + } + } +} + +tasks.register('copyInstaller', Sync) { + group("jpackage") + from ("build/installer/") + into("installer") + rename("LEGUP-${project.version}", "LEGUP-installer-${project.version}") +} + +copyInstaller.dependsOn(jpackage) \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 28861d273a5d270fd8f65dd74570c17c9c507736..d64cd4917707c1f8861d8cb53dd15194d4248596 100644 GIT binary patch literal 43462 zcma&NWl&^owk(X(xVyW%ySuwf;qI=D6|RlDJ2cR^yEKh!@I- zp9QeisK*rlxC>+~7Dk4IxIRsKBHqdR9b3+fyL=ynHmIDe&|>O*VlvO+%z5;9Z$|DJ zb4dO}-R=MKr^6EKJiOrJdLnCJn>np?~vU-1sSFgPu;pthGwf}bG z(1db%xwr#x)r+`4AGu$j7~u2MpVs3VpLp|mx&;>`0p0vH6kF+D2CY0fVdQOZ@h;A` z{infNyvmFUiu*XG}RNMNwXrbec_*a3N=2zJ|Wh5z* z5rAX$JJR{#zP>KY**>xHTuw?|-Rg|o24V)74HcfVT;WtQHXlE+_4iPE8QE#DUm%x0 zEKr75ur~W%w#-My3Tj`hH6EuEW+8K-^5P62$7Sc5OK+22qj&Pd1;)1#4tKihi=~8C zHiQSst0cpri6%OeaR`PY>HH_;CPaRNty%WTm4{wDK8V6gCZlG@U3$~JQZ;HPvDJcT1V{ z?>H@13MJcCNe#5z+MecYNi@VT5|&UiN1D4ATT+%M+h4c$t;C#UAs3O_q=GxK0}8%8 z8J(_M9bayxN}69ex4dzM_P3oh@ZGREjVvn%%r7=xjkqxJP4kj}5tlf;QosR=%4L5y zWhgejO=vao5oX%mOHbhJ8V+SG&K5dABn6!WiKl{|oPkq(9z8l&Mm%(=qGcFzI=eLu zWc_oCLyf;hVlB@dnwY98?75B20=n$>u3b|NB28H0u-6Rpl((%KWEBOfElVWJx+5yg z#SGqwza7f}$z;n~g%4HDU{;V{gXIhft*q2=4zSezGK~nBgu9-Q*rZ#2f=Q}i2|qOp z!!y4p)4o=LVUNhlkp#JL{tfkhXNbB=Ox>M=n6soptJw-IDI|_$is2w}(XY>a=H52d z3zE$tjPUhWWS+5h=KVH&uqQS=$v3nRs&p$%11b%5qtF}S2#Pc`IiyBIF4%A!;AVoI zXU8-Rpv!DQNcF~(qQnyyMy=-AN~U>#&X1j5BLDP{?K!%h!;hfJI>$mdLSvktEr*89 zdJHvby^$xEX0^l9g$xW-d?J;L0#(`UT~zpL&*cEh$L|HPAu=P8`OQZV!-}l`noSp_ zQ-1$q$R-gDL)?6YaM!=8H=QGW$NT2SeZlb8PKJdc=F-cT@j7Xags+Pr*jPtlHFnf- zh?q<6;)27IdPc^Wdy-mX%2s84C1xZq9Xms+==F4);O`VUASmu3(RlgE#0+#giLh-& zcxm3_e}n4{%|X zJp{G_j+%`j_q5}k{eW&TlP}J2wtZ2^<^E(O)4OQX8FDp6RJq!F{(6eHWSD3=f~(h} zJXCf7=r<16X{pHkm%yzYI_=VDP&9bmI1*)YXZeB}F? z(%QsB5fo*FUZxK$oX~X^69;x~j7ms8xlzpt-T15e9}$4T-pC z6PFg@;B-j|Ywajpe4~bk#S6(fO^|mm1hKOPfA%8-_iGCfICE|=P_~e;Wz6my&)h_~ zkv&_xSAw7AZ%ThYF(4jADW4vg=oEdJGVOs>FqamoL3Np8>?!W#!R-0%2Bg4h?kz5I zKV-rKN2n(vUL%D<4oj@|`eJ>0i#TmYBtYmfla;c!ATW%;xGQ0*TW@PTlGG><@dxUI zg>+3SiGdZ%?5N=8uoLA|$4isK$aJ%i{hECP$bK{J#0W2gQ3YEa zZQ50Stn6hqdfxJ*9#NuSLwKFCUGk@c=(igyVL;;2^wi4o30YXSIb2g_ud$ zgpCr@H0qWtk2hK8Q|&wx)}4+hTYlf;$a4#oUM=V@Cw#!$(nOFFpZ;0lc!qd=c$S}Z zGGI-0jg~S~cgVT=4Vo)b)|4phjStD49*EqC)IPwyeKBLcN;Wu@Aeph;emROAwJ-0< z_#>wVm$)ygH|qyxZaet&(Vf%pVdnvKWJn9`%DAxj3ot;v>S$I}jJ$FLBF*~iZ!ZXE zkvui&p}fI0Y=IDX)mm0@tAd|fEHl~J&K}ZX(Mm3cm1UAuwJ42+AO5@HwYfDH7ipIc zmI;1J;J@+aCNG1M`Btf>YT>~c&3j~Qi@Py5JT6;zjx$cvOQW@3oQ>|}GH?TW-E z1R;q^QFjm5W~7f}c3Ww|awg1BAJ^slEV~Pk`Kd`PS$7;SqJZNj->it4DW2l15}xP6 zoCl$kyEF%yJni0(L!Z&14m!1urXh6Btj_5JYt1{#+H8w?5QI%% zo-$KYWNMJVH?Hh@1n7OSu~QhSswL8x0=$<8QG_zepi_`y_79=nK=_ZP_`Em2UI*tyQoB+r{1QYZCpb?2OrgUw#oRH$?^Tj!Req>XiE#~B|~ z+%HB;=ic+R@px4Ld8mwpY;W^A%8%l8$@B@1m5n`TlKI6bz2mp*^^^1mK$COW$HOfp zUGTz-cN9?BGEp}5A!mDFjaiWa2_J2Iq8qj0mXzk; z66JBKRP{p%wN7XobR0YjhAuW9T1Gw3FDvR5dWJ8ElNYF94eF3ebu+QwKjtvVu4L zI9ip#mQ@4uqVdkl-TUQMb^XBJVLW(-$s;Nq;@5gr4`UfLgF$adIhd?rHOa%D);whv z=;krPp~@I+-Z|r#s3yCH+c1US?dnm+C*)r{m+86sTJusLdNu^sqLrfWed^ndHXH`m zd3#cOe3>w-ga(Dus_^ppG9AC>Iq{y%%CK+Cro_sqLCs{VLuK=dev>OL1dis4(PQ5R zcz)>DjEkfV+MO;~>VUlYF00SgfUo~@(&9$Iy2|G0T9BSP?&T22>K46D zL*~j#yJ?)^*%J3!16f)@Y2Z^kS*BzwfAQ7K96rFRIh>#$*$_Io;z>ux@}G98!fWR@ zGTFxv4r~v)Gsd|pF91*-eaZ3Qw1MH$K^7JhWIdX%o$2kCbvGDXy)a?@8T&1dY4`;L z4Kn+f%SSFWE_rpEpL9bnlmYq`D!6F%di<&Hh=+!VI~j)2mfil03T#jJ_s?}VV0_hp z7T9bWxc>Jm2Z0WMU?`Z$xE74Gu~%s{mW!d4uvKCx@WD+gPUQ zV0vQS(Ig++z=EHN)BR44*EDSWIyT~R4$FcF*VEY*8@l=218Q05D2$|fXKFhRgBIEE zdDFB}1dKkoO^7}{5crKX!p?dZWNz$m>1icsXG2N+((x0OIST9Zo^DW_tytvlwXGpn zs8?pJXjEG;T@qrZi%#h93?FP$!&P4JA(&H61tqQi=opRzNpm zkrG}$^t9&XduK*Qa1?355wd8G2CI6QEh@Ua>AsD;7oRUNLPb76m4HG3K?)wF~IyS3`fXuNM>${?wmB zpVz;?6_(Fiadfd{vUCBM*_kt$+F3J+IojI;9L(gc9n3{sEZyzR9o!_mOwFC#tQ{Q~ zP3-`#uK#tP3Q7~Q;4H|wjZHO8h7e4IuBxl&vz2w~D8)w=Wtg31zpZhz%+kzSzL*dV zwp@{WU4i;hJ7c2f1O;7Mz6qRKeASoIv0_bV=i@NMG*l<#+;INk-^`5w@}Dj~;k=|}qM1vq_P z|GpBGe_IKq|LNy9SJhKOQ$c=5L{Dv|Q_lZl=-ky*BFBJLW9&y_C|!vyM~rQx=!vun z?rZJQB5t}Dctmui5i31C_;_}CEn}_W%>oSXtt>@kE1=JW*4*v4tPp;O6 zmAk{)m!)}34pTWg8{i>($%NQ(Tl;QC@J@FfBoc%Gr&m560^kgSfodAFrIjF}aIw)X zoXZ`@IsMkc8_=w%-7`D6Y4e*CG8k%Ud=GXhsTR50jUnm+R*0A(O3UKFg0`K;qp1bl z7``HN=?39ic_kR|^R^~w-*pa?Vj#7|e9F1iRx{GN2?wK!xR1GW!qa=~pjJb-#u1K8 zeR?Y2i-pt}yJq;SCiVHODIvQJX|ZJaT8nO+(?HXbLefulKKgM^B(UIO1r+S=7;kLJ zcH}1J=Px2jsh3Tec&v8Jcbng8;V-`#*UHt?hB(pmOipKwf3Lz8rG$heEB30Sg*2rx zV<|KN86$soN(I!BwO`1n^^uF2*x&vJ$2d$>+`(romzHP|)K_KkO6Hc>_dwMW-M(#S zK(~SiXT1@fvc#U+?|?PniDRm01)f^#55;nhM|wi?oG>yBsa?~?^xTU|fX-R(sTA+5 zaq}-8Tx7zrOy#3*JLIIVsBmHYLdD}!0NP!+ITW+Thn0)8SS!$@)HXwB3tY!fMxc#1 zMp3H?q3eD?u&Njx4;KQ5G>32+GRp1Ee5qMO0lZjaRRu&{W<&~DoJNGkcYF<5(Ab+J zgO>VhBl{okDPn78<%&e2mR{jwVCz5Og;*Z;;3%VvoGo_;HaGLWYF7q#jDX=Z#Ml`H z858YVV$%J|e<1n`%6Vsvq7GmnAV0wW4$5qQ3uR@1i>tW{xrl|ExywIc?fNgYlA?C5 zh$ezAFb5{rQu6i7BSS5*J-|9DQ{6^BVQ{b*lq`xS@RyrsJN?-t=MTMPY;WYeKBCNg z^2|pN!Q^WPJuuO4!|P@jzt&tY1Y8d%FNK5xK(!@`jO2aEA*4 zkO6b|UVBipci?){-Ke=+1;mGlND8)6+P;8sq}UXw2hn;fc7nM>g}GSMWu&v&fqh

iViYT=fZ(|3Ox^$aWPp4a8h24tD<|8-!aK0lHgL$N7Efw}J zVIB!7=T$U`ao1?upi5V4Et*-lTG0XvExbf!ya{cua==$WJyVG(CmA6Of*8E@DSE%L z`V^$qz&RU$7G5mg;8;=#`@rRG`-uS18$0WPN@!v2d{H2sOqP|!(cQ@ zUHo!d>>yFArLPf1q`uBvY32miqShLT1B@gDL4XoVTK&@owOoD)OIHXrYK-a1d$B{v zF^}8D3Y^g%^cnvScOSJR5QNH+BI%d|;J;wWM3~l>${fb8DNPg)wrf|GBP8p%LNGN# z3EaIiItgwtGgT&iYCFy9-LG}bMI|4LdmmJt@V@% zb6B)1kc=T)(|L@0;wr<>=?r04N;E&ef+7C^`wPWtyQe(*pD1pI_&XHy|0gIGHMekd zF_*M4yi6J&Z4LQj65)S zXwdM{SwUo%3SbPwFsHgqF@V|6afT|R6?&S;lw=8% z3}@9B=#JI3@B*#4s!O))~z zc>2_4Q_#&+5V`GFd?88^;c1i7;Vv_I*qt!_Yx*n=;rj!82rrR2rQ8u5(Ejlo{15P% zs~!{%XJ>FmJ})H^I9bn^Re&38H{xA!0l3^89k(oU;bZWXM@kn$#aoS&Y4l^-WEn-fH39Jb9lA%s*WsKJQl?n9B7_~P z-XM&WL7Z!PcoF6_D>V@$CvUIEy=+Z&0kt{szMk=f1|M+r*a43^$$B^MidrT0J;RI` z(?f!O<8UZkm$_Ny$Hth1J#^4ni+im8M9mr&k|3cIgwvjAgjH z8`N&h25xV#v*d$qBX5jkI|xOhQn!>IYZK7l5#^P4M&twe9&Ey@@GxYMxBZq2e7?`q z$~Szs0!g{2fGcp9PZEt|rdQ6bhAgpcLHPz?f-vB?$dc*!9OL?Q8mn7->bFD2Si60* z!O%y)fCdMSV|lkF9w%x~J*A&srMyYY3{=&$}H zGQ4VG_?$2X(0|vT0{=;W$~icCI{b6W{B!Q8xdGhF|D{25G_5_+%s(46lhvNLkik~R z>nr(&C#5wwOzJZQo9m|U<;&Wk!_#q|V>fsmj1g<6%hB{jGoNUPjgJslld>xmODzGjYc?7JSuA?A_QzjDw5AsRgi@Y|Z0{F{!1=!NES-#*f^s4l0Hu zz468))2IY5dmD9pa*(yT5{EyP^G>@ZWumealS-*WeRcZ}B%gxq{MiJ|RyX-^C1V=0 z@iKdrGi1jTe8Ya^x7yyH$kBNvM4R~`fbPq$BzHum-3Zo8C6=KW@||>zsA8-Y9uV5V z#oq-f5L5}V<&wF4@X@<3^C%ptp6+Ce)~hGl`kwj)bsAjmo_GU^r940Z-|`<)oGnh7 zFF0Tde3>ui?8Yj{sF-Z@)yQd~CGZ*w-6p2U<8}JO-sRsVI5dBji`01W8A&3$?}lxBaC&vn0E$c5tW* zX>5(zzZ=qn&!J~KdsPl;P@bmA-Pr8T*)eh_+Dv5=Ma|XSle6t(k8qcgNyar{*ReQ8 zTXwi=8vr>!3Ywr+BhggHDw8ke==NTQVMCK`$69fhzEFB*4+H9LIvdt-#IbhZvpS}} zO3lz;P?zr0*0$%-Rq_y^k(?I{Mk}h@w}cZpMUp|ucs55bcloL2)($u%mXQw({Wzc~ z;6nu5MkjP)0C(@%6Q_I_vsWrfhl7Zpoxw#WoE~r&GOSCz;_ro6i(^hM>I$8y>`!wW z*U^@?B!MMmb89I}2(hcE4zN2G^kwyWCZp5JG>$Ez7zP~D=J^LMjSM)27_0B_X^C(M z`fFT+%DcKlu?^)FCK>QzSnV%IsXVcUFhFdBP!6~se&xxrIxsvySAWu++IrH;FbcY$ z2DWTvSBRfLwdhr0nMx+URA$j3i7_*6BWv#DXfym?ZRDcX9C?cY9sD3q)uBDR3uWg= z(lUIzB)G$Hr!){>E{s4Dew+tb9kvToZp-1&c?y2wn@Z~(VBhqz`cB;{E4(P3N2*nJ z_>~g@;UF2iG{Kt(<1PyePTKahF8<)pozZ*xH~U-kfoAayCwJViIrnqwqO}7{0pHw$ zs2Kx?s#vQr7XZ264>5RNKSL8|Ty^=PsIx^}QqOOcfpGUU4tRkUc|kc7-!Ae6!+B{o~7nFpm3|G5^=0#Bnm6`V}oSQlrX(u%OWnC zoLPy&Q;1Jui&7ST0~#+}I^&?vcE*t47~Xq#YwvA^6^} z`WkC)$AkNub|t@S!$8CBlwbV~?yp&@9h{D|3z-vJXgzRC5^nYm+PyPcgRzAnEi6Q^gslXYRv4nycsy-SJu?lMps-? zV`U*#WnFsdPLL)Q$AmD|0`UaC4ND07+&UmOu!eHruzV|OUox<+Jl|Mr@6~C`T@P%s zW7sgXLF2SSe9Fl^O(I*{9wsFSYb2l%-;&Pi^dpv!{)C3d0AlNY6!4fgmSgj_wQ*7Am7&$z;Jg&wgR-Ih;lUvWS|KTSg!&s_E9_bXBkZvGiC6bFKDWZxsD$*NZ#_8bl zG1P-#@?OQzED7@jlMJTH@V!6k;W>auvft)}g zhoV{7$q=*;=l{O>Q4a@ ziMjf_u*o^PsO)#BjC%0^h>Xp@;5$p{JSYDt)zbb}s{Kbt!T*I@Pk@X0zds6wsefuU zW$XY%yyRGC94=6mf?x+bbA5CDQ2AgW1T-jVAJbm7K(gp+;v6E0WI#kuACgV$r}6L? zd|Tj?^%^*N&b>Dd{Wr$FS2qI#Ucs1yd4N+RBUQiSZGujH`#I)mG&VKoDh=KKFl4=G z&MagXl6*<)$6P}*Tiebpz5L=oMaPrN+caUXRJ`D?=K9!e0f{@D&cZLKN?iNP@X0aF zE(^pl+;*T5qt?1jRC=5PMgV!XNITRLS_=9{CJExaQj;lt!&pdzpK?8p>%Mb+D z?yO*uSung=-`QQ@yX@Hyd4@CI^r{2oiu`%^bNkz+Nkk!IunjwNC|WcqvX~k=><-I3 zDQdbdb|!v+Iz01$w@aMl!R)koD77Xp;eZwzSl-AT zr@Vu{=xvgfq9akRrrM)}=!=xcs+U1JO}{t(avgz`6RqiiX<|hGG1pmop8k6Q+G_mv zJv|RfDheUp2L3=^C=4aCBMBn0aRCU(DQwX-W(RkRwmLeuJYF<0urcaf(=7)JPg<3P zQs!~G)9CT18o!J4{zX{_e}4eS)U-E)0FAt}wEI(c0%HkxgggW;(1E=>J17_hsH^sP z%lT0LGgbUXHx-K*CI-MCrP66UP0PvGqM$MkeLyqHdbgP|_Cm!7te~b8p+e6sQ_3k| zVcwTh6d83ltdnR>D^)BYQpDKlLk3g0Hdcgz2}%qUs9~~Rie)A-BV1mS&naYai#xcZ z(d{8=-LVpTp}2*y)|gR~;qc7fp26}lPcLZ#=JpYcn3AT9(UIdOyg+d(P5T7D&*P}# zQCYplZO5|7+r19%9e`v^vfSS1sbX1c%=w1;oyruXB%Kl$ACgKQ6=qNWLsc=28xJjg zwvsI5-%SGU|3p>&zXVl^vVtQT3o-#$UT9LI@Npz~6=4!>mc431VRNN8od&Ul^+G_kHC`G=6WVWM z%9eWNyy(FTO|A+@x}Ou3CH)oi;t#7rAxdIXfNFwOj_@Y&TGz6P_sqiB`Q6Lxy|Q{`|fgmRG(k+!#b*M+Z9zFce)f-7;?Km5O=LHV9f9_87; zF7%R2B+$?@sH&&-$@tzaPYkw0;=i|;vWdI|Wl3q_Zu>l;XdIw2FjV=;Mq5t1Q0|f< zs08j54Bp`3RzqE=2enlkZxmX6OF+@|2<)A^RNQpBd6o@OXl+i)zO%D4iGiQNuXd+zIR{_lb96{lc~bxsBveIw6umhShTX+3@ZJ=YHh@ zWY3(d0azg;7oHn>H<>?4@*RQbi>SmM=JrHvIG(~BrvI)#W(EAeO6fS+}mxxcc+X~W6&YVl86W9WFSS}Vz-f9vS?XUDBk)3TcF z8V?$4Q)`uKFq>xT=)Y9mMFVTUk*NIA!0$?RP6Ig0TBmUFrq*Q-Agq~DzxjStQyJ({ zBeZ;o5qUUKg=4Hypm|}>>L=XKsZ!F$yNTDO)jt4H0gdQ5$f|d&bnVCMMXhNh)~mN z@_UV6D7MVlsWz+zM+inZZp&P4fj=tm6fX)SG5H>OsQf_I8c~uGCig$GzuwViK54bcgL;VN|FnyQl>Ed7(@>=8$a_UKIz|V6CeVSd2(P z0Uu>A8A+muM%HLFJQ9UZ5c)BSAv_zH#1f02x?h9C}@pN@6{>UiAp>({Fn(T9Q8B z^`zB;kJ5b`>%dLm+Ol}ty!3;8f1XDSVX0AUe5P#@I+FQ-`$(a;zNgz)4x5hz$Hfbg z!Q(z26wHLXko(1`;(BAOg_wShpX0ixfWq3ponndY+u%1gyX)_h=v1zR#V}#q{au6; z!3K=7fQwnRfg6FXtNQmP>`<;!N137paFS%y?;lb1@BEdbvQHYC{976l`cLqn;b8lp zIDY>~m{gDj(wfnK!lpW6pli)HyLEiUrNc%eXTil|F2s(AY+LW5hkKb>TQ3|Q4S9rr zpDs4uK_co6XPsn_z$LeS{K4jFF`2>U`tbgKdyDne`xmR<@6AA+_hPNKCOR-Zqv;xk zu5!HsBUb^!4uJ7v0RuH-7?l?}b=w5lzzXJ~gZcxRKOovSk@|#V+MuX%Y+=;14i*%{)_gSW9(#4%)AV#3__kac1|qUy!uyP{>?U#5wYNq}y$S9pCc zFc~4mgSC*G~j0u#qqp9 z${>3HV~@->GqEhr_Xwoxq?Hjn#=s2;i~g^&Hn|aDKpA>Oc%HlW(KA1?BXqpxB;Ydx)w;2z^MpjJ(Qi(X!$5RC z*P{~%JGDQqojV>2JbEeCE*OEu!$XJ>bWA9Oa_Hd;y)F%MhBRi*LPcdqR8X`NQ&1L# z5#9L*@qxrx8n}LfeB^J{%-?SU{FCwiWyHp682F+|pa+CQa3ZLzBqN1{)h4d6+vBbV zC#NEbQLC;}me3eeYnOG*nXOJZEU$xLZ1<1Y=7r0(-U0P6-AqwMAM`a(Ed#7vJkn6plb4eI4?2y3yOTGmmDQ!z9`wzbf z_OY#0@5=bnep;MV0X_;;SJJWEf^E6Bd^tVJ9znWx&Ks8t*B>AM@?;D4oWUGc z!H*`6d7Cxo6VuyS4Eye&L1ZRhrRmN6Lr`{NL(wDbif|y&z)JN>Fl5#Wi&mMIr5i;x zBx}3YfF>>8EC(fYnmpu~)CYHuHCyr5*`ECap%t@y=jD>!_%3iiE|LN$mK9>- zHdtpy8fGZtkZF?%TW~29JIAfi2jZT8>OA7=h;8T{{k?c2`nCEx9$r zS+*&vt~2o^^J+}RDG@+9&M^K*z4p{5#IEVbz`1%`m5c2};aGt=V?~vIM}ZdPECDI)47|CWBCfDWUbxBCnmYivQ*0Nu_xb*C>~C9(VjHM zxe<*D<#dQ8TlpMX2c@M<9$w!RP$hpG4cs%AI){jp*Sj|*`m)5(Bw*A0$*i-(CA5#%>a)$+jI2C9r6|(>J8InryENI z$NohnxDUB;wAYDwrb*!N3noBTKPpPN}~09SEL18tkG zxgz(RYU_;DPT{l?Q$+eaZaxnsWCA^ds^0PVRkIM%bOd|G2IEBBiz{&^JtNsODs;5z zICt_Zj8wo^KT$7Bg4H+y!Df#3mbl%%?|EXe!&(Vmac1DJ*y~3+kRKAD=Ovde4^^%~ zw<9av18HLyrf*_>Slp;^i`Uy~`mvBjZ|?Ad63yQa#YK`4+c6;pW4?XIY9G1(Xh9WO8{F-Aju+nS9Vmv=$Ac0ienZ+p9*O%NG zMZKy5?%Z6TAJTE?o5vEr0r>f>hb#2w2U3DL64*au_@P!J!TL`oH2r*{>ffu6|A7tv zL4juf$DZ1MW5ZPsG!5)`k8d8c$J$o;%EIL0va9&GzWvkS%ZsGb#S(?{!UFOZ9<$a| zY|a+5kmD5N&{vRqkgY>aHsBT&`rg|&kezoD)gP0fsNYHsO#TRc_$n6Lf1Z{?+DLziXlHrq4sf(!>O{?Tj;Eh@%)+nRE_2VxbN&&%%caU#JDU%vL3}Cb zsb4AazPI{>8H&d=jUaZDS$-0^AxE@utGs;-Ez_F(qC9T=UZX=>ok2k2 ziTn{K?y~a5reD2A)P${NoI^>JXn>`IeArow(41c-Wm~)wiryEP(OS{YXWi7;%dG9v zI?mwu1MxD{yp_rrk!j^cKM)dc4@p4Ezyo%lRN|XyD}}>v=Xoib0gOcdXrQ^*61HNj z=NP|pd>@yfvr-=m{8$3A8TQGMTE7g=z!%yt`8`Bk-0MMwW~h^++;qyUP!J~ykh1GO z(FZ59xuFR$(WE;F@UUyE@Sp>`aVNjyj=Ty>_Vo}xf`e7`F;j-IgL5`1~-#70$9_=uBMq!2&1l zomRgpD58@)YYfvLtPW}{C5B35R;ZVvB<<#)x%srmc_S=A7F@DW8>QOEGwD6suhwCg z>Pa+YyULhmw%BA*4yjDp|2{!T98~<6Yfd(wo1mQ!KWwq0eg+6)o1>W~f~kL<-S+P@$wx*zeI|1t7z#Sxr5 zt6w+;YblPQNplq4Z#T$GLX#j6yldXAqj>4gAnnWtBICUnA&-dtnlh=t0Ho_vEKwV` z)DlJi#!@nkYV#$!)@>udAU*hF?V`2$Hf=V&6PP_|r#Iv*J$9)pF@X3`k;5})9^o4y z&)~?EjX5yX12O(BsFy-l6}nYeuKkiq`u9145&3Ssg^y{5G3Pse z9w(YVa0)N-fLaBq1`P!_#>SS(8fh_5!f{UrgZ~uEdeMJIz7DzI5!NHHqQtm~#CPij z?=N|J>nPR6_sL7!f4hD_|KH`vf8(Wpnj-(gPWH+ZvID}%?~68SwhPTC3u1_cB`otq z)U?6qo!ZLi5b>*KnYHWW=3F!p%h1;h{L&(Q&{qY6)_qxNfbP6E3yYpW!EO+IW3?@J z);4>g4gnl^8klu7uA>eGF6rIGSynacogr)KUwE_R4E5Xzi*Qir@b-jy55-JPC8c~( zo!W8y9OGZ&`xmc8;=4-U9=h{vCqfCNzYirONmGbRQlR`WWlgnY+1wCXbMz&NT~9*| z6@FrzP!LX&{no2!Ln_3|I==_4`@}V?4a;YZKTdw;vT<+K+z=uWbW(&bXEaWJ^W8Td z-3&1bY^Z*oM<=M}LVt>_j+p=2Iu7pZmbXrhQ_k)ysE9yXKygFNw$5hwDn(M>H+e1&9BM5!|81vd%r%vEm zqxY3?F@fb6O#5UunwgAHR9jp_W2zZ}NGp2%mTW@(hz7$^+a`A?mb8|_G*GNMJ) zjqegXQio=i@AINre&%ofexAr95aop5C+0MZ0m-l=MeO8m3epm7U%vZB8+I+C*iNFM z#T3l`gknX;D$-`2XT^Cg*vrv=RH+P;_dfF++cP?B_msQI4j+lt&rX2)3GaJx%W*Nn zkML%D{z5tpHH=dksQ*gzc|}gzW;lwAbxoR07VNgS*-c3d&8J|;@3t^ zVUz*J*&r7DFRuFVDCJDK8V9NN5hvpgGjwx+5n)qa;YCKe8TKtdnh{I7NU9BCN!0dq zczrBk8pE{{@vJa9ywR@mq*J=v+PG;?fwqlJVhijG!3VmIKs>9T6r7MJpC)m!Tc#>g zMtVsU>wbwFJEfwZ{vB|ZlttNe83)$iz`~#8UJ^r)lJ@HA&G#}W&ZH*;k{=TavpjWE z7hdyLZPf*X%Gm}i`Y{OGeeu^~nB8=`{r#TUrM-`;1cBvEd#d!kPqIgYySYhN-*1;L z^byj%Yi}Gx)Wnkosi337BKs}+5H5dth1JA{Ir-JKN$7zC)*}hqeoD(WfaUDPT>0`- z(6sa0AoIqASwF`>hP}^|)a_j2s^PQn*qVC{Q}htR z5-)duBFXT_V56-+UohKXlq~^6uf!6sA#ttk1o~*QEy_Y-S$gAvq47J9Vtk$5oA$Ct zYhYJ@8{hsC^98${!#Ho?4y5MCa7iGnfz}b9jE~h%EAAv~Qxu)_rAV;^cygV~5r_~?l=B`zObj7S=H=~$W zPtI_m%g$`kL_fVUk9J@>EiBH zOO&jtn~&`hIFMS5S`g8w94R4H40mdNUH4W@@XQk1sr17b{@y|JB*G9z1|CrQjd+GX z6+KyURG3;!*BQrentw{B2R&@2&`2}n(z-2&X7#r!{yg@Soy}cRD~j zj9@UBW+N|4HW4AWapy4wfUI- zZ`gSL6DUlgj*f1hSOGXG0IVH8HxK?o2|3HZ;KW{K+yPAlxtb)NV_2AwJm|E)FRs&& z=c^e7bvUsztY|+f^k7NXs$o1EUq>cR7C0$UKi6IooHWlK_#?IWDkvywnzg&ThWo^? z2O_N{5X39#?eV9l)xI(>@!vSB{DLt*oY!K1R8}_?%+0^C{d9a%N4 zoxHVT1&Lm|uDX%$QrBun5e-F`HJ^T$ zmzv)p@4ZHd_w9!%Hf9UYNvGCw2TTTbrj9pl+T9%-_-}L(tES>Or-}Z4F*{##n3~L~TuxjirGuIY#H7{%$E${?p{Q01 zi6T`n;rbK1yIB9jmQNycD~yZq&mbIsFWHo|ZAChSFPQa<(%d8mGw*V3fh|yFoxOOiWJd(qvVb!Z$b88cg->N=qO*4k~6;R==|9ihg&riu#P~s4Oap9O7f%crSr^rljeIfXDEg>wi)&v*a%7zpz<9w z*r!3q9J|390x`Zk;g$&OeN&ctp)VKRpDSV@kU2Q>jtok($Y-*x8_$2piTxun81@vt z!Vj?COa0fg2RPXMSIo26T=~0d`{oGP*eV+$!0I<(4azk&Vj3SiG=Q!6mX0p$z7I}; z9BJUFgT-K9MQQ-0@Z=^7R<{bn2Fm48endsSs`V7_@%8?Bxkqv>BDoVcj?K#dV#uUP zL1ND~?D-|VGKe3Rw_7-Idpht>H6XRLh*U7epS6byiGvJpr%d}XwfusjH9g;Z98H`x zyde%%5mhGOiL4wljCaWCk-&uE4_OOccb9c!ZaWt4B(wYl!?vyzl%7n~QepN&eFUrw zFIOl9c({``6~QD+43*_tzP{f2x41h(?b43^y6=iwyB)2os5hBE!@YUS5?N_tXd=h( z)WE286Fbd>R4M^P{!G)f;h<3Q>Fipuy+d2q-)!RyTgt;wr$(?9ox3;q+{E*ZQHhOn;lM`cjnu9 zXa48ks-v(~b*;MAI<>YZH(^NV8vjb34beE<_cwKlJoR;k6lJNSP6v}uiyRD?|0w+X@o1ONrH8a$fCxXpf? z?$DL0)7|X}Oc%h^zrMKWc-NS9I0Utu@>*j}b@tJ=ixQSJ={4@854wzW@E>VSL+Y{i z#0b=WpbCZS>kUCO_iQz)LoE>P5LIG-hv9E+oG}DtlIDF>$tJ1aw9^LuhLEHt?BCj& z(O4I8v1s#HUi5A>nIS-JK{v!7dJx)^Yg%XjNmlkWAq2*cv#tHgz`Y(bETc6CuO1VkN^L-L3j_x<4NqYb5rzrLC-7uOv z!5e`GZt%B782C5-fGnn*GhDF$%(qP<74Z}3xx+{$4cYKy2ikxI7B2N+2r07DN;|-T->nU&!=Cm#rZt%O_5c&1Z%nlWq3TKAW0w zQqemZw_ue--2uKQsx+niCUou?HjD`xhEjjQd3%rrBi82crq*~#uA4+>vR<_S{~5ce z-2EIl?~s z1=GVL{NxP1N3%=AOaC}j_Fv=ur&THz zyO!d9kHq|c73kpq`$+t+8Bw7MgeR5~`d7ChYyGCBWSteTB>8WAU(NPYt2Dk`@#+}= zI4SvLlyk#pBgVigEe`?NG*vl7V6m+<}%FwPV=~PvvA)=#ths==DRTDEYh4V5}Cf$z@#;< zyWfLY_5sP$gc3LLl2x+Ii)#b2nhNXJ{R~vk`s5U7Nyu^3yFg&D%Txwj6QezMX`V(x z=C`{76*mNb!qHHs)#GgGZ_7|vkt9izl_&PBrsu@}L`X{95-2jf99K)0=*N)VxBX2q z((vkpP2RneSIiIUEnGb?VqbMb=Zia+rF~+iqslydE34cSLJ&BJW^3knX@M;t*b=EA zNvGzv41Ld_T+WT#XjDB840vovUU^FtN_)G}7v)1lPetgpEK9YS^OWFkPoE{ovj^=@ zO9N$S=G$1ecndT_=5ehth2Lmd1II-PuT~C9`XVePw$y8J#dpZ?Tss<6wtVglm(Ok7 z3?^oi@pPio6l&!z8JY(pJvG=*pI?GIOu}e^EB6QYk$#FJQ%^AIK$I4epJ+9t?KjqA+bkj&PQ*|vLttme+`9G=L% ziadyMw_7-M)hS(3E$QGNCu|o23|%O+VN7;Qggp?PB3K-iSeBa2b}V4_wY`G1Jsfz4 z9|SdB^;|I8E8gWqHKx!vj_@SMY^hLEIbSMCuE?WKq=c2mJK z8LoG-pnY!uhqFv&L?yEuxo{dpMTsmCn)95xanqBrNPTgXP((H$9N${Ow~Is-FBg%h z53;|Y5$MUN)9W2HBe2TD`ct^LHI<(xWrw}$qSoei?}s)&w$;&!14w6B6>Yr6Y8b)S z0r71`WmAvJJ`1h&poLftLUS6Ir zC$bG9!Im_4Zjse)#K=oJM9mHW1{%l8sz$1o?ltdKlLTxWWPB>Vk22czVt|1%^wnN@*!l)}?EgtvhC>vlHm^t+ogpgHI1_$1ox9e;>0!+b(tBrmXRB`PY1vp-R**8N7 zGP|QqI$m(Rdu#=(?!(N}G9QhQ%o!aXE=aN{&wtGP8|_qh+7a_j_sU5|J^)vxq;# zjvzLn%_QPHZZIWu1&mRAj;Sa_97p_lLq_{~j!M9N^1yp3U_SxRqK&JnR%6VI#^E12 z>CdOVI^_9aPK2eZ4h&^{pQs}xsijXgFYRIxJ~N7&BB9jUR1fm!(xl)mvy|3e6-B3j zJn#ajL;bFTYJ2+Q)tDjx=3IklO@Q+FFM}6UJr6km7hj7th9n_&JR7fnqC!hTZoM~T zBeaVFp%)0cbPhejX<8pf5HyRUj2>aXnXBqDJe73~J%P(2C?-RT{c3NjE`)om! zl$uewSgWkE66$Kb34+QZZvRn`fob~Cl9=cRk@Es}KQm=?E~CE%spXaMO6YmrMl%9Q zlA3Q$3|L1QJ4?->UjT&CBd!~ru{Ih^in&JXO=|<6J!&qp zRe*OZ*cj5bHYlz!!~iEKcuE|;U4vN1rk$xq6>bUWD*u(V@8sG^7>kVuo(QL@Ki;yL zWC!FT(q{E8#on>%1iAS0HMZDJg{Z{^!De(vSIq&;1$+b)oRMwA3nc3mdTSG#3uYO_ z>+x;7p4I;uHz?ZB>dA-BKl+t-3IB!jBRgdvAbW!aJ(Q{aT>+iz?91`C-xbe)IBoND z9_Xth{6?(y3rddwY$GD65IT#f3<(0o#`di{sh2gm{dw*#-Vnc3r=4==&PU^hCv$qd zjw;>i&?L*Wq#TxG$mFIUf>eK+170KG;~+o&1;Tom9}}mKo23KwdEM6UonXgc z!6N(@k8q@HPw{O8O!lAyi{rZv|DpgfU{py+j(X_cwpKqcalcqKIr0kM^%Br3SdeD> zHSKV94Yxw;pjzDHo!Q?8^0bb%L|wC;4U^9I#pd5O&eexX+Im{ z?jKnCcsE|H?{uGMqVie_C~w7GX)kYGWAg%-?8|N_1#W-|4F)3YTDC+QSq1s!DnOML3@d`mG%o2YbYd#jww|jD$gotpa)kntakp#K;+yo-_ZF9qrNZw<%#C zuPE@#3RocLgPyiBZ+R_-FJ_$xP!RzWm|aN)S+{$LY9vvN+IW~Kf3TsEIvP+B9Mtm! zpfNNxObWQpLoaO&cJh5>%slZnHl_Q~(-Tfh!DMz(dTWld@LG1VRF`9`DYKhyNv z2pU|UZ$#_yUx_B_|MxUq^glT}O5Xt(Vm4Mr02><%C)@v;vPb@pT$*yzJ4aPc_FZ3z z3}PLoMBIM>q_9U2rl^sGhk1VUJ89=*?7|v`{!Z{6bqFMq(mYiA?%KbsI~JwuqVA9$H5vDE+VocjX+G^%bieqx->s;XWlKcuv(s%y%D5Xbc9+ zc(_2nYS1&^yL*ey664&4`IoOeDIig}y-E~_GS?m;D!xv5-xwz+G`5l6V+}CpeJDi^ z%4ed$qowm88=iYG+(`ld5Uh&>Dgs4uPHSJ^TngXP_V6fPyl~>2bhi20QB%lSd#yYn zO05?KT1z@?^-bqO8Cg`;ft>ilejsw@2%RR7;`$Vs;FmO(Yr3Fp`pHGr@P2hC%QcA|X&N2Dn zYf`MqXdHi%cGR@%y7Rg7?d3?an){s$zA{!H;Ie5exE#c~@NhQUFG8V=SQh%UxUeiV zd7#UcYqD=lk-}sEwlpu&H^T_V0{#G?lZMxL7ih_&{(g)MWBnCZxtXg znr#}>U^6!jA%e}@Gj49LWG@*&t0V>Cxc3?oO7LSG%~)Y5}f7vqUUnQ;STjdDU}P9IF9d9<$;=QaXc zL1^X7>fa^jHBu_}9}J~#-oz3Oq^JmGR#?GO7b9a(=R@fw@}Q{{@`Wy1vIQ#Bw?>@X z-_RGG@wt|%u`XUc%W{J z>iSeiz8C3H7@St3mOr_mU+&bL#Uif;+Xw-aZdNYUpdf>Rvu0i0t6k*}vwU`XNO2he z%miH|1tQ8~ZK!zmL&wa3E;l?!!XzgV#%PMVU!0xrDsNNZUWKlbiOjzH-1Uoxm8E#r`#2Sz;-o&qcqB zC-O_R{QGuynW14@)7&@yw1U}uP(1cov)twxeLus0s|7ayrtT8c#`&2~Fiu2=R;1_4bCaD=*E@cYI>7YSnt)nQc zohw5CsK%m?8Ack)qNx`W0_v$5S}nO|(V|RZKBD+btO?JXe|~^Qqur%@eO~<8-L^9d z=GA3-V14ng9L29~XJ>a5k~xT2152zLhM*@zlp2P5Eu}bywkcqR;ISbas&#T#;HZSf z2m69qTV(V@EkY(1Dk3`}j)JMo%ZVJ*5eB zYOjIisi+igK0#yW*gBGj?@I{~mUOvRFQR^pJbEbzFxTubnrw(Muk%}jI+vXmJ;{Q6 zrSobKD>T%}jV4Ub?L1+MGOD~0Ir%-`iTnWZN^~YPrcP5y3VMAzQ+&en^VzKEb$K!Q z<7Dbg&DNXuow*eD5yMr+#08nF!;%4vGrJI++5HdCFcGLfMW!KS*Oi@=7hFwDG!h2< zPunUEAF+HncQkbfFj&pbzp|MU*~60Z(|Ik%Tn{BXMN!hZOosNIseT?R;A`W?=d?5X zK(FB=9mZusYahp|K-wyb={rOpdn=@;4YI2W0EcbMKyo~-#^?h`BA9~o285%oY zfifCh5Lk$SY@|2A@a!T2V+{^!psQkx4?x0HSV`(w9{l75QxMk!)U52Lbhn{8ol?S) zCKo*7R(z!uk<6*qO=wh!Pul{(qq6g6xW;X68GI_CXp`XwO zxuSgPRAtM8K7}5E#-GM!*ydOOG_{A{)hkCII<|2=ma*71ci_-}VPARm3crFQjLYV! z9zbz82$|l01mv`$WahE2$=fAGWkd^X2kY(J7iz}WGS z@%MyBEO=A?HB9=^?nX`@nh;7;laAjs+fbo!|K^mE!tOB>$2a_O0y-*uaIn8k^6Y zSbuv;5~##*4Y~+y7Z5O*3w4qgI5V^17u*ZeupVGH^nM&$qmAk|anf*>r zWc5CV;-JY-Z@Uq1Irpb^O`L_7AGiqd*YpGUShb==os$uN3yYvb`wm6d=?T*it&pDk zo`vhw)RZX|91^^Wa_ti2zBFyWy4cJu#g)_S6~jT}CC{DJ_kKpT`$oAL%b^!2M;JgT zM3ZNbUB?}kP(*YYvXDIH8^7LUxz5oE%kMhF!rnPqv!GiY0o}NR$OD=ITDo9r%4E>E0Y^R(rS^~XjWyVI6 zMOR5rPXhTp*G*M&X#NTL`Hu*R+u*QNoiOKg4CtNPrjgH>c?Hi4MUG#I917fx**+pJfOo!zFM&*da&G_x)L(`k&TPI*t3e^{crd zX<4I$5nBQ8Ax_lmNRa~E*zS-R0sxkz`|>7q_?*e%7bxqNm3_eRG#1ae3gtV9!fQpY z+!^a38o4ZGy9!J5sylDxZTx$JmG!wg7;>&5H1)>f4dXj;B+@6tMlL=)cLl={jLMxY zbbf1ax3S4>bwB9-$;SN2?+GULu;UA-35;VY*^9Blx)Jwyb$=U!D>HhB&=jSsd^6yw zL)?a|>GxU!W}ocTC(?-%z3!IUhw^uzc`Vz_g>-tv)(XA#JK^)ZnC|l1`@CdX1@|!| z_9gQ)7uOf?cR@KDp97*>6X|;t@Y`k_N@)aH7gY27)COv^P3ya9I{4z~vUjLR9~z1Z z5=G{mVtKH*&$*t0@}-i_v|3B$AHHYale7>E+jP`ClqG%L{u;*ff_h@)al?RuL7tOO z->;I}>%WI{;vbLP3VIQ^iA$4wl6@0sDj|~112Y4OFjMs`13!$JGkp%b&E8QzJw_L5 zOnw9joc0^;O%OpF$Qp)W1HI!$4BaXX84`%@#^dk^hFp^pQ@rx4g(8Xjy#!X%+X5Jd@fs3amGT`}mhq#L97R>OwT5-m|h#yT_-v@(k$q7P*9X~T*3)LTdzP!*B} z+SldbVWrrwQo9wX*%FyK+sRXTa@O?WM^FGWOE?S`R(0P{<6p#f?0NJvnBia?k^fX2 zNQs7K-?EijgHJY}&zsr;qJ<*PCZUd*x|dD=IQPUK_nn)@X4KWtqoJNHkT?ZWL_hF? zS8lp2(q>;RXR|F;1O}EE#}gCrY~#n^O`_I&?&z5~7N;zL0)3Tup`%)oHMK-^r$NT% zbFg|o?b9w(q@)6w5V%si<$!U<#}s#x@0aX-hP>zwS#9*75VXA4K*%gUc>+yzupTDBOKH8WR4V0pM(HrfbQ&eJ79>HdCvE=F z|J>s;;iDLB^3(9}?biKbxf1$lI!*Z%*0&8UUq}wMyPs_hclyQQi4;NUY+x2qy|0J; zhn8;5)4ED1oHwg+VZF|80<4MrL97tGGXc5Sw$wAI#|2*cvQ=jB5+{AjMiDHmhUC*a zlmiZ`LAuAn_}hftXh;`Kq0zblDk8?O-`tnilIh|;3lZp@F_osJUV9`*R29M?7H{Fy z`nfVEIDIWXmU&YW;NjU8)EJpXhxe5t+scf|VXM!^bBlwNh)~7|3?fWwo_~ZFk(22% zTMesYw+LNx3J-_|DM~`v93yXe=jPD{q;li;5PD?Dyk+b? zo21|XpT@)$BM$%F=P9J19Vi&1#{jM3!^Y&fr&_`toi`XB1!n>sbL%U9I5<7!@?t)~ z;&H%z>bAaQ4f$wIzkjH70;<8tpUoxzKrPhn#IQfS%9l5=Iu))^XC<58D!-O z{B+o5R^Z21H0T9JQ5gNJnqh#qH^na|z92=hONIM~@_iuOi|F>jBh-?aA20}Qx~EpDGElELNn~|7WRXRFnw+Wdo`|# zBpU=Cz3z%cUJ0mx_1($X<40XEIYz(`noWeO+x#yb_pwj6)R(__%@_Cf>txOQ74wSJ z0#F3(zWWaR-jMEY$7C*3HJrohc79>MCUu26mfYN)f4M~4gD`}EX4e}A!U}QV8!S47 z6y-U-%+h`1n`*pQuKE%Av0@)+wBZr9mH}@vH@i{v(m-6QK7Ncf17x_D=)32`FOjjo zg|^VPf5c6-!FxN{25dvVh#fog=NNpXz zfB$o+0jbRkHH{!TKhE709f+jI^$3#v1Nmf80w`@7-5$1Iv_`)W^px8P-({xwb;D0y z7LKDAHgX<84?l!I*Dvi2#D@oAE^J|g$3!)x1Ua;_;<@#l1fD}lqU2_tS^6Ht$1Wl} zBESo7o^)9-Tjuz$8YQSGhfs{BQV6zW7dA?0b(Dbt=UnQs&4zHfe_sj{RJ4uS-vQpC zX;Bbsuju4%!o8?&m4UZU@~ZZjeFF6ex2ss5_60_JS_|iNc+R0GIjH1@Z z=rLT9%B|WWgOrR7IiIwr2=T;Ne?30M!@{%Qf8o`!>=s<2CBpCK_TWc(DX51>e^xh8 z&@$^b6CgOd7KXQV&Y4%}_#uN*mbanXq(2=Nj`L7H7*k(6F8s6{FOw@(DzU`4-*77{ zF+dxpv}%mFpYK?>N_2*#Y?oB*qEKB}VoQ@bzm>ptmVS_EC(#}Lxxx730trt0G)#$b zE=wVvtqOct1%*9}U{q<)2?{+0TzZzP0jgf9*)arV)*e!f`|jgT{7_9iS@e)recI#z zbzolURQ+TOzE!ymqvBY7+5NnAbWxvMLsLTwEbFqW=CPyCsmJ}P1^V30|D5E|p3BC5 z)3|qgw@ra7aXb-wsa|l^in~1_fm{7bS9jhVRkYVO#U{qMp z)Wce+|DJ}4<2gp8r0_xfZpMo#{Hl2MfjLcZdRB9(B(A(f;+4s*FxV{1F|4d`*sRNd zp4#@sEY|?^FIJ;tmH{@keZ$P(sLh5IdOk@k^0uB^BWr@pk6mHy$qf&~rI>P*a;h0C{%oA*i!VjWn&D~O#MxN&f@1Po# zKN+ zrGrkSjcr?^R#nGl<#Q722^wbYcgW@{+6CBS<1@%dPA8HC!~a`jTz<`g_l5N1M@9wn9GOAZ>nqNgq!yOCbZ@1z`U_N`Z>}+1HIZxk*5RDc&rd5{3qjRh8QmT$VyS;jK z;AF+r6XnnCp=wQYoG|rT2@8&IvKq*IB_WvS%nt%e{MCFm`&W*#LXc|HrD?nVBo=(8*=Aq?u$sDA_sC_RPDUiQ+wnIJET8vx$&fxkW~kP9qXKt zozR)@xGC!P)CTkjeWvXW5&@2?)qt)jiYWWBU?AUtzAN}{JE1I)dfz~7$;}~BmQF`k zpn11qmObXwRB8&rnEG*#4Xax3XBkKlw(;tb?Np^i+H8m(Wyz9k{~ogba@laiEk;2! zV*QV^6g6(QG%vX5Um#^sT&_e`B1pBW5yVth~xUs#0}nv?~C#l?W+9Lsb_5)!71rirGvY zTIJ$OPOY516Y|_014sNv+Z8cc5t_V=i>lWV=vNu#!58y9Zl&GsMEW#pPYPYGHQ|;vFvd*9eM==$_=vc7xnyz0~ zY}r??$<`wAO?JQk@?RGvkWVJlq2dk9vB(yV^vm{=NVI8dhsX<)O(#nr9YD?I?(VmQ z^r7VfUBn<~p3()8yOBjm$#KWx!5hRW)5Jl7wY@ky9lNM^jaT##8QGVsYeaVywmpv>X|Xj7gWE1Ezai&wVLt3p)k4w~yrskT-!PR!kiyQlaxl(( zXhF%Q9x}1TMt3~u@|#wWm-Vq?ZerK={8@~&@9r5JW}r#45#rWii};t`{5#&3$W)|@ zbAf2yDNe0q}NEUvq_Quq3cTjcw z@H_;$hu&xllCI9CFDLuScEMg|x{S7GdV8<&Mq=ezDnRZAyX-8gv97YTm0bg=d)(>N z+B2FcqvI9>jGtnK%eO%y zoBPkJTk%y`8TLf4)IXPBn`U|9>O~WL2C~C$z~9|0m*YH<-vg2CD^SX#&)B4ngOSG$ zV^wmy_iQk>dfN@Pv(ckfy&#ak@MLC7&Q6Ro#!ezM*VEh`+b3Jt%m(^T&p&WJ2Oqvj zs-4nq0TW6cv~(YI$n0UkfwN}kg3_fp?(ijSV#tR9L0}l2qjc7W?i*q01=St0eZ=4h zyGQbEw`9OEH>NMuIe)hVwYHsGERWOD;JxEiO7cQv%pFCeR+IyhwQ|y@&^24k+|8fD zLiOWFNJ2&vu2&`Jv96_z-Cd5RLgmeY3*4rDOQo?Jm`;I_(+ejsPM03!ly!*Cu}Cco zrQSrEDHNyzT(D5s1rZq!8#?f6@v6dB7a-aWs(Qk>N?UGAo{gytlh$%_IhyL7h?DLXDGx zgxGEBQoCAWo-$LRvM=F5MTle`M})t3vVv;2j0HZY&G z22^iGhV@uaJh(XyyY%} zd4iH_UfdV#T=3n}(Lj^|n;O4|$;xhu*8T3hR1mc_A}fK}jfZ7LX~*n5+`8N2q#rI$ z@<_2VANlYF$vIH$ zl<)+*tIWW78IIINA7Rr7i{<;#^yzxoLNkXL)eSs=%|P>$YQIh+ea_3k z_s7r4%j7%&*NHSl?R4k%1>Z=M9o#zxY!n8sL5>BO-ZP;T3Gut>iLS@U%IBrX6BA3k z)&@q}V8a{X<5B}K5s(c(LQ=%v1ocr`t$EqqY0EqVjr65usa=0bkf|O#ky{j3)WBR(((L^wmyHRzoWuL2~WTC=`yZ zn%VX`L=|Ok0v7?s>IHg?yArBcync5rG#^+u)>a%qjES%dRZoIyA8gQ;StH z1Ao7{<&}6U=5}4v<)1T7t!J_CL%U}CKNs-0xWoTTeqj{5{?Be$L0_tk>M9o8 zo371}S#30rKZFM{`H_(L`EM9DGp+Mifk&IP|C2Zu_)Ghr4Qtpmkm1osCf@%Z$%t+7 zYH$Cr)Ro@3-QDeQJ8m+x6%;?YYT;k6Z0E-?kr>x33`H%*ueBD7Zx~3&HtWn0?2Wt} zTG}*|v?{$ajzt}xPzV%lL1t-URi8*Zn)YljXNGDb>;!905Td|mpa@mHjIH%VIiGx- zd@MqhpYFu4_?y5N4xiHn3vX&|e6r~Xt> zZG`aGq|yTNjv;9E+Txuoa@A(9V7g?1_T5FzRI;!=NP1Kqou1z5?%X~Wwb{trRfd>i z8&y^H)8YnKyA_Fyx>}RNmQIczT?w2J4SNvI{5J&}Wto|8FR(W;Qw#b1G<1%#tmYzQ zQ2mZA-PAdi%RQOhkHy9Ea#TPSw?WxwL@H@cbkZwIq0B!@ns}niALidmn&W?!Vd4Gj zO7FiuV4*6Mr^2xlFSvM;Cp_#r8UaqIzHJQg_z^rEJw&OMm_8NGAY2)rKvki|o1bH~ z$2IbfVeY2L(^*rMRU1lM5Y_sgrDS`Z??nR2lX;zyR=c%UyGb*%TC-Dil?SihkjrQy~TMv6;BMs7P8il`H7DmpVm@rJ;b)hW)BL)GjS154b*xq-NXq2cwE z^;VP7ua2pxvCmxrnqUYQMH%a%nHmwmI33nJM(>4LznvY*k&C0{8f*%?zggpDgkuz&JBx{9mfb@wegEl2v!=}Sq2Gaty0<)UrOT0{MZtZ~j5y&w zXlYa_jY)I_+VA-^#mEox#+G>UgvM!Ac8zI<%JRXM_73Q!#i3O|)lOP*qBeJG#BST0 zqohi)O!|$|2SeJQo(w6w7%*92S})XfnhrH_Z8qe!G5>CglP=nI7JAOW?(Z29;pXJ9 zR9`KzQ=WEhy*)WH>$;7Cdz|>*i>=##0bB)oU0OR>>N<21e4rMCHDemNi2LD>Nc$;& zQRFthpWniC1J6@Zh~iJCoLOxN`oCKD5Q4r%ynwgUKPlIEd#?QViIqovY|czyK8>6B zSP%{2-<;%;1`#0mG^B(8KbtXF;Nf>K#Di72UWE4gQ%(_26Koiad)q$xRL~?pN71ZZ zujaaCx~jXjygw;rI!WB=xrOJO6HJ!!w}7eiivtCg5K|F6$EXa)=xUC za^JXSX98W`7g-tm@uo|BKj39Dl;sg5ta;4qjo^pCh~{-HdLl6qI9Ix6f$+qiZ$}s= zNguKrU;u+T@ko(Vr1>)Q%h$?UKXCY>3se%&;h2osl2D zE4A9bd7_|^njDd)6cI*FupHpE3){4NQ*$k*cOWZ_?CZ>Z4_fl@n(mMnYK62Q1d@+I zr&O))G4hMihgBqRIAJkLdk(p(D~X{-oBUA+If@B}j& zsHbeJ3RzTq96lB7d($h$xTeZ^gP0c{t!Y0c)aQE;$FY2!mACg!GDEMKXFOPI^)nHZ z`aSPJpvV0|bbrzhWWkuPURlDeN%VT8tndV8?d)eN*i4I@u zVKl^6{?}A?P)Fsy?3oi#clf}L18t;TjNI2>eI&(ezDK7RyqFxcv%>?oxUlonv(px) z$vnPzRH`y5A(x!yOIfL0bmgeMQB$H5wenx~!ujQK*nUBW;@Em&6Xv2%s(~H5WcU2R z;%Nw<$tI)a`Ve!>x+qegJnQsN2N7HaKzrFqM>`6R*gvh%O*-%THt zrB$Nk;lE;z{s{r^PPm5qz(&lM{sO*g+W{sK+m3M_z=4=&CC>T`{X}1Vg2PEfSj2x_ zmT*(x;ov%3F?qoEeeM>dUn$a*?SIGyO8m806J1W1o+4HRhc2`9$s6hM#qAm zChQ87b~GEw{ADfs+5}FJ8+|bIlIv(jT$Ap#hSHoXdd9#w<#cA<1Rkq^*EEkknUd4& zoIWIY)sAswy6fSERVm&!SO~#iN$OgOX*{9@_BWFyJTvC%S++ilSfCrO(?u=Dc?CXZ zzCG&0yVR{Z`|ZF0eEApWEo#s9osV>F{uK{QA@BES#&;#KsScf>y zvs?vIbI>VrT<*!;XmQS=bhq%46-aambZ(8KU-wOO2=en~D}MCToB_u;Yz{)1ySrPZ z@=$}EvjTdzTWU7c0ZI6L8=yP+YRD_eMMos}b5vY^S*~VZysrkq<`cK3>>v%uy7jgq z0ilW9KjVDHLv0b<1K_`1IkbTOINs0=m-22c%M~l=^S}%hbli-3?BnNq?b`hx^HX2J zIe6ECljRL0uBWb`%{EA=%!i^4sMcj+U_TaTZRb+~GOk z^ZW!nky0n*Wb*r+Q|9H@ml@Z5gU&W`(z4-j!OzC1wOke`TRAYGZVl$PmQ16{3196( zO*?`--I}Qf(2HIwb2&1FB^!faPA2=sLg(@6P4mN)>Dc3i(B0;@O-y2;lM4akD>@^v z=u>*|!s&9zem70g7zfw9FXl1bpJW(C#5w#uy5!V?Q(U35A~$dR%LDVnq@}kQm13{} zd53q3N(s$Eu{R}k2esbftfjfOITCL;jWa$}(mmm}d(&7JZ6d3%IABCapFFYjdEjdK z&4Edqf$G^MNAtL=uCDRs&Fu@FXRgX{*0<(@c3|PNHa>L%zvxWS={L8%qw`STm+=Rd zA}FLspESSIpE_^41~#5yI2bJ=9`oc;GIL!JuW&7YetZ?0H}$$%8rW@*J37L-~Rsx!)8($nI4 zZhcZ2^=Y+p4YPl%j!nFJA|*M^gc(0o$i3nlphe+~-_m}jVkRN{spFs(o0ajW@f3K{ zDV!#BwL322CET$}Y}^0ixYj2w>&Xh12|R8&yEw|wLDvF!lZ#dOTHM9pK6@Nm-@9Lnng4ZHBgBSrr7KI8YCC9DX5Kg|`HsiwJHg2(7#nS;A{b3tVO?Z% za{m5b3rFV6EpX;=;n#wltDv1LE*|g5pQ+OY&*6qCJZc5oDS6Z6JD#6F)bWxZSF@q% z+1WV;m!lRB!n^PC>RgQCI#D1br_o^#iPk>;K2hB~0^<~)?p}LG%kigm@moD#q3PE+ zA^Qca)(xnqw6x>XFhV6ku9r$E>bWNrVH9fum0?4s?Rn2LG{Vm_+QJHse6xa%nzQ?k zKug4PW~#Gtb;#5+9!QBgyB@q=sk9=$S{4T>wjFICStOM?__fr+Kei1 z3j~xPqW;W@YkiUM;HngG!;>@AITg}vAE`M2Pj9Irl4w1fo4w<|Bu!%rh%a(Ai^Zhi zs92>v5;@Y(Zi#RI*ua*h`d_7;byQSa*v9E{2x$<-_=5Z<7{%)}4XExANcz@rK69T0x3%H<@frW>RA8^swA+^a(FxK| zFl3LD*ImHN=XDUkrRhp6RY5$rQ{bRgSO*(vEHYV)3Mo6Jy3puiLmU&g82p{qr0F?ohmbz)f2r{X2|T2 z$4fdQ=>0BeKbiVM!e-lIIs8wVTuC_m7}y4A_%ikI;Wm5$9j(^Y z(cD%U%k)X>_>9~t8;pGzL6L-fmQO@K; zo&vQzMlgY95;1BSkngY)e{`n0!NfVgf}2mB3t}D9@*N;FQ{HZ3Pb%BK6;5#-O|WI( zb6h@qTLU~AbVW#_6?c!?Dj65Now7*pU{h!1+eCV^KCuPAGs28~3k@ueL5+u|Z-7}t z9|lskE`4B7W8wMs@xJa{#bsCGDFoRSNSnmNYB&U7 zVGKWe%+kFB6kb)e;TyHfqtU6~fRg)f|>=5(N36)0+C z`hv65J<$B}WUc!wFAb^QtY31yNleq4dzmG`1wHTj=c*=hay9iD071Hc?oYoUk|M*_ zU1GihAMBsM@5rUJ(qS?9ZYJ6@{bNqJ`2Mr+5#hKf?doa?F|+^IR!8lq9)wS3tF_9n zW_?hm)G(M+MYb?V9YoX^_mu5h-LP^TL^!Q9Z7|@sO(rg_4+@=PdI)WL(B7`!K^ND- z-uIuVDCVEdH_C@c71YGYT^_Scf_dhB8Z2Xy6vGtBSlYud9vggOqv^L~F{BraSE_t} zIkP+Hp2&nH^-MNEs}^`oMLy11`PQW$T|K(`Bu*(f@)mv1-qY(_YG&J2M2<7k;;RK~ zL{Fqj9yCz8(S{}@c)S!65aF<=&eLI{hAMErCx&>i7OeDN>okvegO87OaG{Jmi<|}D zaT@b|0X{d@OIJ7zvT>r+eTzgLq~|Dpu)Z&db-P4z*`M$UL51lf>FLlq6rfG)%doyp z)3kk_YIM!03eQ8Vu_2fg{+osaEJPtJ-s36R+5_AEG12`NG)IQ#TF9c@$99%0iye+ zUzZ57=m2)$D(5Nx!n)=5Au&O0BBgwxIBaeI(mro$#&UGCr<;C{UjJVAbVi%|+WP(a zL$U@TYCxJ=1{Z~}rnW;7UVb7+ZnzgmrogDxhjLGo>c~MiJAWs&&;AGg@%U?Y^0JhL ze(x6Z74JG6FlOFK(T}SXQfhr}RIFl@QXKnIcXYF)5|V~e-}suHILKT-k|<*~Ij|VF zC;t@=uj=hot~*!C68G8hTA%8SzOfETOXQ|3FSaIEjvBJp(A)7SWUi5!Eu#yWgY+;n zlm<$+UDou*V+246_o#V4kMdto8hF%%Lki#zPh}KYXmMf?hrN0;>Mv%`@{0Qn`Ujp) z=lZe+13>^Q!9zT);H<(#bIeRWz%#*}sgUX9P|9($kexOyKIOc`dLux}c$7It4u|Rl z6SSkY*V~g_B-hMPo_ak>>z@AVQ(_N)VY2kB3IZ0G(iDUYw+2d7W^~(Jq}KY=JnWS( z#rzEa&0uNhJ>QE8iiyz;n2H|SV#Og+wEZv=f2%1ELX!SX-(d3tEj$5$1}70Mp<&eI zCkfbByL7af=qQE@5vDVxx1}FSGt_a1DoE3SDI+G)mBAna)KBG4p8Epxl9QZ4BfdAN zFnF|Y(umr;gRgG6NLQ$?ZWgllEeeq~z^ZS7L?<(~O&$5|y)Al^iMKy}&W+eMm1W z7EMU)u^ke(A1#XCV>CZ71}P}0x)4wtHO8#JRG3MA-6g=`ZM!FcICCZ{IEw8Dm2&LQ z1|r)BUG^0GzI6f946RrBlfB1Vs)~8toZf~7)+G;pv&XiUO(%5bm)pl=p>nV^o*;&T z;}@oZSibzto$arQgfkp|z4Z($P>dTXE{4O=vY0!)kDO* zGF8a4wq#VaFpLfK!iELy@?-SeRrdz%F*}hjKcA*y@mj~VD3!it9lhRhX}5YOaR9$} z3mS%$2Be7{l(+MVx3 z(4?h;P!jnRmX9J9sYN#7i=iyj_5q7n#X(!cdqI2lnr8T$IfOW<_v`eB!d9xY1P=2q&WtOXY=D9QYteP)De?S4}FK6#6Ma z=E*V+#s8>L;8aVroK^6iKo=MH{4yEZ_>N-N z`(|;aOATba1^asjxlILk<4}f~`39dBFlxj>Dw(hMYKPO3EEt1@S`1lxFNM+J@uB7T zZ8WKjz7HF1-5&2=l=fqF-*@>n5J}jIxdDwpT?oKM3s8Nr`x8JnN-kCE?~aM1H!hAE z%%w(3kHfGwMnMmNj(SU(w42OrC-euI>Dsjk&jz3ts}WHqmMpzQ3vZrsXrZ|}+MHA7 z068obeXZTsO*6RS@o3x80E4ok``rV^Y3hr&C1;|ZZ0|*EKO`$lECUYG2gVFtUTw)R z4Um<0ZzlON`zTdvVdL#KFoMFQX*a5wM0Czp%wTtfK4Sjs)P**RW&?lP$(<}q%r68Z zS53Y!d@&~ne9O)A^tNrXHhXBkj~$8j%pT1%%mypa9AW5E&s9)rjF4@O3ytH{0z6riz|@< zB~UPh*wRFg2^7EbQrHf0y?E~dHlkOxof_a?M{LqQ^C!i2dawHTPYUE=X@2(3<=OOxs8qn_(y>pU>u^}3y&df{JarR0@VJn0f+U%UiF=$Wyq zQvnVHESil@d|8&R<%}uidGh7@u^(%?$#|&J$pvFC-n8&A>utA=n3#)yMkz+qnG3wd zP7xCnF|$9Dif@N~L)Vde3hW8W!UY0BgT2v(wzp;tlLmyk2%N|0jfG$%<;A&IVrOI< z!L)o>j>;dFaqA3pL}b-Je(bB@VJ4%!JeX@3x!i{yIeIso^=n?fDX`3bU=eG7sTc%g%ye8$v8P@yKE^XD=NYxTb zbf!Mk=h|otpqjFaA-vs5YOF-*GwWPc7VbaOW&stlANnCN8iftFMMrUdYNJ_Bnn5Vt zxfz@Ah|+4&P;reZxp;MmEI7C|FOv8NKUm8njF7Wb6Gi7DeODLl&G~}G4be&*Hi0Qw z5}77vL0P+7-B%UL@3n1&JPxW^d@vVwp?u#gVcJqY9#@-3X{ok#UfW3<1fb%FT`|)V~ggq z(3AUoUS-;7)^hCjdT0Kf{i}h)mBg4qhtHHBti=~h^n^OTH5U*XMgDLIR@sre`AaB$ zg)IGBET_4??m@cx&c~bA80O7B8CHR7(LX7%HThkeC*@vi{-pL%e)yXp!B2InafbDF zjPXf1mko3h59{lT6EEbxKO1Z5GF71)WwowO6kY|6tjSVSWdQ}NsK2x{>i|MKZK8%Q zfu&_0D;CO-Jg0#YmyfctyJ!mRJp)e#@O0mYdp|8x;G1%OZQ3Q847YWTyy|%^cpA;m zze0(5p{tMu^lDkpe?HynyO?a1$_LJl2L&mpeKu%8YvgRNr=%2z${%WThHG=vrWY@4 zsA`OP#O&)TetZ>s%h!=+CE15lOOls&nvC~$Qz0Ph7tHiP;O$i|eDwpT{cp>+)0-|; zY$|bB+Gbel>5aRN3>c0x)4U=|X+z+{ zn*_p*EQoquRL+=+p;=lm`d71&1NqBz&_ph)MXu(Nv6&XE7(RsS)^MGj5Q?Fwude-(sq zjJ>aOq!7!EN>@(fK7EE#;i_BGvli`5U;r!YA{JRodLBc6-`n8K+Fjgwb%sX;j=qHQ z7&Tr!)!{HXoO<2BQrV9Sw?JRaLXV8HrsNevvnf>Y-6|{T!pYLl7jp$-nEE z#X!4G4L#K0qG_4Z;Cj6=;b|Be$hi4JvMH!-voxqx^@8cXp`B??eFBz2lLD8RRaRGh zn7kUfy!YV~p(R|p7iC1Rdgt$_24i0cd-S8HpG|`@my70g^y`gu%#Tf_L21-k?sRRZHK&at(*ED0P8iw{7?R$9~OF$Ko;Iu5)ur5<->x!m93Eb zFYpIx60s=Wxxw=`$aS-O&dCO_9?b1yKiPCQmSQb>T)963`*U+Ydj5kI(B(B?HNP8r z*bfSBpSu)w(Z3j7HQoRjUG(+d=IaE~tv}y14zHHs|0UcN52fT8V_<@2ep_ee{QgZG zmgp8iv4V{k;~8@I%M3<#B;2R>Ef(Gg_cQM7%}0s*^)SK6!Ym+~P^58*wnwV1BW@eG z4sZLqsUvBbFsr#8u7S1r4teQ;t)Y@jnn_m5jS$CsW1um!p&PqAcc8!zyiXHVta9QC zY~wCwCF0U%xiQPD_INKtTb;A|Zf29(mu9NI;E zc-e>*1%(LSXB`g}kd`#}O;veb<(sk~RWL|f3ljxCnEZDdNSTDV6#Td({6l&y4IjKF z^}lIUq*ZUqgTPumD)RrCN{M^jhY>E~1pn|KOZ5((%F)G|*ZQ|r4zIbrEiV%42hJV8 z3xS)=!X1+=olbdGJ=yZil?oXLct8FM{(6ikLL3E%=q#O6(H$p~gQu6T8N!plf!96| z&Q3=`L~>U0zZh;z(pGR2^S^{#PrPxTRHD1RQOON&f)Siaf`GLj#UOk&(|@0?zm;Sx ztsGt8=29-MZs5CSf1l1jNFtNt5rFNZxJPvkNu~2}7*9468TWm>nN9TP&^!;J{-h)_ z7WsHH9|F%I`Pb!>KAS3jQWKfGivTVkMJLO-HUGM_a4UQ_%RgL6WZvrW+Z4ujZn;y@ zz9$=oO!7qVTaQAA^BhX&ZxS*|5dj803M=k&2%QrXda`-Q#IoZL6E(g+tN!6CA!CP* zCpWtCujIea)ENl0liwVfj)Nc<9mV%+e@=d`haoZ*`B7+PNjEbXBkv=B+Pi^~L#EO$D$ZqTiD8f<5$eyb54-(=3 zh)6i8i|jp(@OnRrY5B8t|LFXFQVQ895n*P16cEKTrT*~yLH6Z4e*bZ5otpRDri&+A zfNbK1D5@O=sm`fN=WzWyse!za5n%^+6dHPGX#8DyIK>?9qyX}2XvBWVqbP%%D)7$= z=#$WulZlZR<{m#gU7lwqK4WS1Ne$#_P{b17qe$~UOXCl>5b|6WVh;5vVnR<%d+Lnp z$uEmML38}U4vaW8>shm6CzB(Wei3s#NAWE3)a2)z@i{4jTn;;aQS)O@l{rUM`J@K& l00vQ5JBs~;vo!vr%%-k{2_Fq1Mn4QF81S)AQ99zk{{c4yR+0b! literal 56172 zcmagFV{~WVwk?_pE4FRhwr$(CRk3Z`c2coz+fFL^#m=jD_df5v|GoR1_hGCxKaAPt z?5)i;2YO!$(jcHHKtMl#0s#RD{xu*V;Q#dm0)qVemK9YIq?MEtqXz*}_=lrH_H#1- zUkBB{_ILXK>nJNICn+YXtU@O%b}u_MDI-lwHxDaKOEoh!+oZ&>#JqQWH$^)pIW0R) zElKkO>LS!6^{7~jvK^hY^r+ZqY@j9c3={bA&gsYhw&342{-2$J{vF#png1V~`v3Ys z|J%ph$+Elc9rysnh>4g@{9znhgvHh#m?Ei1t5E5wf>;ad!DTU)Ipl zPT9rK$;H%(&e+D#**Qi{+kH_C;R|h2%}C_u2qcGqkpzJo9a~9qYH;ZOJi2lcQ=i<|gKQUuNz* zeRzLwpgkbJpG3jTf>&Z%BiYff1YVA8;m#hM;b101PJBP{=|CI8ql`RDKr{(EmI6pI z(@dkm8Zhf7+L4B=+o^=N!x>UdkGSH||FmmB8Bw|!kp6^SHPN~GMb}zF;MN~+$OIZ| z5o#vS_+kVQ1*bGU;T$|^HoJY5vdqvvT{g`jDQM16eiU6^81j~-Sf|#?Ak1Z}F>17^ z@XR5%*Sff%YD*lIU8LK5U@Ef`8&RXp(oTZ;YFuN28BSeTUBb3fQjalWGS<#i%yuEo z%*bAG;X6Mn(h`lVZ;4?Po`dByPNhhz9T|klseNj;QhefEtbe8DE~z?p+EBUA4n}+q z?!P_?3317h!l6@Ki48ZD*0m8Q5rY22X;Yu#5!TNM7>4GWU6)iBPwkEw+SYpp!^4Z|TuvFg&b|^G}2S>#jW(>8J zCrA^lSf!{Jkgx$m-HLZq?x)>SyA9QN+LOh!r}V(Sq3}SzL1eRP4%S``)&t4mIPQwl zLFtNv|M`moj?nr*y+5pdaPCvX$L$qsInqP*7Ll)1%3G$`rD+Q68;Y+#Kg}tI=r{H6 zR+@!(m45RVoqqI}M4(R37;n!Qaxpq&>eT2u6rULTa(O&)y>g6JwS&uH6OIffYA-&k zbT^f<*apufy?sS=?WKE6USAu+O3Yl2Iz`Op`J@r}P zd&tvT=l5(Y#~?E4tt=Y7V)AUH!;)I`nK}&}(!MMwRB4X8ok3Vb-3p1GscV(2f(3MM zsdl-XrAoeT+*)zxid^c5*k=-(tF|c)!uNGR@n7IdLso+@Q$dsR^~Vfw}lyqR2vwH zLXxT2WM7EC6wo#8XWm*1xs``gBLqnLB#ZOZg+5DF zJs|x1lpE>&e4hWgfg1bbx&3!o0ISHigBA7JdC3x}q#`h{T>bOn7efEeX)!W^CwnZi z0sn7_tN}*s@a+{c8G$#Uo0&fThn9MLX0rZ}R>8@C(5B~p* zIcj)i!$p5D-sQhW{GTsi5qoz#8+$_&62^aByS~w~Py-AIA-fi=TGVdzfzYeq-GTgj zLOLFSYoTjMiHR!S?C5xX!V#1QE1px{Jn64`H>1dXSdbvb;gEp!9UZdgkknwn3Y(aA z0=={&dhqy+$;R72c~Ny8n>hxe*$QQC_E^hN46-UI?)N9H8Yn_y5aWVv^R1qj(8fYL zniycQBw157{VSmO{@2+a_clQ=S^+wf5dRB<4US#8?fD+aKQXR4ne@Q_jlcqbV;sx> z4@Lzidk;@RR~HLYI~Pl1Ll^sh$C?ynU3(-!6kd?zVN**-)%q1FTWj6Q#-%z71~O1% zBO#e2E9Av8N*RM`w=kHXWPOu^q@Fb~WdC3M6CM!dNK#tcVIA&&IG<-aoX!2e-kw1E ze0f?E#QH;n0z*^3xpwV*C3X|SGCV_>&h5yQ+47YA@dkD3Ue9-Kql)wfI~mQ0ix zXqJK`y8hr^K|hAxgrPWIHuewd)&e)-Lm>agb%ESeyK_*uK5q?oncLH%0zXwnfmDU| zY@-fWu9aTC(~e{p-hW2DaS6WDAM-=L-NX6cvoU2uNM%5vDRz&%Jtv# zBWdQ(QfY8V`vFt6lVNVJDs$K{$RxavLlo3a>|IHy2VVL)1*yWMgk!=W&pMMZ%&@!i zTlpeAb=NJV(P35)l5hJ^e~)C9z!X{=PWCx~bH5-&9H!*EQzmo^Usbv9E(4d@BrJk3 zPU~wXziRl0@Wzy=q|wEX!BF+Qd<#^O8YzHF`2IM|0e`7knK6mbq*hi{rBb#CN!Nj1 z3?ctvcy}h|%>t&aQOFk-#7PvfS*b*vS%4d#rk7y)CXdh+G$*5pr7T=5{u^=VTk3>X7M` zL~O(nt?0Jk%faSj!f$Z8B-e52qHyVY#}t~zirs%6uuI4jn-(}Apg3G0Aj1Fofc@(e z%F%>0Kw0(t^0RDV)`|(%aHPf1fLRkN>&LKh#2}#yAPGhj1RZ%Ih$#+PuI1s5iqGL7 zOJ)Z0q&=e7iXY_t@JW{#puq88V;! z=4JQ&=H^r0=eU!;3)CP<2gcxM9r#=fy?W#GW#wz6m7g$cZ-tuwrHiz8i3a zz8kRH_m?1`F9iSM%sQ$}ezoa5PzQ*wrM^`dAKqVFADTddAD%$|0lg}dy9(3#884SW zU*Nkc)4P=?H^496AHqQ2;r>d~mnkNXvt&J}eZ717upe0w{_qC0Uq!$d^0WpA{2(v% zAMU6KyKJcP~wjp z2a>gyDyU&KO~V>dTS(AywkV!f{z!-!mR8fMpP7`gctumD>YKEabe=@~N@hy_Ag0aG%S4xk_CnVKy3!Td`FSuZm}}V-}XEPmwc-$WBtOAQYc#Djg>c zi1=`DB|B!WDCW%Q>(oV-5ohsuHf`g~TNuL{ZNRE7nNLS>>sos2m?udyEw<5PI5UF` z;bAG~F_edkVR8t`&qWV4^;n0!F@d~i;kgd260)qFdAJXA4@a&sLZmwyG|Su^wPmT! z+dIXxZPFJ2Wy*ttR7MkWt;)F`R@JkLjq1woT9cPf2gExRz8O&su_988hI9BNsOQdR zZtat!y2);uh}vXgTbL?^O26(zCXi{ytDHHGW6F52wi`y!HhHegG=+19d6 z1O@ber1z+=Tt~x`hZC1w7dM&S@4V#8g=}6(2WwOe)#5sKO_8;20>qG6F7AN2Rxx7} zw5`oz9#V@UoSVhW&d>%&_7~0DB|G$|w_Vq^tvega3$=6vQsT;S_E&&~dfgbgrJ>y{ z(ytbvUEsfK&}d8o;Y*ELPajTW9IY+$P^@cX&{yNlWAC>jf~7+OMMuxaP-!aZJ%t3O zah(r@p^B@Rf@nnOvNb1WUy;XQ2GqzBLy|hT1;Kp?5+yohiV0pMuCCOlT7D7?KZyVQVMrY?0B1Zkdl$cI?JO(0D4?4E!Q3 zGo4E$MsD-AWHR1q9{`y;50@rz<2&kGelU zx;$OMKa*ps?SqKNJ%zH$1V=d%WpkXi8*j zYBAL|`$*_WCk_NxsCsLUv8^oBI!3HpNlMMkcQgMIPR>i&OqCgXwK+nu(@)z~O!|>s z6cH_>sTNXiJXTB!KS|8u{5|hG4O8DX$sKv-qONJQk%(zU7zeglNW zY4Tjn6m`*y)qH1!DbZ?}Lw|RREGz$Bsx2rL{nFLSw=zUcuZZW0j8eXsK~JAuPO%pK z9Cu@_riF^IQOt5mVRb${;38s{hFhLDIh}%4(TIDZ${v?iQa8%{V8w7$uSk?%|9I~) zI+JCMPCCX7$>J8XWiPbB#&?OdD%;M~8s;jo{P>Y8kWA;!3wS*!Ni;#kSNy#)O|=Y% zr^2Kz)2pVVg)wZeIY zqG*Q8;8mulHrYXx0Xa(=jkeZe&xG>&;mS9^&@l!@-cc@Cr_>cEr@8z-r86GZWX~?v zHAYOHbau(*4W;2|5~+;#g=Hbk3g3B!{%;z}k^-+>wkdpK&!gF{olEYM`;^F@4D?8U zj{Vs69U4?AjmlssO{(gCgx`b?d!tU-{hCk4Kobljj$H=X0t&o1Yw(qAL0?|$^!f-N z;1b*c_cr957vf+(A8KqYQp)!zN1VP>gPHZwwismV`~!Nzp$PV)+z)m4RIJ4Fyu+0; z&nQh!(+Bf3QSQ#7pTG{PgD4YNSak(m1+Q2>u!Os;Dl9CzL3z+4FuSS@Yqg|pt~~a< zRu0%``)b% z>NDlbS|dj;%VmuXv%bLtLD&`81xBJu>)XkX>IxW-vIdkgeKfNW@4$o!iDQll z^|7cosL)mp@6EC*#M*2iRqSdix3q98e`Z)#QF#+k<3b^MO0=e`8_8SxuT*p_+NICo1QQ zi2_MWRpE~V=g$;2dp($7!OF|<%i9rtXAPsW8-P(Qo?q}mhMl%-<_l`Eg_f$rw&HEx zJ3e)p>keJDY+MDO-2~d6^ z`%{Jj^1^ny(O8H1cLI6J!XW0?pVCG zsD%3EfmPce$1(kbmJf;fr>Hm`6E%n}k7w02gn7wC_V?QY-vYPkfpv%U$`VPCtE0V$ zMsHw#%xYHowgNS>;IB-fp46z;#9B{`4MZ{(%rd3WGG$RRq^1q;7D1-PFD!h6$XXR& z^i8LSQ%pL;&JX*TTAa-834Y%+$XlaHt%uH6ltVq)ZBM4QnrJvj-msPvOCnBn*c3YfL{>pa6>K4fUcGs>tM%=$yc2s%ZRAQKffD{L*k@X5%mID8Br-NR|yZ z^sr9O?A3PwX#GH6&}o5u`cNgE6Y1fcly=6nEE?o!Fo0(4NH;RDh9mFEdN)u1=b(Zr z*MV*(v*GX03h^4G=@HP12Az7nRx-l^7a}Cu!)(zSQ_V)SZ$QOQAOFNl=~X<~1r7uh0RsfY{GaiPdKlZdI$OG#idov23K|>#g)D1m zXK4Okh*Q)yow3z1zi~AeHtx9GwuWjlH@PIW$0KT*!IVsp5855$jkzt4(tkrrt}aA$ z1FY1m)f}g46eJ+qfJ;Kyl3V8%_!x35&C3(_0&YQ>c?NIMZ`aWE(gS`xyStH&wgp#+ z^Lfv>_q;#9_iXom+_?J#-TvH>+at`j><{9oN~O2pNE1LgW#!2cz%gIySLr-ALs@Dn zr%<9rUt%gs)r3`JrmMWx0miLIR#9EpV;Ph+s507(bOP27F0-S8d?{x;Ok7~!jh?L0 z=u1O-Vd_cjQwOwQEa|@|4Ayvn>#yFz!p>T~lnRWVMHC#KhB+6B&z{P|!=L7&oZ)m^ z=rJ+3o==(F^_X)qe*)VI*D3>KNAp;&D^V-}HHj`&UmBtUN1$vex|=hcJr8sltwbXb zG^2O$kV8rxI$lZyTt{e>YkXFmPF-4=sXM`(w$i4vwCPX9=b9HfzE0s`t3#zjW+VsY_9GXVq)nGi<}J2AjxSXrh0 zdPd+SN@XrNEch*rSP#?vmWvV^0wS*7tZ?2m9$|PTolDr67xD;nMrk(H@~xyw zG-swsoej0%*6l?36kCeznagzBY(dcpnSSo13LR27%!2b=QGh4ASLqe#J?pxQS>`3K z&WBZTJsI}K>RqAFsf(2za=+B}bz5@-B$gYa78U`#KKi5Zw>*F)bMzCJ4+X@xTVh=P z5oj*I!c=qsu%M&%Xhmhwh8yP%FhuB9r7jE3Dmzpzi?3y}Y>If%8c?QV|04_-{~_=v zlS>y0)>}oa@)-1%JNX!-NS7xr|KMbGN36Po>?o+5^~>K806JhL!XX&r518=q9oFV{ zK5~erCd-NJqz|t?GZ7tP~sDxibBI%`Ns*Sm7t$xClx*mr3 zf!;%G`z-Shp?e}HN)W;Z;N=oYwe()7kMy4Eo6c`RPs?oI!|@CsICGA0Yq}@hZ9C=X2gr*_bGE!Y*+r zn*dL1_}NkqmQhr=yl&Wtturib4kR6GvtAhA&g7;I3uaBhH5Q)QtZZGrD(_}pfj1(q zvg`WHGzyWsx$sl2HW4=RI*0K3!o9XgZ8`*Nf~{oh2WC*@N=f$%6&#(>rHZ}zs_Rx( z45=~eR$2`CAu9>UNJ%g0A-jV=(?|$aX6;sAt9$BKxynN=OLq=iN(7dh%bz2^T`Kmc z-66UF8zRX-M2ced068v?O#vo=UaPBd?uxdiFIbUZ)ay3{AIkNVVdq+PE=6Rx1jMQD zg(RG6-KhpO0#qj?2w3o7^(3d-kjZ@15k-?1>dKX-+NtNtDJjm;+$W2<37UNoes4dJ zRkGF)0WIEe7)Pi-QJB9W==X>tjiHK&gOCM>BzUhyr4Yzk~-s;oPR8WsOSf( zutzq2lQ?B9y)>Ni9R{VR#rLowY~G>$C{k;_s4yKzY_JIIC~LGBYxIxr{scbh!55@X zvCVjR7#AG!3*UPn5ak#E==W=E)$<&2Kkl3l$hLNU=ffYT`yr6Ga{^4SF=cq3f*lXn zS7#rwK)es+4KF*Rx<2mk*dBSO`K#H1|dBkmacZrwxiLvltmeTkAoCxdn)mhKkKn z<&~zt;pzAphM3(kVrX_GBPTo8>zDT+?XVBJ{(zY9d~uQ%{rL+id*gjeNFR zrM;{Ud~%!Wd1Z?@*KK=HE2P>zE$a=Y8zAB5voC*k-VooANQlM?y|%xSmGL4WPlpAj&U?!FAepU9kjPYnQF&KZkX2s z287*zcr?>At$h@sqfi|H#}Zgwb}>M80thg?i{%!9`--x;#=R}vU8=lfYm=+w<2O2^ zarWPIj#%e6Ob_4Xmc?7e`5VLL=hTfh5}Df=?WCe zAj27m$YbO4!ASs8+S2OWe7fo{*eyUIuY#-Je9KvUl1kAdh-Ny-I3@`(Y)B!p8KxL% z>~cI>7fec0L4JY-JGA+gFF%kDo*~wYW0a~BWqt;n@PUa^lXR6WwEUYQyYQXcgb}Ng zO^bgRV6Zj%{lBSS$o5CkUjOP&x-fu%sQz~c%8sqL zFccY2Kz$?^PvL=Lc9MPE__49mYdd=0?LiV%*Gux2zgGVt6<^S7r3Y}HGQiVEa2Opx z3Z}1ii;9|ctBR^WxZ3>^TKrmyzN>U=`}&6K`BKdDQET#0jJ}%`-E%VxkMg0g;gqK1 zcQkx`_i9YpQ)FagJ$TK|yFS}vXxDv%%E z)nuLD&Aqgoajcvpw%%0NX-xpFn+-urM74<&AzEDnO!^2L1e^=!oW5WdM#Nae&gr%m z4u2L_6socSb2%@_i#upN1)zSU$ch=*ehxcVjESqygr5mT6g_RKaf-6`mRD*Q z3&5`KX~7b=YYxh`D-J4djitIaSS{YNf8^v+KhO=1?&5?sb4pH~D4NBF`tRjIeUS zEd%JlqWw`3$sj}7N7Xnx=&@VxDpFJ{nKUf(WI|(oG-QK1Jt_`GKViXO z6Wc_FG>(qIO7p1Hp#r_oiLWy{l-Af9dtn&0H4Y)8%JA$s7j(v*NIl=7TvwwsY9%`f z@5sDmEG*2djKJC&(Q}3!#MP%%NRTEviFi${P31KuLk}QAvlyU9qcTb$LyIDf)ToRw zCCU#!&eR~JD_EpcXn%Ni>A8{}sUAyD;7zuwHo>$uN?BTU4mPtgYAHuv+b9?{Dn-R$ zJBwu`6C%J_MvidwVsjXZhFG`&_vi+V9hzxbn<8PZXHhuA)O$ zpTM(FLypkoEl3vyRhaO zsZkdJYeYP$s8bs*o4FRfi84=hd1%J9-!(0w)Mo0$fV&mV^~%d6KOQjO?zxb`Ua6^c zGVa@8%&4ZIf1;$Nxyz6g)jcJX<<)Wd;`js2Hv{_+7`KLgy30sKzIjwU(O7Kice<5k zkJAYU5~k#c)s3#{0X|3xRMW0r2PX%t?YF`NW3eXr9#b%NFGg0GLf2L04PLht=HVC&%mEUFNV=>S=>zXzU|Jzq8E`An|M}^As_* z!TWw^BrJTaFV4Yvo^r4)a7DHK=(j`)b%oi8HK;2p2^sJ z`Jpl7`j-5GmVFc59i1(-j>*j(z+JpcBA?sAg8a*b5aittNuUquqCkT7n z)66H1d5^Z-oi}ZPs?_`1(oZ-q&%NiaWWSv9-S04Dk$!hH1YKP*$PB~7(Ugu+9b*1n zTPLLp|B6rWT!IRPGnBAf#)Gmx|cuiDHYAl$H5 z8gY!lA)*EjVMo+pUbYC$f>O!k2M54|T!D)PuxSlmFFBZL@2>LO&n{uop1Uu?IQeV& z0wOS5EFH>zRirL|s3u9yvX&)%D$CP1-WbXktw}P)?aCKap~+GO;bc$BDfxnx*(9(U zz1}uYB)<;LHLV^qq$n-b-VKhBVd1YkN}Bx(ZLSDY$Q4#%3oJlNDxsIYKEKp8AF`j2>PeKg<)Q zF*$LD9ES=N)VReL6g?%TVj-spB=UKLS6J!<8_nn z-CGGde>*o;4Lm`Q9hA~UJ+bK3)Hpy{zgR!DyaZC}a0N_4tv?>sS4}q_ws~i6qv(=9 z?r6reP*zJD`a)qVt+ik3sf3o+Tb5e_XU!^#Rn^gk&^{XkfWFn<@&wihlg4}|wL1aN za;B-3`U0!xw3tp8*wdAz!L5T8Ib4(5#LxX$GQd|h=TADbQoH$~JqYA@dg~6IJE{vC z^z761D?2rx6V{v1KZW94{kE`7p>}Tt$aoswaulH<96(DtK>!PIEuQPB0ywH{Ot^7k z*%|BE!?P+*^}ik9djK{TVG)RL2vt?Orq@>1+2?T(2(Xfb_`}C*|a{T_`0+bX4EIV6S{U=iHO>!Q82p}MKg#R9?owJLf zjm>|FBy-eX-LchCzj9d@DDK)Fx5z|g7qBkK8kMv)GlMyxC9jh+C*-U~86`nnXk?2c zMwyLRCX`YelT%v|S`QlQ3@KS?8xC0JfJ1;w1fWgB^k30AAhhk<8Rg`8v(B_(MjOGz3?9gWt410&f-5kjg8F@#~jH~~lMl#z!{ zJcR0UQchBd-hZin7|$-&(6;?+#Vu;}9YXaT%;C^lCR>RfPxQo*aZb%9B_{D8-UpX(4@R} zX5_l{MAcUSh@$EvS@73t>!v2n*9@BNvn?`#)=J?o#$8e_N{+v}1*nZDu}1CuI)~EH z&FMH18E3}zo@%iQvl*0*iGjJBV;WC&yecxQJ-SGg&*#2w?@*apZc0ty+P?@1{HqxW zYUs^PIX#TA61#sJnbsDQRtClmV3KZgu25uJR9YE1)LS4g-t$aivKePdS9yjy zD)K=I2zVpkRyn8yJqldCR(~j?7WP5AfPt)%cYZs4H=SLz+>}2#MbeJ36SNi*1Jjq9 z^$hc2z;T>ztfh<0*kN}k3A0FHT+2qvog9`OVc85@td(OgyPj5j_HNIxu&f-P6&!26 z$WxBc7KfdND7vS4l~OKAUF(J`mb~7`Peu;4((&AeqtUo0sgt76c4?70N!Y8Of8b3O zV2Y}*2vALhk*#}GQ~|Jh>BA=H)%zlkMn|)ljF)FLxz-&io#%$YxSAn+WF%fz5hc-F&V8>Z{ z;Os6t$R%QSsEv4{Heu22K?XS33%c{dq8~p!-}+kBlx7WZmkg1s@|5gDycC4u?^~ks zuiPT@6z%`53q$h`HO&MD>2Gls^Y_z~X6hIOvtck&_azC3h(Rvf%P9V=dg%QnCH;bS znLM%dhHhB?R*eMy$UI0ApK{|9ZX2u-L^|&h)bDj3%va@ zAZ@HSPBPib!Ey+b<8do#%{|^-&!vAUrQ93(PFPeYbg0poZdSkKiX`Q>8B_oZ;YEAN z)sr|F7i!Mh+T_-lIp#;g@9MOshik%I=}2)u%b?&^9bvw^($DstWkf3;(Kh5hi@Zg? z`y;cT7_~G;)OYNZP4uvzWZEo6ysnD7A5LSAOPygmuh_+}u*n-QZS`xPXafP98;OzdFY+CzchX7HVFyX*@&uQxbO3ViMRTC z#=085j<@IEkv}SYP{1&x)a~*>oEIK zUDW8VjgGaf-V2P6>K|EdYCo}YXgoA5pTMLj$jPQ|(%|c|!b*y|&{SMpEE`H;s>MxP zFb70JS&L`G@S5s~molk=XH^xyv^)K%5)P*hXuce+GMhdK-nV)C1YIn z;gzyCNVI`&so+GMGDQ49T3=d7ftMk=`jYX@qndz2cUa2QB;@;Xda^MgCY{gb2=4wI zf-OQ$$yBcZb)$hUBb;(ReUGw&dzpZyXlNfph*!ITcyNLx#yf`!KT9Oqa5;Lo--J-8 zA05v46|C$dv!-$WEg*}KwHZFmg6J7+F@+T2X#`+NctL3Jh?VdO)$qy1c*U0Q3I5T5 z47#&{5NR>PI0{{&7w#GeyUs^_a31_5V zQ0%(&JLK$x+dYgSnt^mH#COP3V$3{#=t2BAqSKpW!-JNO$OLQRkKS+K ze}?aS(?=V+zkk%3Py+!G{5Ofpzry#w`+J%Y1}ew6-`~!My0H*K1bvM1CMHO1NGPy` z5-gx3Fd(Wvl6r|j*nmH{Bvw@|8r8Zhs`FeI1A?k5NDRO$0oa>XX)RjjHJvTBk)^%g z&wuFBju7JGZ{By%AjJ5v7Q!T_i>4;PjuMff_=PMPa3;ZRoEtvPb-4A99!PxE^2De z>Hd8&zdprl&j`B5creENM?Sv&0d&c0!AMqjbF8|wbAruB!U($chcUgViG8|15riL= z&ezl=|EcuRJrd@p5Q7wlY z1m({w;aad{uNV!?|)Vv6kh#BEj7mKSIcktLK99BSY z7Ws5^yVQk(r9aqS>Mc{MHPj+#JI=MOGGi>6&6kISWr6|+-U6FNW9Ua+RBtRxF~gGY zUiiv>X(CTS1J9!>OIK zX=iZ!+Lf|sR1BDf>L(T3+%z`x<-w}okU|?oGYp3YmNlD7Oo}Od*g}b&aFE^t)>-^% zm_i8duG`h1D8p+#?c<@Xi`{Im0j|szzk$L4dn3H;<0^%sYmE7LiH=P>F@r#lu*uq^ zbf|CT0#V2TOjcbx-aIh?OFeCo-$1LIKS_j$v5~ANbVeP-_ryxG4TP57@E82>N>vjf z0@y6bHL?bLstQ;#L+H~(RBLLn{fqZCZ!LMN=a`uK{tI~4M{rsyd)DKnap7Qwr!OQQ ziLiqKt%)^sBiltyJE96&0&dh$(PL@jyPuhLl%{49D|41CSDPF$7B0NG z)}pq{Og`p_keWf4SR9DHY(Axp2B3Uh9kILr2@yty*h~wxrk-Egq+=;M6u2RMji;-Y zy*VY2HI<2cYSYYwjfOb}oZDxlI#gmyYQ0*hn*j+HGqr?`Bj~65uSKP>xg4_9lKF7Z zgI9pST<8$3OwhYsJZe*zG>zoz`BpMzIdY0&e)Nbo!S@5L9=91yWH3-!@24UjWJojv zj?!p^1j~MCrQTX$WgtQ#?;Xz&Zg>q;aKaLU+tKk~(keltg|NO6dn%u@pFLC1ZLNIx zfNK30h>zz*R=?F!@Ho6)5~EcgB8yktI4XP|?k|=RGnXcp>-MR7R9k6E2}pc#X@o^8 z6VX7N=A=l%17%49>4g(gIjHhqDA0oozf^+{37JvPa3g8VgDBUHVrIm8uA&RLVAN98k^LMo_?!DUJ( ziQ%*~Ym|#KsHU6kRFuI~PfW5zQW$+pt%^zVErHM4i6N5pgh>r$`B|!kL-R?hF@dXI zBn)c)@bM_a<#}O*#j$*twaDF!FiF=>@fx|7amynuT@jzC!L62;+jIZQU1Qg5J%6CN zUOg9nlPKeDRxk5k*yQ4siaUSs{Vh;-f98|3Q6XG5?L&)zuh>r&R=apE^j09ppD&B0 zUw04tVVz@tl*Q7c$!9nJs$=)3yGwq)vj=yc_v~jkx-0M(yNTKh4kDQfJFlnPB%JeX(Mwb;{eN4*C>7(|epF zQ-+@$4*CZ}LFA*rUOZq1{+^giSA6cK=p%jRodDHN4NNm%Z`jzscs?&8R15^lio;9D zL#Q2%Ez?nc%;KIM8(YRd$1?OY711i8_|GmzeI~j5&#E^*tUK-L(2$V_`3a3~`MWj| zVh)RzSHg3)ep78N$AJYh@|FHpeJcZh0`Ps25OIo9!Pu7=3JGZu=CyF4G>$*^(PBb= zgZ83_j0tJF=CWubALpzU_$BHU{z5iF9GGaIN*oi3yg7*;zJ;JPs*%7L{uz~rZ!~8g z?HY&3T>RtmmLJVCv*8DM$Da~A+lEavSgac)ZWkXo-4*vYFV9@xf?~76<`1D7jcs%Y zavu5Vv(OSN5Y&NQ>AH={?#t|9L=-AGP3AL8uW>#}0!J*W)g1nvh8R&bT zH%D&uvKI89Lyt^-@Ne;@{>WIz9nqd@^F|*%5NYcgD_yyw_v>9rcPH4qt)QyQSKzWa zXGjaSCA4d#n066SS_@)@G9L7prX&Y(Fb3n*vAXF&1bz199}wuk!4gKzeAF<*D)1cw>w^1 zHfE;CLenK==$MF~q&#ouc|B5caj0jsdRI#%!qFmB{cO=_H~EdNs->Ww$Je*=kYXct z=gf>q6j#*Hw|-DQCyKwLoavNhPS`r?B`8^#RMp{2+=km$O@{_KLaVG(U~XkA%=_cU zg+R2Vmxcz6bsPPlAG4G&_AjG7(V4Q2r2y4}8cmO?+;luIZllOse)Q})eU2VZE0O9+ z&~NeUPb}wyHFhnJ+Wn!)pA2laaPXE*!#>?xH5mq94De zNV6-~Gk#51O00YwqUsaD%Y-8nxSsd>Lk2dB7KqqCO@mKD;Esh{hA zcF{hDS{LC;K4(XBu_Y6mpCk?hH7gW(8AUCXPdrxcj>=+MPeNrCWW+3POU+e6XAnck zq}z7ZE?JWccpuax6Ivssy+Q1Mt@@SY;Jfx^>R`N>ENg*aQWdI!P1Bc&M8(-oteySH z(z?ip#5o~uBF`n_sO@ni|3W!duY`Fbp{?oIiB^NZdgu_! zdm5;4{b&CcS4`10{&&zbCfYesRjwse3tXi8RKOW*Z@;BvJnk7+=ItyJ&lk4n5@t5g zf{0s_O0-3$Bg$J<5_Xgft(f3)I(C#+y!1EhH#}C6afR!|P(K4BUi>Dk@vh^*7b}o2 zK{8na7QB1Ot%bOH#{)k8Ic-Uya~O}S0-DN3PEdQm*{LwgMgES%F{n7m06hquC@V7g zFMFzJSy8sO)I0~%2q;cdx@v+aVsI$R~$+uy0 zo~?0Qj!0VAhOaK=5cFZ#Z`W#JvUpUurav!4ZVJI?t6ydw<+dc^Kcoii@ibJIDEA9! z^2TKBjR6c6?vxWI_l6*o3VykDD95E`PmFvyRoy){C3$IFQI-32*f|*PFb( zI4dlWZSY+>W1H{$LlkD8s+)swf;c48ksP(;cZ0Y>&u^d-u}kNT%a;j``KF|>0YYpx zJIt2kC(oHEnXV9VC(;Td5@@qIH|`1-?1E;Ot7}DjIGl&I7K*CS1wC`-3f0GhsCCgd z6yrx=SFj-@?+&WK+|pV*UNyajvsN(e7ISVEb54qL!;a7+RPgcyB0pz2h&k68rm$Q_ zYGk4ao~~s909D&6XIK|U#XiPcmrk;Fxz22(?);;y){wM`6yjZ{6YS{hYuwWOP;Y`M zKan3i&OK{uPr9s8yYz)u5DLScA*GkI&9{JuJk#1two-z(juDO$bDF^mr01xwvKoSt z713CtFJ4|7%CcReZSeM+6XKbC?IVOKm6#gZMZtAo{#P1m07le?TuVlAZ((uu$d6)b z1y~#Ftn_pP)f1ZPGQdk_k9OIKK?X4f_iRg&xt-#Vajv32Z~=~}cR?y)MA?r>vaumG zna~c}LYg#R4?v&la$krYcX}qcZ*_Szo%9p7TLTF+lw~Ehg|)43!>=3L)bw^3L7B2T zC6DSL{6B;lV|D*XH*8@I$`qzIgcKLhRxzxzjvl4&jfB{&Nxg6DEi|h9np{(G`4w-l z>vEC5Q*Sv>fw{V!l5bxXqYUyZptmBg$%YECv;^b~FIq7`nzBHgK<|KJ?@F{Z{(gEV z*PSbKAI7YQH1CX(*%`)(+F%p~=N=^Eke#+j(|ccd40@7ucshi_Y`u-$E0Q>WItP4n zmZp?HXv4y)6TiIykBAia=H*-Tpab#2y#kJgZaQmCkb>6Oe3q+ml{aU~Jdg9f=s5SD z5{qj`ZgCLJsbwqD^k?P93XcA?P`oKiO`CRu(tU~=UyaGmozWwGR3R)AR$oq%^ywa|$+u^DRgc z-m>38Y{%I$vcsgk0<5q*g#3deWslIFQQxp}TClu7MEv_#(XDUuS+0Dkn=T4Eshbcb z0=%SucrYBkc#rha4(%L)87Qi3Ja&o}q_KO67x-J=(oBQm1hp^>PapjZ-?zD49>(dY z-UC0yy)`HK$+;uTXC*d)&1-em;cCu{tscS+I8)03u(o8b;H{{vXBG_kV!1s+_q|Y6 zdgP!CDB+3(B4mA;(j8F^F-0V9|B4A)zl$LF9YDE=8I_}7+HT9z8rmQ0Sr8Rp63d{( zq0Q!n6I~yanYa_rjlaUd-3ML=u;!F@3-E+Z^v4O$`5wg&r++Frrq6;1uYr=Zb0~&aPs#m)F1uZ``_}lOmI>OW;IKdlafa&lC8A{8u zG!dpnYh#k!@JtL4l2ba=G8G=Vi>NEy`o#8^c4tT^jEnd+GKBXTS|BIihO|+$N+EDi z2dc?+N}Ed8N8v~0^C~_X>aTjBivLPCT@KLQW??UojUkDE{o3>19xADXbWcK9Kbdac z+i3Uaw8NLPpWfv6n03!62!(0LS%%*o4MHvr3U-bFVn@F~j_kU;psZf?g}k6zeGzK~ zgycSu;su1>ZW2(gS%ysbvLrqvngLsLTF>e4aPo*^_AkK#kP<^QYNB~Dk@)6KL=lGg_ z%;Z)s=ahC$zw0FS^72)Q!5x)8h{0|RwqHs-aAO@TVv)@9 zRGLb3$5vgX@R};XyT!1_Np@|oYWhHYHR>|B*k?rG}bJ|1+)k@O|#ENBSR!w5|4&* z21a2aA}S*b=x?|1u@&$%uoOI*0}Qf?73xxq`1q2TxL8kvpuuCeliv6OCp21!;kp;z z-N`X$7$ZIq{~c?*?Buz3_-u`3`((8u{LfgUoP)*x%!Gs_**MI6LmT`+OjEZviQW=g zq;R3Z)aPuEVrC|jmAXu<{Z{WjIg(V}&{&BUW7w~lCt>!WUet_a`7oH65N&V@dd~J2xOxF;8gKni zI}(pFbebw5hvMlK<8b%0x`GIPQH+%ITWj3`vIG&*2#7@3b8;s_L^M9RZDeO@v`eiF z${9X#g>MVksS}Sih;bnjFx7g=D0_MdCh1ofet0d$LYVjI`OZl)@VdUDq)t{$frzE? zr;vke<9Vw;FoL|6eD=}Y886=T6J-dn9S%H`bTBS8R8j^a(06^teGOUlUqYuS`#MSV z1jWT*!z_ZMl$7%Co}(STXflhF)KSK~mF4zzyV!H4ZeV`E5Hk~tZTu0)F-eZ7lP1<> zjUG!*$itJdh;AIzy1}NH$Io+c>yeU{usTD7yGe#sE-%!0plXs{OisL`c5aGAU<{+H zo~3z>%e)%e+dPgeQQB{zadM|BL{?g(uzxjNOXXbo>Hn9RreG^Uka|!M5Djn;5U&4h zt4c<$mclMBW_HH5X3k`C4kkvnVxMDN&Q`_%S1X5q^uwm8=*r>>qrFdT3?otMyZ4$FJl3GWix9qozEd6jU``%@?GDT0{&m3; z*5Uu?3-t|^aF8i5goKYS|rWw{ywVA5LU0|}lic)pS$(IhWr_(gmHi(GDLU0`LQ{Li?0DoS84TZ$JWGTk_- zVW^JoQ(W){28Y?Z!*F$pnznCi8_DFAhWx5uO$d! zfj}zEPsWEK`^prt!tqC&D)JNVJSFA|Iz*FRln-oz4_3(F0dUDYW{6~&f&8;eimS*; zm9J6rj2;G z*nk4|przj$W1Ls~C~LWncWJ8);&w1WgWm;+jn1`eU(kG>;1|2w`8R5HFIOUXFP_M6 zq5gf(Qpp8EVt%$a7=3csQ2c+`!QZPSDH>LyxC`j~;E599peER-0mLcH^1%?LZn(eL zBXog_GDyv~)NUv&xpi2&(aF<8q32d7g)fN=R?Cg@53ZDUBrSO{oe!J*EvoxpBBwA@% ziBbw!WNY3kx%Yq=;iF2;uL?@z}iTCdSd#GI^a(FNbs9+lQH-zh{+&1 ziLvxCFOra&i$`B;_9n@ExNdyD-UNdVQfIjy-kYQ*O-4exJ0i-(BxzQaHtI&zg*MHc zRh9Mz&gJMw6m0(N!rf0Vni}1fIX(of7G+2~RLF|m!_QEd^PnaEwe=UsZE&UO9cfGVzhFV8)j96MWpoPWBu!1fnYA;WV#?}YJo|vhm1TKew zt<`p<&@eV%7txw4ciX;JEqP=5aSXNV0B_Q6XL!g5rjpKW0%k59S3;F(j<`)`#<0mH zg>y>OSpJLvk8F!rybVVh)%+SI91GF;ggHvXAw)gx1vP6!hvL7K zJQC7vRu-vN*@`*vdudt{5Vh>P(7s4Xvqt+ddl;QQWYxh_HgTm1kinvCiSrs(oao!( zFxI1}wHFeJwC#-j{F(ILYogYP3M$QtIDt8GpF#Yy^20ZUorIDtdRrKQ@Usy?@DJ1X z97_){MQg235S^{qv*SVM&!uX6r4fR*!EF%Tz^J)^%_5E;1&`n$BUW;9sNsk;TIbBA zO@d!g8hWPh1AvjkK>11+fi-@u!C#dUI@$opLYkqS5=C-{6Usc@*w&1~9VI<}r-y8=6Bs3Hi-| zNo94qc4SHwuErL|aNjyZa9<@aYn#`amdm}}_)Cc22XA{nA08o}R>9!c#!jbSr#w3d zHgCE0Q$_w@W_7ut8`FCa6>>U1R2T2IZof~gc1$CSvcjKhd5 z>By?~Xf-lNiD~urwJ=&^SWV2i#Z0HMI6)$jDig;--2e(v%N( zdCTKJfgrpW9x*zvqj&ZRuXu3L;DSO`r>bc!$K;aW0{4a9H1G*d+^60uz}lhvGT;l2 zsH*BpYD|>igD(%DJu8HK{{|`50Qpv3w37{VkS5C`C!=6GT6twmP@DLLIt-gp0d0yR zst#d+(mPBeasbY&l(whd9GQwQmRe!CCsUD2zdVu0+m#ncs_vSJcz#To!!)h4R$YQM00Bphy%Sq;ApP3i?Eok-9_5vsqy;8|!>y*7Z>+pDwHc__Z0 zA5mhja)Q_E42B^nbbyrs6MBstN+iW==aH-up7F}{)J^4#zR4F))VmMcTFxb)`p`!z zc$%;w5Z}crx2m0{+tZ-D!?Ag-q-QlEpC9TS@6^IR%sC|KA9Ap}D|Oq4znVn+?O_aQ z+RM$+nOjJrL;V&2ujY8+W)4-icSvns{!wl7gr@pVuv{@{AHBn+bL0Y*w5GT_+lS#t znEOF|yUijX@v1Rk@%4t!JL4J*L*GHd`c$%Zx86V68G58VGEUW`W#E}dQRWChQBXpQ zY_)?YrgbrGd_;F*!oB~MXs1^dNNjOz*~1DG@& z+;$w_hAh7hs>;z$zjQN7!_(vJY(v}RO}*~^0CF`5^9&))H>_4w8-C0G%e!8}2StKj zd3R>L|6yU3WSn_VrTEppUT!J${V%Td?1g}G^K(kB_LKRS=|8(xRnO0{c)QOb`A>pe zS1U6YDI@z&cHMt++^VW-qP=rSa}nc-3C(G#MQZfW*I`zWOX;FpQ$fg3g?B89a#2Y3 zavu#x2szyQ)hK37EQb9CoXVB3-jjbdD;97o798ej+7O5!hMDI1QTe&qZ5Vi;IaGBd zc7D9=D1s<%>42=ID_uH+Af!WoLs5m@27N4a<^h3Zb-s$s9H)_@N>{zK2BA;CG%<*U zQ^`y+W(Gk&Ab)K#Z;$27xT0W?x=Q6UokpY&ASWx*N)<_)iW-+9uIf^9l+NX^OHarB z*~-Mq%P-2zLBK1yw@ZE&i7{+xPLt?p+bbsysiUB4J~1t4VKBN2_&$K#%a*AOs#xk^ z(B-|XQw#*mFx`3hnMwaTXe^3m$kLXkXRTQZ)k{k@ptReC_(Dm~i!Qyi>?{#ixvaxc zv69f|H8HJeZW{$RIOSr&o@D-$*tO8L|{dX2^yEBU%Yc&VIE&vas1OYdF5W_=*MZ0daZxBe<6)m&<$Lb>tb6+X+;Ef~+;AaEF3 z2gXk^giOkDzUP6p>9Y41E;cIA(C8LF*6rY)(&5qE7&rUk5xjU*65 zI-zTwUUjc61=^6sWY1JFk&`(BAJ&es?6+OHiaw z$<+41#?X1<6u#%%$e@UNW26n{4(G`3S#_W$8!ma(-u5%jw81QXc>x_~WmXgO^?cp% zih_N&dphpctltY;5ki6%6+&; za2@2#W3bN;ImAD!f;=sZ0)j1v+2`%te*vVM@1a{qw|2 zwMlKeM`b{@k>S+flHwsA^t0ZqpAM&ES5OG<1IHKp9#H`=Wb;iUJis7PtO?e5du+Q8 z9)9x6)*xtO;vfeL7MVZ4X;oSd=nTrfM`nZ33<^0j9G3Af_#GPT4v8AUP3hM_i%Z(r z7P5&MT|}M;*qc|X)^OgDCH7O&`moz&kJOL2Y;$-Visl=vs>0Oe9lW@oR ziaYk(hWTL)=XCdk|DK4P%i=;Me1a!WpF|t~m$~A93}cEq*qd8f0Gy5fnT5tA*(st5 zBMpA6SR4!IfPjiuMK*>xszByQdz40&8J7xe<2r{l;8ANjyU+J27DdEFFusELQSF?r zft|I=`>?X|vVJUWOf+?VyuL!_21;7#_4vTTiAwcKZ4o>~t*SM*Opb%wrzUDCY!e5$ zS$hAr;pF+f=7uFqxh;xU}vw5`R`z^CP=I9?@H;c$V#0%_YNmgLhWY80$oS zK5lGe#<|0#C;rtqCp5_e?VcigDfX;}NlbQ6KXlRSCI0wF#+jA_FD1gLuLFlp_u3hF zLz7J_hhUWHm|#7BsB_gBM@+E|0g!H|!6rLfr@9XF`3`t9ZSSU+)PQ7PZ1sfe%Q%@j za=pTuy_!sW_u%*^kd4M?`EaTEogJM|{YL9(!(jfM;d-t+HwJ^O7rYV;o8J0*Il1}tkBe`#`B&%b4P0lYuv|NJZuMK;9> zo&1gTk>Y_1LE=Lqj_l{X+0b(k zJPBtA{mO)OK*_66!au@#J^PHv#7}rcQhs2f-xtJ%+&Ap-{gq|Osc$%zL_#@(MO#jV zEd*x7dW&d8F2SNXuwok}h_9yq?n26!pD-0E5YFjUk1xhXq+MhUdA({9kkBe54YfpK zW&Z_rpqGL9yQI#gM(9a%9!SIp5vxo*NsMNIm{~lF)h#H|Ywu;01GVrr%TPPYE)a)| zA&4%qm<5E4R>(Y=NR(wL5oI?P$5iTzr(6alxR5iLsRm49yl^(Hu#9zlFnqmCMiVHJ zC#Z@>AemWwIf|HO(C54SOgjOH3KEga_x*Fjf46O|sS|O=&nSTBvk{T%KSu)pux)V< zGZVl+nTIu>{Ac&EKWOSmCBs3!f})7nh=7>zLQpAH&m9yK*O`JTTJ8eUJ@dw?@Hm9^6a5K(+FQerbDokqGSxSPrs7wIw}3u zin0JoFZ;Z(l$o(U;k{idebVA&C(;#4u$FF_!;~ziVJB!r<=ML6x0uaKpPiqVo{?Q3 zd$-dn>>OKe<b_iVrsK{d;;e3bWxr4U?mP(G6`SzDF&ts_#Xe~I# zWoy)jp^5HvxD2`RIuDl=hJmM7GPxR!sLc#|rL?=$n8&5gj&*?j(X>3eXhjHvfOf6w zPWqgqnzdfP66(sF8@j6cWt^}7UClFj3$3C(Zy#NBtp=THcpws<%hVDKLy~i`$GLn- zfNg5LoBB|kR3CPQ9o9_1vuD19Xq(owE{_HqPMwgY-j%X~_D3P5tcXtRwT^nRUc(U7 zT8qzgV;szV1<7xUZCG&=5%vz8L@!sBR4B0R=?_XPv3X}`Z5J}H-DjN}(c}H)QFC7_ z{8sx!KbhZ}Mr~-lY6!Hpp#AAYHYdKO@hBMx)VWXQV32h9H{G4WDUanMp!G{%k5x@? zz?^eX;b~F;(|B7j zvTKS1M86gC-y*ZDHa3l<23#H~?yeHY!TU4I z)jWxC>Y5rh*jn}xTh-q{qV~Igcd#K#-g=3DA}a5lF^36vWSiPSht2@CoZ%>DiGvP=ms$t+?vX#;0V2yMe4$L5 zd}W~!NhcxxDn4L%#fj{nc7^z=+Vxw2-+0ewH`rW3BDQSS?GnzDy(-4Wnj(MCN4_8N&C5CK`n?B>4RCEUJbg}y+nJ-6U}`q^fcu?0@ThWvgMIB0 zk{oxo&p{`LTVr|kIIIW2@d%LW#7w)TNlyh-{ocSt4>e|gbJr63NU)v`?`Zz%#+a** z&N1zmW6_y;kDvV}v+VA5|7+T>(_%y9g<;ZFDv5-37^luGtUAZU7)PL$#82i2~P(0nV@qAr_SyK2CDW zr7>3E#zhC2-5t1ftaXgC%T3ol)?>WKQcjNzU;}6F2`|95BhZE!j85*SWt$aqD4|zt z4r72gG^OAO;{h`e>xyDDmZoz;-qLy{Io>H8*UpTfWH7Qi1ykOiVu~{R!_uBvqFtFT zxMsk+a0!^e}I|5XNm^P?^mwY;6(Zup?AX(<&x&Zc;1)d=EKu3>RIu64S zG&qNh-qhZkW|Ku7`>bBz$k;JC`m>TEY%+^YQ$b*o_8q|w6#q*umK-7y-Fj<+m9SxO z_xl0VhDG7dtOKIEt5pfms(kBGQE+CC_y~mRSBi2%g(V$WX?$t;q_HmQ0i`V z_e{BKxVYxLsUbh%CInURu!v9E`yD3yDkpUT3BhMCM{6gzaa*Gyg+cw4CZC)^IO0J# zup;$|mW}gO#Ot?_QPk{F;fMOz_MI9!Y_#1+O53A0cgW@Km}GqKi8d)WrPzd=1}%|5 zY^Ms}(eVYQ^O7;tN_EiU6m}ytr_6Ji!h0BJtuBC2^5JdA9#-w(@S+kO14OAMt=*6} z3-hiF{1#|M63a}`*BMZea$o|ApHwkr_yXzG@m^zjJrkibQ%<4&R5|5{F-`V(8(7SD z+EOd{F|ul+^mJ_iMpGRZ`CYV<%q~U`Se}&W9!U=(>NQJ`-giwEmX6575R zFW0Sk+Cz+&x(NGqc@F19=~6!eBVB#c z$B$P^ZM-!)Sm*Y>XmQzJUla8AfB&K+u_Oe>%j1S1R%;?Oc+=&L?4ga%jqiyM8R{{A zr>AWaZthY7znrj9hpmBIZ9$0WZKvDl(IzWZzNOplJraU@N|{R`*ajYI+>5C&jNCrk zB&)GNKfeM_-Ao?$Y7pn06>vKAFkwe*r);#?Ja*UgkyGP?nr~g9UWWYBJ_b3o*LEj5 z=SC&XTj2;l1fntp`?S#4T(>?EPP8xtF08SVK0ntc@pd`2o1bnd=Ai{^G0@1yplhsq zqXH|^z;)yp{!enx9bOT=3=Vemf+1ZSqy7f&;i5_Nyeod(XkIQYuU1A(sdMDHXcGWS zLm5s~GaLrcZTT!}wB)dw8~3B)8Av$CY_!QC`rLZLqTKg80_CgRYOic)4+2FnF?UUb zkvEL;77ME~U<=+GNLeDE7di#)=Zrrezjk`ZisWO(%+3m5gYnhQK3mMp&Ajw*Vk1;0 zq#!lJk6zS21VRe>jhDom(Owm}J0>>Xnpw-+-rP4GS}aX!+wbK+}|uhAxxZ`t@w7=!4|etrC<^cxj) z=VbkfOJaR$dhz~m%l&Ut{3j~;e>ci1jWtbNb)=6q)1(kHI5HHZJoNav;6gDwS(`kn zqPc-kM0rRnTDJ!69+AbEHeC2;!N+s%-w#c{#jf!9eeVTl3jVbGjHj?Iq#oSe^&88I z+ZbE@@pI$jX^#`+VoMiBw3*ykxrfO9#z?vc--m3AVaDf$*>Ei>zPmmcz4HDWLeA}` zs_BzsCtQy7rBMeQEgEU$m}+$#A;KqKfY?p#@ge+gV%YOYjP{8i1$+!*2fm%LK@@W z*RKD;6KAyc44vk%09qdbV%Ey7Y)?Y!#p4U=lD_@St)fnqZ}uPxBzGTYx^nj0<~S)< z*r_HawO6hR3D`=7im71PAY<2slUSOLDl;o$!xgM68B39q0h3ityl?CU6lwiQr6HGX zu)|bo)@Sp5CKGR!R?k4m=b~_zsN^>Jbu|zbD@?;)KgKvA?HW{tc~I-><5>-?pYSyD zqP{7-)cd16$DinU7yg(y60Ah0u2vPQ+h;Q3slkX9xwHS;rWxxT_HEn3b<2J*KyP?{ zwYr$6!HF?~_`|Sip?Z6NA~=mSwcdP5rHPkkQZK*ZIeWj=v^~}+^gYSTtUZDmdj|_u zSk8fzQY0lIjKU-^$F_jTI4tLo#Let9kIL9E6g0`1p&+=%RBMy-qZl5_?8^{W*8&R- z*KRMTtESFt3i2SDemg6G*7*gUMBeP6ioPb2Vj8kSX?+2{#3>GYz~GN(>D>T@ zujEuok9X;st-ba$c4<#V6ux)>p0#`O*uLfI5T|EdW{7v>Zjbrd$1i6pY^ru7On0b@ zagCQo!2`Ln(cjS8?e)K84nhhcdDu7}Ts`x3TWov6B>{@ax9?|tn2{gRf6ITUp}(IN z3nj%@kj;rvf^1FRK*j243YA$6|k`kT{S0O8=hE1dX3K#5<6wgnh zw;JRr!WIMJn-t6tN!u*u4NAOPfY!eA{A>Qw0q$aELvFvC0ksBE6W4Py89QIk<%aY% zBtHDapOk#t_Z}+ry|4h6fh|;ftR=5wsZ)q)->SdYB_!I(Wk!wU>2tzTEIT{Vt?cV@ zh=QU13Do0M7UnzTzXK}1RTG|)pWQ36pC0u;c+-E`u!Nm00Ct~(PM-w5W{&>^3{w)u zWx$!yLKL4_3z~pBcC^Pm=Z)%6s~WH*usxeSspqp+=@RBB!(*j2d*z!wP?vdqWc2Ed z(B@7_-p&{9ibF4hC%6HuY_e3}MuY7z0hkD22bpl$_t3{-@BF@n24doecdGs3i~Kk! zXbgMl$ZEa}i*^`s={Qr$g((?~;5Z0n+Y~ubA+9~BfvAS%Q*h|`l4Ecr=lUaD#m2To zm^5R?6f+eE0sMt}kqqB)8_4qVir$@trwq2wezK%fJ(=$7_Vx#uM^MbCX&@y(v#5f$ z?GHGdFq)KnI(Fn(81%piK?CvH7xoVZRO+~;Z4~<5JI3@BaAs6jSHPcHPlXGGHdaW_ zx(8aG)XL?#6ke_Ql7UK@6PwiS+-Sf!Q{_k|pul4H?i|QFsJiRdbMHF)I|P4h1cS-_ zD{Bc2M`geKivA14zpqNe#`ZJz=c-tIt_t=4b}aw0Du0P>VwB}&dxemEXa5Y$)s$0C zlCZ%_@NpCoi7P`>k$G$spVX7D4Y{d4ukbyBzbbEYgrLa5>T9{}kNG))a2vTlrP3n~ZYmNwDDX+_7QuuEYtsqi>rrGQ%%k zhu1`CAP6FZWmRUraqqL)v{-1MPj6E7c^53=4&FOq42C z-f@LZPP!MVxDh*`P#Q)_$#x!@3YcIPI^$V)Ys?z%DCw()k}vEe&$@d=p21sq(-L*qIb41^&0aBT!4cvL}RI!SAldyIu8 zi15H8)I>>242WRyFpM^n^g`z~?KV+WR@OQT?~3{uqQkL<2R<4{NGkJH!(5zfJBbc_ z3OP!}yLie@n!%wg4=_|L%$ZKl#Ox-UBgk0(m|@kPr^(0&K1(qSlaUo2H&0YeEwf+^ z>b+G`V^!6gtN(L5&X=X(tq_A{o!3QbQ}GbG-NTys2bNm(*RWLhT#qdD(UO{zK~r-g z(RhO4z!>^XLu(UJUT22k#26WCaRx`D>Bv+PX-mI2`%i+|hUG&1zI|L78&6f)veeX6 zB&?Z+R(3jKoSR_6CN|Y9&c^O_Y?${1Jss2{k})wSCj-`!eokSoG?f_a`MLh(CHUP; zS0AsqpUvY_Uz(gLs2{5!v*tJMU3*fRTs)-@E8!<*cp;AWrgL2?is{$^W_sf*)j%Hm zVGmUi<9?!ip}c5wc?Mc*K;*Tq%#K5zPD^zRU1RF(L z@j*01#p2bG*SJq)(2aXTh8{|;N{KC9+kJe2RD4a!W}k>M(@y!ull~{c0xTqZZ!Cog z!sO)q05U#IG7{HO)F@HauAZ>7BK`45B$`oc7y_yLnr=|B7Gs!8){9kU#IdL74W6fR#i3!xUUzQkFawFrNq{~O>><}$q!`e~2u zoG*8ebW?2?6)cBQL-a57_MkIZV1#7NVoTAce*2)X>ZQO0)#E4mk7bR0XmlK!PqgA< zE6Z)VL9Smu!fx(2sBC4XSVeR)BopPyl#5n4Sc8G|z^o#~J?|7k`<>vx$;+0@H<9kN zN15&glH1f0^zy*R-B&YualeG+Q4`OGZHh)S)`rYnUq6ZxRowTZhLTum=;QP530QuQ zYLy?Y*;DpR<$^YyG+{Mj(yIV;*l(un<3jj#%MBt!zJRcTX|%+$6k0o{dwBYv$SCIa z1t=VS67QqTLO7XN>o5i}vAgg=YQad5xCVGpEjBp7YbZa`k0@v&l19k;Fj~R~UlD`z z)-ZpyK)Z%DAIaeB)eEP0^3ylB^D_~`g|?PwaQVxdHz77l!Em=a9AL=HmLXUPX^1d8%0^ZjrX(X z0T(d%KTYxCyKw=~k5R%hWt~H!yKL| z<=PI&+}FKK+JR9f1D!SP4L1m)ZI=INYjqnU(Xo-gc!)N_RHoQUeEGE{TCDb13#^e2LbZ!Xwe0S0WBI zfD8J_!FBkwRdLnoYn84Z%$=J5GRY6PjtwD{9cAATNxDNFsupL|MveX=?KH^Eg%wD8|l zK*c{Sn{?pZ_FBVjf(-Jgpd$k*!_Sm-XCM-fxAZ(f5Xp<1UAKJp{RPI_|4Y9?0*?e9 z89Be9WhwJlig6Det2`;7u7)kA5MZ0u)GpiOTHs=)S2PO#OH(yC9ch0cHNUZ5iOyL) zBIlq#5=5kZHp8yC(B%|bIt)$bSOt%f{S)+mlax`JJlf**Wqic=w#nKx^|I)&>riSl zeE1h3(0V%G8|BYl=abJe+c0;)37 zy8<F5tRAGDlq ztbPkABj ztDgCCOB+1@m1bz=B$d~+R2qw!)R%+y@)56mBJ?O0tC;z_X;rweZC6u7cALUt9+Xfw zd3oGK`$8bRxGE%{(P904Dm4mD@SQVN%V#zf2q`@dH5*!8`lQ8f(fs>BeQ{Sbsqnya zyZrKS)T&s3TOC=ae2n*KMVE(9s6KH`D;YSZX!K_R9vq8fq6p(y5|87g|DK~SjmeM% zK3n3PIoztM&|(ie1T&#c#v<5aEW%#Tu_uH9v_WCa$e>G=5+mO9uqKTtG@>=OU5Qi8 zPPa-K-FGk|^RsfiT8Eb6q7M!?*wq$?3V}n%S`l5^O%u0TW%j$0DLT7s7AIo3{<8tt z^~q9h5Qe100slDQS>4qbSxZLELWP4CGb;NEN!_aP`v4X&qsf#igy;_AqJb3N`ncVe z30`9&M$KG*0_Vk@RvRpP`j!V}xlIT40B^a@`Ic?D9S%XhQ)1dL%jhywZ;P@l4QlH{ zChLQ(^st1`pOPOreY776=Pcvf&P~id05NO-a8+#X=*~BA{N&~${|G$G?y#sSXmpV- zV+jw>mf%xFN?PK%IeavrrC?Z$FVx0#T*Nm{V=-c&gV5*&zU>1p!|pLQwWtfx^+H(d zCZTYC)NLBr0Ob^Oa@Jk9e}g)Ty@(0CNdM}h*~(3%D~72n!YJF_t0Cv!o|*^lzTF%F z>Kt@oKRqEK9JbkQ*Mm)FPrK;g0kP`jBTK5B1wdXrEr~sJ7 z{)EGRzy%ltS0SRxG~r(Jw`uxB5$|=gnz&I z)uMeb$uxP}Bj&$n5%+tBW`%#tAU?a&|Dv|?pLeDIdQ$%$@w)u|39U-8Q=C=$oUHkU zdvf>%mnwV`E>H+AIWIq)8QBMVSPaz^*&tmH$Wy*nbriWRdD-?Tf|4SJ`d_0p_L`Dw z60ieoNBjq?F8&9Z-jjBJ7wzRsWh+geiyu&9lx~f*LXaM_W@0YMFE!34R&_c7FqD() zYQYzfFI4gkeC3_=Ov^pO)^u@QDz^!zSG6`T`2&kJ&RX3{#9uykc{rYX^ zIr#__P3=z9-BS4B4V)7-nc1krgoHTB1D8pu;DFb_{1L_&-7vxj~! zUX7MX5}2=@4_PJG@Il76ZTYZI_a8vFseV+I->-pBZJWm+WWc;&^(M$B*NFbX zz82f;8sypZ{B82V;|FisA7sMsEU>rza-zVG+*9gAuiPO4QdvT)I4M=jvBOi4NP8b) z;~X`}x7%~cKn(#&#FgLyU_9xH<1D^sCK#BsF*bh*GnxpdWwL?Hwn0c$ zLvs0;ac@zPHOk8B$Sczccnodkr zNsSb5iDv!EwMEf%oSq>9A{!)GR$+y5N$)3e8~Oe(U(arzrUQofnZ~?geLF`=a6F~?~>`I5^qOFoB81N!D^6KUUgHVR6GAVVKH5ecXR>C zkKHFwh*AS!cSF zpSM4Bi)~MXpLJwl)yuhd_h0K}*Ia&eo^{9WW3R|(&D;)+G4H5c`8DqxL$}plRMym1 zZg=T4O6A-PpP>Hs+w5ckzHJNb=bnb#m%U=E<9i)>J2qEm-AhR96P$22oVk1bw)oi= z%uwM`I-c?~Gy?8WGnwXIrro;^J+>pI%Br$g(K~N;ebsU6*2Be6?Qwuk@mrpI9|b(< ze6{m2&-V0^cC}!_E}$I-2jeUJYzM_U9N(OTdS1#76}zWECX+~&-G&NbOPFj11+pxW ze1OqQ74(=tqf0e(2xY@7>!2WZs21Z1)^7fMBRdMB=Dt+eB)lL5WC?TmH;4lhL!BAVy&^} zPr#aMwZQakD$xW`L_*hCdVYxUn3|b~dpbSS2>Pr7sN`2_6AK|P49PR;k+YR}k@^R5 zX-et=h9Hg1|7yHkj4_}+nKn*cR}lKJHe&3mhJTI2zlDGrZ!*HDqhx08q$p8ceik=o zv4>8-`i6h?z=~0Gmf6~>9JXBqk4ee1;`nQCi(7iOib0hf=NajcGX!b}QEt?IK;#Fg zoB!d!h%OcXSxTFxf@lqCUaP`PWrdh55N^U-lC?>*msJ1HwU2+NF!ueE(c=g9JEL>b zU_>Mpe*?)ak4YX9{h=ZVgdnGD&FpjIS~LOb_fXX$q4G!gJbd_$Rq^IN%|eNO&Fl+4 z0B8SJ_IEMI1_%JM30;^IFqlkNB38efLKm<#>D_g|d6M3T*1g|hbqoV-4Ch2fy^l4W z)C1pPGVFY%romE@sm9E@t*FR<57AW~!fafA$uiaj>J& zXXB;AKU&m_ROKCJKY_awpJte^2v)ecN;)!mPx%TXpm}QONHEkYuu^4S8)W~7vbTWB zE6KV*A-Dy1cX#*T?oM!bcMb0D?(Po3-5~^b3l^N<`o8{q=5;sIGp}E*br+Yls9l%3 zr|O=nI%n_I+QFuZCZ$WYd-ygxN+gJZG~Yl9{Dx)~WkpCNi1Uf5E_Y_zj;DvGkQgAg zO9B{V*M`&?Dd@ZFdYk;heq&@6WLD%m%7|~EtMTCD-UhDh z@rDouMK2yq;i)N}@9HtRk$MO3q1}nB-UJ>G2K3$I|4u}5Qh;{kCC-8Ut{qJB;%xRh_Sy@QGeVNQe6^QJzZ

ZM+x{iQDVZRnLYbdXrQjU&=u%hsN4|smH&B~F zl9&;!OVFi3WD3zQ4LVBdL(o~|cH9FsJF;ercBChpx%O(MV?;LbB0l@%fAs}pz_{r# z0Dj;jA`lSoKe1XV8(UYK-+jT~Ka@&N`cB5bdxh)jN3O^!C~uu?r-esfioO{{^p#dw z&nEf9gwJa#P?^hDhztY~V$S+G6;DZPBCxOBp~k5wC=8&^H7ncko(=o+?V=< z;zNM<*-26bU?p4017Y-n0GT^U$in3)LKr5+RfKc;*uERo+g%7~JAMRsuz67MLA4<8 zzov)@dBTTNFE0tQ^~Ms4+@R%tT|@?&x<7Gl_;jJrZ%IJW*B?qD=_Fr-f3f<=_0{~E zE7^vGq(d^XDS_g8*%~8#J_)c8Y5>zDE>1F&QMceJYZ{98uuS1($i=!0wJ~EaO|H^l zP1vJHr?{no%=86UkPB{=GDIH0A*v3$ClNrRtjC?7Avqy3pAOO?gKYe9=ZwVP&Q(aJ zet6kIe`xOO=Q<7c;tN{$_dGBGtMabUw1{%F6kJ zV<=;Dkr?i^9D9mko~Eqw>d#o}57svg&7ACcoE0jbJ0w9ja4l^i#G}21LlmfOlr-|W zi;y&_i6!gNCS}p1X{r`nFX>GS^iuBM;G7?ssUPZ@dZ#go(JxOKKv+?lb(oC@8!eq>W5#H*(LQEHe$=8gB(2_>*YSHm z20m@1amL={>u8c2DpDsbK&)a~sZ}oSYLp&w&>|{;Q1Ba?eM+1vQTc3`o&!4me7a9^ zO1%MAJvYDNEV(vkHOPQFsL)~-Zb5OxWtR8ZG5_O&%}V9qNW%+9&sitkE*uVu`m#C2 zN>6SBEpahyMKhCGnvjQ91hs2MG7@*x5gL^3m>Z1kxOzlrq)_OX8-xPXIkZ+L`W4=K zGi61`L>}=|i=>Dw*OOOjqv+(@PHE(wop9e16JJjV6JMV|IVvXpE;6PVCk8HWSz&?F zph@HESgnaU^MWsIj^gR)eI(;O4zW`0-I&-AML%EgF47QKqSqkFE=(pu>kodN`VXhf zm1mTKzZ|}$n>x!tvP>2afzf3yzlZ`7W%eYhczms4=JvW_Uorx1?64vz*FdPW52+m* zi{avqj78R|#D>d8<`>l66`7G_yDcj+(nsb>VB+T8ywaUkU|CZfesX4w7IJ2qbI%o! zuImh{cnvjPO;OhBgXt-Vk+lSd6qbe)RcBQi4xKEp*5#o?Ga}dF!k{;4d2WzU^Lysf9|L)HF=YZEYU0dTW@1_=5Z~y5wD3KH`D$yK0ekO^fexAO~L$t>TxAV zFds-}dk7IFa1aB!pBzD*KR6!|B_utHteSL$0{z%NfkS7(}92TyLX zl?=WtJmKFv)tx?EJzjD8(KEVw>)$(ycMjVxV2pLy;0$(LySU%7RYhPAGj;|OX_SYbpBRuc42l!-phN_8Nj!up>1#Y)etTxkGn}8$5WoMCp_3 z`V_N7?=vKE3Dbq%y+eMP5upZ=*OE|w0Uqv1=%R;cGawUqEYVlHIJr!m_=Fc#`^)~c z=T|Fc%Y9m1X#FY5g7_hK5E9h!tKbdg$l1;slS$Vke4fY<$w$T3y0SJZc@-9Ldn-*0 zUHf&-(@SF{g&}Y%^X+Pzy9mi4Tpxwe)>(QgOxHG%!HOvPb!xo?OTu6@^kM_5j#D#H zNc0&m`!8?q%h8shyQ=95Xaj=j=MZmg4Y=GOdGCoK;=e3U|F->d2RLZ_M=Mbob4N#j zYxw&|7jWGEr!Q{SzxQEWvDX)zndA}h(?E^kN7#fveL@}#!5~kc(DSdMt4w2Er`wS*qqT zxD-Xn4NV=oB5cU z*KBdZc6r0#sWTmIQAh~md6mdfG*64xB2pBPyDnQ_Ia<5v%uIshD9gjJOajXh*g1t{ z^<(t;Rs5t#f$}esHrfMrjC?INWgl`Krb1kM(7GAm8Q>M&JEdrK#{vD)xwr?u!$i+J z1~CvLoEeiV@wu{FEg#K@W6y?=DU#`t6$`^KXZ)5F^!OoHOdY~k6u~Azd;B_E z+HCNqxpr%us=*mMV07<~))FJ`qL-8)g)saG>%*VyJ@8lV3|r;+=&&)G?T!#iNU{nc zN7Wec{Lh1-$WT)qBJo3fY{nUv{mDLan%L6{)82c8=HuwT+2&NQEu)hxso|S~1_RT9 zr1u#?x{D{z$H>)gd)E@inCOLs9`G|0CGRv`oAcxM_Q85_&BvSZ*t>d}*oMc4fjN+`>crs2PN*33oyS;~fcCTEBKA_AWUkv0CeAcrAGsouCrlrUY7 zGtPsyX-ALgw$o|dO}>3CVK^lm6*QFz%YeMHz0x3U zu-l|fQ>zMnT5@kJ-EzKy8KjOaR*>c_4bNU5<4;Rp1}Rv?yP_i_6OUYOyA4sonek%d zudbMQCIQ>MSIDT~#*@`bbx@c~RxRbhZbKC^;joD(ShlLI3`OSZzqG z>R2u_2`5B^(AJU)lb05Xt#OeCVo=*xBIsIoc8zam^P68%&)vv>MER*UujZRnW?T&@ zYJ<)yDvN!Pz%^y8DZn>%S{tej2g8j}SFEet{a8Bb=r>r|VFy=d13gUJQsI-XU#q5G zzHXSxg?Z2$rvQH=tLCs~n#ynd8I$a7&rPM0;fp?x+X{2T28)=?LG2>3z^+{9?#*KW zJ3vxr!wTCstwxevC57uIbI~Gr*J$75kS-=`%Vn%>{guAuzRQf|x!cCmbpG)La2DMvls&nXmi@NeH-Bc#9|x=wpWI2#oa&BurvxqldPC9SY3m zJ5RlUp-=@F3he)6?e+Umc)vxE^zT8iFr&bRQ8VTxU_S;O$@B>!9CFGmnMRLEXlIzo z#zbN={`RjO6c_b?)m(cWA^Nd$;A)cBuCUH{J z9A;Q$=?q(TY|k}s!xN1{%yJIa{uNd&r4yl|AKlEn!4p$?wp=cw<~Uf@+uU?QL$&_JTC3I4#xl+J>7unv+bdeQdCvx`FQ2t$41EDV!ASZ3`<3xoQv8kRRlDvGS6` zX3a-Mf=A6lVD3L;HR(gwh>gYe9WnL%l_%{jTT=fYqm8cc(UN56{K!aK_z z<7Rpi1}O}^OToAnQJ&soj2ZsM`{IjBbBNO~-m)-5AQl7GR6X@V0I5CP+p)q1u5xy) zmQAXsk6|5StC6Vm3BBa9r2c?<{bU_NR*jqd*LN^zTeT8VTEpxOgBPa&@Izb*LNd{4 z7oo;kv!d~!fon;) z$R1OKw$m=93x&)igIz5QbXlJ`yFwRYI1qh@8J_$oZyQjZDfK=UKp&ymv@mH5;l>9Z zfUFIIKFH4Wp2d+EH&e7f>AO%H5$Y6{m`=^GOT8f%M%Qo{a6u*`c58{(OIp%Y!XNA8 z)B)MWnSX%43_T&D_nQ{7u9|HXI3}5=iTdDfEI}t*d`wFh+XnqY zll^2uw++hQGZ~Gr+SOofsLx=6lK}Zv1}rDgFA1*1W6CS`F=A?3Ql2>^+P^-N!S0P) z5*ywG919;tZwLFJc2Sc$QSV3)g*tqXcE$)yzavJxCc)s99dyR%^hBvX3oS zTyC^q(}<{|Bi08A5Abc4%qJH4ELLPV*h64%QfkW-$nlP{@2O4|%b7Dlxb=ahMm$QH zap=3CgTK!ejh}tGHXC^n(K1*{=Z6-u#v84gL3YvarorJxZu>byOF$A)*LVj%r3;Po zLoxp51+9jHE)wdZ4z{(CEm5g*%Q?J4U8>IF7wNbcGa^5!6WPv*`{mD61~j>X7Ppk- zPPqsCQeKLbykCg!i^I_RVRl&vMQg-=ofEZ#LqKW(b7BV|i{l@iP5%D&f8RX)7j>4> z>2J{kysoSD#u}2ey7?5K;f*lHl==65;d7}Nh|=<~ukBXs#`f*2Cv>9tgX9tz7(yPN@{BH1hr>(^H#b;MFm z3~Z$x@WOHxKG8yu==WRhC3aG$1IJe zxvR-L2p4QLShE7lOC4=mbGFcOvIV#4V68CP(%Rk&BDN%B%CzDl2<|O|7O6ktwe9XA zZ|{z=;siKJ6qu|8>-f1+yvJoSShLushDxgQi=Z*!`N+$HK&hd?RCdYk;Xp;Fgv&d~ zpk1_mk=VxDZ4f&?IvfJ_Xe6daMIH!4N2m1W7iIFETcTWpU}8|J;fO9tOkTw2WZd9~ zt7n=bHRu!^@zsqcXJ7W(lY{7`{!cJ{k>WG~ z!_nKwIzB14VVFa(FO}=l_f$Th)s(UqCR&N}gjd4i+yv5CeF@lDUl!SZf@)wzWaHF1 zVZtD%710K13TwTY`(PtF=g??+j8|aiUy$bdF7Y`t_K>I4!O`?zr?gHKd;}eSBB)Cz z@myoHjP8PaQzeGAP}zJR9DxE(kVQ;o`j~f~<%CXrR1&MmsHp11w;-)k@KwUkN?HbA zV3|K7dXs5AR7e&)-=KpN0o9!oAx~xt4QZK$Ouh|h$LE)Nx@h=qaVuHaia zx*aOksgYl5$$K@ON6&?f6oCDE0_^|)hkN|@hX+~8o4=jXzn)pQ2p;JXNsB=ELq7Q> z0t=2n`q2<-Fbx_73vbdDU=Du&%{8FD_>n>Hc?pIj6WR61j=9@*Dr|ok3EzG&{4&M4 z$;sWK+tv97sfSp>^%yssH!dWkBcu=#E_Ri=s5fRA4}&F%g@ze_+-werIM23yGThaP#tYGd zFF?Urd%T8&2$H6+YM!UtoXxxLT-~I&4Sz>b_*0!N(lPCc#xk-znS9_7^zGqQ%bS z&Dv(`W$ogMwGLP&JpyAr%ox^62CLg2>WF?S&LHD(C*Sz$zNQ%DLkOy7vM_|h3O%}R zz*fAq38}>o_8VZd*=WKlb-qEZAP+laYztgFm@S{(h4+5o<;}V^_<~msO$Q;hK%hY; zp@~TXjlOj*zKxO3Oqr!6knThbz6CBykPGgwZTA^gqS!a!GmtN%5c} zYDP!6KuVmV*@%&}*oCmj{zzsBZck*6Fkd5!x_};4 z&bxJ>_Q8+e_1KxGHtfGobDRl*_i z`GrC+wGk>_{7!)#Y(oEp`>!*88w5!$1i<3k0q15+|HKRak5yoj(x&ZqfSJouqQE$U zwUjw3tjX(HDc_keq>HmK60Ram;N80T1v^u=>^Cz%@;~fEkn!C^+>2pOTQ3_0fSP~L z#=pxv_d3X2-SqW&{a^>QD2m3-=CCwcV6h98tqC|MLU5q>J{qopO!L?c)N|>}6H`BZ z{LbBhamRZja1C;s*uMPtcnp2`4LLi&~(j)V+>8t;+5X4NpSiYjw`EBjozv0&&_p)gK(@ zY%-Cqe4H@j5iJTerUnpI1v!IE^i$*|Z!A0H4p7pRT!$_9L(}0fbvvzVQ)IBTCBZ%L`z@gSbEQb&@Hw)f8Fe`n;2+*%_E}u0j2ulJhx=a zN_&D@7ZV?Zrf-{e+uH66!u2!9Ga%Kj_W1|YYD7l6D$P3h9Ru3smbC8H7!hbgpRd}- z$2z@3#0w;wy1n`zQ3UNzAVch`uuIRA=H#3dwK~!u>eU~}m<1?-sT!mORx*vv4ox_J z;qEVDGgv}Rh+@U}k*wfW`eE4N-XU#0Ed_Srz*jG^B4=!7Of(m#DnK8Zjf5l&pwmQ2 zd}bb;-&0<0pWJFv)CJfPXCBbAq9T9dUDvwy@yj-b4 z2JixPd3)ptg*AiJr-LKC5%xhgpc|G@<5k2opVrAB0}Pp#mB>63p`LG}5rgfk+2f0C zDtX?%1@_jToKGZSXF_TN_>u`pM1;(eP-w4sox{990;*}5RyLq3uejuaEjM*0R$@CoSW%uIIW#&{1>a?O^5V)S74=!U_hbt9=szDlAX z=O1ch!c&mYC@^QVNN7i)?>eQC%pUl*IKt zVjOr8oKpOes5r`a7{13PTKT4Tcv{)fLS@j7^c!dJ41n11d)Jgf(j_;s{)Fjxe!??@ z$WCey7TQ~C1BZ-?4pB@XMuvtKJhkt;-0Kliq1GZKARq;*{~)dX+eO&#o_CgpyI$ga z(_7ZWl}wkHl^;+64IJ9C-@IP#O&S*PPU=RvmP8E3cW zSxU=vhaFB2jXNzmx1A(wiHhUUfbk(KC>hTos|d;Pz(;$`9kzi4avetL)E(wH>bBri zvS2BlY;`6Yx!`fgd4PgzV%TTWP4WVn$YjP~lvE6ILvJS87rYv*?tG46;gZbb1SkuW zd<(L&v{63FLOO?Rxnc~ad0|G6`6-cLlne@i8o4P``dMYAd=5z!rDD)T>NeE!vcl|- zo7X&L@tEb9CL_|w^GxHhFwzrA%fSIMowTheE8`WKnAvGx;3kjdrE3=MEYtT7cIK>g7ALut}?IfTES1R{Q%_moQDb`%u zT#Q=Wct#Og%CJ!Ori?N~7siR@PFTbv2`xPQa4=rlnTfTg{iK(?0^RcsYMS!@+Y z?Om^8-uJ6@Eb)ugFNp?CE5-q|PkL35A*YA+@&srNhW>RGtGm78t&DhZ!Jkt^T$&*A z{oF__MqGM-82hDm65%xT*Xi-NMXl$EGko8cJ+MTL?B?lU##zR7L0bgPXXIYNfFH0H zT4~)aGSz^A7Bx=WAfzaTA2L{5(Wr`Q{zSsmYSZUaUKPs^_7Ou;Lz@(iKiC_>d=W&H2i_ce9W6}l!hGU#Ut0K~537P~S%=yPun@Zupw;o;Z$8}Bi$_#lAIQSt zwl^=&IETx}c2j-FfvkcT4*2P6@Ez9{M)4|9PGQlWE$ODQB5tcMUIyfp_LN?rp{Z~* zFR)|3D~E+V0>fW(JsTkXz=hbm7SB?S%0pjt|E;;9u@7n*+63OhXyyw?2}%vFjlR_{ zJyixsqET_BkCXXblIZ<}=@J{_2DWOSBu1dn7}38Qh^_WNXXd0&u_PdV-`K3BDM^}i zQ(`7#a(LV-HpSv)V^-%{O#n_fWvLJBhCb6rS?EYO%G07 zpi6})iR6b?0e45LsxS&9u-vyc=da2v*85%xx619A$Bq^OlqC1QjVh zh%`TqPe7Cmr4;3o35#wtMS}s2aH+_25lg66QJWWbId15uir38l5^Ax!ng%6%i)dOY z4!$29Cj9xtjA=Pjqe$0tZlijdgp-*`rdy>qRdKm#_Kc)M3mMYcPALXAT5SHDtAu`J zV1aU9p`QhwnzlxUAT!f%h55{D!%va9~I|G+;^-G)Mr7rEP@AtsiwDZ&!?Wg6!BOU!u zpmY>U#nr}8NA;`%%Fp$0R_U8HIJFR%#R!gR8ug) zeVn;G65**O!uM#glV#8oL*inMX{^bD=XD??GHMPqC&PR&uG=;+y7C2{m!t-&n`kMZ z2G(msu^*+XB`d(EVJ>P)`fTJJEM1k;lE*&$`k zW_10^UFs~3UcFxK7FkXbZCDZ+1*RlL<4UAW4bgiv{^^I0L9ve7xCN^20N;XeSlbxw z?071Oxmj}M&CmQ9@ws@2#P7S{#o`Qe`SoIEivd^0Qe8w4G@PY4m$4@;KPs+jNp%yR zXdk#rhl#J?b~;Ey5*uG3I0#BV$kGvm6y$&F>)zR81nx(w4o4LSTNMKaHEdwM zOKwp^ZIG+ol1*B5qnkim+i*O(3fmkFOkjVUn|^Ll5kveCHi0b%=j_S1fgL}y4m($d z4ONaRhZQFn*DYBgo%$cG9abZEDxxQ-R#^E1ec~K*8cR4(!yvs3sMfYHf#$L-OIk~7 zL&%mUp@SGX7WC`ZS!^##APbycLOyz<)RJ*fq#5YC-EA*lR}l6#YAIRE*S;22&c&5f&Npv^YiN`TJ>{K zB|iKNeVrAMRWq0YtP@`Qm%PBB6z)pjNJ`2{)&A%;)Wfyn?CBY|t4>w<_#(QsQa%K& zbwtR)M??}ie^6?0j>8)E&8^ebwc;s8_Jumy8ECV#~bcps}wF} z9?>2kTtZ>k8pb(A9}6&adEz}#QjAo*-70WRd1p(yj^+djKW`_p8-;w{wdRsO`qClZ zN{A$jw)*z*|WEG$AMZ<|na#c!PNWxib;b zlb`6-!mOo^jVd;@H*`G%uQXPyhhNN?xb8th@YSLN_W}+aS$A<$MakP54H^6l)JB#| ziRh1Q?}!`VJ=mCV_OI(D-GXLV_$|8UUKtk-hr%Jhob%3cvwZpjfE*stL!p+DTIiE` zR)uiuntu$=OuKgghhU_KsaouhaFO~6T!hpS03*s=pwu0}Pg>IO z>cbMga+G$#9 ze&_=1t`a5xj`T8F7>r{CQqa;F0iJ=I8ix~;H-@+S+=B&_pO2iA69pKq@D3RsdTdF& zF`0%V$T)t^p#48R89K@;{m+vT;r50Z;%gvVHoajBKp}qMvW}s9;TKr)B>Bj(58=d? zJZC@q+eGqyiQ~msEL0z6cN*=_ymj5p1mOrt^nnkXJ{=0gs@YtP3L|OF22Eh;b?P?# z(PtxFean>yR!E`T7`%D$E9Hr5(i1O@j%*fX(kZ*x*%PS{<@nA`$tfXca4vv?z!|X& zo~Q<5kSF?=E*VUiMaP&`_Z>#@-nUJ|BpO=-u_|1j^jK{}Gf85Bww8JbQWWKM-GwLz z5v`3V=y|!)%LniEQl2kf-Sp;kD!uC#9v%TDTrC7@ZIwR}_P)346bHorfO$w*fGZ?q{_|~0b6atm=;bA z7o9V}Ro!uDK1S>TKN&zh6h^k`6D{s18(KHv38!_#Q`>=93di52dJa#-*Ta5|G`Y?f z3GPj{U!p^vp$alfP&|o+sZ+v2jF(v=ykN6JSSJ^Im6x1xa|c=wn4IN68xpMS4`Ty6VoN@JTngOcp4anJNO=W zHuFV?Uw;Y1@F&;p6Z2i!yugB4_1=Y^IHkE$60|HMEg%114zhjY`kGzbwa$sVhHiww zvW^@D4E+?2_`wyG@RHJS_)lg-uPi)FNG6b`4dJoCL}vw|PYt0<5qKSkp|O%HHg+}* zg4x8WD!Lo;?j0+q<+mtq&}$*7b70vTtQ+A*E;_M7$R-DR{nmIUJx{2^3}WBpk9rV? zRLH)SYU(SCu+yFVd?~G@FE6?1_|$!Wm>?nCgLzWn9&U+AitY9j8xu@&bCTy$B9i1l zOJ=`MN?0C!`zz?M#K8~+%CA89nZBk%x3te+p{9{<%Gw(PNgi!X_$aP#7+rOGE3T!l zDznm%GZjpEQO|V3Z?N1Zdyc_3^r)Ryhbg#E7TsP2eUckYY>8Vp-Q`@S-?*|zCzIh-5% z=)Mk$*+aSJK~pC#Eyk4?;|Iod$0OVLR&VkIOKFGufD?f7C_eeZl=cQ_hNf^cggv29 zyPPLv8+@Vt!ud8sdkW9-We<3c$HYU&zK;7O#J^y55Rq$;yyZs3JIER^Ri!S1Y5Ft1 zhqoB9ZzR9CiRtvm{E+FOK1U!-5Pu{{-n9;jXiZzHHsDV2 zjK5b7^Qz6^gKvzlUi1B)`*S2#D}xkX-*nisjpi+qPu?#D<3+36=8m4BGO%64{hV^EQ}4Qpe!1%%^nCY#J8{`2qJIX2|pNczPVlB1>us~*i(TmD%I+&DGU~t|-?|Jwv|9$~|$)uDMhqzJk1!+1rx7 zMvzy@+fe#MZJI?SGw|IOZMvkt`Z{$2FJPU`Vi<3=I6w!xK&;=j%az7C`o3hdi=o?o zKG<(fDJk`G=;-L$xhGO19Ln zfsRd2IHrAB%n7P`Ztldcf{`lP(HPogO_SbL z1gVPe8)}MFju0z8d~V6mH#MchlD2zV-aGCE4c{J@XZq@c7212`mpjw^zTts#xzrSF6{ zZp!EtnHGB_bM`GRA?sncl6xG%rP!8Ff_K^C2HI}Q?BsArc7ySZu2p+l-@@mR!i5*2 z{rqxYnbR?qc78?d`ni_0Z!{tO2ff)M1E0Tqr_izb_^U-1Wx+~BE6 zcSvT|NsV(xYxK)aCjRg%_$_;Vci3_N^5%pO{nO_)&eo(C>%#7=mjm$@&5rxewr6ke zvep}D&R|{uTf~Nd%`US4+$R3Nvj(GoC8z(!8ThXwX0>Bo95qZI6Z(mIX-IiGKe8jT zy?Pp{ZzL-~lu6$P0)YVPO(gS&fmt*OblgU+XhN1UpQ|*_U1h2k%iY4#=RhSdZ)JRa z?ml#JpPzOEafI@V%=m+$=0p;G39=xu zR~a-w(Ko%!bmOVnQBqLm=BA(9nr&4LK);N4>!{persBgE!9~ko3RAPV;M7vOe8BPo zt`WTuLDdcaelo7WvO`VPg(ZTGMs%O<=F97E8+ykcG}IEf*J62rtA#v%4*li4?A`}- zvEZ=BlJy=~2c3%_B?doi_?XJ4Qm=&7Hba%o*UJ9;RN69&>k!>BjE8P78?*QB<8!Y6 zPYLF%`BT9udAqOA#|oxtGYv<45PEhKV?|HjIeC*9A5EA{HjzE(Yzsvz+c%X zEk&m@XB~^x+cV}r9`FcKC})-t=rvQD(Ok;nnSAE-ncXMNk>D=Y155kt_GcK4Qr}YkW6{CrHk#8tm2NY;T+f@F4LP$zXYvG z4I7O*Aw7nWrZ)Ku#hg--?4U!kLC=%(VSi~$Si#O|6|GB0ZTjbf!3^slHS51+6x zXR`e88SC!JpR>W%ai)t{48lI@2FT`snWu zH@cx-W9(Q>uh6ECOEJXx4zF3c%uyYfhoF?C{q~{nLHf+$#4ebTz6yMo;N>5WUi=mT zf{O3PZRW=R(Sjo~02*)Uo-1?wD8gS44!;M2lbof)FUL{c>>kXgOdqOS5urV2b7JXM zedfaQS#;2L86l%h&0eVg{K69~WG#&o;dq4HaIYn)LCvQqtdpsS8J)f%mX#-{g!LJi z-JRc>k=reg#1PA7TP8Z14$hRZOdqs3n181^oEwV|IKDFyb?PY|vsYH)I4xgoxMm82 z4!#{H$3PqRp;~>R-jH$^sXz`F0du_EO{$;D#?lR&63((!Tfzp+@g#2SNO_H>9RwA0 z*FiXAL)1}&JV`5=s$?3pEs4$QR9=;COzf)=NmIdzmhJ6aiauAjh)be%VwFY`kMPt5 z@ulR&7_KgSIh{ruXBNf_pY_v(XMoij{o`{-oQySW*Ofr?4H$A-U464n_+f^Z0Rkx7 zql_YWHky;uBj!Vp#%I1;v*|EW9J!)kW=v?=BSU=OvF3{u7f87L-MrkG3ZRW)R_yi9 z_&bjm#lPL~`(t&*BbRi#vf~6>l6ThfVH%$0#)PZ|u zU;OCrJ0u|W3K3$AfmB+b(DC|1?!}DaL;E>II}~6Zj|lM4QE8%r6T*{d8lkJI*6?Gf}Qn7nk{sf(6}ABonW+U{z&}I z11r7aH8S}~&mXpwdWn@27s((BrC%@-@{+c3Bay-X<8Y%;@FB^aq0 zmbMUf!^M`H*~sYJC-Dm!M>}(Tb_8oD}BpP;$I0 z(*}~?@$&Y>7$(K@wQ`1;rRPMc0vE*Am01Yg;NhtFievBFL(5t(@EgCb`DRLH?$h0s z02JS~at<{_tt1iT3~s^f`VBd#PyqvAzZ*I z$)h?VK;koP{7>o48=4I=SY=6;bl`QxIGha4U)Hza=(#6e-UltYh;1}Md0Q>;fV7^SWHXG@gM^MdWWfm~ zECx|%iAdo(Gf4I$W!!DSxL%G4CQ!uJ`m9)5f;~vvjl38($8qEy!@X6$)jPc#fq4ITTVe=a2PqyIyl9=4bpM52}wEXsl3PdJjw# zY9_AAs1eZHqVK8*-hNtqinLvFVYL$hpIQnkF=y(Vcq#i?PlMz#Z#He!a~cr03y`P< z#IC3IC9u>}l&6Xl`x`*xwq_Ua1&5E4T(cmxruEWFliGjoIxlUd-kf!4E7|D^hk!=< zJYi+0CeYkC+MK#^5m=TIcsxlVo)o0dShH;hMogPy8qhFGBSh~RT^pIkNhL7>E#>A2 zogZ|m0#+x|E;)!xs(+ahwZi49)8L#y)E2L;zfa{D$P?0=+CmsAk!QpmY{OA$;m~OS z{etSKrK8VD@x-;Y;T0Bw=TO=XV8 z>p|ugJqKH%ijGsDu$x?xTVls1#T9EbOxfmpDP_aJuKX#vQze#e6|ST&2Wr%13+E^S zNkRzT1Jx<3R@)AznU>P>P*@hAv4R4d<)qCfW5bX@b9w*$3Hq*%f*5F0&H8Mgc6Hpg zmNwgT!DXWxC!v0(HarB&grOprUz&XXL9_o_c>RY!u~b>ir`hRds`(3yUsz})c{6X= z=ah*_H!?be@T+n$!Do@wE+5X5&5O3j6lmCWgK`rqqrdlPf}{E*bXD|em(O=vYvuV; zNbzI9Nq-eTr{fa&7R7No>Yzz4Z}d@N1$cRfFL8&E$nq)FN93d-$2(5-LD!$kKzUY- zn|5TF^!n)@q!q{DG*EqZ&^Giu{}dstDf4U0kLexsfse67dH8*Hj}$n(pUC`mzulHH z{d7Gcjn37fx;Z3y7WgUOBd>IKRQp80%P7oMluq~~tn5eLtc1xR>FY*aY#=_4jel4O zgCDCJg-cQwgh95VF!UnH$N=yPk=v}r7zUGY<#fr(L9m+xyT2tL+}BRRonNu4ban;W zy>xR+V)a|Ib=O~Zg^`D~66QFFmffKgFTx_<-jRuFxeN(<0YZ9V03p3xe=|lLY%Pop zo&E_Oa#p;QT;C^@plL8rVK099{``|3&~yyvU1Ehu>U#;${Cl0cWKU!GC4P|0gI4x`Wm3yy3e1`u-&cp>ypGMLr!sAAeWI5p}j@L)ht~D zrIo&B)~+EDcH@C-SKDYTvQKGBaZPj^N(%p4nmEkHK#0~~_s zD1E<1nuxpr9*uMv9Tbg26`~tfy4T5nvk=NfK@`H{w-RXJD>)x^3x$qbU9}YMbY*g^ zLnU?BI*$vz*;EXtuCj4~rP_%bS+Hi#fXC=NVhPvR>-#avjw2w;6+*LalS7%o^o$=1 zQ~p}Ncq${!Ix%wUls6!ILI@g6sR7v$7p54k1h^mq*$Zl%Q7dNqTJxtpIIXwPtnQ)Y zhxBZb@vuXS59w(l)KH}luH=jUz!On-$!URP%?y?+HO7H%BNF z7|_UM{x$tJnc3Fi+tCHw18kK-03StUg_5TcIQhW}HCKedcZ`Q@8p>$pG4@mQ_^^2H ziYeZP^g3d=CznH_;<;l4mk^aYi|jyUX6=_Ag&dgGMlf7%GtH085c&i&oycoqgqYyk zXJ6;A#UfnV*p-OFkw36v8yi5|dXKh><<2ZT#W;z|gm^S_#`?QA*Ejp9ds0w3+DYrN z8`IT-N~zMo-7BlRjpm2nbSIh!gDK|%iF_y&%f%UxA67&0+Xa@it~T?juNuN<;S@Nv zaI0#XsfDYWb?i60oq#i)OUt)G;CLQpEnC&jr4#i-nTzjstcBpb*-{w)5H^*+Q;(HK zg`DL0ME@yU#S}`CYTvN#qcJMAW55_SV;A&1=oyJ!ao2U@7q;%aGG6V11G?6UB0{b~UHBp|?2`2W<^|HbDI2>AHlT>g9S8T=t3ApsBqfa{Nf z0k}1AHn%dObuczGHn(&7vnqfTE!EV-^e^g38A;lD)){6NAV53{1SDukx52+3NL~u~ z0}2q}w?AP6Oz-~+fN}0!kr7cApp}pnrGH;dKJzZ|w{S2O!1WvSAB7Td`~Oyx5s;M- z6;V>AlM#K7@LP?4Hw*|_{8LE>-2Wz0@V{yR*oXd9y8cz;U$O@Ot0MBBssRBV{k7u1 zBp3dpWg-q4YBqplLJ$4Brkb-@EV_7k8}0q_4$#SgGQ z^S=NA9}YKn0cR&O01LIb;UC;7?^`&A+P7)~F#E>f0s#^J2_Fb(2Vg<}qlMqSwfAuD ze$x4Q0GKhr^&3U@A7uex?EeD}@VurD#*U8C0Ihdpn}5qsyoaasDD3Y5bY&Rq@0k#P zzz<>mEj)mL+sfGyz$7DTZe=WBXb5OQM&Cx?^uINbbvp{`0qF2xK!^XP2lz*sCHUJ0 z#2oYi+Nml4o=S0BYh!6!TT5rVzwa8d?P0VBfX#IPIsy+nWB@w;gEC4^$5r^r`?KjN>n0>9T(dCJ#_<5pZ-gwl)Ch<&sF-8tPjK0}R%| z+`#z{miPBY`(Et+kB0K)|G!)L`)+uz^7{woi`w5}zV|);qWSy&iQlVY{((-d{kQ1< zGSa`%$b1j|UX<_;Xb8Rk1^riv!uP1}Rd@bC^)mlQ8a(d-e**wm+5eT_bawtIs{p`1 z8SQV8pYJQbSKaxeGPK2iRQ|W{$$xhS-^0IGQuzZu$?Ctt|C5Ep`-a}@9sJRdy8VAN z^rz?lFX{*H;olSY{{esI@W0^S`O5EM-}BY~0W0hDzhM8o3Gp8DJ!kPBnAslx3-kB1 zjQ=(>zGnyi12x?9AE5qsuHgTtk~2n8Ac%tKBpzaqu&Hekst^n z8Y#wNCPo7yW{a0GwZ~Dbd9B@ljip}u8M@mVsR` zVy0iH{ltuN`^&dq0!RoW(t@0)W=IgDB85?0QT}FTiXY4+fLTWmu=pn+H8FEfFvh3TTt b+=;!jU|P+J`>$CfFsoU|bwOU-ceCsYH7qU$ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2d2fd7c74..1af9e0930 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists \ No newline at end of file +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index cccdd3d51..1aa94a426 100755 --- a/gradlew +++ b/gradlew @@ -1,78 +1,127 @@ -#!/usr/bin/env sh +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -81,92 +130,120 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=$((i+1)) + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" fi +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index f9553162f..93e3f59f1 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,4 +1,20 @@ -@if "%DEBUG%" == "" @echo off +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -9,19 +25,23 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -35,7 +55,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -45,38 +65,26 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/src/main/resources/edu/rpi/legup/images/Legup/logo.ico b/src/main/resources/edu/rpi/legup/images/Legup/logo.ico new file mode 100644 index 0000000000000000000000000000000000000000..746d1ba26f98e86c7e21a34e941cb51b7277a473 GIT binary patch literal 2174 zcmb7G%}*Ow5O;4q_SAEZ{fnwfJydFxgr;c%0c;bDzhM2fw%1Z{C}kH}ih;TRR+|(f7(14*qoveeQ64 z>2Nr{BDwOfuwFj2cJb3{weTrvx7)C#+wID8r_(vt@tQs7(H7Q!$~UjCt*xQiY+fq7 z)@U@ava*8ZbYUZD3IeZOM&YPmU zGxRMi(?DZo74Gq2xJRzbntS9L++(+}MzN+QU1H-IAHoFrxO@8sYIG+VJ%yWBzs5|! zgLOKi9h*mv-)?u1R2AfP1$sh(k&3`GF^XJTftd;;tE)&v1DKu7!S8V)9i2orO*Kx2 zks}*Toq?)G5e9a)MH+BxhrcpT2vC-Q8Wm^eo}3 z+wI`}`@g9UdBHa0;Vs#)?cSqDI668KEHFm+&bPO>aeRC%SUf#F#b0mU;LksPC%HPix3$(}XdT z^4XAHn9CbTCRC{j*T~4EQ7YyT4ERwb%yUmxs};F3L)TzsG|8X)iSIO>O3=NS@cX=& zpR>R*c6J`1Om?Yc43?21`zqDDi*RTfKF>IG!s_Pc7E)Rg(}bM~*BI1TjLs34Ix0aA zVag4+=%aGC%s117ZJ)<^9)FE+Ju~ei%umwZaYPg^T;q2UjYh;a6r4oR?~z{M^C~mb z@K3psN@)_GF%zEgAr?8)-@bK2`rV`+RLF0HupIDCVECsW$R>r*On`dWCH1#?CK&KR z33@R$I)ZpqK{Oo1)IBGnp@78ZeqyZfe)b!UgoKCI*ViSFL_7wQI4MgUqiG4L6=RLL zhk55rpOkyh(<#K&nD8|FW64n8aUQy^LrW&a7jp>v}nO>Dl(;|AGHI{|749!YKd% literal 0 HcmV?d00001 From 2b036c0e6b947683e06d659f2ee9385649fc62f5 Mon Sep 17 00:00:00 2001 From: Charles Tian <46334090+charlestian23@users.noreply.github.com> Date: Wed, 21 Feb 2024 13:33:00 -0500 Subject: [PATCH 10/11] Update build.gradle (#741) * Update build.gradle Fixing the deprecation issues in the autoformatter * Update build.gradle * Update build.gradle * Update to use Java 21 * Automated Java code formatting changes --------- Co-authored-by: Bram van Heuveln --- .github/workflows/java-autoformat.yml | 5 +++-- build.gradle | 17 ++++++++++------- .../rules/caserule/CaseRule_Generic.java | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/workflows/java-autoformat.yml b/.github/workflows/java-autoformat.yml index 0a2f42112..7aa2487cb 100644 --- a/.github/workflows/java-autoformat.yml +++ b/.github/workflows/java-autoformat.yml @@ -11,10 +11,11 @@ jobs: with: ref: ${{ github.head_ref }} - - name: Set up JDK 11 + - name: Set up JDK 21 uses: actions/setup-java@v1 with: - java-version: 11 + java-version: 21 + distribution: temurin - name: Grant execute permission for gradlew run: chmod +x gradlew diff --git a/build.gradle b/build.gradle index 445a7f8ea..75a2ec77e 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ version '5.3.2' apply plugin: 'java' apply plugin: 'application' -spotless{ +spotless { enforceCheck false format 'misc', { @@ -23,7 +23,7 @@ spotless{ endWithNewline() } - java{ + java { // Use the default importOrder configuration importOrder() @@ -38,9 +38,14 @@ spotless{ apply plugin: 'checkstyle' -mainClassName = 'edu.rpi.legup.Legup' +application { + mainClass.set('edu.rpi.legup.Legup') +} -sourceCompatibility = 21 +java { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 +} dependencies { implementation 'org.jetbrains:annotations:20.1.0' @@ -133,11 +138,9 @@ task buildNativeWindows(type: Exec, dependsOn: 'createExe') { commandLine 'cmd', '/c', 'make_windows_installer.bat' } - repositories { mavenCentral() } -targetCompatibility = JavaVersion.VERSION_21 tasks.register("jpackage") { group("jpackage") @@ -168,4 +171,4 @@ tasks.register('copyInstaller', Sync) { rename("LEGUP-${project.version}", "LEGUP-installer-${project.version}") } -copyInstaller.dependsOn(jpackage) \ No newline at end of file +copyInstaller.dependsOn(jpackage) 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 600a9898d..5885f98f8 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 @@ -60,4 +60,4 @@ public String checkRuleRaw(TreeTransition transition) { public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { return checkRuleRaw(transition); } -} \ No newline at end of file +} From 5189a0b7196cd1a5bc51ed78d050da313a1eca8f Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Wed, 21 Feb 2024 13:34:57 -0500 Subject: [PATCH 11/11] Updating to version 6.0.0 Changing to 6.0.0 since Java upgrade may break backwards compatibility --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 75a2ec77e..319cefa4f 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { id 'com.diffplug.spotless' version '6.25.0' } -version '5.3.2' +version '6.0.0' apply plugin: 'java' apply plugin: 'application'