From fc9513374ad2eb3dde1321a90383796c1676cf37 Mon Sep 17 00:00:00 2001 From: Marcus Moreno <148644006+morenomarcus03@users.noreply.github.com> Date: Fri, 15 Mar 2024 17:40:45 -0400 Subject: [PATCH] Retrofit because I forgot to merge for two weeks (#764) * Fixed Short Truth Table case rule bug (#707) * Revert "Bugfix 549 (#682)" This reverts commit 5048ee69d958fdde9b1bb35854c56c9920068346. * Case rule test fix (#705) Co-authored-by: Chase Grajeda <76405306+Chase-Grajeda@users.noreply.github.com> * Rapid fix for STT case rules Case rules broke at some point from legacy code or merge conflict. Provided is a quick fix in CaseRule and CaseRule_Generic * Revert "Revert "Bugfix 549 (#682)"" (#706) This reverts commit e9fe310378721aa4b4fa358aa57ec44f21d086c1. --------- Co-authored-by: Chase-Grajeda Co-authored-by: Chase Grajeda <76405306+Chase-Grajeda@users.noreply.github.com> * Skyscrapers Test Suite (#708) * Simplify rule names * Contradiction Test Suite * checkstyle * Update Exporter * Revert "Update Exporter" This reverts commit bae1a1f531e407e3b9dd1d28cc79330aa181f410. * Case Rule Test Suite * Update SkyscrapersExporter.java * allow null transitions * Update TreeTransition.java * Direct Rule Test Suite * added tests pass * Update DirectRule.java Commenting out print statement --------- Co-authored-by: ThisMatt Co-authored-by: ThisMatt <98851950+ThisMatt@users.noreply.github.com> Co-authored-by: Chase Grajeda <76405306+Chase-Grajeda@users.noreply.github.com> * Update ThermometerBoard.java * Skyscrapers puzzle editor (#720) * Fixed Short Truth Table case rule bug (#707) * Revert "Bugfix 549 (#682)" This reverts commit 5048ee69d958fdde9b1bb35854c56c9920068346. * Case rule test fix (#705) Co-authored-by: Chase Grajeda <76405306+Chase-Grajeda@users.noreply.github.com> * Rapid fix for STT case rules Case rules broke at some point from legacy code or merge conflict. Provided is a quick fix in CaseRule and CaseRule_Generic * Revert "Revert "Bugfix 549 (#682)"" (#706) This reverts commit e9fe310378721aa4b4fa358aa57ec44f21d086c1. --------- Co-authored-by: Chase-Grajeda Co-authored-by: Chase Grajeda <76405306+Chase-Grajeda@users.noreply.github.com> * Implementing Puzzle Editor Removing Extraneous TreeTent Code Allowing setting tile number * Allow for editing clues on all axies * Remove Extraneous Code Removed functionality required for TreeTent but unnecessary for Skyscrapers * Remove Extraneous Code * Clue Tile in Editor Editor now requires selecting the clue tile to edit clues Added images for the tiles * Merge branch 'dev' into skyscrapersPuzzleEditor * Checkstyle Requirement * Necessary Code * Allow for test functionality --------- Co-authored-by: Charles Tian <46334090+charlestian23@users.noreply.github.com> Co-authored-by: Chase-Grajeda Co-authored-by: Chase Grajeda <76405306+Chase-Grajeda@users.noreply.github.com> * Created element files * Element/rule images * Java Autoformatter (#728) * Create java-autoformat.yml * Setup Java * Run spotless on repository * Adding spotless dependency during build * Adding spotless dependency during build * Give permissions to run spotless * Syntax * Adding Debug Tag * Check for modified files Also removed debug tag * Automated Java code formatting changes * Test command syntax * Correctly Identify modified files * Test autoformatter * Test autoformatter * Test autoformatter * Debugging * Debugging * Change method for detecting changed files * Try building before calling spotless * Update java-autoformat.yml * Update java-autoformat.yml * Update java-autoformat.yml * Purposely bad formatting Purposely adding some bad formatting to see if the auto-formatter triggers * Update build.gradle Disabling Checkstyle in build so the auto-formatter can trigger * Update java-autoformat.yml Have auto-formatter trigger when more commits are added to a pull request * Debugging * Adding more awful formatting * Update java-autoformat.yml * Changing repo URL * Going back to checkout v1 * Trying URL change * Trying out using env * Trying this now...? * Introducing more horrible changes * Spotless formatting using google format v1.19.2 * Manual formatting fix * Automated Java code formatting changes * Different format type Trying to get it to pass checkstyle * Disable checkstyle temporarily * Automated Java code formatting changes * Default google formatting style * Automated Java code formatting changes * Comments and reordering styles * Adding extra newlines * Automated Java code formatting changes * Changing tabs from 2 to 4 spaces Supposedly the only difference that aosp makes is the 2 spaces? Hopefully it doesn't break anything else * Remove solo } requirement and reactivate checkstyle * Automated Java code formatting changes * Update checkstyle.xml Removed problematic LeftCurly and RightCurly requirements * Changing back to tabWidth * Add newline to test formatter + build * Automated Java code formatting changes * Trying some ChatGPT stuff * Getting rid of problematic experimentation --------- Co-authored-by: Bram van Heuveln Co-authored-by: Charles Tian <46334090+charlestian23@users.noreply.github.com> Co-authored-by: charlestian23 * Java21 (#714) * Fixed Short Truth Table case rule bug (#707) * Revert "Bugfix 549 (#682)" This reverts commit 5048ee69d958fdde9b1bb35854c56c9920068346. * Case rule test fix (#705) Co-authored-by: Chase Grajeda <76405306+Chase-Grajeda@users.noreply.github.com> * Rapid fix for STT case rules Case rules broke at some point from legacy code or merge conflict. Provided is a quick fix in CaseRule and CaseRule_Generic * Revert "Revert "Bugfix 549 (#682)"" (#706) This reverts commit e9fe310378721aa4b4fa358aa57ec44f21d086c1. --------- Co-authored-by: Chase-Grajeda Co-authored-by: Chase Grajeda <76405306+Chase-Grajeda@users.noreply.github.com> * Change Java version to 21 and setup JPackage to bundle Java with the app * Setup gradle action for java 21 * Fix distribution in gradle.yml * Fix java version in tests * Fix java distribution in tests * Add jpackage task * Add Linux to jpackage task * Fix jpackage task * Add java setup to jpackage tasks * Separate build into separate tasks for different operating systems * Fix mac jpackage not working and changed names of artifacts * Potential macos installer build fix * Potential macos installer build fix attempt 2 * Potential macos installer build fix attempt 3 * Add quotes around executable name for macos installer * Add logo and shortcut prompt * Update version in build.gradle * Make installer name different to app (It's a weird way to do it, it renames the file in a gradle task). * Update java-autoformat.yml Added check to make sure the pull request is not from a fork --------- Co-authored-by: Charles Tian <46334090+charlestian23@users.noreply.github.com> Co-authored-by: Chase-Grajeda Co-authored-by: Chase Grajeda <76405306+Chase-Grajeda@users.noreply.github.com> Co-authored-by: charlestian23 * Update build.gradle (#741) * Update build.gradle Fixing the deprecation issues in the autoformatter * Update build.gradle * Update build.gradle * Update to use Java 21 * Automated Java code formatting changes --------- Co-authored-by: Bram van Heuveln * Updating to version 6.0.0 Changing to 6.0.0 since Java upgrade may break backwards compatibility * Too many mercury 1st draft * Too few mercury contradiction rule * error fixes * misc cleanup * Starting on case rules * Rest is Empty direct rule and getHead for vials * Prior is filled rule and getTail functionality * Prior filled small fix * Retrofit because I forgot to merge for 2 weeks * Rest empty quick fix --------- Co-authored-by: Charles Tian <46334090+charlestian23@users.noreply.github.com> Co-authored-by: Chase-Grajeda Co-authored-by: Chase Grajeda <76405306+Chase-Grajeda@users.noreply.github.com> Co-authored-by: ThisMatt Co-authored-by: ThisMatt <98851950+ThisMatt@users.noreply.github.com> Co-authored-by: Jaden Tian <56417002+jadeandtea@users.noreply.github.com> Co-authored-by: Bram van Heuveln Co-authored-by: charlestian23 Co-authored-by: Fisher Luba <145061313+FisherLuba@users.noreply.github.com> --- .../puzzle/thermometer/ThermometerVial.java | 3 + .../thermometer/elements/HeadTileBlck.java | 5 +- .../thermometer/elements/HeadTileEmp.java | 5 +- .../thermometer/elements/HeadTileFill.java | 5 +- .../thermometer/elements/ShaftTileBlck.java | 5 +- .../thermometer/elements/ShaftTileEmp.java | 5 +- .../thermometer/elements/ShaftTileFill.java | 5 +- .../thermometer/elements/TipTileBlck.java | 5 +- .../thermometer/elements/TipTileEmp.java | 5 +- .../thermometer/elements/TipTileFill.java | 5 +- ...DiscontinuousMercuryContradictionRule.java | 4 +- .../FinishColumnWithEmptyDirectRule.java | 46 ---------- .../rules/FinishRowWithEmptyDirectRule.java | 46 ---------- .../rules/MercuryOrBlockedCaseRule.java | 2 +- .../rules/PriorFilledDirectRule.java | 91 ++++++++++++++++++ .../rules/RestEmptyDirectRule.java | 92 +++++++++++++++++++ .../rules/RestIsEmptyDirectRule.java | 48 ---------- .../rules/TooFewMercuryContradiction.java | 14 ++- .../rules/TooManyMercuryContradiction.java | 15 ++- 19 files changed, 251 insertions(+), 155 deletions(-) delete mode 100644 src/main/java/edu/rpi/legup/puzzle/thermometer/rules/FinishColumnWithEmptyDirectRule.java delete mode 100644 src/main/java/edu/rpi/legup/puzzle/thermometer/rules/FinishRowWithEmptyDirectRule.java create mode 100644 src/main/java/edu/rpi/legup/puzzle/thermometer/rules/PriorFilledDirectRule.java create mode 100644 src/main/java/edu/rpi/legup/puzzle/thermometer/rules/RestEmptyDirectRule.java delete mode 100644 src/main/java/edu/rpi/legup/puzzle/thermometer/rules/RestIsEmptyDirectRule.java diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerVial.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerVial.java index 19f6c4ce2..54e28ede1 100644 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerVial.java +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/ThermometerVial.java @@ -71,6 +71,9 @@ public boolean containsCell(ThermometerCell cell){ return false; } + public ThermometerCell getHead(){return cells.get(0);} + public ThermometerCell getTail(){return cells.get(cells.size());} + //checking for discontinuous flow inside of vial public boolean continuousFlow(){ //bool which is true until it runs into an empty/blocked cell in the vial diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/HeadTileBlck.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/HeadTileBlck.java index 8629fec65..39516323c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/HeadTileBlck.java +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/HeadTileBlck.java @@ -4,6 +4,9 @@ public class HeadTileBlck extends PlaceableElement { public HeadTileBlck(){ - super("Therm-PLAC-0003", "Head Tile Block", "The tile corresponding to the blocked head of a thermometer", "edu/rpi/legup/images/thermometer/HeadBlock.png"); + super("Therm-PLAC-0003", + "Head Tile Block", + "The tile corresponding to the blocked head of a thermometer", + "edu/rpi/legup/images/thermometer/HeadBlock.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/HeadTileEmp.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/HeadTileEmp.java index 432ae8e42..8fb7045a4 100644 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/HeadTileEmp.java +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/HeadTileEmp.java @@ -4,6 +4,9 @@ public class HeadTileEmp extends PlaceableElement { public HeadTileEmp(){ - super("Therm-PLAC-0001", "Head Tile Empty", "The tile corresponding to the empty head of a thermometer", "edu/rpi/legup/images/thermometer/HeadEmp.png"); + super("Therm-PLAC-0001", + "Head Tile Empty", + "The tile corresponding to the empty head of a thermometer", + "edu/rpi/legup/images/thermometer/HeadEmp.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/HeadTileFill.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/HeadTileFill.java index 85a4d103c..4c536fba8 100644 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/HeadTileFill.java +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/HeadTileFill.java @@ -4,6 +4,9 @@ public class HeadTileFill extends PlaceableElement { public HeadTileFill(){ - super("Therm-PLAC-0002", "Head Tile Filled", "The tile corresponding to the filled head of a thermometer", "edu/rpi/legup/images/thermometer/HeadFill.png"); + super("Therm-PLAC-0002", + "Head Tile Filled", + "The tile corresponding to the filled head of a thermometer", + "edu/rpi/legup/images/thermometer/HeadFill.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/ShaftTileBlck.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/ShaftTileBlck.java index 000a10936..e2220e048 100644 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/ShaftTileBlck.java +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/ShaftTileBlck.java @@ -4,6 +4,9 @@ public class ShaftTileBlck extends PlaceableElement { public ShaftTileBlck(){ - super("Therm-PLAC-0006", "Shaft Tile Blocked", "The tile corresponding to a Blocked middle segment of a thermometer", "edu/rpi/legup/images/thermometer/ShaftBlock.png"); + super("Therm-PLAC-0006", + "Shaft Tile Blocked", + "The tile corresponding to a Blocked middle segment of a thermometer", + "edu/rpi/legup/images/thermometer/ShaftBlock.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/ShaftTileEmp.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/ShaftTileEmp.java index 85850a9ae..da8d6e1aa 100644 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/ShaftTileEmp.java +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/ShaftTileEmp.java @@ -4,6 +4,9 @@ public class ShaftTileEmp extends PlaceableElement { public ShaftTileEmp(){ - super("Therm-PLAC-0004", "Shaft Tile Empty", "The tile corresponding to an empty middle segment of a thermometer", "edu/rpi/legup/images/thermometer/ShaftEmp.png"); + super("Therm-PLAC-0004", + "Shaft Tile Empty", + "The tile corresponding to an empty middle segment of a thermometer", + "edu/rpi/legup/images/thermometer/ShaftEmp.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/ShaftTileFill.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/ShaftTileFill.java index c092b8ca9..ca9487427 100644 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/ShaftTileFill.java +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/ShaftTileFill.java @@ -4,6 +4,9 @@ public class ShaftTileFill extends PlaceableElement { public ShaftTileFill(){ - super("Therm-PLAC-0005", "Shaft Tile Filled", "The tile corresponding to a filled middle segment of a thermometer", "edu/rpi/legup/images/thermometer/ShaftFill.png"); + super("Therm-PLAC-0005", + "Shaft Tile Filled", + "The tile corresponding to a filled middle segment of a thermometer", + "edu/rpi/legup/images/thermometer/ShaftFill.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/TipTileBlck.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/TipTileBlck.java index 4315b2d90..f3b2e9186 100644 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/TipTileBlck.java +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/TipTileBlck.java @@ -4,6 +4,9 @@ public class TipTileBlck extends PlaceableElement { public TipTileBlck(){ - super("Therm-PLAC-0009", "Tip Tile Block", "The tile corresponding to the Blocked tip of a thermometer", "edu/rpi/legup/images/thermometer/TipBlock.png"); + super("Therm-PLAC-0009", + "Tip Tile Block", + "The tile corresponding to the Blocked tip of a thermometer", + "edu/rpi/legup/images/thermometer/TipBlock.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/TipTileEmp.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/TipTileEmp.java index 76dd82fee..25c59e1d2 100644 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/TipTileEmp.java +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/TipTileEmp.java @@ -4,6 +4,9 @@ public class TipTileEmp extends PlaceableElement { public TipTileEmp(){ - super("Therm-PLAC-0007", "Tip Tile Empty", "The tile corresponding to the empty tip of a thermometer", "edu/rpi/legup/images/thermometer/TipEmp.png"); + super("Therm-PLAC-0007", + "Tip Tile Empty", + "The tile corresponding to the empty tip of a thermometer", + "edu/rpi/legup/images/thermometer/TipEmp.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/TipTileFill.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/TipTileFill.java index 59c18894d..20b9165cd 100644 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/TipTileFill.java +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/elements/TipTileFill.java @@ -4,6 +4,9 @@ public class TipTileFill extends PlaceableElement { public TipTileFill(){ - super("Therm-PLAC-0008", "Tip Tile Fill", "The tile corresponding to the filled tip of a thermometer", "edu/rpi/legup/images/thermometer/TipFill.png"); + super("Therm-PLAC-0008", + "Tip Tile Fill", + "The tile corresponding to the filled tip of a thermometer", + "edu/rpi/legup/images/thermometer/TipFill.png"); } } diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/DiscontinuousMercuryContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/DiscontinuousMercuryContradictionRule.java index 8a8ef00f6..2b60a2630 100644 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/DiscontinuousMercuryContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/DiscontinuousMercuryContradictionRule.java @@ -15,10 +15,10 @@ public class DiscontinuousMercuryContradictionRule extends ContradictionRule{ private final String INVALID_USE_MESSAGE = "Contradiction must be a vial"; public DiscontinuousMercuryContradictionRule() { - super("DiscontinuousMercury", + super("THERM-CONT-0003", "Discontinuous Mercury", "A vial has a filled cell after an empty or blocked cell", - null); + "edu/rpi/legup/images/thermometer/MercuryInBody.png"); } diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/FinishColumnWithEmptyDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/FinishColumnWithEmptyDirectRule.java deleted file mode 100644 index 6fd634df8..000000000 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/FinishColumnWithEmptyDirectRule.java +++ /dev/null @@ -1,46 +0,0 @@ -package edu.rpi.legup.puzzle.thermometer.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.thermometer.ThermometerBoard; - -public class FinishColumnWithEmptyDirectRule extends DirectRule { - - public FinishColumnWithEmptyDirectRule() { - super("FCE", - "Finish Column with Empty", - "When a column is filled with mercury equal to the corresponding edge number, the rest are blocked.", - "edu/rpi/legup/images/nurikabe/rules/FinishColumnWithEmpty.png"); - } - - /** - * Checks whether the child node logically follows from the parent node at the specific - * puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified - * puzzleElement, otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - ThermometerBoard board = (ThermometerBoard) transition.getBoard(); - ThermometerBoard origBoard = (ThermometerBoard) transition.getParents().get(0).getBoard(); - - // Grab the puzzleElement (Array of X'd cells? Or compare board to origBoard?) - // Get the column that is being changed - // Get the number of filled vials in the row - // If the number filled != number given, throw error - - // All is well, valid - return null; - } - - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/FinishRowWithEmptyDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/FinishRowWithEmptyDirectRule.java deleted file mode 100644 index 9082d8359..000000000 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/FinishRowWithEmptyDirectRule.java +++ /dev/null @@ -1,46 +0,0 @@ -package edu.rpi.legup.puzzle.thermometer.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.thermometer.ThermometerBoard; - -public class FinishRowWithEmptyDirectRule extends DirectRule { - - public FinishRowWithEmptyDirectRule() { - super("FRE", - "Finish Row with Empty", - "When a row is filled with mercury equal to the corresponding edge number, the rest are blocked.", - "edu/rpi/legup/images/nurikabe/rules/FinishRowWithEmpty.png"); - } - - /** - * Checks whether the child node logically follows from the parent node at the specific - * puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified - * puzzleElement, otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - ThermometerBoard board = (ThermometerBoard) transition.getBoard(); - ThermometerBoard origBoard = (ThermometerBoard) transition.getParents().get(0).getBoard(); - - // Grab the puzzleElement (Array of X'd cells? Or compare board to origBoard?) - // Get the row that is being changed - // Get the number of filled vials in the row - // If the number filled != number given, throw error - - // All is well, valid - return null; - } - - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/MercuryOrBlockedCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/MercuryOrBlockedCaseRule.java index ccc066f2d..75b4a9eb6 100644 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/MercuryOrBlockedCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/MercuryOrBlockedCaseRule.java @@ -12,7 +12,7 @@ public class MercuryOrBlockedCaseRule extends CaseRule { public MercuryOrBlockedCaseRule() { - super("MOB", + super("THERM-CASE-0001", "Mercury or Blocked", "Each unassigned tile must be filled with mercury or blocked.", "edu/rpi/legup/images/thermometers/cases/MercuryOrBlocked.png"); diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/PriorFilledDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/PriorFilledDirectRule.java new file mode 100644 index 000000000..813691e4b --- /dev/null +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/PriorFilledDirectRule.java @@ -0,0 +1,91 @@ +package edu.rpi.legup.puzzle.thermometer.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.thermometer.ThermometerBoard; +import edu.rpi.legup.puzzle.thermometer.ThermometerCell; +import edu.rpi.legup.puzzle.thermometer.ThermometerFill; +import edu.rpi.legup.puzzle.thermometer.ThermometerVial; + +import java.util.ArrayList; + +public class PriorFilledDirectRule extends DirectRule { + + public PriorFilledDirectRule() { + super( + "THERM-BASC-0002", + "Prior is Filled", + "All tiles proceeding a filled tile in a vial must be filled", + "edu/rpi/legup/images/Thermometer/PriorIsFilled.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + ThermometerBoard initialBoard = (ThermometerBoard) transition.getParents().get(0).getBoard(); + ThermometerBoard finalBoard = (ThermometerBoard) transition.getBoard(); + + ThermometerCell cell = (ThermometerCell) finalBoard.getPuzzleElement(puzzleElement); + if (cell.getFill() != ThermometerFill.FILLED) { + return super.getInvalidUseOfRuleMessage() + ": Cell is not filled at this index"; + } + + ArrayList allVials = finalBoard.getVials(); + ThermometerVial host = null; + for(ThermometerVial vials: allVials){ + if(vials.containsCell((cell))){ + host = vials; + } + } + if(host == null) return super.getInvalidUseOfRuleMessage() + ": Something went wrong - 1"; + int x = (int)cell.getLocation().getX(); + int y = (int)cell.getLocation().getX(); + + //Identifies next cell from tail location, checks if it is filled + if(host.getTail() == cell){ + return super.getInvalidUseOfRuleMessage() + ": rule can not apply to tail"; + }else if(host.getTail().getLocation().getX() == x){ + if(host.getTail().getLocation().getY() > y){ + if(initialBoard.getCell(x, y + 1).getFill() == ThermometerFill.FILLED){ + return null; + } else{ + return super.getInvalidUseOfRuleMessage() + "rule does not apply to this cell"; + } + }else if(host.getTail().getLocation().getY() < y){ + if(initialBoard.getCell(x, y - 1).getFill() == ThermometerFill.FILLED){ + return null; + } else{ + return super.getInvalidUseOfRuleMessage() + "rule does not apply to this cell"; + } + } else return super.getInvalidUseOfRuleMessage() + ": Something went wrong - 2"; + }else if(host.getTail().getLocation().getY() == y){ + if(host.getTail().getLocation().getX() > x){ + if(initialBoard.getCell(x + 1, y).getFill() == ThermometerFill.FILLED){ + return null; + } else{ + return super.getInvalidUseOfRuleMessage() + "rule does not apply to this cell"; + } + }else if(host.getTail().getLocation().getX() < x){ + if(initialBoard.getCell(x - 1, y).getFill() == ThermometerFill.FILLED){ + return null; + } else{ + return super.getInvalidUseOfRuleMessage() + "rule does not apply to this cell"; + } + } else return super.getInvalidUseOfRuleMessage() + ": Something went wrong - 2.1"; + } + return super.getInvalidUseOfRuleMessage() + "Something went wrong - 3"; + } + + @Override + public Board getDefaultBoard(TreeNode node) {return null;} +} \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/RestEmptyDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/RestEmptyDirectRule.java new file mode 100644 index 000000000..a7d4e1e39 --- /dev/null +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/RestEmptyDirectRule.java @@ -0,0 +1,92 @@ +package edu.rpi.legup.puzzle.thermometer.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.gameboard.PuzzleElement; +import edu.rpi.legup.model.rules.DirectRule; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.thermometer.ThermometerBoard; +import edu.rpi.legup.puzzle.thermometer.ThermometerCell; +import edu.rpi.legup.puzzle.thermometer.ThermometerFill; +import edu.rpi.legup.puzzle.thermometer.ThermometerVial; + +import java.util.ArrayList; +import java.util.Set; + +public class RestEmptyDirectRule extends DirectRule { + + public RestEmptyDirectRule() { + super( + "THERM-BASC-0001", + "Rest is Empty", + "All tiles following a blocked tile in a vial must be blocked", + "edu/rpi/legup/images/Thermometer/RestEmpty.png"); + } + + /** + * Checks whether the child node logically follows from the parent node at the specific + * puzzleElement index using this rule + * + * @param transition transition to check + * @param puzzleElement equivalent puzzleElement + * @return null if the child node logically follow from the parent node at the specified + * puzzleElement, otherwise error message + */ + public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { + ThermometerBoard initialBoard = (ThermometerBoard) transition.getParents().get(0).getBoard(); + ThermometerBoard finalBoard = (ThermometerBoard) transition.getBoard(); + + ThermometerCell cell = (ThermometerCell) finalBoard.getPuzzleElement(puzzleElement); + if (cell.getFill() != ThermometerFill.BLOCKED) { + return super.getInvalidUseOfRuleMessage() + ": Cell is not blocked at this index"; + } + + ArrayList allVials = finalBoard.getVials(); + ThermometerVial host = null; + for(ThermometerVial vials: allVials){ + if(vials.containsCell((cell))){ + host = vials; + } + } + if(host == null) return super.getInvalidUseOfRuleMessage() + ": Something went wrong - 1"; + int x = (int)cell.getLocation().getX(); + int y = (int)cell.getLocation().getX(); + + //Identifies previous cell from head location, checks if it is blocked + if(host.getHead() == cell){ + return super.getInvalidUseOfRuleMessage() + ": rule can not apply to head"; + }else if(host.getHead().getLocation().getX() == x){ + if(host.getHead().getLocation().getY() > y){ + if(initialBoard.getCell(x, y + 1).getFill() == ThermometerFill.BLOCKED){ + return null; + } else{ + return super.getInvalidUseOfRuleMessage() + "rule does not apply to this cell"; + } + }else if(host.getHead().getLocation().getY() < y){ + if(initialBoard.getCell(x, y - 1).getFill() == ThermometerFill.BLOCKED){ + return null; + } else{ + return super.getInvalidUseOfRuleMessage() + "rule does not apply to this cell"; + } + } else return super.getInvalidUseOfRuleMessage() + ": Something went wrong - 2"; + }else if(host.getHead().getLocation().getY() == y){ + if(host.getHead().getLocation().getX() > x){ + if(initialBoard.getCell(x + 1, y).getFill() == ThermometerFill.BLOCKED){ + return null; + } else{ + return super.getInvalidUseOfRuleMessage() + "rule does not apply to this cell"; + } + }else if(host.getHead().getLocation().getX() < x){ + if(initialBoard.getCell(x - 1, y).getFill() == ThermometerFill.BLOCKED){ + return null; + } else{ + return super.getInvalidUseOfRuleMessage() + "rule does not apply to this cell"; + } + } else return super.getInvalidUseOfRuleMessage() + ": Something went wrong - 2.1"; + } + return super.getInvalidUseOfRuleMessage() + "Something went wrong - 3"; + } + + @Override + public Board getDefaultBoard(TreeNode node) {return null;} +} diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/RestIsEmptyDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/RestIsEmptyDirectRule.java deleted file mode 100644 index 7a479f4c2..000000000 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/RestIsEmptyDirectRule.java +++ /dev/null @@ -1,48 +0,0 @@ -package edu.rpi.legup.puzzle.thermometer.rules; - -import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.rules.DirectRule; -import edu.rpi.legup.model.tree.TreeNode; -import edu.rpi.legup.model.tree.TreeTransition; -import edu.rpi.legup.puzzle.thermometer.ThermometerBoard; - -public class RestIsEmptyDirectRule extends DirectRule { - - public RestIsEmptyDirectRule() { - super("RIE", - "Rest Is Empty", - "If mercury is blocked at a non-tail section, the rest of the thermometer is also blocked.", - "edu/rpi/legup/images/nurikabe/rules/RestIsEmpty.png"); - } - - /** - * Checks whether the child node logically follows from the parent node at the specific - * puzzleElement index using this rule - * - * @param transition transition to check - * @param puzzleElement equivalent puzzleElement - * @return null if the child node logically follow from the parent node at the specified - * puzzleElement, otherwise error message - */ - @Override - public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - ThermometerBoard board = (ThermometerBoard) transition.getBoard(); - ThermometerBoard origBoard = (ThermometerBoard) transition.getParents().get(0).getBoard(); - - // Grab the puzzleElement (Array of X'd cells? Or compare board to origBoard?) - // Ensure we only X'd a single vial, else return error - // Find the closest cell to the head of the vial - // If vertical, check to ensure # of filled cells in that row = outside #, else return error - // If horizontal, check to ensure # of filled cells in that column = outside #, else return error - // Make sure every vial from the closest to head cell to the tail is X'd, else return error - - // All is well, valid - return null; - } - - @Override - public Board getDefaultBoard(TreeNode node) { - return null; - } -} \ No newline at end of file diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/TooFewMercuryContradiction.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/TooFewMercuryContradiction.java index fbc1d75b8..16180a021 100644 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/TooFewMercuryContradiction.java +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/TooFewMercuryContradiction.java @@ -13,9 +13,21 @@ public class TooFewMercuryContradiction extends ContradictionRule{ public TooFewMercuryContradiction(){ - super("THERM-CONT-0002", "Too Many Mercury", "More mercury in column/row than target", "edu/rpi/legup/images/thermometer/TooManyMercury.png"); + super("THERM-CONT-0002", + "Too Many Mercury", + "More mercury in column/row than target", + "edu/rpi/legup/images/thermometer/TooManyMercury.png"); } + /** + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule + * + * @param board board to check contradiction + * @param puzzleElement equivalent puzzleElement + * @return null if the transition contains a contradiction at the specified puzzleElement, + * otherwise error message + */ @Override //Checks if row or column of input element has too many blocked tiles public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { diff --git a/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/TooManyMercuryContradiction.java b/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/TooManyMercuryContradiction.java index 97996c1b7..763705d26 100644 --- a/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/TooManyMercuryContradiction.java +++ b/src/main/java/edu/rpi/legup/puzzle/thermometer/rules/TooManyMercuryContradiction.java @@ -13,11 +13,22 @@ public class TooManyMercuryContradiction extends ContradictionRule{ public TooManyMercuryContradiction(){ - super("THERM-CONT-0002", "Too Many Mercury", "More mercury in column/row than target", "edu/rpi/legup/images/thermometer/TooManyMercury.png"); + super("THERM-CONT-0001", + "Too Many Mercury", + "More mercury in column/row than target", + "edu/rpi/legup/images/thermometer/TooManyMercury.png"); } + /** + * Checks whether the transition has a contradiction at the specific puzzleElement index using + * this rule + * + * @param board board to check contradiction + * @param puzzleElement equivalent puzzleElement + * @return null if the transition contains a contradiction at the specified puzzleElement, + * otherwise error message + */ @Override - //Checks if mercury tiles in column or row of input element exceed limit. public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { ThermometerBoard grid = (ThermometerBoard) board; ThermometerCell cell = (ThermometerCell) grid.getPuzzleElement(puzzleElement);