From 44de9898ca559e634e5fdd79363bd40648c584fb Mon Sep 17 00:00:00 2001 From: summerhenson Date: Tue, 23 Jul 2024 14:13:11 -0400 Subject: [PATCH 1/8] Test case files for Regions Within Columns direct rule --- .../ColumnsWithinRowsDirectRuleTest.java | 1 - .../RegionsWithinColumnsDirectRuleTest.java | 29 ++++++++++++++ .../FalseStarOverlap | 40 +++++++++++++++++++ .../OneRegionOneCell | 29 ++++++++++++++ .../OneRegionTwoCells | 29 ++++++++++++++ .../PartialRegionOneCell | 29 ++++++++++++++ .../TwoColumnsStarOverlap | 40 +++++++++++++++++++ .../TwoColumnsTwoCells | 40 +++++++++++++++++++ .../TwoRegionsOneCell | 40 +++++++++++++++++++ 9 files changed, 276 insertions(+), 1 deletion(-) create mode 100644 src/test/java/puzzles/starbattle/rules/RegionsWithinColumnsDirectRuleTest.java create mode 100644 src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/FalseStarOverlap create mode 100644 src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/OneRegionOneCell create mode 100644 src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/OneRegionTwoCells create mode 100644 src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/PartialRegionOneCell create mode 100644 src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoColumnsStarOverlap create mode 100644 src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoColumnsTwoCells create mode 100644 src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsOneCell diff --git a/src/test/java/puzzles/starbattle/rules/ColumnsWithinRowsDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/ColumnsWithinRowsDirectRuleTest.java index a0906c3cf..89986b57c 100644 --- a/src/test/java/puzzles/starbattle/rules/ColumnsWithinRowsDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/ColumnsWithinRowsDirectRuleTest.java @@ -15,7 +15,6 @@ import org.junit.Test; import java.awt.*; -import java.io.FileNotFoundException; public class ColumnsWithinRowsDirectRuleTest { diff --git a/src/test/java/puzzles/starbattle/rules/RegionsWithinColumnsDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/RegionsWithinColumnsDirectRuleTest.java new file mode 100644 index 000000000..39896cb55 --- /dev/null +++ b/src/test/java/puzzles/starbattle/rules/RegionsWithinColumnsDirectRuleTest.java @@ -0,0 +1,29 @@ +package puzzles.starbattle.rules; + +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.starbattle.StarBattle; +import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; +import edu.rpi.legup.puzzle.starbattle.StarBattleCell; +import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; +import edu.rpi.legup.puzzle.starbattle.rules.RegionsWithinColumnsDirectRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.awt.*; + +public class RegionsWithinColumnsDirectRuleTest { + + private static final RegionsWithinColumnsDirectRule RULE = new RegionsWithinColumnsDirectRule(); + private static StarBattle starbattle; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + starbattle = new StarBattle(); + } +} diff --git a/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/FalseStarOverlap b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/FalseStarOverlap new file mode 100644 index 000000000..812f00b66 --- /dev/null +++ b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/FalseStarOverlap @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/OneRegionOneCell b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/OneRegionOneCell new file mode 100644 index 000000000..c459a9231 --- /dev/null +++ b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/OneRegionOneCell @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/OneRegionTwoCells b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/OneRegionTwoCells new file mode 100644 index 000000000..50a775d0b --- /dev/null +++ b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/OneRegionTwoCells @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/PartialRegionOneCell b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/PartialRegionOneCell new file mode 100644 index 000000000..057dc96f0 --- /dev/null +++ b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/PartialRegionOneCell @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoColumnsStarOverlap b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoColumnsStarOverlap new file mode 100644 index 000000000..e7495cabf --- /dev/null +++ b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoColumnsStarOverlap @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoColumnsTwoCells b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoColumnsTwoCells new file mode 100644 index 000000000..cea670809 --- /dev/null +++ b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoColumnsTwoCells @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsOneCell b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsOneCell new file mode 100644 index 000000000..0ee0205ab --- /dev/null +++ b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsOneCell @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From d92d5670152f5211b7b7edd9d92d4e7a0b04168d Mon Sep 17 00:00:00 2001 From: summerhenson Date: Tue, 23 Jul 2024 14:51:05 -0400 Subject: [PATCH 2/8] Regions Within Columns direct rule test suite --- .../ColumnsWithinRegionsDirectRuleTest.java | 1 - .../RegionsWithinColumnsDirectRuleTest.java | 317 ++++++++++++++++++ ...lumnsStarOverlap => TwoRegionsStarOverlap} | 0 ...{TwoColumnsTwoCells => TwoRegionsTwoCells} | 0 .../TwoRegionsTwoCells2 | 40 +++ 5 files changed, 357 insertions(+), 1 deletion(-) rename src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/{TwoColumnsStarOverlap => TwoRegionsStarOverlap} (100%) rename src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/{TwoColumnsTwoCells => TwoRegionsTwoCells} (100%) create mode 100644 src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsTwoCells2 diff --git a/src/test/java/puzzles/starbattle/rules/ColumnsWithinRegionsDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/ColumnsWithinRegionsDirectRuleTest.java index 2f9ed2596..3297b1d5e 100644 --- a/src/test/java/puzzles/starbattle/rules/ColumnsWithinRegionsDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/ColumnsWithinRegionsDirectRuleTest.java @@ -208,7 +208,6 @@ public void ColumnsWithinRegionsDirectRule_TwoColumnsStarOverlap() @Test public void ColumnsWithinRegionsDirectRule_FalseColumnsWithinRegions1() throws InvalidFileFormatException { - System.out.println("Starting false CWR:"); TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/OneColumnOneCell", starbattle); TreeNode rootNode = starbattle.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); diff --git a/src/test/java/puzzles/starbattle/rules/RegionsWithinColumnsDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/RegionsWithinColumnsDirectRuleTest.java index 39896cb55..68b11d091 100644 --- a/src/test/java/puzzles/starbattle/rules/RegionsWithinColumnsDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/RegionsWithinColumnsDirectRuleTest.java @@ -26,4 +26,321 @@ public static void setUp() { MockGameBoardFacade.getInstance(); starbattle = new StarBattle(); } + + @Test + public void RegionsWithinColumnsDirectRule_OneRegionOneCell() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/OneRegionOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(0,2); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(0,2); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinColumnsDirectRule_OneRegionTwoCells() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/OneRegionTwoCells", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(0,1); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(0,2); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location1 = new Point(0,1); + Point location2 = new Point(0,2); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(location1) || point.equals(location2)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinColumnsDirectRule_PartialRegionOneCell() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/PartialRegionOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(0,2); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(0,2); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinColumnsDirectRule_TwoRegionsOneCell() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(1,3); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(1,3); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinColumnsDirectRule_TwoRegionsTwoCells() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsTwoCells", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(1,1); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(1,3); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location1 = new Point(1,1); + Point location2 = new Point(1,3); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(location1) || point.equals(location2)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinColumnsDirectRule_TwoRegionsTwoCells2() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsTwoCells2", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(0,3); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(1,3); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location1 = new Point(0,3); + Point location2 = new Point(1,3); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(location1) || point.equals(location2)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinColumnsDirectRule_TwoRegionsStarOverlap() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsStarOverlap", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(1,1); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(1,1); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinColumnsDirectRule_FalseRegionsWithinColumns1() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/OneRegionOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(0,2); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + StarBattleCell cell2 = board.getCell(1,2); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNotNull(RULE.checkRule(transition)); + + Point location = new Point(0,2); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinColumnsDirectRule_FalseRegionsWithinColumns2() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/OneRegionOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(0,2); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + StarBattleCell cell2 = board.getCell(0,1); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNotNull(RULE.checkRule(transition)); + + Point location = new Point(0,2); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinColumnsDirectRule_FalseRegionsWithinColumns3() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/FalseStarOverlap", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(1,1); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + StarBattleCell cell2 = board.getCell(1,3); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNotNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + + @Test + public void RegionsWithinColumnsDirectRule_FalseRegionsWithinColumns4() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsTwoCells2", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(0,3); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNotNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } } diff --git a/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoColumnsStarOverlap b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsStarOverlap similarity index 100% rename from src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoColumnsStarOverlap rename to src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsStarOverlap diff --git a/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoColumnsTwoCells b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsTwoCells similarity index 100% rename from src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoColumnsTwoCells rename to src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsTwoCells diff --git a/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsTwoCells2 b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsTwoCells2 new file mode 100644 index 000000000..01ecce3ee --- /dev/null +++ b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsTwoCells2 @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From c1510b7e8d8ee628563234dd9fac082d86c968a3 Mon Sep 17 00:00:00 2001 From: summerhenson Date: Fri, 26 Jul 2024 14:04:33 -0400 Subject: [PATCH 3/8] New 5x5 1 star puzzle file --- ...Star Battle 1 star Normal 1.xml => 050101} | 0 ... visualized (DO NOT OPEN AS A PUZZLE).png} | Bin .../5x5 Star Battle 1 star Normal/050102 | 53 ++++++++++++++++++ .../RegionsWithinRowsDirectRuleTest.java | 30 ++++++++++ 4 files changed, 83 insertions(+) rename puzzles files/starbattle/5x5 Star Battle 1 star Normal/{5x5 Star Battle 1 star Normal 1.xml => 050101} (100%) rename puzzles files/starbattle/5x5 Star Battle 1 star Normal/{5x5 Star Battle Normal visualized (DO NOT OPEN AS A PUZZLE).png => 050101 visualized (DO NOT OPEN AS A PUZZLE).png} (100%) create mode 100644 puzzles files/starbattle/5x5 Star Battle 1 star Normal/050102 create mode 100644 src/test/java/puzzles/starbattle/rules/RegionsWithinRowsDirectRuleTest.java diff --git a/puzzles files/starbattle/5x5 Star Battle 1 star Normal/5x5 Star Battle 1 star Normal 1.xml b/puzzles files/starbattle/5x5 Star Battle 1 star Normal/050101 similarity index 100% rename from puzzles files/starbattle/5x5 Star Battle 1 star Normal/5x5 Star Battle 1 star Normal 1.xml rename to puzzles files/starbattle/5x5 Star Battle 1 star Normal/050101 diff --git a/puzzles files/starbattle/5x5 Star Battle 1 star Normal/5x5 Star Battle Normal visualized (DO NOT OPEN AS A PUZZLE).png b/puzzles files/starbattle/5x5 Star Battle 1 star Normal/050101 visualized (DO NOT OPEN AS A PUZZLE).png similarity index 100% rename from puzzles files/starbattle/5x5 Star Battle 1 star Normal/5x5 Star Battle Normal visualized (DO NOT OPEN AS A PUZZLE).png rename to puzzles files/starbattle/5x5 Star Battle 1 star Normal/050101 visualized (DO NOT OPEN AS A PUZZLE).png diff --git a/puzzles files/starbattle/5x5 Star Battle 1 star Normal/050102 b/puzzles files/starbattle/5x5 Star Battle 1 star Normal/050102 new file mode 100644 index 000000000..73d131d69 --- /dev/null +++ b/puzzles files/starbattle/5x5 Star Battle 1 star Normal/050102 @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/puzzles/starbattle/rules/RegionsWithinRowsDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/RegionsWithinRowsDirectRuleTest.java new file mode 100644 index 000000000..716e65c9a --- /dev/null +++ b/src/test/java/puzzles/starbattle/rules/RegionsWithinRowsDirectRuleTest.java @@ -0,0 +1,30 @@ +package puzzles.starbattle.rules; + +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.starbattle.StarBattle; +import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; +import edu.rpi.legup.puzzle.starbattle.StarBattleCell; +import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; +import edu.rpi.legup.puzzle.starbattle.rules.RegionsWithinRowsDirectRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.awt.*; + +public class RegionsWithinRowsDirectRuleTest { + + private static final RegionsWithinRowsDirectRule RULE = new RegionsWithinRowsDirectRule(); + private static StarBattle starbattle; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + starbattle = new StarBattle(); + } + +} From b0afc3634263ca54811253eb87f3c0942e0be923 Mon Sep 17 00:00:00 2001 From: summerhenson Date: Fri, 26 Jul 2024 14:55:23 -0400 Subject: [PATCH 4/8] First half of Regions Within Rows direct rule test suite --- .../RegionsWithinRowsDirectRuleTest.java | 143 ++++++++++++++++++ .../OneRegionOneCell | 29 ++++ .../PartialRegionOneCell | 29 ++++ .../PartialRegionTwoCells | 29 ++++ .../RegionsWithinRowsDirectRule/StarOverlap | 40 +++++ .../TwoRegionsOneCell | 40 +++++ 6 files changed, 310 insertions(+) create mode 100644 src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/OneRegionOneCell create mode 100644 src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/PartialRegionOneCell create mode 100644 src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/PartialRegionTwoCells create mode 100644 src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/StarOverlap create mode 100644 src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/TwoRegionsOneCell diff --git a/src/test/java/puzzles/starbattle/rules/RegionsWithinRowsDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/RegionsWithinRowsDirectRuleTest.java index 716e65c9a..b78ad9fb3 100644 --- a/src/test/java/puzzles/starbattle/rules/RegionsWithinRowsDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/RegionsWithinRowsDirectRuleTest.java @@ -27,4 +27,147 @@ public static void setUp() { starbattle = new StarBattle(); } + @Test + public void RegionsWithinRowsDirectRule_OneRegionOneCell() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/OneRegionOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(2,0); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(2,0); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinRowsDirectRule_PartialRegionOneCell() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/PartialRegionOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(2,0); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(2,0); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinRowsDirectRule_PartialRegionTwo() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/PartialRegionTwoCells", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(1,0); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(2,0); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location1 = new Point(1,0); + Point location2 = new Point(2,0); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(location1) || point.equals(location2)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinRowsDirectRule_TwoRegionsOneCell() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/TwoRegionsOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(3,1); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(3,1); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinRowsDirectRule_StarOverlap() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/StarOverlap", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(3,1); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(3,1); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } } diff --git a/src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/OneRegionOneCell b/src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/OneRegionOneCell new file mode 100644 index 000000000..056b67059 --- /dev/null +++ b/src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/OneRegionOneCell @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/PartialRegionOneCell b/src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/PartialRegionOneCell new file mode 100644 index 000000000..eb9a69787 --- /dev/null +++ b/src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/PartialRegionOneCell @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/PartialRegionTwoCells b/src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/PartialRegionTwoCells new file mode 100644 index 000000000..0654ed4dc --- /dev/null +++ b/src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/PartialRegionTwoCells @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/StarOverlap b/src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/StarOverlap new file mode 100644 index 000000000..5a6901ead --- /dev/null +++ b/src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/StarOverlap @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/TwoRegionsOneCell b/src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/TwoRegionsOneCell new file mode 100644 index 000000000..4e19386e4 --- /dev/null +++ b/src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/TwoRegionsOneCell @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 562cdbbcbbf3056d0ff5a4b4dfac37a38ae1d55a Mon Sep 17 00:00:00 2001 From: summerhenson Date: Tue, 30 Jul 2024 15:03:13 -0400 Subject: [PATCH 5/8] Finish Regions Within Rows inference rule tests --- .../rules/EmptyAdjacentDirectRule.java | 2 +- .../RegionsWithinRowsDirectRuleTest.java | 85 +++++++++++++++++++ .../FalseStarOverlap | 40 +++++++++ 3 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/FalseStarOverlap diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/EmptyAdjacentDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/EmptyAdjacentDirectRule.java index 17909e233..0cb43ce06 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/EmptyAdjacentDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/EmptyAdjacentDirectRule.java @@ -64,7 +64,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem StarBattleCell temp = adjacent[i]; if (temp != null && temp.getType() == StarBattleCellType.UNKNOWN) { - temp.setData(StarBattleCellType.BLACK.value); + //temp.setData(StarBattleCellType.BLACK.value); int X = temp.getLocation().x; int Y = temp.getLocation().y; modified.getCell(X,Y).setData(StarBattleCellType.BLACK.value); diff --git a/src/test/java/puzzles/starbattle/rules/RegionsWithinRowsDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/RegionsWithinRowsDirectRuleTest.java index b78ad9fb3..3ffaa82fd 100644 --- a/src/test/java/puzzles/starbattle/rules/RegionsWithinRowsDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/RegionsWithinRowsDirectRuleTest.java @@ -170,4 +170,89 @@ public void RegionsWithinRowsDirectRule_StarOverlap() } } } + + @Test + public void RegionsWithinRowsDirectRule_FalseRegionsWithinRows1() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/OneRegionOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(2,0); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(2,1); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNotNull(RULE.checkRule(transition)); + + Point location = new Point(2,0); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinRowsDirectRule_FalseRegionsWithinRows2() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/OneRegionOneCell", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell1 = board.getCell(2,0); + cell1.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell1); + StarBattleCell cell2 = board.getCell(1,0); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + + Assert.assertNotNull(RULE.checkRule(transition)); + + Point location = new Point(2,0); + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void RegionsWithinRowsDirectRule_FalseStarOverlap() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/RegionsWithinRowsDirectRule/FalseStarOverlap", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(3,1); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNotNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } diff --git a/src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/FalseStarOverlap b/src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/FalseStarOverlap new file mode 100644 index 000000000..a582d1c46 --- /dev/null +++ b/src/test/resources/puzzles/starbattle/rules/RegionsWithinRowsDirectRule/FalseStarOverlap @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 54184dfd9dcf51aa7bbaaeb55b59c6519cac69d8 Mon Sep 17 00:00:00 2001 From: summerhenson Date: Fri, 2 Aug 2024 15:09:45 -0400 Subject: [PATCH 6/8] Rewrite Columns Within Regions inference rule --- .../rules/ColumnsWithinRegionsDirectRule.java | 66 +++++++++++++++++-- .../ColumnsWithinRegionsDirectRuleTest.java | 13 +++- .../RegionsWithinColumnsDirectRuleTest.java | 11 +++- 3 files changed, 78 insertions(+), 12 deletions(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/ColumnsWithinRegionsDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/ColumnsWithinRegionsDirectRule.java index 6e4830138..db8f12f23 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/ColumnsWithinRegionsDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/ColumnsWithinRegionsDirectRule.java @@ -8,11 +8,9 @@ import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; import edu.rpi.legup.puzzle.starbattle.StarBattleCell; import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; +import io.opencensus.trace.Link; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; public class ColumnsWithinRegionsDirectRule extends DirectRule { public ColumnsWithinRegionsDirectRule() { @@ -23,6 +21,25 @@ public ColumnsWithinRegionsDirectRule() { "edu/rpi/legup/images/starbattle/rules/ColumnsWithinRegionsDirectRule.png"); } + private void generateSubsets(List> subsets, int current, int skip, int size) { + if (current == size) { + return; + } + List> newSubsets = new LinkedList>(); + if (current != skip) { + for (List subset: subsets) { + List copy = new LinkedList(subset); + copy.add(current); + newSubsets.add(copy); + } + subsets.addAll(newSubsets); + List oneMember = new LinkedList(); + oneMember.add(current); + subsets.add(oneMember); + } + generateSubsets(subsets, current + 1 == skip ? current + 2 : current + 1, skip, size); + } + /** * Checks whether the child node logically follows from the parent node at the specific * puzzleElement index using this rule @@ -34,13 +51,48 @@ public ColumnsWithinRegionsDirectRule() { */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - // assumption: the rule has been applied to its fullest extent and the rows and regions - // are now mutually encompassing + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleBoard origBoard = (StarBattleBoard) transition.getParents().get(0).getBoard(); StarBattleCell cell = (StarBattleCell) board.getPuzzleElement(puzzleElement); + int dim = board.getSize(); + int region = cell.getGroupIndex(); + int column = cell.getLocation().x; + if (cell.getType() != StarBattleCellType.BLACK) { return "Only black cells are allowed for this rule!"; } + + List> subsets = new LinkedList>(); + generateSubsets(subsets,0, column, dim); + + for (List columnSubset: subsets) { + Set regions = new HashSet(); + boolean containsRegion = false; + int columnStars = 0; + int regionStars = 0; + for (int c: columnSubset) { + columnStars += board.columnStars(c); + for (StarBattleCell ce: origBoard.getCol(c)) { + if (ce.getType() == StarBattleCellType.UNKNOWN) { + if (regions.add(ce.getGroupIndex())) { + regionStars += board.getRegion(ce.getGroupIndex()).numStars(); + } + if (ce.getGroupIndex() == region) { + containsRegion = true; + } + } + } + } + if (containsRegion && board.getPuzzleNumber() * columnSubset.size() - columnStars + >= board.getPuzzleNumber() * regions.size() - regionStars) { + return null; + } + } + /* + //StarBattleBoard modified = (StarBattleBoard) origBoard.copy(); + //modified.getPuzzleElement(puzzleElement).setData(StarBattleCellType.BLACK.value); + // the columns that are contained Set columns = new HashSet(); // the regions that contain them @@ -94,7 +146,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem } } */ - return null; + return "Wrong!"; } /** diff --git a/src/test/java/puzzles/starbattle/rules/ColumnsWithinRegionsDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/ColumnsWithinRegionsDirectRuleTest.java index 3297b1d5e..185d31f5c 100644 --- a/src/test/java/puzzles/starbattle/rules/ColumnsWithinRegionsDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/ColumnsWithinRegionsDirectRuleTest.java @@ -268,7 +268,7 @@ public void ColumnsWithinRegionsDirectRule_FalseColumnsWithinRegions2() } @Test - public void ColumnsWithinRegionsDirectRule_FalseColumnsWithinRegions3() + public void ColumnsWithinRegionsDirectRule_PartialRemoval() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/PartialColumnTwoCells", starbattle); TreeNode rootNode = starbattle.getTree().getRootNode(); @@ -280,11 +280,18 @@ public void ColumnsWithinRegionsDirectRule_FalseColumnsWithinRegions3() cell1.setData(StarBattleCellType.BLACK.value); board.addModifiedData(cell1); - Assert.assertNotNull(RULE.checkRule(transition)); + Assert.assertNull(RULE.checkRule(transition)); + Point location1 = new Point(0, 1); for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { - Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + Point point = new Point(k,i); + if (point.equals(location1)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } } } } diff --git a/src/test/java/puzzles/starbattle/rules/RegionsWithinColumnsDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/RegionsWithinColumnsDirectRuleTest.java index 68b11d091..a45f7455f 100644 --- a/src/test/java/puzzles/starbattle/rules/RegionsWithinColumnsDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/RegionsWithinColumnsDirectRuleTest.java @@ -335,11 +335,18 @@ public void RegionsWithinColumnsDirectRule_FalseRegionsWithinColumns4() cell.setData(StarBattleCellType.BLACK.value); board.addModifiedData(cell); - Assert.assertNotNull(RULE.checkRule(transition)); + Assert.assertNull(RULE.checkRule(transition)); + Point location = new Point(0,3); for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { - Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + Point point = new Point(k,i); + if (point.equals(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } } } } From 2d0026e64094acecc3adaf2e7788d89169a9a487 Mon Sep 17 00:00:00 2001 From: summerhenson Date: Tue, 6 Aug 2024 14:26:34 -0400 Subject: [PATCH 7/8] Finish reworking X Within Y rules --- .../rules/ColumnsWithinRegionsDirectRule.java | 63 +------------ .../rules/ColumnsWithinRowsDirectRule.java | 92 +++++++++---------- .../rules/RegionsWithinColumnsDirectRule.java | 4 +- .../rules/RegionsWithinRowsDirectRule.java | 4 +- .../rules/RowsWithinColumnsDirectRule.java | 4 +- .../rules/RowsWithinRegionsDirectRule.java | 61 +++++++++++- .../ColumnsWithinRowsDirectRuleTest.java | 13 ++- 7 files changed, 122 insertions(+), 119 deletions(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/ColumnsWithinRegionsDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/ColumnsWithinRegionsDirectRule.java index db8f12f23..9fdaa23a8 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/ColumnsWithinRegionsDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/ColumnsWithinRegionsDirectRule.java @@ -72,11 +72,11 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem int columnStars = 0; int regionStars = 0; for (int c: columnSubset) { - columnStars += board.columnStars(c); + columnStars += origBoard.columnStars(c); for (StarBattleCell ce: origBoard.getCol(c)) { if (ce.getType() == StarBattleCellType.UNKNOWN) { if (regions.add(ce.getGroupIndex())) { - regionStars += board.getRegion(ce.getGroupIndex()).numStars(); + regionStars += origBoard.getRegion(ce.getGroupIndex()).numStars(); } if (ce.getGroupIndex() == region) { containsRegion = true; @@ -89,64 +89,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem return null; } } - /* - //StarBattleBoard modified = (StarBattleBoard) origBoard.copy(); - //modified.getPuzzleElement(puzzleElement).setData(StarBattleCellType.BLACK.value); - - // the columns that are contained - Set columns = new HashSet(); - // the regions that contain them - Set regions = new HashSet(); - // columns and regions to process - List columnsToCheck = new ArrayList(); - List regionsToCheck = new ArrayList(); - int columnStars = 0; - int regionStars = 0; - regions.add(cell.getGroupIndex()); - regionsToCheck.add(cell.getGroupIndex()); - - while (!columnsToCheck.isEmpty() || !regionsToCheck.isEmpty()) { - for (int i = 0; i < regionsToCheck.size(); ++i) { - int r = regionsToCheck.get(i); - regionStars += board.getRegion(r).numStars(); - for (StarBattleCell c : board.getRegion(r).getCells()) { - int column = ((StarBattleCell) c).getLocation().x; - if (column != cell.getLocation().x && c.getType() == StarBattleCellType.UNKNOWN && columns.add(column)) { - columnsToCheck.add(column); - } - } - regionsToCheck.remove(i); - --i; - } - for (int j = 0; j < columnsToCheck.size(); ++j) { - int c = columnsToCheck.get(j); - columnStars += board.columnStars(c); - for (int i = 0; i < board.getSize(); ++i) { - int region = board.getCell(c, i).getGroupIndex(); - if (board.getCell(c,i).getType() == StarBattleCellType.UNKNOWN && regions.add(region)) { - regionsToCheck.add(region); - } - } - columnsToCheck.remove(j); - --j; - } - } - // are the columns and regions missing an equal amount of stars - if (board.getPuzzleNumber() * columns.size() - columnStars - != board.getPuzzleNumber() * regions.size() - regionStars) { - return "The number of missing stars in the columns and regions must be equal and every extraneous cell must be black!"; - } - if (columns.contains(cell.getLocation().x)) { - return "Only black out cells outside the column(s)!"; - } - /* - for (int c: columns) { - if (c == cell.getLocation().x) { - return "Only black out cells outside the column(s)!"; - } - } - */ - return "Wrong!"; + return "The columns must fully fit within regions with the same number of stars missing!"; } /** diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/ColumnsWithinRowsDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/ColumnsWithinRowsDirectRule.java index 765a84d5b..da5c7bfd3 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/ColumnsWithinRowsDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/ColumnsWithinRowsDirectRule.java @@ -9,10 +9,7 @@ import edu.rpi.legup.puzzle.starbattle.StarBattleCell; import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; public class ColumnsWithinRowsDirectRule extends DirectRule { @@ -24,6 +21,25 @@ public ColumnsWithinRowsDirectRule() { "edu/rpi/legup/images/starbattle/rules/ColumnsWithinRowsDirectRule.png"); } + private void generateSubsets(List> subsets, int current, int skip, int size) { + if (current == size) { + return; + } + List> newSubsets = new LinkedList>(); + if (current != skip) { + for (List subset: subsets) { + List copy = new LinkedList(subset); + copy.add(current); + newSubsets.add(copy); + } + subsets.addAll(newSubsets); + List oneMember = new LinkedList(); + oneMember.add(current); + subsets.add(oneMember); + } + generateSubsets(subsets, current + 1 == skip ? current + 2 : current + 1, skip, size); + } + /** * Checks whether the child node logically follows from the parent node at the specific * puzzleElement index using this rule @@ -39,59 +55,43 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem // assumption: the rule has been applied to its fullest extent and the rows and columns // are now mutually encompassing StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleBoard origBoard = (StarBattleBoard) transition.getParents().get(0).getBoard(); StarBattleCell cell = (StarBattleCell) board.getPuzzleElement(puzzleElement); + int dim = board.getSize(); + int row = cell.getLocation().y; + int column = cell.getLocation().x; + if (cell.getType() != StarBattleCellType.BLACK) { return "Only black cells are allowed for this rule!"; } - // the columns that are contained - Set columns = new HashSet(); - // the rows that contain them - Set rows = new HashSet(); - // columns and rows to process - List columnsToCheck = new ArrayList(); - List rowsToCheck = new ArrayList(); - int columnStars = 0; - int rowStars = 0; - int firstRow = cell.getLocation().y; - rows.add(firstRow); - rowsToCheck.add(firstRow); + List> subsets = new LinkedList>(); + generateSubsets(subsets,0, column, dim); - while (!columnsToCheck.isEmpty() || !rowsToCheck.isEmpty()) { - for (int i = 0; i < rowsToCheck.size(); ++i) { - int r = rowsToCheck.get(i); - rowStars += board.rowStars(r); - for (StarBattleCell c : board.getRow(r)) { - int column = c.getLocation().x; - if (c.getType() == StarBattleCellType.UNKNOWN && columns.add(column)) { - columnsToCheck.add(column); + for (List columnSubset: subsets) { + Set rows = new HashSet(); + boolean containsRow = false; + int columnStars = 0; + int rowStars = 0; + for (int c: columnSubset) { + columnStars += origBoard.columnStars(c); + for (StarBattleCell ce: origBoard.getCol(c)) { + if (ce.getType() == StarBattleCellType.UNKNOWN) { + if (rows.add(ce.getLocation().y)) { + rowStars += origBoard.rowStars(ce.getLocation().y); + } + if (ce.getLocation().y == row) { + containsRow = true; + } } } - rowsToCheck.remove(i); - --i; } - for (int i = 0; i < columnsToCheck.size(); ++i) { - int c = columnsToCheck.get(i); - columnStars += board.columnStars(c); - for (StarBattleCell r : board.getCol(c)) { - int row = r.getLocation().y; - if (r.getType() == StarBattleCellType.UNKNOWN && rows.add(row)) { - rowsToCheck.add(row); - } - } - columnsToCheck.remove(i); - --i; + if (containsRow && board.getPuzzleNumber() * columnSubset.size() - columnStars + >= board.getPuzzleNumber() * rows.size() - rowStars) { + return null; } } - // are the columns and regions missing an equal amount of stars - if (board.getPuzzleNumber() * columns.size() - columnStars - != board.getPuzzleNumber() * rows.size() - rowStars) { - return "The number of missing stars in the columns and rows must be equal and every extraneous cell must be black!"; - } - if (columns.contains(cell.getLocation().x)) { - return "Only black out cells outside the column(s)!"; - } - return null; + return "The columns must fully fit within rows with the same number of stars missing!"; } /** diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/RegionsWithinColumnsDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/RegionsWithinColumnsDirectRule.java index ac2f0da9a..06d73cc1f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/RegionsWithinColumnsDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/RegionsWithinColumnsDirectRule.java @@ -28,8 +28,8 @@ public RegionsWithinColumnsDirectRule() { public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { ColumnsWithinRegionsDirectRule correspondingRule = new ColumnsWithinRegionsDirectRule(); String result = correspondingRule.checkRuleRawAt(transition, puzzleElement); - if (result != null && result.equals("Only black out cells outside the column(s)!")) { - return "Only black out cells outside the region(s)!"; + if (result != null && result.equals("The columns must fully fit within regions with the same number of stars missing!")) { + return "The regions must fully fit within columns with the same number of stars missing!"; } return result; } diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/RegionsWithinRowsDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/RegionsWithinRowsDirectRule.java index 8219f9c01..012dc0640 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/RegionsWithinRowsDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/RegionsWithinRowsDirectRule.java @@ -29,8 +29,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem RowsWithinRegionsDirectRule correspondingRule = new RowsWithinRegionsDirectRule(); String result = correspondingRule.checkRuleRawAt(transition, puzzleElement); - if (result != null && result.equals("Only black out cells outside the row(s)!")) { - return "Only black out cells outside the region(s)!"; + if (result != null && result.equals("The rows must fully fit within regions with the same number of stars missing!")) { + return "The regions must fully fit within rows with the same number of stars missing!"; } return result; } diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/RowsWithinColumnsDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/RowsWithinColumnsDirectRule.java index 39e3b46c4..a22c31a59 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/RowsWithinColumnsDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/RowsWithinColumnsDirectRule.java @@ -30,8 +30,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem ColumnsWithinRowsDirectRule correspondingRule = new ColumnsWithinRowsDirectRule(); String result = correspondingRule.checkRuleRawAt(transition, puzzleElement); - if (result != null && result.equals("Only black out cells outside the column(s)!")) { - return "Only black out cells outside the row(s)!"; + if (result != null && result.equals("The columns must fully fit within rows with the same number of stars missing!")) { + return "The rows must fully fit within columns with the same number of stars missing!"; } return result; } diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/RowsWithinRegionsDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/RowsWithinRegionsDirectRule.java index faa75d01c..de9aaf044 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/RowsWithinRegionsDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/RowsWithinRegionsDirectRule.java @@ -9,10 +9,7 @@ import edu.rpi.legup.puzzle.starbattle.StarBattleCell; import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; public class RowsWithinRegionsDirectRule extends DirectRule { public RowsWithinRegionsDirectRule() { @@ -23,6 +20,25 @@ public RowsWithinRegionsDirectRule() { "edu/rpi/legup/images/starbattle/rules/RowsWithinRegionsDirectRule.png"); } + private void generateSubsets(List> subsets, int current, int skip, int size) { + if (current == size) { + return; + } + List> newSubsets = new LinkedList>(); + if (current != skip) { + for (List subset: subsets) { + List copy = new LinkedList(subset); + copy.add(current); + newSubsets.add(copy); + } + subsets.addAll(newSubsets); + List oneMember = new LinkedList(); + oneMember.add(current); + subsets.add(oneMember); + } + generateSubsets(subsets, current + 1 == skip ? current + 2 : current + 1, skip, size); + } + /** * Checks whether the child node logically follows from the parent node at the specific * puzzleElement index using this rule @@ -38,10 +54,45 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem // assumption: the rule has been applied to its fullest extent and the rows and regions // are now mutually encompassing StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleBoard origBoard = (StarBattleBoard) transition.getParents().get(0).getBoard(); StarBattleCell cell = (StarBattleCell) board.getPuzzleElement(puzzleElement); + int dim = board.getSize(); + int region = cell.getGroupIndex(); + int row = cell.getLocation().y; + if (cell.getType() != StarBattleCellType.BLACK) { return "Only black cells are allowed for this rule!"; } + + List> subsets = new LinkedList>(); + generateSubsets(subsets,0, row, dim); + + for (List rowSubset: subsets) { + Set regions = new HashSet(); + boolean containsRegion = false; + int rowStars = 0; + int regionStars = 0; + for (int r: rowSubset) { + rowStars += origBoard.rowStars(r); + for (StarBattleCell ce: origBoard.getRow(r)) { + if (ce.getType() == StarBattleCellType.UNKNOWN) { + if (regions.add(ce.getGroupIndex())) { + regionStars += origBoard.getRegion(ce.getGroupIndex()).numStars(); + } + if (ce.getGroupIndex() == region) { + containsRegion = true; + } + } + } + } + if (containsRegion && board.getPuzzleNumber() * rowSubset.size() - rowStars + >= board.getPuzzleNumber() * regions.size() - regionStars) { + return null; + } + } + return "The rows must fully fit within regions with the same number of stars missing!"; + + /* // the rows that are contained Set rows = new HashSet(); // the regions that contain them @@ -89,6 +140,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem return "Only black out cells outside the row(s)!"; } return null; + + */ } /** diff --git a/src/test/java/puzzles/starbattle/rules/ColumnsWithinRowsDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/ColumnsWithinRowsDirectRuleTest.java index 89986b57c..8f9c938cb 100644 --- a/src/test/java/puzzles/starbattle/rules/ColumnsWithinRowsDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/ColumnsWithinRowsDirectRuleTest.java @@ -191,7 +191,7 @@ public void ColumnsWithinRowsDirectRule_FalseColumnsWithinRows1() } @Test - public void ColumnsWithinRowsDirectRule_FalseColumnsWithinRows2() + public void ColumnsWithinRowsDirectRule_PartialCover() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRowsDirectRule/OneColumn", starbattle); TreeNode rootNode = starbattle.getTree().getRootNode(); @@ -203,11 +203,18 @@ public void ColumnsWithinRowsDirectRule_FalseColumnsWithinRows2() cell1.setData(StarBattleCellType.BLACK.value); board.addModifiedData(cell1); - Assert.assertNotNull(RULE.checkRule(transition)); + Assert.assertNull(RULE.checkRule(transition)); + Point location = new Point(1,0); for (int i = 0; i < board.getHeight(); i++) { for (int k = 0; k < board.getWidth(); k++) { - Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + Point point = new Point(k,i); + if (point.equals(location)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } } } } From 9e9d8b27b5cb2b2e5903420416a9f297cf5a668e Mon Sep 17 00:00:00 2001 From: summerhenson Date: Tue, 6 Aug 2024 14:58:38 -0400 Subject: [PATCH 8/8] Star or Empty case rule test --- .../rules/StarOrEmptyCaseRuleTest.java | 68 +++++++++++++++++++ .../StarOrEmptyCaseRule/SimpleStarOrEmpty | 29 ++++++++ 2 files changed, 97 insertions(+) create mode 100644 src/test/java/puzzles/starbattle/rules/StarOrEmptyCaseRuleTest.java create mode 100644 src/test/resources/puzzles/starbattle/rules/StarOrEmptyCaseRule/SimpleStarOrEmpty diff --git a/src/test/java/puzzles/starbattle/rules/StarOrEmptyCaseRuleTest.java b/src/test/java/puzzles/starbattle/rules/StarOrEmptyCaseRuleTest.java new file mode 100644 index 000000000..e1f9cb990 --- /dev/null +++ b/src/test/java/puzzles/starbattle/rules/StarOrEmptyCaseRuleTest.java @@ -0,0 +1,68 @@ +package puzzles.starbattle.rules; + +import edu.rpi.legup.model.gameboard.Board; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.nurikabe.NurikabeType; +import edu.rpi.legup.puzzle.starbattle.StarBattle; +import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; +import edu.rpi.legup.puzzle.starbattle.StarBattleCell; +import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; +import edu.rpi.legup.puzzle.starbattle.rules.StarOrEmptyCaseRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; +import java.util.ArrayList; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class StarOrEmptyCaseRuleTest { + + private static final StarOrEmptyCaseRule RULE = new StarOrEmptyCaseRule(); + private static StarBattle starBattle; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + starBattle = new StarBattle(); + } + + @Test + public void StarOrEmptyCaseRuleTest_SimpleStarOrEmpty() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/StarOrEmptyCaseRule/SimpleStarOrEmpty", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + StarBattleCell cell = board.getCell(0,0); + ArrayList cases = RULE.getCases(board, cell); + + StarBattleBoard caseBoard1 = (StarBattleBoard) cases.get(0); + StarBattleBoard caseBoard2 = (StarBattleBoard) cases.get(1); + StarBattleCellType board1Type = caseBoard1.getCell(0, 0).getType(); + StarBattleCellType board2Type = caseBoard2.getCell(0, 0).getType(); + + Assert.assertTrue( + (board1Type.equals(StarBattleCellType.BLACK) || board1Type.equals(StarBattleCellType.STAR)) + && (board2Type.equals(StarBattleCellType.BLACK) + || board2Type.equals(StarBattleCellType.STAR))); + Assert.assertFalse(board1Type.equals(board2Type)); + Assert.assertEquals(caseBoard1.getHeight(), caseBoard2.getHeight(), board.getHeight()); + Assert.assertEquals(caseBoard1.getWidth(), caseBoard2.getWidth(), board.getWidth()); + + for (int i = 0; i < caseBoard1.getHeight(); i++) { + for (int k = 0; k < caseBoard1.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(caseBoard1.getCell(k, i).getLocation())) { + continue; + } + Assert.assertTrue(caseBoard1.getCell(k, i).equals(caseBoard2.getCell(k, i))); + } + } + } + +} diff --git a/src/test/resources/puzzles/starbattle/rules/StarOrEmptyCaseRule/SimpleStarOrEmpty b/src/test/resources/puzzles/starbattle/rules/StarOrEmptyCaseRule/SimpleStarOrEmpty new file mode 100644 index 000000000..4d065b28f --- /dev/null +++ b/src/test/resources/puzzles/starbattle/rules/StarOrEmptyCaseRule/SimpleStarOrEmpty @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file