diff --git a/.github/workflows/publish-javadoc.yml b/.github/workflows/publish-javadoc.yml index 2e02596fb..37eac9482 100644 --- a/.github/workflows/publish-javadoc.yml +++ b/.github/workflows/publish-javadoc.yml @@ -6,6 +6,8 @@ on: push: branches: - dev +permissions: + contents: write jobs: publish: diff --git a/bin/main/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md b/bin/main/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md index 94ef1e214..4695f25f2 100644 --- a/bin/main/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md +++ b/bin/main/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md @@ -11,7 +11,7 @@ spreadsheet : https://docs.google.com/spreadsheets/d/1l7aUZtavtysM8dtGnaEIXhBKMR 4. Refactoring: - document utility functions in the reference sheet, COMMENTS! - review and identify dead code - - remove all these damn print statments (commented ones too if they aren't useful) + - remove all these damn print statements (commented ones too if they aren't useful) - Edit to allow blank clues - Display flags somewhere 5. Flags diff --git a/src/main/java/edu/rpi/legup/app/Config.java b/src/main/java/edu/rpi/legup/app/Config.java index adae8459a..1847e14e4 100644 --- a/src/main/java/edu/rpi/legup/app/Config.java +++ b/src/main/java/edu/rpi/legup/app/Config.java @@ -25,7 +25,7 @@ public class Config { /** * Config Constructor for logic puzzles * - * @throws InvalidConfigException + * @throws InvalidConfigException if configuration is invalid */ public Config() throws InvalidConfigException { this.puzzles = new Hashtable<>(); diff --git a/src/main/java/edu/rpi/legup/app/GameBoardFacade.java b/src/main/java/edu/rpi/legup/app/GameBoardFacade.java index 43896bae1..55273ab4f 100644 --- a/src/main/java/edu/rpi/legup/app/GameBoardFacade.java +++ b/src/main/java/edu/rpi/legup/app/GameBoardFacade.java @@ -255,6 +255,7 @@ public void loadPuzzle(String game, String[] statements) { * Loads a puzzle file * * @param fileName file name of the board file + * @throws InvalidFileFormatException if input is invalid */ public void loadPuzzle(String fileName) throws InvalidFileFormatException { try { @@ -344,7 +345,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 */ public void loadPuzzle(InputStream inputStream) throws InvalidFileFormatException { diff --git a/src/main/java/edu/rpi/legup/app/LegupPreferences.java b/src/main/java/edu/rpi/legup/app/LegupPreferences.java index f9c3791f6..578cefc5b 100644 --- a/src/main/java/edu/rpi/legup/app/LegupPreferences.java +++ b/src/main/java/edu/rpi/legup/app/LegupPreferences.java @@ -8,6 +8,8 @@ public class LegupPreferences { private static LegupPreferences instance; + private static String SAVED_PATH = ""; + private static final Preferences preferences = Preferences.userNodeForPackage(LegupPreferences.class); private static final Map preferencesMap = new HashMap<>(); @@ -104,4 +106,13 @@ public boolean getUserPrefAsBool(String key) { } } } + + + public String getSavedPath() { + return SAVED_PATH; + } + + public void setSavedPath(String path) { + SAVED_PATH = path; + } } diff --git a/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java b/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java index 8bc423334..b42f73c9a 100644 --- a/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java +++ b/src/main/java/edu/rpi/legup/history/AutoCaseRuleCommand.java @@ -29,6 +29,9 @@ public class AutoCaseRuleCommand extends PuzzleCommand { * * @param elementView currently selected puzzle puzzleElement view 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) { this.elementView = elementView; diff --git a/src/main/java/edu/rpi/legup/history/ICommand.java b/src/main/java/edu/rpi/legup/history/ICommand.java index 188cee92e..bc82c4df5 100644 --- a/src/main/java/edu/rpi/legup/history/ICommand.java +++ b/src/main/java/edu/rpi/legup/history/ICommand.java @@ -2,12 +2,13 @@ public interface ICommand { /** - * Executes an command + * Executes a command */ void execute(); /** * Determines whether this command can be executed + * @return true if can execute, false otherwise */ boolean canExecute(); @@ -20,12 +21,12 @@ public interface ICommand { String getError(); /** - * Undoes an command + * Undoes a command */ void undo(); /** - * Redoes an command + * Redoes a command */ void redo(); } \ 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 923b17dda..398f17478 100644 --- a/src/main/java/edu/rpi/legup/history/ValidateCaseRuleCommand.java +++ b/src/main/java/edu/rpi/legup/history/ValidateCaseRuleCommand.java @@ -25,6 +25,7 @@ public class ValidateCaseRuleCommand extends PuzzleCommand { * AutoCaseRuleCommand Constructor creates a command for verifying a case rule * * @param selection currently selected tree puzzleElement views that is being edited + * @param caseRule currently selected caseRule puzzleElement view that is being edited */ public ValidateCaseRuleCommand(TreeViewSelection selection, CaseRule caseRule) { this.selection = selection.copy(); diff --git a/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java b/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java index c5e2de258..c5f8f0831 100644 --- a/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java +++ b/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java @@ -22,7 +22,7 @@ public class ValidateContradictionRuleCommand extends PuzzleCommand { * ValidateContradictionRuleCommand Constructor creates a puzzle command for verifying a contradiction rule * * @param selection currently selected tree puzzleElement views - * @param rule contradiction rule to set to all of 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(); @@ -32,7 +32,7 @@ public ValidateContradictionRuleCommand(TreeViewSelection selection, Contradicti } /** - * Executes an command + * Executes a command */ @Override public void executeCommand() { @@ -117,7 +117,7 @@ public String getErrorString() { } /** - * Undoes an command + * Undoes a command */ @Override public void undoCommand() { diff --git a/src/main/java/edu/rpi/legup/model/Puzzle.java b/src/main/java/edu/rpi/legup/model/Puzzle.java index 88a5620d8..9467afc5b 100644 --- a/src/main/java/edu/rpi/legup/model/Puzzle.java +++ b/src/main/java/edu/rpi/legup/model/Puzzle.java @@ -258,8 +258,8 @@ public boolean isPuzzleComplete() { /** * Imports the board using the file stream * - * @param fileName - * @throws InvalidFileFormatException + * @param fileName the file that is imported + * @throws InvalidFileFormatException if file is invalid */ public void importPuzzle(String fileName) throws InvalidFileFormatException { try { @@ -274,8 +274,8 @@ public void importPuzzle(String fileName) throws InvalidFileFormatException { /** * Imports the board using the file stream * - * @param inputStream - * @throws InvalidFileFormatException + * @param inputStream the file stream that is imported + * @throws InvalidFileFormatException if file stream is invalid */ public void importPuzzle(InputStream inputStream) throws InvalidFileFormatException { Document document; diff --git a/src/main/java/edu/rpi/legup/model/PuzzleExporter.java b/src/main/java/edu/rpi/legup/model/PuzzleExporter.java index 4b87b03c1..2fd77bd71 100644 --- a/src/main/java/edu/rpi/legup/model/PuzzleExporter.java +++ b/src/main/java/edu/rpi/legup/model/PuzzleExporter.java @@ -26,6 +26,7 @@ public abstract class PuzzleExporter { /** * PuzzleExporter Constructor exports the puzzle object to a file + * @param puzzle puzzle that is to be exported */ public PuzzleExporter(Puzzle puzzle) { this.puzzle = puzzle; @@ -35,7 +36,7 @@ public PuzzleExporter(Puzzle puzzle) { * Exports the puzzle to an xml formatted file * * @param fileName name of file to be exported - * @throws ExportFileException + * @throws ExportFileException if puzzle can not be exported */ public void exportPuzzle(String fileName) throws ExportFileException { try { diff --git a/src/main/java/edu/rpi/legup/model/PuzzleImporter.java b/src/main/java/edu/rpi/legup/model/PuzzleImporter.java index 0ce2de840..bf535b4cd 100644 --- a/src/main/java/edu/rpi/legup/model/PuzzleImporter.java +++ b/src/main/java/edu/rpi/legup/model/PuzzleImporter.java @@ -21,6 +21,7 @@ public abstract class PuzzleImporter { /** * PuzzleImporter Constructor creates the puzzle object + * @param puzzle puzzle that is imported */ public PuzzleImporter(Puzzle puzzle) { this.puzzle = puzzle; @@ -35,7 +36,7 @@ public PuzzleImporter(Puzzle puzzle) { * * @param rows number of rows on the puzzle * @param columns number of columns on the puzzle - * @throws RuntimeException + * @throws RuntimeException if puzzle can not be made */ public void initializePuzzle(int rows, int columns) throws RuntimeException { if (this.puzzle.isValidDimensions(rows, columns)) { @@ -57,7 +58,7 @@ public void initializePuzzle(String[] statements) throws InputMismatchException, * Initializes the puzzle attributes * * @param node xml document node - * @throws InvalidFileFormatException + * @throws InvalidFileFormatException if file is invalid */ public void initializePuzzle(Node node) throws InvalidFileFormatException { if (node.getNodeName().equalsIgnoreCase("puzzle")) { @@ -111,7 +112,7 @@ public void initializePuzzle(Node node) throws InvalidFileFormatException { * * @param rows number of rows on the puzzle * @param columns number of columns on the puzzle - * @throws RuntimeException + * @throws RuntimeException if board can not be created */ public abstract void initializeBoard(int rows, int columns); @@ -119,7 +120,7 @@ public void initializePuzzle(Node node) throws InvalidFileFormatException { * Creates an empty board for building * * @param node xml document node - * @throws InvalidFileFormatException + * @throws InvalidFileFormatException if file is invalid */ public abstract void initializeBoard(Node node) throws InvalidFileFormatException; @@ -129,7 +130,7 @@ public void initializePuzzle(Node node) throws InvalidFileFormatException { * Creates the proof for building * * @param node xml document node - * @throws InvalidFileFormatException + * @throws InvalidFileFormatException if file is invalid */ public void initializeProof(Node node) throws InvalidFileFormatException { if (node.getNodeName().equalsIgnoreCase("proof")) { @@ -163,6 +164,7 @@ public void initializeProof(Node node) throws InvalidFileFormatException { * Sets the puzzleElement from the xml document node * * @param node xml document node + * @throws InvalidFileFormatException if file is invalid */ protected void setCells(Node node) throws InvalidFileFormatException { NodeList dataList = ((org.w3c.dom.Element) node).getElementsByTagName("cell"); @@ -176,8 +178,8 @@ protected void setCells(Node node) throws InvalidFileFormatException { /** * Creates the tree for the edu.rpi.legup.puzzle * - * @param node - * @throws InvalidFileFormatException + * @param node xml document node + * @throws InvalidFileFormatException if file is invalid */ protected void createTree(Node node) throws InvalidFileFormatException { Element treeElement = (org.w3c.dom.Element) node; 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 cc222b809..31ef92359 100644 --- a/src/main/java/edu/rpi/legup/model/tree/Tree.java +++ b/src/main/java/edu/rpi/legup/model/tree/Tree.java @@ -101,7 +101,7 @@ public Set getLeafTreeElements() { /** * Gets a Set of TreeNodes that are leaf nodes from the sub tree rooted at the specified node - * + * @param node node that is input * @return Set of TreeNodes that are leaf nodes from the sub tree */ public Set getLeafTreeElements(TreeNode node) { 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 dc4e2a587..59f6e736e 100644 --- a/src/main/java/edu/rpi/legup/model/tree/TreeNode.java +++ b/src/main/java/edu/rpi/legup/model/tree/TreeNode.java @@ -328,4 +328,9 @@ public boolean isRoot() { public void setRoot(boolean isRoot) { this.isRoot = isRoot; } + + public void clearChildren() { + this.children.clear(); + } + } \ No newline at end of file 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 bc244856b..81629c360 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipCellFactory.java @@ -17,7 +17,7 @@ public class BattleshipCellFactory extends ElementFactory { * @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 + * @throws InvalidFileFormatException if file is invalid */ @Override public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormatException { 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 5076ad9eb..749ceaaa9 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipImporter.java @@ -28,7 +28,7 @@ public boolean acceptsTextInput() { * * @param rows the number of rows on the board * @param columns the number of columns on the board - * @throws RuntimeException + * @throws RuntimeException if board can not be created */ @Override public void initializeBoard(int rows, int columns) { @@ -39,7 +39,7 @@ public void initializeBoard(int rows, int columns) { * Creates the board for building * * @param node xml document node - * @throws InvalidFileFormatException + * @throws InvalidFileFormatException if file is invalid */ @Override public void initializeBoard(Node node) throws InvalidFileFormatException { 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 de643d1ca..6994222e3 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipType.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipType.java @@ -13,7 +13,7 @@ public enum BattleshipType { /** * Gets the enum of this BattleShipType - * + * @param value the integer value input * @return enum equivalent BattleShipType of integer value */ public static BattleshipType getType(int value) { 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 65061bf2e..fcc48bccd 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellFactory.java @@ -17,7 +17,7 @@ public class FillapixCellFactory extends ElementFactory { * @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 + * @throws InvalidFileFormatException if file is invalid */ @Override public FillapixCell importCell(Node node, Board board) throws InvalidFileFormatException { 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 3cc39e228..6c30b2272 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixImporter.java @@ -28,7 +28,7 @@ public boolean acceptsTextInput() { * * @param rows the number of rows on the board * @param columns the number of columns on the board - * @throws RuntimeException + * @throws RuntimeException if board can not be made */ @Override public void initializeBoard(int rows, int columns) { @@ -39,7 +39,7 @@ public void initializeBoard(int rows, int columns) { * Creates the board for building * * @param node xml document node - * @throws InvalidFileFormatException + * @throws InvalidFileFormatException if file is invalid */ @Override public void initializeBoard(Node node) throws InvalidFileFormatException { 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 2b1d329f0..96fc20e6f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeFactory.java @@ -17,7 +17,7 @@ public class HeyawakeFactory extends ElementFactory { * @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 + * @throws InvalidFileFormatException if file is invalid */ @Override public HeyawakeCell importCell(Node node, Board board) throws InvalidFileFormatException { 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 b28dd2f27..7527c717f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeImporter.java @@ -29,7 +29,7 @@ public boolean acceptsTextInput() { * * @param rows the number of rows on the board * @param columns the number of columns on the board - * @throws RuntimeException + * @throws RuntimeException if board can not be created */ @Override public void initializeBoard(int rows, int columns) { @@ -40,7 +40,7 @@ public void initializeBoard(int rows, int columns) { * Creates the board for building * * @param node xml document node - * @throws InvalidFileFormatException + * @throws InvalidFileFormatException if file is invalid */ @Override public void initializeBoard(Node node) throws InvalidFileFormatException { 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 5cb8353df..4914facfa 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCellFactory.java @@ -17,7 +17,7 @@ public class LightUpCellFactory extends ElementFactory { * @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 + * @throws InvalidFileFormatException if file is invalid */ @Override public LightUpCell importCell(Node node, Board board) throws InvalidFileFormatException { 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 58fe540a8..7ef24ca69 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpImporter.java @@ -28,7 +28,7 @@ public boolean acceptsTextInput() { * * @param rows the number of rows on the board * @param columns the number of columns on the board - * @throws RuntimeException + * @throws RuntimeException if board can not be created */ @Override public void initializeBoard(int rows, int columns) { @@ -51,7 +51,7 @@ public void initializeBoard(int rows, int columns) { * Creates the board for building * * @param node xml document node - * @throws InvalidFileFormatException + * @throws InvalidFileFormatException if file is invalid */ @Override public void initializeBoard(Node node) throws InvalidFileFormatException { 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 2fbcf3826..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 @@ -181,8 +181,8 @@ public String checkRuleRaw(TreeTransition transition) { for (LightUpCell c : spots) { ArrayList cases = getCases(parent.getBoard(), c); - // We want to return false if cases.size() is equal to 1 because case rules aren't supposed to have only 1 option - if (cases.size() == childTransitions.size() && cases.size() > 1) { + // We will allow case rules to have only one option + if (cases.size() == childTransitions.size() && cases.size() >= 1) { boolean foundSpot = true; for (TreeTransition childTrans : childTransitions) { LightUpBoard actCase = (LightUpBoard) childTrans.getBoard(); 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 27120f097..5278e0036 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuCellFactory.java @@ -17,7 +17,7 @@ public class MasyuCellFactory extends ElementFactory { * @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 + * @throws InvalidFileFormatException if file is invalid */ @Override public MasyuCell importCell(Node node, Board board) throws InvalidFileFormatException { 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 d3519bd4d..3e0d328c4 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuImporter.java @@ -28,7 +28,7 @@ public boolean acceptsTextInput() { * * @param rows the number of rows on the board * @param columns the number of columns on the board - * @throws RuntimeException + * @throws RuntimeException if board can not be created */ @Override public void initializeBoard(int rows, int columns) { @@ -39,7 +39,7 @@ public void initializeBoard(int rows, int columns) { * Creates the board for building * * @param node xml document node - * @throws InvalidFileFormatException + * @throws InvalidFileFormatException if file is invalid */ @Override public void initializeBoard(Node node) throws InvalidFileFormatException { 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 cd9ee854c..f84a3c9f1 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCell.java @@ -46,38 +46,36 @@ public NurikabeType getType() { */ @Override public void setType(Element e, MouseEvent m) { - if (e.getElementID().equals("NURI-PLAC-0001")) { - this.data = -1; - } - else { - if (e.getElementID().equals("NURI-PLAC-0002")) { + switch (e.getElementID()){ + case "NURI-PLAC-0001": + this.data = -1; + break; + case "NURI-PLAC-0002": this.data = 0; - } - else { - if (e.getElementID().equals("NURI-UNPL-0001")) { - if (m.getButton() == MouseEvent.BUTTON1) { + break; + case "NURI-UNPL-0001": + switch (m.getButton()){ + case MouseEvent.BUTTON1: if (this.data <= 0 || this.data > 8) { this.data = 1; } else { this.data = this.data + 1; } - } - else { - if (m.getButton() == MouseEvent.BUTTON3) { - if (this.data > 1) { - this.data = this.data - 1; - } - else { - this.data = 9; - } + break; + case MouseEvent.BUTTON3: + if (this.data > 1) { + this.data = this.data - 1; } - } - } - else { // unknown tile - this.data = -2; + else { + this.data = 9; + } + break; } - } + break; + default: + this.data = -2; + break; } } @@ -94,4 +92,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 47113325b..b754f3e46 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeCellFactory.java @@ -17,7 +17,7 @@ public class NurikabeCellFactory extends ElementFactory { * @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 + * @throws InvalidFileFormatException if file is invalid */ @Override public NurikabeCell importCell(Node node, Board board) throws InvalidFileFormatException { 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 0a95f59b2..2cbcc9ad0 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeImporter.java @@ -28,7 +28,7 @@ public boolean acceptsTextInput() { * * @param rows the number of rows on the board * @param columns the number of columns on the board - * @throws RuntimeException + * @throws RuntimeException if board can not be created */ @Override public void initializeBoard(int rows, int columns) { @@ -49,7 +49,7 @@ public void initializeBoard(int rows, int columns) { * Creates the board for building * * @param node xml document node - * @throws InvalidFileFormatException + * @throws InvalidFileFormatException if file is invalid */ @Override public void initializeBoard(Node node) throws InvalidFileFormatException { 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 d084cd2ff..e5011182a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableBoard.java @@ -4,6 +4,7 @@ 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.*; @@ -42,6 +43,11 @@ public ShortTruthTableCell getCellFromElement(PuzzleElement element) { return (ShortTruthTableCell) getPuzzleElement(element); } + @Override + public ShortTruthTableCell getCell(int x, int y) { + return (ShortTruthTableCell) super.getCell(x, y); + } + @Override public ShortTruthTableBoard copy() { @@ -93,6 +99,17 @@ public static List copyStatementList(List> allCe //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 statment 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()); @@ -219,7 +219,7 @@ private void setGivenCells(ShortTruthTableBoard sttBoard, List statements) throws InvalidFileFormatException { - //if it is normal, set all predicats 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) for (int i = 0; i < statements.size() - 1; i++) { 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 bb0ffcf08..e40a10cf0 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableStatement.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableStatement.java @@ -95,7 +95,7 @@ static String removeParens(String statement) { if (c == ')') openParenCount--; } - //if the first paren has been closed and it is not the end of the string, + //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; @@ -164,7 +164,7 @@ static void removeParens(List cells) { if (c == ')') openParenCount--; } - //if the first paren has been closed and it is not the end of the string, + //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; @@ -241,7 +241,7 @@ 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 - * exist or is is an unknown value. + * exist or is an unknown value. * * @return the assigned values to this statement and its sub-statements */ @@ -285,14 +285,29 @@ public void setCellLocations(int rowIndex) { public ShortTruthTableStatement copy() { //copy all the cells - List cellsCopy = new ArrayList(); + List cellsCopy = new ArrayList<>(); for (ShortTruthTableCell c : cells) { cellsCopy.add(c.copy()); } //make a copy of the statement with all the copied cells - ShortTruthTableStatement statementCopy = new ShortTruthTableStatement(stringRep, cellsCopy); //return the new statement - return statementCopy; + return new ShortTruthTableStatement(stringRep, cellsCopy); + } + + public ShortTruthTableStatement replace(int column, ShortTruthTableCell cell) { + //copy all the cells (replacing one) + List cellsCopy = new ArrayList<>(); + for (ShortTruthTableCell c : cells) { + if (c.getX() == column) { + cellsCopy.add(cell); + } + else { + cellsCopy.add(c); + } + } + //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/skyscrapers/SkyscrapersBoard.java b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java index a8fc3170b..ca6bcbe02 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersBoard.java @@ -51,28 +51,28 @@ public ArrayList getLines() { } /** - * Returns 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; } /** - * Returns a list of the southern clues ordered from loc.x = 0 to max + * @return southClues a list of the southern clues ordered from loc.x = 0 to max */ public ArrayList getSouthClues() { return southClues; } /** - * Returns a list of the western clues ordered from loc.y = 0 to max + * @return westClues a list of the western clues ordered from loc.y = 0 to max */ public ArrayList getWestClues() { return westClues; } /** - * Returns a list of the northern clues ordered from loc.x = 0 to max + * @return northClues a list of the northern clues ordered from loc.x = 0 to max */ public ArrayList getNorthClues() { return northClues; @@ -164,7 +164,7 @@ public void notifyDeletion(PuzzleElement puzzleElement) { * Gets the cells of a certain type directly adjacent to a given cell * * @param cell at the center, - * type of cell to collect + * @param type of cell to collect * @return list of cells of the given type */ public List getAdjacent(SkyscrapersCell cell, SkyscrapersType type) { @@ -193,7 +193,7 @@ public List getAdjacent(SkyscrapersCell cell, SkyscrapersType t * Gets the cells of a certain type directly diagonal to a given cell * * @param cell at the center, - * type of cell to collect + * @param type of cell to collect * @return list of cells of the given type */ public List getDiagonals(SkyscrapersCell cell, SkyscrapersType type) { @@ -222,8 +222,8 @@ public List getDiagonals(SkyscrapersCell cell, SkyscrapersType * Gets the cells of a certain type in a given row/column * * @param index: y pos of row or x pos of col, - * type of cell to collect, - * boolean true if row, false if col + * @param type of cell to collect, + * @param isRow true if row, false if col * @return list of cells of the given type, ordered west to east or north to south */ public List getRowCol(int index, SkyscrapersType type, boolean isRow) { 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 6f0c6edfd..bb4b49b6c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCellFactory.java @@ -17,7 +17,7 @@ public class SkyscrapersCellFactory extends ElementFactory { * @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 + * @throws InvalidFileFormatException if input is invalid */ @Override public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormatException { 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 f663de406..525a8c021 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersImporter.java @@ -28,7 +28,7 @@ public boolean acceptsTextInput() { * * @param rows the number of rows on the board * @param columns the number of columns on the board - * @throws RuntimeException + * @throws RuntimeException if board can not be created */ @Override public void initializeBoard(int rows, int columns) { @@ -39,7 +39,7 @@ public void initializeBoard(int rows, int columns) { * Creates the board for building * * @param node xml document node - * @throws InvalidFileFormatException + * @throws InvalidFileFormatException if file is invalid */ @Override public void initializeBoard(Node node) throws InvalidFileFormatException { diff --git a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md index d0be95913..60a8bd19d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/rules/TODO.md @@ -11,7 +11,7 @@ spreadsheet : https://docs.google.com/spreadsheets/d/1l7aUZtavtysM8dtGnaEIXhBKMR 4. Refactoring: - document utility functions in the reference sheet, COMMENTS! - review and identify dead code - - remove all these damn print statments (commented ones too if they aren't useful) + - remove all these damn print statements (commented ones too if they aren't useful) - Edit to allow blank clues - Display flags somewhere 5. Flags 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 6e13d70dc..0e1595d03 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCell.java @@ -17,6 +17,7 @@ public class SudokuCell extends GridCell { * @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 */ public SudokuCell(int value, Point location, int groupIndex, int size) { super(value, location); 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 e9bafa43a..90f84d519 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuCellFactory.java @@ -17,7 +17,7 @@ public class SudokuCellFactory extends ElementFactory { * @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 + * @throws InvalidFileFormatException if file is invalid */ @Override public SudokuCell importCell(Node node, Board board) throws InvalidFileFormatException { 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 4af53b547..dccec52d4 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuImporter.java @@ -28,7 +28,7 @@ public boolean acceptsTextInput() { * * @param rows the number of rows on the board * @param columns the number of columns on the board - * @throws RuntimeException + * @throws RuntimeException if board can not be created */ @Override public void initializeBoard(int rows, int columns) { @@ -55,7 +55,7 @@ public void initializeBoard(int rows, int columns) { * Creates the board for building * * @param node xml document node - * @throws InvalidFileFormatException + * @throws InvalidFileFormatException if file is invalid */ @Override public void initializeBoard(Node node) throws InvalidFileFormatException { 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 e5e7603a6..969ffdf0f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCellFactory.java @@ -17,7 +17,7 @@ public class TreeTentCellFactory extends ElementFactory { * @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 + * @throws InvalidFileFormatException if file is invalid */ @Override public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormatException { 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 2c03bbccb..2b4861c9f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentImporter.java @@ -28,7 +28,7 @@ public boolean acceptsTextInput() { * * @param rows the number of rows on the board * @param columns the number of columns on the board - * @throws RuntimeException + * @throws RuntimeException if board can not be created */ @Override public void initializeBoard(int rows, int columns) { @@ -60,7 +60,7 @@ public void initializeBoard(int rows, int columns) { * Creates the board for building * * @param node xml document node - * @throws InvalidFileFormatException + * @throws InvalidFileFormatException if file is invalid */ @Override public void initializeBoard(Node node) throws InvalidFileFormatException { diff --git a/src/main/java/edu/rpi/legup/ui/LegupUI.java b/src/main/java/edu/rpi/legup/ui/LegupUI.java index 9eb1977aa..82ef7dc44 100644 --- a/src/main/java/edu/rpi/legup/ui/LegupUI.java +++ b/src/main/java/edu/rpi/legup/ui/LegupUI.java @@ -27,6 +27,7 @@ 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(); diff --git a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java index b27c4bb05..aac040bdb 100644 --- a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java @@ -220,10 +220,14 @@ public JMenuBar getMenuBar() { 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(); } } @@ -376,6 +380,9 @@ public Object[] promptPuzzle() { LegupPreferences preferences = LegupPreferences.getInstance(); String preferredDirectory = preferences.getUserPref(LegupPreferences.WORK_DIRECTORY); + if (preferences.getSavedPath() != "") { + preferredDirectory = preferences.getSavedPath(); + } File preferredDirectoryFile = new File(preferredDirectory); JFileChooser fileBrowser = new JFileChooser(preferredDirectoryFile); @@ -384,7 +391,7 @@ public Object[] promptPuzzle() { fileBrowser.showOpenDialog(this); fileBrowser.setVisible(true); - fileBrowser.setCurrentDirectory(new File(LegupPreferences.WORK_DIRECTORY)); + fileBrowser.setCurrentDirectory(new File(preferredDirectory)); fileBrowser.setDialogTitle("Select Proof File"); fileBrowser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileBrowser.setAcceptAllFileFilterUsed(false); @@ -394,6 +401,8 @@ public Object[] promptPuzzle() { if (puzzlePath != null) { fileName = puzzlePath.getAbsolutePath(); + String lastDirectoryPath = fileName.substring(0, fileName.lastIndexOf(File.separator)); + preferences.setSavedPath(lastDirectoryPath); puzzleFile = puzzlePath; } else { 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 77e6449e4..602672a9e 100644 --- a/src/main/java/edu/rpi/legup/ui/boardview/BoardView.java +++ b/src/main/java/edu/rpi/legup/ui/boardview/BoardView.java @@ -24,6 +24,7 @@ public abstract class BoardView extends ScrollView implements IBoardListener { * 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 */ public BoardView(BoardController boardController, ElementController elementController) { super(boardController); 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 e851d14d7..5fdacc6b0 100644 --- a/src/main/java/edu/rpi/legup/ui/boardview/GridBoardView.java +++ b/src/main/java/edu/rpi/legup/ui/boardview/GridBoardView.java @@ -14,7 +14,8 @@ public class GridBoardView extends BoardView { * 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 gridSize dimension of the grid + * @param elementController controller that handles the ui events */ public GridBoardView(BoardController boardController, ElementController elementController, Dimension gridSize) { this(boardController, elementController); 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 411b7bc4c..f11fee5b4 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 @@ -80,13 +80,14 @@ public void updateRules() { /** * Search a certain rule in all the puzzles and set it for the searchBarPanel * - * @param puzzle, ruleName - *

