From 50ba53ff44cc91f2a080707593373d5650bfce17 Mon Sep 17 00:00:00 2001 From: Antonio Orta <60408336+19690ao@users.noreply.github.com> Date: Fri, 29 Sep 2023 16:43:19 -0400 Subject: [PATCH 01/35] Region Based Changes (#559) Co-authored-by: Hanson Gu <123511202+hansongu123@users.noreply.github.com> --- .../puzzle/nurikabe/NurikabeUtilities.java | 63 +++++++++++++++++++ .../rules/NoNumberContradictionRule.java | 22 +++---- 2 files changed, 73 insertions(+), 12 deletions(-) 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 34278ff9f..024cf6bb2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeUtilities.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeUtilities.java @@ -241,4 +241,67 @@ public static HashMap getWhiteRegionMap(NurikabeBoard boa } return whiteRegionMap; } + + /** + * Gets all the non-black cells connected to the given cell + * + * @param board nurikabe board + * @param center nurikabe cell + * @return a set of all white/numbered cells in the region + */ + public static Set getSurroundedRegionOf(NurikabeBoard board, NurikabeCell center) { + int width = board.getWidth(); + int height = board.getHeight(); + + // Mark all the vertices as not visited(By default + // set as false) + Set visited = new HashSet<>(); + + // Create a queue for BFS + LinkedList queue = new LinkedList<>(); + + // Mark the current node as visited and enqueue it + visited.add(center); + queue.add(center); + + // Set of cells in the current region + Set connected = new HashSet<>(); + + while (queue.size() != 0) { + // Dequeue a vertex from queue and print it + // s is the source node in the graph + NurikabeCell s = queue.poll(); + System.out.print(s + " "); + + // Make a set of all adjacent squares + Set adj = new HashSet<>(); + + Point loc = s.getLocation(); + // First check if the side is on the board + if (loc.x >= 1) { + adj.add(board.getCell(loc.x - 1, loc.y)); + } + if (loc.x < width - 1) { + adj.add(board.getCell(loc.x + 1, loc.y)); + } + if (loc.y >= 1) { + adj.add(board.getCell(loc.x, loc.y - 1)); + } + if (loc.y < height - 1) { + adj.add(board.getCell(loc.x, loc.y + 1)); + } + // Get all adjacent vertices of the dequeued vertex s + // If a adjacent has not been visited, then mark it + // visited and enqueue it + for (NurikabeCell n : adj) { + if (!visited.contains(n) && n.getType() != NurikabeType.BLACK) { + connected.add(n); + visited.add(n); + queue.add(n); + } + } + } + + return connected; + } } 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 06eb9d2eb..c2752da7a 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 @@ -42,20 +42,18 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { return super.getInvalidUseOfRuleMessage() + ": " + this.INVALID_USE_MESSAGE; } -// If the transition creates a room of white cells with no number, a contradiction occurs. - DisjointSets anotherRegion = NurikabeUtilities.getPossibleWhiteRegions(nurikabeBoard); - List> allsets = anotherRegion.getAllSets(); - for (Set s : allsets) { - boolean numberExists = false; - for (NurikabeCell c : s) { - if (c.getType() == NurikabeType.NUMBER) { - numberExists = true; - } - } - if (!numberExists) { - return null; + Set region = NurikabeUtilities.getSurroundedRegionOf(nurikabeBoard, cell); + + boolean numberExists = false; + for (NurikabeCell c : region) { + if (c.getType() == NurikabeType.NUMBER) { + numberExists = true; + break; } } + if (!numberExists) { + return null; + } return super.getNoContradictionMessage() + ": " + this.NO_CONTRADICTION_MESSAGE; } From f3dbafb2791ed0c1280730649441fb1edbd83345 Mon Sep 17 00:00:00 2001 From: Charles Tian <46334090+charlestian23@users.noreply.github.com> Date: Fri, 29 Sep 2023 17:15:00 -0400 Subject: [PATCH 02/35] Short Truth Table Puzzle Editor (#451) * Created files for STT elements * Renamed Tiles classes to Elements to match package name Also added an elements reference sheet and renamed rules reference sheet accordingly * More progress made This won't compile, just saving progress made * More progress being made * Fixed file name typo and added placeholder tiles * Added image paths * Created element classes and added placeholder tile images (#452) * Renamed Tiles classes to Elements to match package name Also added an elements reference sheet and renamed rules reference sheet accordingly * More progress made This won't compile, just saving progress made * More progress being made * Fixed file name typo and added placeholder tiles * Added image paths * Set the current board on boardView * Fixed typo and turned on STT puzzle editor for testing * Added preliminary valid dimensions checker This will most definitely change in the future, hopefully can change to accept a number of statements * Fixed image file paths * Added ActionListener Allows us to determine what puzzle is selected by the user * Hide rows and columns input for Short Truth Table * Added text area for Short Truth Table * Added scrollbars to show up as needed * Reformatted code * More code reformatting * Even more reformatting * Separate the data from the TextArea into different lines * Did some researching/testing Tested certain variable values with a STT file with no true/false values * Made more progress Added new methods to handle creating Short Truth Table boards from an array of strings * Added a bunch of TODOs - Implemented a couple functions to be used later - Added a bunch of TODO comments for future work * Made some more progress * Implemented abstract methods from PuzzleImporter * Added abstract methods to Fillapix and added other exception reporting * CheckStyle formatting * Removed a TODO comment * Statements show up in puzzle editor Fixed a bug where the importer was not properly being initialized. Statements now show up in the puzzle editor. * Removed empty statements * Changed InvalidFormatException to IllegalArgumentException * Remove argument that has already been caught * Removed elements that will not be used * Added puzzle editor cell clicking functionality * Added ability to toggle certain logical elements * New icons and more functionality implemented * Fixed a bug where spacer rows could be modified * Added statement error checking * Fixed formatting * Only one logic symbol element needed * Changed InputMismatchException to UnsupportedOperationException * Renamed variables to not be STT specific * Finding initial issue and starting fix * Issue is statement copying and modifying * STT exporter now working. Overrode setCell for STTBoard. * Added code documentation * removed testing println() * Gradle fixes * Revert "Merge pull request #545 from MMosley502/puzzle_editor-short_truth_table-file_saving" This reverts commit 2e82547896a7fb3e52ec27634cd8938ef299732f, reversing changes made to beb60a2ab67c8317d404f54e52471739f698bf22. * Saving files now works * Fixed the blank element to be categorized as a placeable element * Fixed a bug where file wouldn't save due to batch grader updates * Reformatted code in STT * Reformatted code again * MORE REFORMATTING Pls like my code CheckStyle --------- Co-authored-by: Matthew Mosley Co-authored-by: MMosley502 <74743867+MMosley502@users.noreply.github.com> --- bin/main/edu/rpi/legup/legup/config | 2 +- puzzles files/shorttruthtable/empty_test.xml | 14 +++ .../edu/rpi/legup/app/GameBoardFacade.java | 84 ++++++++++++-- src/main/java/edu/rpi/legup/model/Puzzle.java | 14 +++ .../edu/rpi/legup/model/PuzzleExporter.java | 1 + .../edu/rpi/legup/model/PuzzleImporter.java | 19 +++- .../java/edu/rpi/legup/model/tree/Tree.java | 1 + .../puzzle/battleship/BattleshipImporter.java | 15 +++ .../puzzle/fillapix/FillapixImporter.java | 15 +++ .../puzzle/heyawake/HeyawakeImporter.java | 15 +++ .../legup/puzzle/lightup/LightUpImporter.java | 15 +++ .../rpi/legup/puzzle/masyu/MasyuImporter.java | 15 +++ .../puzzle/nurikabe/NurikabeImporter.java | 15 +++ .../shorttruthtable/ShortTruthTable.java | 29 ++++- .../shorttruthtable/ShortTruthTableCell.java | 103 +++++++++++++++++- .../ShortTruthTableCellType.java | 1 + .../ShortTruthTableController.java | 2 +- .../ShortTruthTableExporter.java | 9 +- .../ShortTruthTableImporter.java | 80 ++++++++++++-- .../elements/ArgumentElement.java | 9 ++ .../elements/GreenElement.java | 9 ++ .../elements/LogicSymbolElement.java | 9 ++ .../shorttruthtable/elements/RedElement.java | 9 ++ .../elements/UnknownElement.java | 9 ++ .../shorttruthtable_elements_reference_sheet | 6 + ...shorttruthtable_rules_reference_sheet.txt} | 0 .../skyscrapers/SkyscrapersImporter.java | 15 +++ .../legup/puzzle/sudoku/SudokuImporter.java | 15 +++ .../puzzle/treetent/TreeTentImporter.java | 15 +++ .../edu/rpi/legup/ui/CreatePuzzleDialog.java | 79 ++++++++++++-- src/main/java/edu/rpi/legup/ui/HomePanel.java | 27 ++++- .../edu/rpi/legup/ui/PuzzleEditorPanel.java | 14 +++ .../shorttruthtable/tiles/AndOrTile.png | Bin 0 -> 442 bytes .../tiles/ConditionalBiconditionalTile.png | Bin 0 -> 326 bytes .../shorttruthtable/tiles/GreenTile.png | Bin 0 -> 190 bytes .../shorttruthtable/tiles/LetterTile.png | Bin 0 -> 579 bytes .../images/shorttruthtable/tiles/RedTile.png | Bin 0 -> 152 bytes .../shorttruthtable/tiles/UnknownTile.png | Bin 0 -> 9733 bytes src/main/resources/edu/rpi/legup/legup/config | 2 +- 39 files changed, 629 insertions(+), 38 deletions(-) create mode 100644 puzzles files/shorttruthtable/empty_test.xml create mode 100644 src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/ArgumentElement.java create mode 100644 src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/GreenElement.java create mode 100644 src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/LogicSymbolElement.java create mode 100644 src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/RedElement.java create mode 100644 src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/UnknownElement.java create mode 100644 src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/shorttruthtable_elements_reference_sheet rename src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/{shorttruthtable_reference_sheet.txt => shorttruthtable_rules_reference_sheet.txt} (100%) create mode 100644 src/main/resources/edu/rpi/legup/images/shorttruthtable/tiles/AndOrTile.png create mode 100644 src/main/resources/edu/rpi/legup/images/shorttruthtable/tiles/ConditionalBiconditionalTile.png create mode 100644 src/main/resources/edu/rpi/legup/images/shorttruthtable/tiles/GreenTile.png create mode 100644 src/main/resources/edu/rpi/legup/images/shorttruthtable/tiles/LetterTile.png create mode 100644 src/main/resources/edu/rpi/legup/images/shorttruthtable/tiles/RedTile.png create mode 100644 src/main/resources/edu/rpi/legup/images/shorttruthtable/tiles/UnknownTile.png diff --git a/bin/main/edu/rpi/legup/legup/config b/bin/main/edu/rpi/legup/legup/config index bb7da871a..24fdcf365 100644 --- a/bin/main/edu/rpi/legup/legup/config +++ b/bin/main/edu/rpi/legup/legup/config @@ -27,7 +27,7 @@ + fileCreationDisabled="false"/> diff --git a/puzzles files/shorttruthtable/empty_test.xml b/puzzles files/shorttruthtable/empty_test.xml new file mode 100644 index 000000000..2d8e4b6c8 --- /dev/null +++ b/puzzles files/shorttruthtable/empty_test.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/main/java/edu/rpi/legup/app/GameBoardFacade.java b/src/main/java/edu/rpi/legup/app/GameBoardFacade.java index 2686086a8..55273ab4f 100644 --- a/src/main/java/edu/rpi/legup/app/GameBoardFacade.java +++ b/src/main/java/edu/rpi/legup/app/GameBoardFacade.java @@ -1,23 +1,22 @@ package edu.rpi.legup.app; +import edu.rpi.legup.history.History; import edu.rpi.legup.history.IHistoryListener; import edu.rpi.legup.history.IHistorySubject; +import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.PuzzleImporter; import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.tree.Tree; +import edu.rpi.legup.save.InvalidFileFormatException; +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 edu.rpi.legup.save.InvalidFileFormatException; -import edu.rpi.legup.ui.LegupUI; -import edu.rpi.legup.history.History; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -144,6 +143,30 @@ 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 + * @throws RuntimeException if any of the input is invalid + */ + public boolean validateTextInput(String game, String[] statements) throws RuntimeException { + String qualifiedClassName = config.getPuzzleClassForName(game); + try { + Class c = Class.forName(qualifiedClassName); + Constructor constructor = c.getConstructor(); + Puzzle puzzle = (Puzzle) constructor.newInstance(); + return puzzle.isValidTextInput(statements); + } + catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | + InstantiationException e) { + LOGGER.error(e); + throw new RuntimeException("Error validating puzzle text input"); + } + } + /** * Loads an empty puzzle * @@ -159,7 +182,6 @@ public void loadPuzzle(String game, int rows, int columns) throws RuntimeExcepti Class c = Class.forName(qualifiedClassName); Constructor cons = c.getConstructor(); Puzzle puzzle = (Puzzle) cons.newInstance(); - setWindowTitle(puzzle.getName(), "New " + puzzle.getName() + " Puzzle"); PuzzleImporter importer = puzzle.getImporter(); if (importer == null) { @@ -167,6 +189,13 @@ public void loadPuzzle(String game, int rows, int columns) throws RuntimeExcepti throw new RuntimeException("Puzzle importer null"); } + // 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"); + } + + setWindowTitle(puzzle.getName(), "New " + puzzle.getName() + " Puzzle"); importer.initializePuzzle(rows, columns); puzzle.initializeView(); @@ -183,6 +212,45 @@ public void loadPuzzle(String game, int rows, int columns) throws RuntimeExcepti } } + public void loadPuzzle(String game, String[] statements) { + String qualifiedClassName = config.getPuzzleClassForName(game); + LOGGER.debug("Loading " + qualifiedClassName); + + try { + Class c = Class.forName(qualifiedClassName); + Constructor cons = c.getConstructor(); + Puzzle puzzle = (Puzzle) cons.newInstance(); + + PuzzleImporter importer = puzzle.getImporter(); + if (importer == null) { + LOGGER.error("Puzzle importer is null"); + throw new RuntimeException("Puzzle importer null"); + } + + // 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"); + } + + setWindowTitle(puzzle.getName(), "New " + puzzle.getName() + " Puzzle"); + importer.initializePuzzle(statements); + + puzzle.initializeView(); +// puzzle.getBoardView().onTreeElementChanged(puzzle.getTree().getRootNode()); + setPuzzleEditor(puzzle); + } + catch (IllegalArgumentException exception) { + throw new IllegalArgumentException(exception.getMessage()); + } + catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | + IllegalAccessException | InstantiationException e) { + LOGGER.error(e); + throw new RuntimeException("Puzzle creation error"); + } + + } + /** * Loads a puzzle file * diff --git a/src/main/java/edu/rpi/legup/model/Puzzle.java b/src/main/java/edu/rpi/legup/model/Puzzle.java index d25afa2cb..18614131b 100644 --- a/src/main/java/edu/rpi/legup/model/Puzzle.java +++ b/src/main/java/edu/rpi/legup/model/Puzzle.java @@ -204,12 +204,26 @@ public boolean isValidDimensions(int rows, int columns) { return rows > 0 && columns > 0; } + /** + * Checks if the given array of statements is valid text input for the given puzzle + * + * @param statements + * @return + */ + public boolean isValidTextInput(String[] statements) { + return statements.length > 0; + } + /** * Determines if the edu.rpi.legup.puzzle was solves correctly * * @return true if the board was solved correctly, false otherwise */ public boolean isPuzzleComplete() { + if (tree == null) { + return false; + } + boolean isComplete = tree.isValid(); if (isComplete) { for (TreeElement leaf : tree.getLeafTreeElements()) { diff --git a/src/main/java/edu/rpi/legup/model/PuzzleExporter.java b/src/main/java/edu/rpi/legup/model/PuzzleExporter.java index a2f662772..613d2ed1c 100644 --- a/src/main/java/edu/rpi/legup/model/PuzzleExporter.java +++ b/src/main/java/edu/rpi/legup/model/PuzzleExporter.java @@ -29,6 +29,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) { diff --git a/src/main/java/edu/rpi/legup/model/PuzzleImporter.java b/src/main/java/edu/rpi/legup/model/PuzzleImporter.java index c2b5b37fc..327a92773 100644 --- a/src/main/java/edu/rpi/legup/model/PuzzleImporter.java +++ b/src/main/java/edu/rpi/legup/model/PuzzleImporter.java @@ -12,10 +12,7 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public abstract class PuzzleImporter { private static final Logger LOGGER = LogManager.getLogger(PuzzleImporter.class.getName()); @@ -24,12 +21,17 @@ public abstract class PuzzleImporter { /** * PuzzleImporter Constructor creates the puzzle object + * * @param puzzle puzzle that is imported */ public PuzzleImporter(Puzzle puzzle) { this.puzzle = puzzle; } + public abstract boolean acceptsRowsAndColumnsInput(); + + public abstract boolean acceptsTextInput(); + /** * Initializes an empty puzzle * @@ -46,6 +48,13 @@ public void initializePuzzle(int rows, int columns) throws RuntimeException { } } + 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. + initializeBoard(statements); + } + /** * Initializes the puzzle attributes * @@ -116,6 +125,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; + /** * Creates the proof for building * 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 31ef92359..79c0bcece 100644 --- a/src/main/java/edu/rpi/legup/model/tree/Tree.java +++ b/src/main/java/edu/rpi/legup/model/tree/Tree.java @@ -101,6 +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 */ 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 aa7209f71..749ceaaa9 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipImporter.java @@ -13,6 +13,16 @@ public BattleshipImporter(Battleship battleShip) { super(battleShip); } + @Override + public boolean acceptsRowsAndColumnsInput() { + return true; + } + + @Override + public boolean acceptsTextInput() { + return false; + } + /** * Creates an empty board for building * @@ -177,4 +187,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { "unknown value where integer expected"); } } + + @Override + public void initializeBoard(String[] statements) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Battleship cannot accept text input"); + } } 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 45ad786e8..6c30b2272 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixImporter.java @@ -13,6 +13,16 @@ public FillapixImporter(Fillapix fillapix) { super(fillapix); } + @Override + public boolean acceptsRowsAndColumnsInput() { + return true; + } + + @Override + public boolean acceptsTextInput() { + return false; + } + /** * Creates an empty board for building * @@ -88,4 +98,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { throw new InvalidFileFormatException("Fillapix Importer: unknown value where integer expected"); } } + + @Override + public void initializeBoard(String[] statements) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Fillapix cannot accept text input"); + } } 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 d09a15389..7527c717f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeImporter.java @@ -14,6 +14,16 @@ public HeyawakeImporter(Heyawake heyawake) { super(heyawake); } + @Override + public boolean acceptsRowsAndColumnsInput() { + return true; + } + + @Override + public boolean acceptsTextInput() { + return false; + } + /** * Creates an empty board for building * @@ -91,4 +101,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { throw new InvalidFileFormatException("Heyawake Importer: unknown value where integer expected"); } } + + @Override + public void initializeBoard(String[] statements) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Hey Awake cannot accept text input"); + } } 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 fd9fd49e9..7ef24ca69 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpImporter.java @@ -13,6 +13,16 @@ public LightUpImporter(LightUp lightUp) { super(lightUp); } + @Override + public boolean acceptsRowsAndColumnsInput() { + return true; + } + + @Override + public boolean acceptsTextInput() { + return false; + } + /** * Creates an empty board for building * @@ -102,4 +112,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { throw new InvalidFileFormatException("lightup Importer: unknown value where integer expected"); } } + + @Override + public void initializeBoard(String[] statements) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Light Up cannot accept text input"); + } } 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 50bf0c0c7..3e0d328c4 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuImporter.java @@ -13,6 +13,16 @@ public MasyuImporter(Masyu masyu) { super(masyu); } + @Override + public boolean acceptsRowsAndColumnsInput() { + return true; + } + + @Override + public boolean acceptsTextInput() { + return false; + } + /** * Creates an empty board for building * @@ -90,4 +100,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { throw new InvalidFileFormatException("Masyu Importer: unknown value where integer expected"); } } + + @Override + public void initializeBoard(String[] statements) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Masyu cannot accept text input"); + } } 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 7665a4865..2cbcc9ad0 100644 --- a/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/nurikabe/NurikabeImporter.java @@ -13,6 +13,16 @@ public NurikabeImporter(Nurikabe nurikabe) { super(nurikabe); } + @Override + public boolean acceptsRowsAndColumnsInput() { + return true; + } + + @Override + public boolean acceptsTextInput() { + return false; + } + /** * Creates an empty board for building * @@ -100,4 +110,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { throw new InvalidFileFormatException("nurikabe Importer: unknown value where integer expected"); } } + + @Override + public void initializeBoard(String[] statements) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Nurikabe cannot accept text input"); + } } 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 3ce185b6c..e8f9ffc0d 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTable.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTable.java @@ -25,6 +25,7 @@ public ShortTruthTable() { public void initializeView() { ShortTruthTableBoard sttBoard = (ShortTruthTableBoard) currentBoard; boardView = new ShortTruthTableView(sttBoard); + boardView.setBoard(currentBoard); addBoardListener(boardView); } @@ -48,8 +49,32 @@ public Board generatePuzzle(int difficulty) { * @return true if the given dimensions are valid for Short Truth Table, false otherwise */ public boolean isValidDimensions(int rows, int columns) { - // This is a placeholder, this method needs to be implemented - throw new UnsupportedOperationException(); + // Number of rows must be odd to allow for proper spacing between the statements + if (rows % 2 != 1) { + return false; + } + + return true; + } + + /** + * Determines if the given statements are valid for Short Truth Table + * + * @param statements + * @return true if the statements are valid for Short Truth Table, false otherwise + */ + public boolean isValidTextInput(String[] statements) { + if (statements.length == 0) { + return false; + } + + ShortTruthTableImporter importer = (ShortTruthTableImporter) this.getImporter(); + for (String s : statements) { + if (!importer.validGrammar(s)) { + return false; + } + } + return true; } /** diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCell.java b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCell.java index 768b4ed2a..59b5f4272 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCell.java @@ -1,15 +1,17 @@ package edu.rpi.legup.puzzle.shorttruthtable; +import edu.rpi.legup.model.elements.Element; import edu.rpi.legup.model.gameboard.GridCell; import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableStatement; import java.awt.Point; +import java.awt.event.MouseEvent; public class ShortTruthTableCell extends GridCell { //The symbol on the cell - private final char symbol; + private char symbol; //This is a reference to the statement that contains this cell private ShortTruthTableStatement statement; @@ -127,5 +129,104 @@ public ShortTruthTableCell copy() { return copy; } + /** + * Sets the type of this ShortTruthTableCell + * + * @param e element to set the type of this Short Truth Table cell to + */ + @Override + public void setType(Element e, MouseEvent m) { + // Do not allow odd rows to be modified since they are spacer rows + if (this.getLocation().getY() % 2 == 1) { + return; + } + // Red Element + if (e.getElementID().equals("STTT-PLAC-0002")) { + this.data = ShortTruthTableCellType.FALSE; + } + // Green Element + else { + if (e.getElementID().equals("STTT-PLAC-0001")) { + this.data = ShortTruthTableCellType.TRUE; + } + // Unknown Element + else { + if (e.getElementID().equals("STTT-PLAC-0003")) { + this.data = ShortTruthTableCellType.UNKNOWN; + } + // Argument Element + else { + if (e.getElementID().equals("STTT-UNPL-0001")) { + // Prevents non-argument symbols from being changed + if (!(this.symbol >= 'A' && this.symbol <= 'Z')) { + return; + } + + if (m.getButton() == MouseEvent.BUTTON1) { + this.symbol += 1; + if (this.symbol > 'Z') { + this.symbol = 'A'; + } + } + else { + if (m.getButton() == MouseEvent.BUTTON3) { + this.symbol -= 1; + if (this.symbol < 'A') { + this.symbol = 'Z'; + } + } + } + } + // And/Or Element + else { + if (e.getElementID().equals("STTT-UNPL-0002")) { + if (m.getButton() == MouseEvent.BUTTON1) { + if (this.symbol == '^') { + this.symbol = '|'; + } + else { + if (this.symbol == '|') { + this.symbol = '>'; + } + else { + if (this.symbol == '>') { + this.symbol = '-'; + } + else { + if (this.symbol == '-') { + this.symbol = '^'; + } + } + } + } + } + else { + if (m.getButton() == MouseEvent.BUTTON3) { + if (this.symbol == '^') { + this.symbol = '-'; + } + else { + if (this.symbol == '|') { + this.symbol = '^'; + } + else { + if (this.symbol == '>') { + this.symbol = '|'; + } + else { + if (this.symbol == '-') { + this.symbol = '>'; + } + } + } + } + } + } + } + } + } + } + } + } } \ No newline at end of file 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 c01fe74d8..c997faf5f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellType.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableCellType.java @@ -26,6 +26,7 @@ public static ShortTruthTableCellType valueOf(int cellType) { /** * Gets the char value of a cell, Used for debugging + * * @param type cell type input * @return true if value is 1, false if value is 0, ? if value is -1, or blank otherwise */ 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 ccf4e9274..bddde44a5 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableController.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableController.java @@ -12,7 +12,7 @@ public void changeCell(MouseEvent e, PuzzleElement data) { System.out.println("STTController: Cell change"); - //cast the data to a short truth table cell + // cast the data to a short truth table cell ShortTruthTableCell cell = (ShortTruthTableCell) data; if (e.getButton() == MouseEvent.BUTTON1) { 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 bcb744789..9d6553c7c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableExporter.java @@ -2,6 +2,7 @@ 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 { @@ -12,7 +13,13 @@ public ShortTruthTableExporter(ShortTruthTable stt) { @Override protected org.w3c.dom.Element createBoardElement(Document newDocument) { - ShortTruthTableBoard board = (ShortTruthTableBoard) puzzle.getTree().getRootNode().getBoard(); + ShortTruthTableBoard board; + if (puzzle.getTree() != null) { + board = (ShortTruthTableBoard) puzzle.getTree().getRootNode().getBoard(); + } + else { + board = (ShortTruthTableBoard) puzzle.getBoardView().getBoard(); + } org.w3c.dom.Element boardElement = newDocument.createElement("board"); 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 cccdbca19..84d04fb45 100644 --- a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/ShortTruthTableImporter.java @@ -3,16 +3,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 org.w3c.dom.NamedNodeMap; +import javax.swing.*; import java.awt.*; - -import java.util.List; import java.util.ArrayList; - -import javax.swing.*; +import java.util.LinkedList; +import java.util.List; class ShortTruthTableImporter extends PuzzleImporter { @@ -55,8 +54,8 @@ private List getCells(String statement, int y) { * @return the length, in chars, of the longest statement */ private int parseAllStatementsAndCells(final NodeList statementData, - List> allCells, - List statements) throws InvalidFileFormatException { + List> allCells, + List statements) throws InvalidFileFormatException { int maxStatementLength = 0; @@ -65,7 +64,10 @@ private int parseAllStatementsAndCells(final NodeList statementData, //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 if (!validGrammar(statementRep)) { @@ -85,10 +87,32 @@ private int parseAllStatementsAndCells(final NodeList statementData, } return maxStatementLength; + } + + 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"); + } + + //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 + maxStatementLength = Math.max(maxStatementLength, statementData[i].length()); + } + return maxStatementLength; } - private boolean validGrammar(String sentence) { + protected boolean validGrammar(String sentence) { int open = 0; int close = 0; char[] valid_characters = new char[]{'^', 'v', '!', '>', '-', '&', '|', '~', '$', '%'}; @@ -217,6 +241,16 @@ private void setGivenCells(ShortTruthTableBoard sttBoard, } + @Override + public boolean acceptsRowsAndColumnsInput() { + return false; + } + + @Override + public boolean acceptsTextInput() { + return true; + } + /** * Creates an empty board for building * @@ -278,9 +312,37 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { catch (NumberFormatException e) { throw new InvalidFileFormatException("short truth table Importer: unknown value where integer expected"); } + } + /** + * Creates the board for building using statements + * + * @param statementInput + * @throws UnsupportedOperationException + * @throws IllegalArgumentException + */ + public void initializeBoard(String[] statementInput) throws UnsupportedOperationException, IllegalArgumentException { + List statementsList = new LinkedList<>(); + for (String s : statementInput) { + if (s.strip().length() > 0) { + statementsList.add(s); + } + } + String[] statementData = statementsList.toArray(new String[statementsList.size()]); - } + if (statementData.length == 0) { + throw new IllegalArgumentException("short truth table Importer: no statements found for board"); + } + // Store all cells and statements + List> allCells = new ArrayList<>(); + List statements = new ArrayList<>(); + // Parse the data + int maxStatementLength = parseAllStatementsAndCells(statementData, allCells, statements); + + // Generate and set the board - don't set given cell values since none are given + ShortTruthTableBoard sttBoard = generateBoard(allCells, statements, maxStatementLength); + puzzle.setCurrentBoard(sttBoard); + } } 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 new file mode 100644 index 000000000..9f238a9bf --- /dev/null +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/ArgumentElement.java @@ -0,0 +1,9 @@ +package edu.rpi.legup.puzzle.shorttruthtable.elements; + +import edu.rpi.legup.model.elements.NonPlaceableElement; + +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"); + } +} 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 new file mode 100644 index 000000000..605f6a207 --- /dev/null +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/GreenElement.java @@ -0,0 +1,9 @@ +package edu.rpi.legup.puzzle.shorttruthtable.elements; + +import edu.rpi.legup.model.elements.PlaceableElement; + +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"); + } +} 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 new file mode 100644 index 000000000..b2adfddef --- /dev/null +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/LogicSymbolElement.java @@ -0,0 +1,9 @@ +package edu.rpi.legup.puzzle.shorttruthtable.elements; + +import edu.rpi.legup.model.elements.NonPlaceableElement; + +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"); + } +} 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 new file mode 100644 index 000000000..ecc7d5a02 --- /dev/null +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/RedElement.java @@ -0,0 +1,9 @@ +package edu.rpi.legup.puzzle.shorttruthtable.elements; + +import edu.rpi.legup.model.elements.PlaceableElement; + +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"); + } +} 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 new file mode 100644 index 000000000..9a9ab8b84 --- /dev/null +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/UnknownElement.java @@ -0,0 +1,9 @@ +package edu.rpi.legup.puzzle.shorttruthtable.elements; + +import edu.rpi.legup.model.elements.PlaceableElement; + +public class UnknownElement extends PlaceableElement { + public UnknownElement() { + 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/elements/shorttruthtable_elements_reference_sheet b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/shorttruthtable_elements_reference_sheet new file mode 100644 index 000000000..471631553 --- /dev/null +++ b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/elements/shorttruthtable_elements_reference_sheet @@ -0,0 +1,6 @@ +STTT-UNPL-0001 : ArgumentElement +STTT-UNPL-0002 : ConditionalBiconditionalElement + +STTT-PLAC-0001 : GreenElement +STTT-PLAC-0002 : RedElement +STTT-PLAC-0003 : UnknownElement \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/shorttruthtable_reference_sheet.txt b/src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/shorttruthtable_rules_reference_sheet.txt similarity index 100% rename from src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/shorttruthtable_reference_sheet.txt rename to src/main/java/edu/rpi/legup/puzzle/shorttruthtable/rules/shorttruthtable_rules_reference_sheet.txt 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 22af18a4c..6dded9764 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersImporter.java @@ -13,6 +13,16 @@ public SkyscrapersImporter(Skyscrapers skyscrapers) { super(skyscrapers); } + @Override + public boolean acceptsRowsAndColumnsInput() { + return true; + } + + @Override + public boolean acceptsTextInput() { + return false; + } + /** * Creates an empty board for building * @@ -150,4 +160,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { throw new InvalidFileFormatException("Skyscraper Importer: unknown value where integer expected"); } } + + @Override + public void initializeBoard(String[] statements) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Skyscrapers cannot accept text input"); + } } 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 f77a68d7a..dccec52d4 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuImporter.java @@ -13,6 +13,16 @@ public SudokuImporter(Sudoku sudoku) { super(sudoku); } + @Override + public boolean acceptsRowsAndColumnsInput() { + return true; + } + + @Override + public boolean acceptsTextInput() { + return false; + } + /** * Creates an empty board for building * @@ -112,4 +122,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { throw new InvalidFileFormatException("Sudoku Importer: unknown value where integer expected"); } } + + @Override + public void initializeBoard(String[] statements) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Sudoku cannot accept text input"); + } } 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 e48122a7a..2b4861c9f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentImporter.java @@ -13,6 +13,16 @@ public TreeTentImporter(TreeTent treeTent) { super(treeTent); } + @Override + public boolean acceptsRowsAndColumnsInput() { + return true; + } + + @Override + public boolean acceptsTextInput() { + return false; + } + /** * Creates an empty board for building * @@ -174,4 +184,9 @@ public void initializeBoard(Node node) throws InvalidFileFormatException { throw new InvalidFileFormatException("TreeTent Importer: unknown value where integer expected"); } } + + @Override + public void initializeBoard(String[] statements) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Tree Tent cannot accept text input"); + } } diff --git a/src/main/java/edu/rpi/legup/ui/CreatePuzzleDialog.java b/src/main/java/edu/rpi/legup/ui/CreatePuzzleDialog.java index 8e0858b72..fa049ab38 100644 --- a/src/main/java/edu/rpi/legup/ui/CreatePuzzleDialog.java +++ b/src/main/java/edu/rpi/legup/ui/CreatePuzzleDialog.java @@ -9,35 +9,71 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Arrays; +import java.util.Objects; 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 JLabel puzzleLabel = new JLabel("Puzzle:"); + private JLabel puzzleLabel; + private JLabel rowsLabel; private JTextField rows; + private JLabel columnsLabel; private JTextField columns; + private JTextArea textArea; + 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 e the event to be processed + * @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("") || rows.getText().equals("") || columns.getText().equals("")) { + 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 { - homePanel.openEditorWithNewPuzzle(game, Integer.valueOf(rows.getText()), Integer.valueOf(columns.getText())); + 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) { @@ -75,6 +111,7 @@ public CreatePuzzleDialog(JFrame parent, HomePanel homePanel) { Container c = getContentPane(); c.setLayout(null); + puzzleLabel = new JLabel("Puzzle:"); puzzleLabel.setBounds(10, 30, 70, 25); gameBox.setBounds(80, 30, 190, 25); @@ -87,8 +124,8 @@ public CreatePuzzleDialog(JFrame parent, HomePanel homePanel) { rows = new JTextField(); columns = new JTextField(); - JLabel rowsLabel = new JLabel("Rows:"); - JLabel columnsLabel = new JLabel("Columns:"); + rowsLabel = new JLabel("Rows:"); + columnsLabel = new JLabel("Columns:"); rowsLabel.setBounds(30, 70, 60, 25); columnsLabel.setBounds(30, 95, 60, 25); @@ -102,9 +139,31 @@ public CreatePuzzleDialog(JFrame parent, HomePanel homePanel) { c.add(rows); c.add(columns); + textArea = new JTextArea(); + 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); + c.add(ok); c.add(cancel); + if (Objects.equals(this.gameBox.getSelectedItem(), "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); + } + + ActionListener cursorSelectedGame = CursorController.createListener(this, gameBoxListener); + gameBox.addActionListener(cursorSelectedGame); ActionListener cursorPressedOk = CursorController.createListener(this, okButtonListener); ok.addActionListener(cursorPressedOk); ActionListener cursorPressedCancel = CursorController.createListener(this, cancelButtonListener); @@ -123,7 +182,13 @@ public void actionPerformed(ActionEvent e) { String game = Config.convertDisplayNameToClassName((String) gameBox.getSelectedItem()); try { - this.homePanel.openEditorWithNewPuzzle(game, Integer.valueOf(this.rows.getText()), Integer.valueOf(this.columns.getText())); + 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.setVisible(false); } catch (IllegalArgumentException exception) { diff --git a/src/main/java/edu/rpi/legup/ui/HomePanel.java b/src/main/java/edu/rpi/legup/ui/HomePanel.java index f72694cc0..48f0d03d7 100644 --- a/src/main/java/edu/rpi/legup/ui/HomePanel.java +++ b/src/main/java/edu/rpi/legup/ui/HomePanel.java @@ -1,11 +1,9 @@ package edu.rpi.legup.ui; -import edu.rpi.legup.Legup; 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.app.LegupPreferences; import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.PuzzleExporter; import edu.rpi.legup.save.ExportFileException; @@ -29,7 +27,6 @@ import java.io.FileWriter; import java.net.URI; import java.net.URL; -import java.util.Objects; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -640,4 +637,28 @@ public void openEditorWithNewPuzzle(String game, int rows, int columns) throws I this.legupUI.displayPanel(2); this.legupUI.getPuzzleEditor().loadPuzzleFromHome(game, rows, columns); } + + /** + * 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 + */ + 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.", + "ERROR: Invalid Text Input", + JOptionPane.ERROR_MESSAGE); + throw new IllegalArgumentException("ERROR: Invalid dimensions given"); + } + + // Set game type on the puzzle editor + this.legupUI.displayPanel(2); + this.legupUI.getPuzzleEditor().loadPuzzleFromHome(game, statements); + } } diff --git a/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java b/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java index cce4feec5..90f0c3cdf 100644 --- a/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java @@ -327,6 +327,20 @@ public void loadPuzzleFromHome(String game, int rows, int columns) throws Illega } } + public void loadPuzzleFromHome(String game, String[] statements) { + GameBoardFacade facade = GameBoardFacade.getInstance(); + try { + facade.loadPuzzle(game, statements); + } + catch (IllegalArgumentException exception) { + throw new IllegalArgumentException(exception.getMessage()); + } + catch (RuntimeException e) { + e.printStackTrace(); + LOGGER.error(e.getMessage()); + } + } + // File opener public Object[] promptPuzzle() { GameBoardFacade facade = GameBoardFacade.getInstance(); diff --git a/src/main/resources/edu/rpi/legup/images/shorttruthtable/tiles/AndOrTile.png b/src/main/resources/edu/rpi/legup/images/shorttruthtable/tiles/AndOrTile.png new file mode 100644 index 0000000000000000000000000000000000000000..9ea93250297e9bc46769cc2b1df83fa1fdfdf6a6 GIT binary patch literal 442 zcmV;r0Y(0aP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGf5&!@T5&_cPe*6Fc0Z&OpK~z{r?UFyL zgFq0*CD_J*h2#J^frXyIM#L_cNMRQc3ojrZKu8@@`L9U8KUH$8d9Gxa>^dfS%@ZCQ z_`%Hg&CYyal;H;pqrl_wSOghB29N<{fd3hwC<;`kbX~{luLAhK57+Az^)Pf@hcFCL z&ooU4f`Ij31$Yjj-W+rDqW;`HzdT72ux%Sws}<@~qA23}&1M7V^O@5QhXZ(?$7vq} zP%qDO*lxEIpJEsW*SBrU-cqnTL>s^ZkfWNWv3_ojKn{wUs;Y3m-^V)3GT7~QlbN>x zL_LmUuq=zy2*=}bq7llng!Oto*6(hh0dBV&`Uum=KU>r&Wd3rwpzo+ZfFB~CK-3+_ zf&G5ZX-(5`{VS)_Y24NKJ?g&=AZnCXFHKX!lvI6;>1s;*b3=G^tAk28_ZrvZC;B8MA$B+p3w|yHqTMa~9buXnba%+p9;P6XK zpRK1Hv2=REV-~#!Oie3T?r8m&Hu%%-sLFNdIV<0jd(*}JzSurXRobj`T6+Nl7ZClK z?ht$Z-oK9HENzJ&zNOo!2^`HpV$-uM2lEXSG8IlI&#iZ{%*^CduID~M-Ia|#lP#+3s{dyoCpnV z+%rk#zopr0F1hR+W-In literal 0 HcmV?d00001 diff --git a/src/main/resources/edu/rpi/legup/images/shorttruthtable/tiles/GreenTile.png b/src/main/resources/edu/rpi/legup/images/shorttruthtable/tiles/GreenTile.png new file mode 100644 index 0000000000000000000000000000000000000000..a438e30375f0598657b2a7e3873d3d03655a5b31 GIT binary patch literal 190 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=G^tAk28_ZrvZCV6dl)V@QPi(G!M@K;u{zuFosdJy64^lau~k lJFPP^Y1#}`(x|jD`L~l9qAz|@;AI@Px#1ZP1_K>z@;j|==^1poj532;bRa{vGf5&!@T5&_cPe*6Fc0oX}IK~z{r?Ug;R z0YMaoNk|Bh=twmD0+lETg-S%JRZ?itXb_cxMARw;AsUIoM|_5Vb?!YUcQ?zPowd97 z#w}LzL^9`{vrl$*W*px?_%IH5JRTpx7O(|=MPRjBvE%RXD+1AI6o$hgThqg`z+f<- zCh2sVt?OY~ARdoX6Q9oqhr@x*h_EEE-|rz941(9|rAFm)nazo?Bv2?6pi-$oE|;T5 zkw}Eii7+j2yWJoV2*7+khtX(6jhs#=Y&IJ-Y@ zxL&W|_xoWonaE?cT8)~y-EP?Jc29W`rUa(bDY#rNIG@k**mAj)nnAnWe#(n5C6LeO zq0wll##5=3EOEJ9RCNx+0(k7=Ywq{^DsV?g0?OqPVOXHqY|{E?G8q<0pj0Zc^ItI} zfL}X4Ty*(Vt5s@>Z|R*aX-J^c>Cn;3)g-8GK;V^|4iv^rcCpL>5k4LE2 z>#_h|R!lvI6;>1s;*b3=G_YAk0{w5C;92(%$B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qe6D_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 bb7da871a..24fdcf365 100644 --- a/src/main/resources/edu/rpi/legup/legup/config +++ b/src/main/resources/edu/rpi/legup/legup/config @@ -27,7 +27,7 @@ + fileCreationDisabled="false"/> From bcb8629d97adcd839413702045aefae473de0fed Mon Sep 17 00:00:00 2001 From: Viane Matsibekker <117249183+04vmatsibekker@users.noreply.github.com> Date: Fri, 29 Sep 2023 17:34:47 -0400 Subject: [PATCH 03/35] Have null changes be valid and fix IsolatedBlackContradicitonRule error message (#561) * Get Tests to be called Revert "Create first cypress test template" This reverts commit 3e50909b93b5aa9634cf0d296e9aeff756b0a909. First commit Finish Lightup tests * Add more tests Update TestRunner.java * Somehow ended up in the wrong spot Fix Import * Please let this be the fix Update TreeTransition.java Update TreeTransition.java Update DirectRule.java Check to see which is not correct Update ElementController.java Revert "maybe the null is making it think that it's not valid" This reverts commit 7bf1de0d66ced6749ee37fbb9c252636b2fcdc79. Just trying to change color Revert "Just trying to change color" This reverts commit ec44695ee578d664055d135a668927a0fd900f5d. Revert "maybe the null is making it think that it's not valid" This reverts commit 3f162fbdc32e6fbd23da321a14a6af96f0ff520d. Check to see which is not correct Revert "Check to see which is not correct" This reverts commit 136b0a41b9d103e6f3e9a7f8cd5d970bf76b050b. Update TreeTransition.java Update TreeTransition.java Revert "Update TreeTransition.java" This reverts commit cde45bb9001cfbfa4f6e2a49b4e9990d2fa7ad33. * Fix error with isolated Black Fix error message with isolated black * Removed excess whitespace and imports. Added short JavaDoc for `TestRunner.java` --------- Co-authored-by: Charles Tian <46334090+charlestian23@users.noreply.github.com> Co-authored-by: Bram van Heuveln Co-authored-by: Corppet --- .../history/ValidateContradictionRuleCommand.java | 12 ++++++++++-- .../java/edu/rpi/legup/model/rules/DirectRule.java | 14 ++++---------- src/test/java/legup/TestRunner.java | 7 ++++--- src/test/java/legup/TestUtilities.java | 9 --------- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java b/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java index c5f8f0831..a0f58a571 100644 --- a/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java +++ b/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java @@ -86,9 +86,17 @@ public void executeCommand() { } else { TreeTransitionView transitionView = (TreeTransitionView) firstSelectedView; - finalTreeElement = transitionView.getChildView().getTreeElement(); + if (transitionView.getChildView() != null) { + finalTreeElement = transitionView.getChildView().getTreeElement(); + } + else { + finalTreeElement = null; + } + } + + if (finalTreeElement != null) { + puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement)); } - puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement)); puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection)); } 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 940bbe32f..4acc7573e 100644 --- a/src/main/java/edu/rpi/legup/model/rules/DirectRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/DirectRule.java @@ -29,18 +29,12 @@ public DirectRule(String ruleID, String ruleName, String description, String ima */ public String checkRule(TreeTransition transition) { Board finalBoard = transition.getBoard(); - - if (!finalBoard.isModified()) { - return "State must be modified"; + if (transition.getParents().size() != 1 || + transition.getParents().get(0).getChildren().size() != 1) { + return "State must have only 1 parent and 1 child"; } else { - if (transition.getParents().size() != 1 || - transition.getParents().get(0).getChildren().size() != 1) { - return "State must have only 1 parent and 1 child"; - } - else { - return checkRuleRaw(transition); - } + return checkRuleRaw(transition); } } diff --git a/src/test/java/legup/TestRunner.java b/src/test/java/legup/TestRunner.java index 7e2dbe737..9d79c590e 100644 --- a/src/test/java/legup/TestRunner.java +++ b/src/test/java/legup/TestRunner.java @@ -9,6 +9,9 @@ import puzzles.nurikabe.rules.*; import puzzles.treetent.rules.*; +/** + * 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 @@ -103,6 +106,4 @@ private static void printTestResults(Result result) { 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 d49529921..9f203b223 100644 --- a/src/test/java/legup/TestUtilities.java +++ b/src/test/java/legup/TestUtilities.java @@ -6,11 +6,6 @@ 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 { @@ -21,8 +16,4 @@ public static void importTestBoard(String fileName, Puzzle puzzle) throws Invali TreeTransition transition = new TreeTransition(rootNode, board); rootNode.getChildren().add(transition); } - - } - - From f1c798576c3b4248ae35971d914d101697a5542b Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 3 Oct 2023 16:33:29 -0400 Subject: [PATCH 04/35] Fixed a bug --- .../rpi/legup/puzzle/battleship/BattleshipExporter.java | 9 ++++++++- .../edu/rpi/legup/puzzle/fillapix/FillapixExporter.java | 9 ++++++++- .../edu/rpi/legup/puzzle/heyawake/HeyawakeExporter.java | 9 ++++++++- .../edu/rpi/legup/puzzle/lightup/LightUpExporter.java | 9 ++++++++- .../java/edu/rpi/legup/puzzle/masyu/MasyuExporter.java | 9 ++++++++- .../legup/puzzle/skyscrapers/SkyscrapersExporter.java | 9 ++++++++- .../java/edu/rpi/legup/puzzle/sudoku/SudokuExporter.java | 9 ++++++++- 7 files changed, 56 insertions(+), 7 deletions(-) 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 b954a1065..4205d0125 100644 --- a/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/battleship/BattleshipExporter.java @@ -2,6 +2,7 @@ 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 { @@ -18,7 +19,13 @@ public BattleshipExporter(Battleship battleShip) { */ @Override protected org.w3c.dom.Element createBoardElement(Document newDocument) { - BattleshipBoard board = (BattleshipBoard) puzzle.getTree().getRootNode().getBoard(); + BattleshipBoard board; + if (puzzle.getTree() != null) { + board = (BattleshipBoard) puzzle.getTree().getRootNode().getBoard(); + } + else { + board = (BattleshipBoard) puzzle.getBoardView().getBoard(); + } org.w3c.dom.Element boardElement = newDocument.createElement("board"); boardElement.setAttribute("width", String.valueOf(board.getWidth())); 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 f7dc9d375..757d14cd8 100644 --- a/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixExporter.java @@ -2,6 +2,7 @@ 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 { @@ -12,7 +13,13 @@ public FillapixExporter(Fillapix fillapix) { @Override protected org.w3c.dom.Element createBoardElement(Document newDocument) { - FillapixBoard board = (FillapixBoard) puzzle.getTree().getRootNode().getBoard(); + FillapixBoard board; + if (puzzle.getTree() != null) { + board = (FillapixBoard) puzzle.getTree().getRootNode().getBoard(); + } + else { + board = (FillapixBoard) puzzle.getBoardView().getBoard(); + } org.w3c.dom.Element boardElement = newDocument.createElement("board"); boardElement.setAttribute("width", String.valueOf(board.getWidth())); 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 a23273ab4..344a0be92 100644 --- a/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/heyawake/HeyawakeExporter.java @@ -2,6 +2,7 @@ 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 { @@ -12,7 +13,13 @@ public HeyawakeExporter(Heyawake heyawake) { @Override protected org.w3c.dom.Element createBoardElement(Document newDocument) { - HeyawakeBoard board = (HeyawakeBoard) puzzle.getTree().getRootNode().getBoard(); + HeyawakeBoard board; + if (puzzle.getTree() != null) { + board = (HeyawakeBoard) puzzle.getTree().getRootNode().getBoard(); + } + else { + board = (HeyawakeBoard) puzzle.getBoardView().getBoard(); + } org.w3c.dom.Element boardElement = newDocument.createElement("board"); boardElement.setAttribute("width", String.valueOf(board.getWidth())); 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 78270e112..89024ad6c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpExporter.java @@ -2,6 +2,7 @@ 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 { @@ -12,7 +13,13 @@ public LightUpExporter(LightUp lightUp) { @Override protected org.w3c.dom.Element createBoardElement(Document newDocument) { - LightUpBoard board = (LightUpBoard) puzzle.getTree().getRootNode().getBoard(); + LightUpBoard board; + if (puzzle.getTree() != null) { + board = (LightUpBoard) puzzle.getTree().getRootNode().getBoard(); + } + else { + board = (LightUpBoard) puzzle.getBoardView().getBoard(); + } org.w3c.dom.Element boardElement = newDocument.createElement("board"); boardElement.setAttribute("width", String.valueOf(board.getWidth())); 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 471be22f1..e5fb071b4 100644 --- a/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/masyu/MasyuExporter.java @@ -2,6 +2,7 @@ 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 { @@ -12,7 +13,13 @@ public MasyuExporter(Masyu masyu) { @Override protected org.w3c.dom.Element createBoardElement(Document newDocument) { - MasyuBoard board = (MasyuBoard) puzzle.getTree().getRootNode().getBoard(); + MasyuBoard board; + if (puzzle.getTree() != null) { + board = (MasyuBoard) puzzle.getTree().getRootNode().getBoard(); + } + else { + board = (MasyuBoard) puzzle.getBoardView().getBoard(); + } org.w3c.dom.Element boardElement = newDocument.createElement("board"); boardElement.setAttribute("width", String.valueOf(board.getWidth())); 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 dac09bd16..d5d5a9911 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java @@ -2,6 +2,7 @@ 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 { @@ -12,7 +13,13 @@ public SkyscrapersExporter(Skyscrapers skyscrapers) { @Override protected org.w3c.dom.Element createBoardElement(Document newDocument) { - SkyscrapersBoard board = (SkyscrapersBoard) puzzle.getTree().getRootNode().getBoard(); + SkyscrapersBoard board; + if (puzzle.getTree() != null) { + board = (SkyscrapersBoard) puzzle.getTree().getRootNode().getBoard(); + } + else { + board = (SkyscrapersBoard) puzzle.getBoardView().getBoard(); + } org.w3c.dom.Element boardElement = newDocument.createElement("board"); boardElement.setAttribute("width", String.valueOf(board.getWidth())); 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 5950fa7f4..45e320293 100644 --- a/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/sudoku/SudokuExporter.java @@ -2,6 +2,7 @@ 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 { @@ -12,7 +13,13 @@ public SudokuExporter(Sudoku sudoku) { @Override protected org.w3c.dom.Element createBoardElement(Document newDocument) { - SudokuBoard board = (SudokuBoard) puzzle.getTree().getRootNode().getBoard(); + SudokuBoard board; + if (puzzle.getTree() != null) { + board = (SudokuBoard) puzzle.getTree().getRootNode().getBoard(); + } + else { + board = (SudokuBoard) puzzle.getBoardView().getBoard(); + } org.w3c.dom.Element boardElement = newDocument.createElement("board"); boardElement.setAttribute("size", String.valueOf(board.getSize())); From 473300c6a7b721acca5fce92171eaa5290246ea2 Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 3 Oct 2023 16:57:53 -0400 Subject: [PATCH 05/35] Update BlackTile.java Black tile should not be placeable --- .../edu/rpi/legup/puzzle/lightup/elements/BlackTile.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 b72ae1fab..d3e8cf506 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 @@ -1,9 +1,9 @@ package edu.rpi.legup.puzzle.lightup.elements; -import edu.rpi.legup.model.elements.PlaceableElement; +import edu.rpi.legup.model.elements.NonPlaceableElement; -public class BlackTile extends PlaceableElement { +public class BlackTile extends NonPlaceableElement { public BlackTile() { - super("LTUP-PLAC-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"); } } From 0832621a55f4c96f439dafe159a03bccbc4b6e69 Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 3 Oct 2023 17:04:55 -0400 Subject: [PATCH 06/35] Added unknown tile stuff --- .../puzzle/lightup/elements/UnknownTile.java | 9 +++++++++ .../edu/rpi/legup/images/lightup/UnknownTile.png | Bin 0 -> 9733 bytes 2 files changed, 9 insertions(+) create mode 100644 src/main/java/edu/rpi/legup/puzzle/lightup/elements/UnknownTile.java create mode 100644 src/main/resources/edu/rpi/legup/images/lightup/UnknownTile.png 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 new file mode 100644 index 000000000..b2b93667a --- /dev/null +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/elements/UnknownTile.java @@ -0,0 +1,9 @@ +package edu.rpi.legup.puzzle.lightup.elements; + +import edu.rpi.legup.model.elements.NonPlaceableElement; + +public class UnknownTile extends NonPlaceableElement { + public UnknownTile() { + super("NURI-UNPL-0003", "Unknown Tile", "A blank tile", "edu/rpi/legup/images/lightup/UnknownTile.png"); + } +} diff --git a/src/main/resources/edu/rpi/legup/images/lightup/UnknownTile.png b/src/main/resources/edu/rpi/legup/images/lightup/UnknownTile.png new file mode 100644 index 0000000000000000000000000000000000000000..850fbf127f04020fe83c6a4f6db75078967916ea GIT binary patch literal 9733 zcmeHNc{G&m`yaAXmTak)X=KYg%*HS^C}WMXl|9BR3}%Lz(F{qlgir~QEfj5%rPW@R z5)lchi0qNbR+8UCz3*G+_dVx#-gAE6|ID0c=6SCBx<1!^eeUbJ&)nCU7_0pz8-?VA zKp@aYGgF)m@C{zQ1o(hYW>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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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 From 23d6558aa567c50906318f2fc6518a94dd653593 Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 3 Oct 2023 17:07:12 -0400 Subject: [PATCH 07/35] ID error --- .../rpi/legup/puzzle/lightup/LightUpCell.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 3189eff7a..1cffa7f82 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCell.java @@ -1,8 +1,10 @@ package edu.rpi.legup.puzzle.lightup; +import edu.rpi.legup.model.elements.Element; import edu.rpi.legup.model.gameboard.GridCell; import java.awt.*; +import java.awt.event.MouseEvent; public class LightUpCell extends GridCell { private boolean isLite; @@ -12,6 +14,21 @@ public LightUpCell(int valueInt, Point location) { this.isLite = false; } + @Override + public void setType(Element e, MouseEvent m) { + switch (e.getElementID()) { + case "LTUP-PLAC-0001": + this.data = -4; + break; + case "LTUP-UNPL-0002": + this.data = -1; + break; + case "LTUP-UNPL-0003": + this.data = -2; + break; + } + } + public LightUpCellType getType() { switch (data) { case -4: From 145e316dc7f00329b1d287297e562bb341743050 Mon Sep 17 00:00:00 2001 From: Hanson Gu <123511202+hansongu123@users.noreply.github.com> Date: Tue, 3 Oct 2023 17:07:57 -0400 Subject: [PATCH 08/35] Some Fixes to Recently Discussed UX Bugs (#563) * frame and panels default sizes, default pos on screen * hardcoded version number * homepanel default size * set panels' own sizes * some changes * Removed unused import --------- Co-authored-by: Charles Tian <46334090+charlestian23@users.noreply.github.com> Co-authored-by: Corppet --- src/main/java/edu/rpi/legup/ui/HomePanel.java | 2 +- src/main/java/edu/rpi/legup/ui/LegupUI.java | 7 +++---- src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java | 3 ++- src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java | 3 ++- .../rpi/legup/ui/proofeditorui/rulesview/RuleFrame.java | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/edu/rpi/legup/ui/HomePanel.java b/src/main/java/edu/rpi/legup/ui/HomePanel.java index 48f0d03d7..2270c92b8 100644 --- a/src/main/java/edu/rpi/legup/ui/HomePanel.java +++ b/src/main/java/edu/rpi/legup/ui/HomePanel.java @@ -481,7 +481,7 @@ private void initText() { credits.setFont(new Font("Roboto", Font.PLAIN, 12)); credits.setAlignmentX(Component.CENTER_ALIGNMENT); - JLabel version = new JLabel("Version 3.0.0"); // This should be autochanged in the future + JLabel version = new JLabel("Version 5.1.0"); // This should be autochanged in the future version.setFont(new Font("Roboto", Font.ITALIC, 10)); version.setAlignmentX(Component.CENTER_ALIGNMENT); diff --git a/src/main/java/edu/rpi/legup/ui/LegupUI.java b/src/main/java/edu/rpi/legup/ui/LegupUI.java index 82ef7dc44..452bbb487 100644 --- a/src/main/java/edu/rpi/legup/ui/LegupUI.java +++ b/src/main/java/edu/rpi/legup/ui/LegupUI.java @@ -72,8 +72,6 @@ public LegupUI() { setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH); } - setVisible(true); - this.addWindowListener(this); addKeyListener(new KeyAdapter() { /** @@ -88,8 +86,8 @@ public void keyTyped(KeyEvent e) { super.keyTyped(e); } }); - setLocationRelativeTo(null); setMinimumSize(getPreferredSize()); + setVisible(true); } private void initPanels() { @@ -112,6 +110,7 @@ protected void displayPanel(int option) { panels[option].makeVisible(); this.window.add(panels[option]); pack(); + setLocationRelativeTo(null); revalidate(); repaint(); } @@ -208,4 +207,4 @@ public DynamicView getEditorDynamicBoardView() { public TreePanel getTreePanel() { return getProofEditor().getTreePanel(); } -} \ 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 12cd0ca3b..e83f660e7 100644 --- a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java @@ -97,6 +97,7 @@ public ProofEditorPanel(FileDialog fileDialog, JFrame frame, LegupUI legupUI) { this.frame = frame; this.legupUI = legupUI; setLayout(new BorderLayout()); + setPreferredSize(new Dimension(800, 700)); } @Override @@ -343,7 +344,7 @@ public void actionPerformed(ActionEvent e) { about.add(aboutLegup); aboutLegup.addActionListener(l -> { - JOptionPane.showMessageDialog(null, "Version: 2.0.0"); + JOptionPane.showMessageDialog(null, "Version: 5.1.0"); }); about.add(helpLegup); diff --git a/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java b/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java index 90f0c3cdf..2c4f37c85 100644 --- a/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java @@ -64,6 +64,7 @@ public PuzzleEditorPanel(FileDialog fileDialog, JFrame frame, LegupUI legupUI) { this.frame = frame; this.legupUI = legupUI; setLayout(new BorderLayout()); + setPreferredSize(new Dimension(800, 700)); } protected void setupContent() { @@ -202,7 +203,7 @@ public void actionPerformed(ActionEvent e) { }); menus[2].add(aboutLegup); aboutLegup.addActionListener(l -> { - JOptionPane.showMessageDialog(null, "Version: 2.0.0"); + JOptionPane.showMessageDialog(null, "Version: 5.1.0"); }); // add menus to menubar for (JMenu menu : menus) { 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 a2d37e800..0fe03d476 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 @@ -70,7 +70,7 @@ protected boolean shouldRotateTabRuns(int i) { setLayout(new BorderLayout()); setMinimumSize(new Dimension(250, 256)); - setPreferredSize(new Dimension(330, 256)); + setPreferredSize(new Dimension(355, 256)); add(tabbedPane); add(status, BorderLayout.SOUTH); From 1357dbd01b0485b11dd2895f2620bf004c1c59cc Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 3 Oct 2023 17:08:05 -0400 Subject: [PATCH 09/35] Oops pushed the wrong file Yeah some tiles work now but this is the ID error --- .../java/edu/rpi/legup/puzzle/lightup/elements/UnknownTile.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b2b93667a..6839e70de 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,6 @@ public class UnknownTile extends NonPlaceableElement { public UnknownTile() { - super("NURI-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"); } } From f3ba447f43ffbdf819596f6ba605091a7e9e6975 Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 3 Oct 2023 17:20:04 -0400 Subject: [PATCH 10/35] Number Tile working --- .../rpi/legup/puzzle/lightup/LightUpCell.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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 1cffa7f82..36e5a5088 100644 --- a/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/lightup/LightUpCell.java @@ -26,6 +26,26 @@ public void setType(Element e, MouseEvent m) { case "LTUP-UNPL-0003": this.data = -2; break; + case "LTUP-UNPL-0001": + switch (m.getButton()){ + case MouseEvent.BUTTON1: + if (this.data < 0 || this.data > 3) { + this.data = 0; + } + else { + this.data = this.data + 1; + } + break; + case MouseEvent.BUTTON3: + if (this.data > 0) { + this.data = this.data - 1; + } + else { + this.data = 4; + } + break; + } + break; } } From b603f1a837562fb35ed83dc7c059596d95c43c44 Mon Sep 17 00:00:00 2001 From: ThisMatt <98851950+ThisMatt@users.noreply.github.com> Date: Fri, 6 Oct 2023 16:45:17 -0400 Subject: [PATCH 11/35] Update Exporter (#627) * Update Exporter * Delete Test_Save --------- Co-authored-by: Charles Tian <46334090+charlestian23@users.noreply.github.com> --- .../skyscrapers/SkyscrapersCellFactory.java | 2 +- .../puzzle/skyscrapers/SkyscrapersExporter.java | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) 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 d276c8bff..da6899f75 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersCellFactory.java @@ -35,7 +35,7 @@ public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormat if (x >= width || y >= height) { throw new InvalidFileFormatException("TreeTent Factory: cell location out of bounds"); } - if (value < 0 || value > 3) { + if (value < 0 || value > width) { throw new InvalidFileFormatException("TreeTent Factory: cell unknown value"); } 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 d5d5a9911..155a1466c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/skyscrapers/SkyscrapersExporter.java @@ -22,8 +22,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { } org.w3c.dom.Element boardElement = newDocument.createElement("board"); - boardElement.setAttribute("width", String.valueOf(board.getWidth())); - boardElement.setAttribute("height", String.valueOf(board.getHeight())); + boardElement.setAttribute("size", String.valueOf(board.getWidth())); org.w3c.dom.Element cellsElement = newDocument.createElement("cells"); for (PuzzleElement puzzleElement : board.getPuzzleElements()) { @@ -37,20 +36,20 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) { org.w3c.dom.Element axisEast = newDocument.createElement("axis"); axisEast.setAttribute("side", "east"); - for (SkyscrapersClue clue : board.getEastClues()) { + for (int i=0; i Date: Tue, 10 Oct 2023 13:32:31 -0400 Subject: [PATCH 12/35] Create run-tests.yml --- .github/workflows/run-tests.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/run-tests.yml diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 000000000..0cce6a9f1 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,26 @@ +name: Java CI with Gradle + +on: + push: + branches: + - master, dev + pull_request: + branches: + - master, dev + +jobs: + test: + runs-on: ubuntu-latest, windows-latest, macos-latest + + steps: + - name: Check Out Code + uses: actions/checkout@v2 + + - name: Set up JDK + uses: actions/setup-java@v2 + with: + java-version: 11 + + - name: Run Gradle Build and Tests + run: | + ./gradlew clean build test From 20ff3dc954221919c23bc639759a89c0a7b0c89a Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 10 Oct 2023 13:34:52 -0400 Subject: [PATCH 13/35] Update run-tests.yml --- .github/workflows/run-tests.yml | 44 +++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 0cce6a9f1..068f3831e 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -3,14 +3,16 @@ name: Java CI with Gradle on: push: branches: - - master, dev + - master + - dev pull_request: branches: - - master, dev + - master + - dev jobs: - test: - runs-on: ubuntu-latest, windows-latest, macos-latest + linux-build-and-test: + runs-on: ubuntu-latest steps: - name: Check Out Code @@ -21,6 +23,38 @@ jobs: with: java-version: 11 - - name: Run Gradle Build and Tests + - name: Run Gradle Build and Tests on Linux run: | ./gradlew clean build test + + windows-build-and-test: + runs-on: windows-latest + + steps: + - name: Check Out Code + uses: actions/checkout@v2 + + - name: Set up JDK + uses: actions/setup-java@v2 + with: + java-version: 11 + + - name: Run Gradle Build and Tests on Windows + run: | + .\gradlew clean build test + + macos-build-and-test: + runs-on: macos-latest + + steps: + - name: Check Out Code + uses: actions/checkout@v2 + + - name: Set up JDK + uses: actions/setup-java@v2 + with: + java-version: 11 + + - name: Run Gradle Build and Tests on macOS + run: | + ./gradlew clean build test \ No newline at end of file From 4df83139bc8188309437b23437e16c184e4cf574 Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 10 Oct 2023 13:37:50 -0400 Subject: [PATCH 14/35] Update run-tests.yml --- .github/workflows/run-tests.yml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 068f3831e..527302973 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -1,4 +1,4 @@ -name: Java CI with Gradle +name: Run JUnit Tests on: push: @@ -11,50 +11,50 @@ on: - dev jobs: - linux-build-and-test: + test: runs-on: ubuntu-latest steps: - name: Check Out Code uses: actions/checkout@v2 - - name: Set up JDK + - name: Set up JDK and Gradle on Linux uses: actions/setup-java@v2 with: java-version: 11 - - name: Run Gradle Build and Tests on Linux + - name: Run JUnit Tests on Linux run: | - ./gradlew clean build test + ./gradlew test - windows-build-and-test: - runs-on: windows-latest + test-macos: + runs-on: macos-latest steps: - name: Check Out Code uses: actions/checkout@v2 - - name: Set up JDK + - name: Set up JDK and Gradle on macOS uses: actions/setup-java@v2 with: java-version: 11 - - name: Run Gradle Build and Tests on Windows + - name: Run JUnit Tests on macOS run: | - .\gradlew clean build test + ./gradlew test - macos-build-and-test: - runs-on: macos-latest + test-windows: + runs-on: windows-latest steps: - name: Check Out Code uses: actions/checkout@v2 - - name: Set up JDK + - name: Set up JDK and Gradle on Windows uses: actions/setup-java@v2 with: java-version: 11 - - name: Run Gradle Build and Tests on macOS + - name: Run JUnit Tests on Windows run: | - ./gradlew clean build test \ No newline at end of file + .\gradlew.bat test \ No newline at end of file From 60c99db64326d9f9534d3575e04740c47dbee37c Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 10 Oct 2023 13:41:27 -0400 Subject: [PATCH 15/35] Update run-tests.yml --- .github/workflows/run-tests.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 527302973..3d18134c4 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -11,7 +11,7 @@ on: - dev jobs: - test: + ubuntu-test: runs-on: ubuntu-latest steps: @@ -22,6 +22,7 @@ jobs: uses: actions/setup-java@v2 with: java-version: 11 + distribution: 'adopt' - name: Run JUnit Tests on Linux run: | @@ -38,6 +39,7 @@ jobs: uses: actions/setup-java@v2 with: java-version: 11 + distribution: 'adopt' - name: Run JUnit Tests on macOS run: | @@ -54,6 +56,7 @@ jobs: uses: actions/setup-java@v2 with: java-version: 11 + distribution: 'adopt' - name: Run JUnit Tests on Windows run: | From 84517f8b99d4010689627bc57d0407f08801851c Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 10 Oct 2023 13:44:15 -0400 Subject: [PATCH 16/35] Update run-tests.yml --- .github/workflows/run-tests.yml | 36 ++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 3d18134c4..45ecbd346 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -18,11 +18,16 @@ jobs: - name: Check Out Code uses: actions/checkout@v2 - - name: Set up JDK and Gradle on Linux - uses: actions/setup-java@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v1 with: java-version: 11 - distribution: 'adopt' + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + run: ./gradlew build -x test - name: Run JUnit Tests on Linux run: | @@ -35,11 +40,16 @@ jobs: - name: Check Out Code uses: actions/checkout@v2 - - name: Set up JDK and Gradle on macOS - uses: actions/setup-java@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v1 with: java-version: 11 - distribution: 'adopt' + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + run: ./gradlew build -x test - name: Run JUnit Tests on macOS run: | @@ -52,11 +62,19 @@ jobs: - name: Check Out Code uses: actions/checkout@v2 - - name: Set up JDK and Gradle on Windows - uses: actions/setup-java@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v1 with: java-version: 11 - distribution: 'adopt' + + - name: Grant execute permission for gradlew + run: | + gradlew.bat + echo "gradlew.bat granted execute permission" + + - name: Build with Gradle + run: | + gradlew.bat build -x test - name: Run JUnit Tests on Windows run: | From 57532c4ad9559b9bbe9dc669fcfe3b7ce8b65735 Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 10 Oct 2023 13:47:38 -0400 Subject: [PATCH 17/35] Windows things --- .github/workflows/run-tests.yml | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 45ecbd346..1a22769f7 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -62,19 +62,11 @@ jobs: - name: Check Out Code uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 + - name: Set up JDK and Gradle on Windows + uses: actions/setup-java@v2 with: java-version: 11 - - - name: Grant execute permission for gradlew - run: | - gradlew.bat - echo "gradlew.bat granted execute permission" - - - name: Build with Gradle - run: | - gradlew.bat build -x test + distribution: 'adopt' # Specify the distribution, e.g., 'adopt', 'adopt@1.11', etc. - name: Run JUnit Tests on Windows run: | From aac1ed4b76fec617e808993bf21e49115bf32a7a Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 10 Oct 2023 13:58:20 -0400 Subject: [PATCH 18/35] Added print messages --- .github/workflows/run-tests.yml | 40 ++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 1a22769f7..d81bafc36 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -29,9 +29,19 @@ jobs: - name: Build with Gradle run: ./gradlew build -x test - - name: Run JUnit Tests on Linux + - name: Run JUnit Tests run: | - ./gradlew test + test_output=$(./gradlew test --quiet | grep -E "tests? passed|tests? failed") + echo "$test_output" + tests_run=$(echo "$test_output" | grep -Eo "[0-9]+" | head -n 1) + tests_passed=$(echo "$test_output" | grep -Eo "[0-9]+" | tail -n 1) + tests_failed=$((tests_run - tests_passed)) + echo "Tests Run: $tests_run" + echo "Tests Passed: $tests_passed" + echo "Tests Failed: $tests_failed" + if [[ $tests_failed -gt 0 ]]; then + exit 1 + fi test-macos: runs-on: macos-latest @@ -53,7 +63,17 @@ jobs: - name: Run JUnit Tests on macOS run: | - ./gradlew test + test_output=$(./gradlew test --quiet | grep -E "tests? passed|tests? failed") + echo "$test_output" + tests_run=$(echo "$test_output" | grep -Eo "[0-9]+" | head -n 1) + tests_passed=$(echo "$test_output" | grep -Eo "[0-9]+" | tail -n 1) + tests_failed=$((tests_run - tests_passed)) + echo "Tests Run: $tests_run" + echo "Tests Passed: $tests_passed" + echo "Tests Failed: $tests_failed" + if [[ $tests_failed -gt 0 ]]; then + exit 1 + fi test-windows: runs-on: windows-latest @@ -66,8 +86,18 @@ jobs: uses: actions/setup-java@v2 with: java-version: 11 - distribution: 'adopt' # Specify the distribution, e.g., 'adopt', 'adopt@1.11', etc. + distribution: 'adopt' - name: Run JUnit Tests on Windows run: | - .\gradlew.bat test \ No newline at end of file + test_output=$(./gradlew.bat test --quiet | grep -E "tests? passed|tests? failed") + echo "$test_output" + tests_run=$(echo "$test_output" | grep -Eo "[0-9]+" | head -n 1) + tests_passed=$(echo "$test_output" | grep -Eo "[0-9]+" | tail -n 1) + tests_failed=$((tests_run - tests_passed)) + echo "Tests Run: $tests_run" + echo "Tests Passed: $tests_passed" + echo "Tests Failed: $tests_failed" + if [[ $tests_failed -gt 0 ]]; then + exit 1 + fi \ No newline at end of file From 25d559af58e87f3a367ff57197e6c0a8d3555a9c Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 10 Oct 2023 14:00:23 -0400 Subject: [PATCH 19/35] More Windows things --- .github/workflows/run-tests.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index d81bafc36..897894c1c 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -98,6 +98,7 @@ jobs: echo "Tests Run: $tests_run" echo "Tests Passed: $tests_passed" echo "Tests Failed: $tests_failed" - if [[ $tests_failed -gt 0 ]]; then + + if %tests_failed% gtr 0 ( exit 1 - fi \ No newline at end of file + ) \ No newline at end of file From 48479a6d06cd1f0e834f03b298ce5675f58be1b4 Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 10 Oct 2023 14:02:00 -0400 Subject: [PATCH 20/35] Debugging --- .github/workflows/run-tests.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 897894c1c..18ba0c425 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -29,6 +29,24 @@ jobs: - name: Build with Gradle run: ./gradlew build -x test + - name: Debug Info + run: | + echo "Java version:" + java -version + echo "Gradle version:" + ./gradlew --version + shell: bash + + - name: Run JUnit Tests on Linux + run: | + ./gradlew test + test_result=$? + if [ $test_result -ne 0 ]; then + echo "Tests failed with exit code $test_result" + exit $test_result + fi + shell: bash + - name: Run JUnit Tests run: | test_output=$(./gradlew test --quiet | grep -E "tests? passed|tests? failed") From 28c06bc3bb60b576ecf41119f9381e0b79fee424 Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 10 Oct 2023 14:07:39 -0400 Subject: [PATCH 21/35] Update run-tests.yml --- .github/workflows/run-tests.yml | 58 +++++++-------------------------- 1 file changed, 12 insertions(+), 46 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 18ba0c425..21704c965 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -29,35 +29,12 @@ jobs: - name: Build with Gradle run: ./gradlew build -x test - - name: Debug Info - run: | - echo "Java version:" - java -version - echo "Gradle version:" - ./gradlew --version - shell: bash - - name: Run JUnit Tests on Linux run: | - ./gradlew test - test_result=$? - if [ $test_result -ne 0 ]; then + ./gradlew test --tests '*' | grep -E 'Test:|PASSED|FAILED' + test_result=${PIPESTATUS[0]} + if [[ $test_result -ne 0 ]]; then echo "Tests failed with exit code $test_result" - exit $test_result - fi - shell: bash - - - name: Run JUnit Tests - run: | - test_output=$(./gradlew test --quiet | grep -E "tests? passed|tests? failed") - echo "$test_output" - tests_run=$(echo "$test_output" | grep -Eo "[0-9]+" | head -n 1) - tests_passed=$(echo "$test_output" | grep -Eo "[0-9]+" | tail -n 1) - tests_failed=$((tests_run - tests_passed)) - echo "Tests Run: $tests_run" - echo "Tests Passed: $tests_passed" - echo "Tests Failed: $tests_failed" - if [[ $tests_failed -gt 0 ]]; then exit 1 fi @@ -81,15 +58,10 @@ jobs: - name: Run JUnit Tests on macOS run: | - test_output=$(./gradlew test --quiet | grep -E "tests? passed|tests? failed") - echo "$test_output" - tests_run=$(echo "$test_output" | grep -Eo "[0-9]+" | head -n 1) - tests_passed=$(echo "$test_output" | grep -Eo "[0-9]+" | tail -n 1) - tests_failed=$((tests_run - tests_passed)) - echo "Tests Run: $tests_run" - echo "Tests Passed: $tests_passed" - echo "Tests Failed: $tests_failed" - if [[ $tests_failed -gt 0 ]]; then + ./gradlew test --tests '*' | grep -E 'Test:|PASSED|FAILED' + test_result=${PIPESTATUS[0]} + if [[ $test_result -ne 0 ]]; then + echo "Tests failed with exit code $test_result" exit 1 fi @@ -108,15 +80,9 @@ jobs: - name: Run JUnit Tests on Windows run: | - test_output=$(./gradlew.bat test --quiet | grep -E "tests? passed|tests? failed") - echo "$test_output" - tests_run=$(echo "$test_output" | grep -Eo "[0-9]+" | head -n 1) - tests_passed=$(echo "$test_output" | grep -Eo "[0-9]+" | tail -n 1) - tests_failed=$((tests_run - tests_passed)) - echo "Tests Run: $tests_run" - echo "Tests Passed: $tests_passed" - echo "Tests Failed: $tests_failed" - - if %tests_failed% gtr 0 ( + ./gradlew.bat test --tests '*' | findstr /C:"Test:" /C:"PASSED" /C:"FAILED" + test_result=${PIPESTATUS[0]} + if [[ $test_result -ne 0 ]]; then + echo "Tests failed with exit code $test_result" exit 1 - ) \ No newline at end of file + fi From 7377a15ce91224eca96585f82f8683f667a9396b Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 10 Oct 2023 14:13:11 -0400 Subject: [PATCH 22/35] Update run-tests.yml --- .github/workflows/run-tests.yml | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 21704c965..cdc519538 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -31,12 +31,7 @@ jobs: - name: Run JUnit Tests on Linux run: | - ./gradlew test --tests '*' | grep -E 'Test:|PASSED|FAILED' - test_result=${PIPESTATUS[0]} - if [[ $test_result -ne 0 ]]; then - echo "Tests failed with exit code $test_result" - exit 1 - fi + ./gradlew test --info test-macos: runs-on: macos-latest @@ -58,12 +53,7 @@ jobs: - name: Run JUnit Tests on macOS run: | - ./gradlew test --tests '*' | grep -E 'Test:|PASSED|FAILED' - test_result=${PIPESTATUS[0]} - if [[ $test_result -ne 0 ]]; then - echo "Tests failed with exit code $test_result" - exit 1 - fi + ./gradlew test --info test-windows: runs-on: windows-latest @@ -80,9 +70,4 @@ jobs: - name: Run JUnit Tests on Windows run: | - ./gradlew.bat test --tests '*' | findstr /C:"Test:" /C:"PASSED" /C:"FAILED" - test_result=${PIPESTATUS[0]} - if [[ $test_result -ne 0 ]]; then - echo "Tests failed with exit code $test_result" - exit 1 - fi + .\gradlew.bat test --info \ No newline at end of file From 49fb14f9aa83c148abaf742b4e5334c9e6b4fcb1 Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 10 Oct 2023 14:27:18 -0400 Subject: [PATCH 23/35] Maybe this will work now? --- build.gradle | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build.gradle b/build.gradle index fafa54cac..f838f7ade 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,12 @@ mainClassName = 'edu.rpi.legup.Legup' sourceCompatibility = 11 +sourceSets { + test { + java.srcDirs = ['src/test/java'] + } +} + dependencies { implementation 'org.jetbrains:annotations:20.1.0' implementation 'org.jetbrains:annotations:20.1.0' From cfeee6aa5264c2ca8523d9854645edc3b603128b Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 10 Oct 2023 14:31:17 -0400 Subject: [PATCH 24/35] Didn't work --- build.gradle | 6 ------ 1 file changed, 6 deletions(-) diff --git a/build.gradle b/build.gradle index f838f7ade..fafa54cac 100644 --- a/build.gradle +++ b/build.gradle @@ -13,12 +13,6 @@ mainClassName = 'edu.rpi.legup.Legup' sourceCompatibility = 11 -sourceSets { - test { - java.srcDirs = ['src/test/java'] - } -} - dependencies { implementation 'org.jetbrains:annotations:20.1.0' implementation 'org.jetbrains:annotations:20.1.0' From 7b49c11b00566cfe86b645fa6ede9d1856bc4164 Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 10 Oct 2023 14:33:58 -0400 Subject: [PATCH 25/35] Update run-tests.yml --- .github/workflows/run-tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index cdc519538..d4ac97181 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -31,7 +31,7 @@ jobs: - name: Run JUnit Tests on Linux run: | - ./gradlew test --info + ./gradlew test --info --tests "*" test-macos: runs-on: macos-latest @@ -53,7 +53,7 @@ jobs: - name: Run JUnit Tests on macOS run: | - ./gradlew test --info + ./gradlew test --info --tests "*" test-windows: runs-on: windows-latest @@ -70,4 +70,4 @@ jobs: - name: Run JUnit Tests on Windows run: | - .\gradlew.bat test --info \ No newline at end of file + .\gradlew.bat test --info --tests "*" \ No newline at end of file From 4029b7c798f0967ba7047c8bbd1313ff85f011e9 Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 10 Oct 2023 14:39:13 -0400 Subject: [PATCH 26/35] Update run-tests.yml --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index d4ac97181..9c3804aa2 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -31,7 +31,7 @@ jobs: - name: Run JUnit Tests on Linux run: | - ./gradlew test --info --tests "*" + ./gradlew test --tests "*" test-macos: runs-on: macos-latest From 19f0c26a52e1a674d3d9235345c932e2606ae16e Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 10 Oct 2023 14:42:49 -0400 Subject: [PATCH 27/35] Create DummyTest.java For debugging purposes --- src/test/java/DummyTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/test/java/DummyTest.java diff --git a/src/test/java/DummyTest.java b/src/test/java/DummyTest.java new file mode 100644 index 000000000..e7b9f7eb9 --- /dev/null +++ b/src/test/java/DummyTest.java @@ -0,0 +1,10 @@ +import org.junit.Test; +import static org.junit.Assert.fail; + +public class DummyTest { + + @Test + public void testFailure() { + fail("This test intentionally fails. Your JUnit configuration is working if you see this message."); + } +} From f2b1cfaa461895f7c59bee6e5224921d42b05246 Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 10 Oct 2023 14:44:55 -0400 Subject: [PATCH 28/35] Added another dummy test --- .../puzzles/shorttruthtable/rules/DummyTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/test/java/puzzles/shorttruthtable/rules/DummyTest.java diff --git a/src/test/java/puzzles/shorttruthtable/rules/DummyTest.java b/src/test/java/puzzles/shorttruthtable/rules/DummyTest.java new file mode 100644 index 000000000..4d8106f86 --- /dev/null +++ b/src/test/java/puzzles/shorttruthtable/rules/DummyTest.java @@ -0,0 +1,13 @@ +package puzzles.shorttruthtable.rules; + +import org.junit.Test; + +import static org.junit.Assert.fail; + +public class DummyTest { + + @Test + public void testFailure() { + fail("This test intentionally fails. Your JUnit configuration is working if you see this message."); + } +} From 7fd577b89422da5e280bfc713d2b78711ef03b26 Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 10 Oct 2023 14:46:43 -0400 Subject: [PATCH 29/35] Update run-tests.yml --- .github/workflows/run-tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 9c3804aa2..3282dfddc 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -31,7 +31,7 @@ jobs: - name: Run JUnit Tests on Linux run: | - ./gradlew test --tests "*" + ./gradlew test test-macos: runs-on: macos-latest @@ -53,7 +53,7 @@ jobs: - name: Run JUnit Tests on macOS run: | - ./gradlew test --info --tests "*" + ./gradlew test --info test-windows: runs-on: windows-latest @@ -70,4 +70,4 @@ jobs: - name: Run JUnit Tests on Windows run: | - .\gradlew.bat test --info --tests "*" \ No newline at end of file + .\gradlew.bat test --info \ No newline at end of file From 8675598712dd9d3826303ec7d7d0753e53212915 Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 10 Oct 2023 14:48:55 -0400 Subject: [PATCH 30/35] Update run-tests.yml Get rid of all this info --- .github/workflows/run-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 3282dfddc..bed9d7ad2 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -53,7 +53,7 @@ jobs: - name: Run JUnit Tests on macOS run: | - ./gradlew test --info + ./gradlew test test-windows: runs-on: windows-latest @@ -70,4 +70,4 @@ jobs: - name: Run JUnit Tests on Windows run: | - .\gradlew.bat test --info \ No newline at end of file + .\gradlew.bat test \ No newline at end of file From 4bd17879d144fb513073e1f888a0e6a62bc4c6e8 Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Tue, 10 Oct 2023 14:52:56 -0400 Subject: [PATCH 31/35] Deleted the dummy tests --- src/test/java/DummyTest.java | 10 ---------- .../puzzles/shorttruthtable/rules/DummyTest.java | 13 ------------- 2 files changed, 23 deletions(-) delete mode 100644 src/test/java/DummyTest.java delete mode 100644 src/test/java/puzzles/shorttruthtable/rules/DummyTest.java diff --git a/src/test/java/DummyTest.java b/src/test/java/DummyTest.java deleted file mode 100644 index e7b9f7eb9..000000000 --- a/src/test/java/DummyTest.java +++ /dev/null @@ -1,10 +0,0 @@ -import org.junit.Test; -import static org.junit.Assert.fail; - -public class DummyTest { - - @Test - public void testFailure() { - fail("This test intentionally fails. Your JUnit configuration is working if you see this message."); - } -} diff --git a/src/test/java/puzzles/shorttruthtable/rules/DummyTest.java b/src/test/java/puzzles/shorttruthtable/rules/DummyTest.java deleted file mode 100644 index 4d8106f86..000000000 --- a/src/test/java/puzzles/shorttruthtable/rules/DummyTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package puzzles.shorttruthtable.rules; - -import org.junit.Test; - -import static org.junit.Assert.fail; - -public class DummyTest { - - @Test - public void testFailure() { - fail("This test intentionally fails. Your JUnit configuration is working if you see this message."); - } -} From 6f6572e0a3a08ec2770df38582087500890b42b5 Mon Sep 17 00:00:00 2001 From: pitbull51067 Date: Fri, 20 Oct 2023 17:36:32 -0400 Subject: [PATCH 32/35] BulbsInPathContradictionRuleTest looks good. I added one more function to check for the BlockInHorizontalPath test case. --- .../rules/BulbsInPathContradictionRuleTest.java | 16 ++++++++++++++++ .../BlockInHorizontalPath | 11 +++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/test/resources/puzzles/lightup/rules/BulbsInPathContradictionRule/BlockInHorizontalPath diff --git a/src/test/java/puzzles/lightup/rules/BulbsInPathContradictionRuleTest.java b/src/test/java/puzzles/lightup/rules/BulbsInPathContradictionRuleTest.java index b595fec15..0e7930751 100644 --- a/src/test/java/puzzles/lightup/rules/BulbsInPathContradictionRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/BulbsInPathContradictionRuleTest.java @@ -34,6 +34,7 @@ public void BulbsInPathContradictionRule_LightInHorizontalPath() throws InvalidF 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))); } @@ -67,4 +68,19 @@ public void BulbsInPathContradictionRule_BlockInVerticalPath() throws InvalidFil Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 1))); } + + @Test + 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))); + + } } diff --git a/src/test/resources/puzzles/lightup/rules/BulbsInPathContradictionRule/BlockInHorizontalPath b/src/test/resources/puzzles/lightup/rules/BulbsInPathContradictionRule/BlockInHorizontalPath new file mode 100644 index 000000000..3c8786e54 --- /dev/null +++ b/src/test/resources/puzzles/lightup/rules/BulbsInPathContradictionRule/BlockInHorizontalPath @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file From 07422af0a5259cf9231c420f5ed19ce251274e3f Mon Sep 17 00:00:00 2001 From: pitbull51067 Date: Tue, 31 Oct 2023 17:42:36 -0400 Subject: [PATCH 33/35] I think I might have run into a problem on the testing function. I will confirm this problem next time and will write another test case. --- ...CannotLightACellContradictionRuleTest.java | 30 +++++++++++++++---- .../CanLightTest | 18 +++++++++++ .../FullLightTest | 2 +- 3 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 src/test/resources/puzzles/lightup/rules/CannotLightACellContradictionRule/CanLightTest diff --git a/src/test/java/puzzles/lightup/rules/CannotLightACellContradictionRuleTest.java b/src/test/java/puzzles/lightup/rules/CannotLightACellContradictionRuleTest.java index 447476dbb..070ab6abe 100644 --- a/src/test/java/puzzles/lightup/rules/CannotLightACellContradictionRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/CannotLightACellContradictionRuleTest.java @@ -21,13 +21,13 @@ public static void setUp() { lightUp = new LightUp(); } - @Test + @Test //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); 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 @@ -36,7 +36,7 @@ public void FullLightTest() throws InvalidFileFormatException { //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 Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 0))); Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 1))); @@ -44,13 +44,13 @@ public void FullLightTest() throws InvalidFileFormatException { Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(3, 2))); } - @Test + @Test //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); 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 @@ -68,4 +68,24 @@ public void CannotLightMiddleTest() throws InvalidFileFormatException { Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 2))); Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 1))); } + + @Test + public void CanLightTest() throws InvalidFileFormatException { + 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 + Assert.assertNull(RULE.checkContradiction(board)); + + //confirm these are not required to be lit because they are already lit or unable to be + 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))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 1))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 0))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(3, 2))); + } } diff --git a/src/test/resources/puzzles/lightup/rules/CannotLightACellContradictionRule/CanLightTest b/src/test/resources/puzzles/lightup/rules/CannotLightACellContradictionRule/CanLightTest new file mode 100644 index 000000000..4169bf382 --- /dev/null +++ b/src/test/resources/puzzles/lightup/rules/CannotLightACellContradictionRule/CanLightTest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/lightup/rules/CannotLightACellContradictionRule/FullLightTest b/src/test/resources/puzzles/lightup/rules/CannotLightACellContradictionRule/FullLightTest index 62e8b32f8..f0a5977ff 100644 --- a/src/test/resources/puzzles/lightup/rules/CannotLightACellContradictionRule/FullLightTest +++ b/src/test/resources/puzzles/lightup/rules/CannotLightACellContradictionRule/FullLightTest @@ -9,7 +9,7 @@ - + From fc08c8a1d23fc4745e061033ce0d2435fb2f61fa Mon Sep 17 00:00:00 2001 From: pitbull51067 Date: Tue, 7 Nov 2023 16:56:06 -0500 Subject: [PATCH 34/35] I made another puzzle and test case to check what would happen if the cells could actually be lit, meaning there would be no contradiction. The test case passed and so I think CannotLightACellContradictionRule works correctly for all cases. --- .../lightup/rules/CannotLightACellContradictionRuleTest.java | 4 ++-- .../rules/CannotLightACellContradictionRule/FullLightTest | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/puzzles/lightup/rules/CannotLightACellContradictionRuleTest.java b/src/test/java/puzzles/lightup/rules/CannotLightACellContradictionRuleTest.java index 070ab6abe..37d5a8b05 100644 --- a/src/test/java/puzzles/lightup/rules/CannotLightACellContradictionRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/CannotLightACellContradictionRuleTest.java @@ -71,14 +71,14 @@ public void CannotLightMiddleTest() throws InvalidFileFormatException { @Test public void CanLightTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/lightup/rules/CannotLightACellContradictionRule/FullLightTest", 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 a contradiction somewhere on the board - Assert.assertNull(RULE.checkContradiction(board)); + Assert.assertNotNull(RULE.checkContradiction(board)); //confirm these are not required to be lit because they are already lit or unable to be Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 3))); diff --git a/src/test/resources/puzzles/lightup/rules/CannotLightACellContradictionRule/FullLightTest b/src/test/resources/puzzles/lightup/rules/CannotLightACellContradictionRule/FullLightTest index f0a5977ff..62e8b32f8 100644 --- a/src/test/resources/puzzles/lightup/rules/CannotLightACellContradictionRule/FullLightTest +++ b/src/test/resources/puzzles/lightup/rules/CannotLightACellContradictionRule/FullLightTest @@ -9,7 +9,7 @@ - + From f9764aad5a1d09c8acd8ec85206259eb8dc9a626 Mon Sep 17 00:00:00 2001 From: pitbull51067 Date: Tue, 7 Nov 2023 17:03:05 -0500 Subject: [PATCH 35/35] I made another puzzle and test case to check what would happen if the cells could actually be lit, meaning there would be no contradiction. The test case passed and so I think CannotLightACellContradictionRule works correctly for all cases. --- .../lightup/rules/CannotLightACellContradictionRuleTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/puzzles/lightup/rules/CannotLightACellContradictionRuleTest.java b/src/test/java/puzzles/lightup/rules/CannotLightACellContradictionRuleTest.java index 37d5a8b05..7b3ffd2b9 100644 --- a/src/test/java/puzzles/lightup/rules/CannotLightACellContradictionRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/CannotLightACellContradictionRuleTest.java @@ -77,10 +77,10 @@ public void CanLightTest() throws InvalidFileFormatException { transition.setRule(RULE); LightUpBoard board = (LightUpBoard) transition.getBoard(); - //confirm there is a contradiction somewhere on the board + //confirm there is not a contradiction somewhere on the board Assert.assertNotNull(RULE.checkContradiction(board)); - //confirm these are not required to be lit because they are already lit or unable to be + //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)));