- * 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) + * @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) */ public void searchForRule(Puzzle puzzle, String ruleName) { @@ -160,9 +161,11 @@ public void searchForRule(Puzzle puzzle, String ruleName) { /** * Calculates the similarity (a number within 0 and 1) between two strings. - * This funtion will take two para String s1 and String s2, which s1 is the user's input + * 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. */ @@ -181,6 +184,9 @@ 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 */ public static int editDistance(String s1, String s2) { s1 = s1.toLowerCase(); @@ -216,6 +222,7 @@ public static int editDistance(String s1, String s2) { * 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) { 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 d0b25257a..332fd64a0 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 @@ -9,6 +9,7 @@ public class TreeToolbarPanel extends JPanel { /** * TreeToolbarPanel Constructor - creates the tree tool mBar panel + * @param treePanel treePanel input */ public TreeToolbarPanel(TreePanel treePanel) { this.treePanel = treePanel; diff --git a/src/main/java/edu/rpi/legup/utility/LegupUtils.java b/src/main/java/edu/rpi/legup/utility/LegupUtils.java index 8c09cfd1e..dbdd24e7f 100644 --- a/src/main/java/edu/rpi/legup/utility/LegupUtils.java +++ b/src/main/java/edu/rpi/legup/utility/LegupUtils.java @@ -21,8 +21,8 @@ public class LegupUtils { * * @param packageName The base package * @return The classes - * @throws ClassNotFoundException - * @throws IOException + * @throws ClassNotFoundException if class is not in package + * @throws IOException if file is not found */ public static Class[] getClasses(String packageName) throws ClassNotFoundException, IOException { diff --git a/src/test/java/legup/TestRunner.java b/src/test/java/legup/TestRunner.java new file mode 100644 index 000000000..7e2dbe737 --- /dev/null +++ b/src/test/java/legup/TestRunner.java @@ -0,0 +1,108 @@ +package legup; + + +import org.junit.runner.JUnitCore; +import org.junit.runner.Result; +import org.junit.runner.notification.Failure; +import puzzles.battleship.rules.*; +import puzzles.lightup.rules.*; +import puzzles.nurikabe.rules.*; +import puzzles.treetent.rules.*; + +public class TestRunner { + public static void main(String[] args) { + // Battleship Tests + Result result1 = JUnitCore.runClasses(AdjacentShipsContradictionRuleTest.class); + printTestResults(result1); + Result result2 = JUnitCore.runClasses(FinishWithShipsDirectRuleTests.class); + printTestResults(result2); + + // Lightup Tests + Result result3 = JUnitCore.runClasses(BulbsInPathContradictionRuleTest.class); + printTestResults(result3); + Result result4 = JUnitCore.runClasses(CannotLightACellContradictionRuleTest.class); + printTestResults(result4); + Result result5 = JUnitCore.runClasses(EmptyCellinLightDirectRuleTest.class); + printTestResults(result5); + Result result6 = JUnitCore.runClasses(EmptyCornersDirectRuleTest.class); + printTestResults(result6); + Result result7 = JUnitCore.runClasses(FinishWithBulbsDirectRuleTest.class); + printTestResults(result7); + Result result8 = JUnitCore.runClasses(LightOrEmptyCaseRuleTest.class); + printTestResults(result8); + Result result9 = JUnitCore.runClasses(MustLightDirectRuleTest.class); + printTestResults(result9); + Result result10 = JUnitCore.runClasses(SatisfyNumberCaseRuleTest.class); + printTestResults(result10); + Result result11 = JUnitCore.runClasses(TooFewBulbsContradictionRuleTest.class); + printTestResults(result11); + Result result12 = JUnitCore.runClasses(TooManyBulbsContradictionRuleTest.class); + printTestResults(result12); + + + + //nurikabe tests + Result result13 = JUnitCore.runClasses(BlackBetweenRegionsDirectRuleTest.class); + printTestResults(result13); + Result result14 = JUnitCore.runClasses(BlackBottleNeckDirectRuleTest.class); + printTestResults(result14); + Result result15 = JUnitCore.runClasses(BlackOrWhiteCaseRuleTest.class); + printTestResults(result15); + Result result16 = JUnitCore.runClasses(BlackSquareContradictionRuleTest.class); + printTestResults(result16); + Result result17 = JUnitCore.runClasses(CornerBlackDirectRuleTest.class); + printTestResults(result17); + Result result18 = JUnitCore.runClasses(FillinBlackDirectRuleTest.class); + printTestResults(result18); + Result result19 = JUnitCore.runClasses(FillinWhiteDirectRuleTest.class); + printTestResults(result19); + Result result20 = JUnitCore.runClasses(IsolateBlackContradictionRuleTest.class); + printTestResults(result20); + Result result21 = JUnitCore.runClasses(MultipleNumbersContradictionRuleTest.class); + printTestResults(result21); + Result result22 = JUnitCore.runClasses(NoNumbersContradictionRuleTest.class); + printTestResults(result22); + Result result23 = JUnitCore.runClasses(PreventBlackSquareDirectRuleTest.class); + printTestResults(result23); + Result result24 = JUnitCore.runClasses(SurroundRegionDirectRuleTest.class); + printTestResults(result24); + Result result25 = JUnitCore.runClasses(TooFewSpacesContradictionRuleTest.class); + printTestResults(result25); + Result result26 = JUnitCore.runClasses(TooManySpacesContradictionRuleTest.class); + printTestResults(result26); + Result result27 = JUnitCore.runClasses(WhiteBottleNeckDirectRuleTest.class); + printTestResults(result27); + + + // Treetent + Result result28 = JUnitCore.runClasses(EmptyFieldDirectRuleTest.class); + printTestResults(result28); + Result result29 = JUnitCore.runClasses(FinishWithGrassDirectRuleTest.class); + printTestResults(result29); + Result result30 = JUnitCore.runClasses(FinishWithTentsDirectRuleTest.class); + printTestResults(result30); + Result result31 = JUnitCore.runClasses(LastCampingSpotDirectRuleTest.class); + printTestResults(result31); + Result result32 = JUnitCore.runClasses(NoTentForTreeContradictionRuleTest.class); + printTestResults(result32); + Result result33 = JUnitCore.runClasses(NoTreeForTentContradictionRuleTest.class); + printTestResults(result33); + Result result34 = JUnitCore.runClasses(SurroundTentWithGrassDirectRuleTest.class); + printTestResults(result34); + Result result35 = JUnitCore.runClasses(TreeForTentDirectRuleTest.class); + printTestResults(result35); + } + + private static void printTestResults(Result result) { + for (Failure failure : result.getFailures()) { + System.out.println(failure.toString()); + } + + System.out.println("Tests run: " + result.getRunCount()); + System.out.println("Tests failed: " + result.getFailureCount()); + System.out.println("All tests passed: " + result.wasSuccessful()); + System.out.println(); + } + + +} \ No newline at end of file diff --git a/src/test/java/legup/TestUtilities.java b/src/test/java/legup/TestUtilities.java index 9f203b223..d49529921 100644 --- a/src/test/java/legup/TestUtilities.java +++ b/src/test/java/legup/TestUtilities.java @@ -6,6 +6,11 @@ import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.save.InvalidFileFormatException; +import org.junit.runner.JUnitCore; +import org.junit.runner.Result; +import org.junit.runner.notification.Failure; +import puzzles.battleship.rules.AdjacentShipsContradictionRuleTest; +import puzzles.battleship.rules.FinishWithShipsDirectRuleTests; public final class TestUtilities { public static void importTestBoard(String fileName, Puzzle puzzle) throws InvalidFileFormatException { @@ -16,4 +21,8 @@ public static void importTestBoard(String fileName, Puzzle puzzle) throws Invali TreeTransition transition = new TreeTransition(rootNode, board); rootNode.getChildren().add(transition); } + + } + + diff --git a/src/test/java/puzzles/nurikabe/rules/BlackBottleNeckDirectRuleTest.java b/src/test/java/puzzles/nurikabe/rules/BlackBottleNeckDirectRuleTest.java index 45ed97030..91dcec802 100644 --- a/src/test/java/puzzles/nurikabe/rules/BlackBottleNeckDirectRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/BlackBottleNeckDirectRuleTest.java @@ -3,9 +3,18 @@ import legup.MockGameBoardFacade; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.Assert; 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.BlackBottleNeckDirectRule; import edu.rpi.legup.save.InvalidFileFormatException; +import legup.TestUtilities; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import java.awt.*; + public class BlackBottleNeckDirectRuleTest { @@ -20,28 +29,29 @@ public static void setUp() { @Test public void BlackBottleNeckDirectRule_TwoSurroundBlackTest() throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBottleNeckDirectRule/SimpleBlackBottleNeck", nurikabe); -// TreeNode rootNode = nurikabe.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// NurikabeBoard board = (NurikabeBoard)transition.getBoard(); -// NurikabeCell cell = board.getCell(2,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))); -// } -// } -// } + TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBottleNeckDirectRule/SimpleBlackBottleNeck", nurikabe); + TreeNode rootNode = nurikabe.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + NurikabeBoard board = (NurikabeBoard)transition.getBoard(); + NurikabeCell cell = board.getCell(2,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))); + } + } + } } } diff --git a/src/test/java/puzzles/nurikabe/rules/CornerBlackDirectRuleTest.java b/src/test/java/puzzles/nurikabe/rules/CornerBlackDirectRuleTest.java index 2b23754f3..0ee3c247b 100644 --- a/src/test/java/puzzles/nurikabe/rules/CornerBlackDirectRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/CornerBlackDirectRuleTest.java @@ -1,11 +1,21 @@ package puzzles.nurikabe.rules; +import edu.rpi.legup.puzzle.nurikabe.NurikabeType; import legup.MockGameBoardFacade; import org.junit.BeforeClass; import org.junit.Test; import edu.rpi.legup.puzzle.nurikabe.Nurikabe; import edu.rpi.legup.puzzle.nurikabe.rules.CornerBlackDirectRule; import edu.rpi.legup.save.InvalidFileFormatException; +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.nurikabe.NurikabeBoard; +import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; + +import java.awt.*; + public class CornerBlackDirectRuleTest { @@ -20,26 +30,28 @@ public static void setUp() { @Test public void CornerBlackContradictionRule_SimpleCornerBlackTest() throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/nurikabe/rules/TooFewSpacesContradictionRule/TwoSurroundBlack", nurikabe); -// TreeNode rootNode = nurikabe.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// transition.getBoard().getModifiedData().clear(); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// NurikabeBoard board = (NurikabeBoard)transition.getBoard(); -// Point location = new Point(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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } + TestUtilities.importTestBoard("puzzles/nurikabe/rules/TooFewSpacesContradictionRule/TwoSurroundBlack", nurikabe); + TreeNode rootNode = nurikabe.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + NurikabeBoard board = (NurikabeBoard) transition.getBoard(); + transition.setRule(RULE); + + NurikabeCell cell = board.getCell(2, 0); + cell.setData(NurikabeType.BLACK.toValue()); + board.addModifiedData(cell); + + Assert.assertNotNull(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)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } } } diff --git a/src/test/java/puzzles/nurikabe/rules/FillinWhiteDirectRuleTest.java b/src/test/java/puzzles/nurikabe/rules/FillinWhiteDirectRuleTest.java index dbc664a15..4acc54f98 100644 --- a/src/test/java/puzzles/nurikabe/rules/FillinWhiteDirectRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/FillinWhiteDirectRuleTest.java @@ -6,6 +6,16 @@ import edu.rpi.legup.puzzle.nurikabe.Nurikabe; import edu.rpi.legup.puzzle.nurikabe.rules.FillinWhiteDirectRule; import edu.rpi.legup.save.InvalidFileFormatException; +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.nurikabe.NurikabeBoard; +import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; +import edu.rpi.legup.puzzle.nurikabe.NurikabeType; + +import java.awt.*; + public class FillinWhiteDirectRuleTest { private static final FillinWhiteDirectRule RULE = new FillinWhiteDirectRule(); @@ -19,28 +29,29 @@ public static void setUp() { @Test public void FillinWhiteDirectRule_UnknownSurroundWhiteTest() throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/nurikabe/rules/FillinWhiteDirectRule/UnknownSurroundWhite", 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.WHITE.toValue()); -// board.addModifiedData(cell); -// -// Assert.assertNull(RULE.checkRule(transition)); -// -// Point location = new Point(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(location)) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } + TestUtilities.importTestBoard("puzzles/nurikabe/rules/FillinWhiteDirectRule/UnknownSurroundWhite", 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.WHITE.toValue()); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(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(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } } } diff --git a/src/test/java/puzzles/nurikabe/rules/TooManySpacesContradictionRuleTest.java b/src/test/java/puzzles/nurikabe/rules/TooManySpacesContradictionRuleTest.java index 2783b1565..48979d886 100644 --- a/src/test/java/puzzles/nurikabe/rules/TooManySpacesContradictionRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/TooManySpacesContradictionRuleTest.java @@ -27,25 +27,26 @@ public static void setUp() { @Test public void TooManySpacesContradictionRule_TwoSurroundBlackTest() throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/nurikabe/rules/TooManySpacesContradictionRule/TwoSurroundWhite", nurikabe); -// TreeNode rootNode = nurikabe.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// Assert.assertNull(RULE.checkContradiction((NurikabeBoard)transition.getBoard())); -// -// NurikabeBoard board = (NurikabeBoard)transition.getBoard(); -// -// 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(new Point(1, 0)) || point.equals(new Point(1, 1)) || -// point.equals(new Point(2, 1)) || point.equals(new Point(1, 2))) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } + TestUtilities.importTestBoard("puzzles/nurikabe/rules/TooManySpacesContradictionRule/TwoSurroundWhite", nurikabe); + TreeNode rootNode = nurikabe.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + Assert.assertNull(RULE.checkContradiction((NurikabeBoard)transition.getBoard())); + + NurikabeBoard board = (NurikabeBoard)transition.getBoard(); + + 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(new Point(1, 0)) || point.equals(new Point(1, 1)) || + point.equals(new Point(2, 1)) || point.equals(new Point(1, 2)) || point.equals(new Point(0, 1))) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } } } diff --git a/src/test/resources/puzzles/nurikabe/rules/BlackBottleNeckDirectRule/SimpleBlackBottleNeck b/src/test/resources/puzzles/nurikabe/rules/BlackBottleNeckDirectRule/SimpleBlackBottleNeck index 5501725fe..07f3cc9be 100644 --- a/src/test/resources/puzzles/nurikabe/rules/BlackBottleNeckDirectRule/SimpleBlackBottleNeck +++ b/src/test/resources/puzzles/nurikabe/rules/BlackBottleNeckDirectRule/SimpleBlackBottleNeck @@ -3,6 +3,7 @@ + diff --git a/src/test/resources/puzzles/nurikabe/rules/FillinWhiteDirectRule/UnknownSurroundWhite b/src/test/resources/puzzles/nurikabe/rules/FillinWhiteDirectRule/UnknownSurroundWhite index 200f518cb..eb23eb55d 100644 --- a/src/test/resources/puzzles/nurikabe/rules/FillinWhiteDirectRule/UnknownSurroundWhite +++ b/src/test/resources/puzzles/nurikabe/rules/FillinWhiteDirectRule/UnknownSurroundWhite @@ -6,6 +6,7 @@ +