From 7d02f11f288be2c55e8bcdf1391c6255adcf2e1b Mon Sep 17 00:00:00 2001 From: summerhenson Date: Fri, 14 Jun 2024 14:50:02 -0400 Subject: [PATCH 1/4] Finish Too Few Stars contradiction rule tests --- .../rules/TooFewStarsContradictionRule.java | 5 +- .../ClashingOrbitContradictionRuleTest.java | 3 +- .../TooFewStarsContradictionRuleTest.java | 112 ++++++++++++++++++ .../rules/TooFewStarsContradictionRule/Column | 32 ++--- .../FalseContradiction | 28 ++--- .../rules/TooFewStarsContradictionRule/Region | 28 ++--- .../rules/TooFewStarsContradictionRule/Row | 28 ++--- 7 files changed, 174 insertions(+), 62 deletions(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/TooFewStarsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/TooFewStarsContradictionRule.java index e88b7c6b9..100243a65 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/TooFewStarsContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/TooFewStarsContradictionRule.java @@ -38,13 +38,14 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { int rowCount = 0; int columnCount = 0; for (int i = 0; i < sbBoard.getSize(); ++i) { - if (sbBoard.getCell(row, i).getType() != StarBattleCellType.BLACK) { + if (sbBoard.getCell(i, row).getType() != StarBattleCellType.BLACK) { ++rowCount; } - if (sbBoard.getCell(i, column).getType() != StarBattleCellType.BLACK) { + if (sbBoard.getCell(column, i).getType() != StarBattleCellType.BLACK) { ++columnCount; } } + if (rowCount < sbBoard.getPuzzleNumber() || columnCount < sbBoard.getPuzzleNumber()) { return null; } diff --git a/src/test/java/puzzles/starbattle/rules/ClashingOrbitContradictionRuleTest.java b/src/test/java/puzzles/starbattle/rules/ClashingOrbitContradictionRuleTest.java index 84be82fb0..ae8aaa08e 100644 --- a/src/test/java/puzzles/starbattle/rules/ClashingOrbitContradictionRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/ClashingOrbitContradictionRuleTest.java @@ -130,8 +130,7 @@ public void ClashingOrbitContradictionRule_FalseContradiction() for (int i = 0; i < board.getHeight(); ++i) { for (int j = 0; j < board.getWidth(); ++j) { - Point point = new Point(j,i); - Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); } } } diff --git a/src/test/java/puzzles/starbattle/rules/TooFewStarsContradictionRuleTest.java b/src/test/java/puzzles/starbattle/rules/TooFewStarsContradictionRuleTest.java index 8e682ae06..2e9f3ddef 100644 --- a/src/test/java/puzzles/starbattle/rules/TooFewStarsContradictionRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/TooFewStarsContradictionRuleTest.java @@ -7,6 +7,7 @@ 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.TooFewStarsContradictionRule; import edu.rpi.legup.save.InvalidFileFormatException; import java.awt.*; import legup.MockGameBoardFacade; @@ -16,12 +17,123 @@ import org.junit.Test; public class TooFewStarsContradictionRuleTest { + private static final TooFewStarsContradictionRule RULE = new TooFewStarsContradictionRule(); + private static StarBattle starBattle; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + starBattle = new StarBattle(); + } + /*Too few stars in column */ + @Test + public void TooFewStarsContradictionRule_Column() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/TooFewStarsContradictionRule/Column", 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,0); + StarBattleCell cell2 = board.getCell(0,1); + StarBattleCell cell3 = board.getCell(0,2); + StarBattleCell cell4 = board.getCell(0,3); + + Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || + point.equals(cell3.getLocation()) || point.equals(cell4.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + + } /*Too few stars in row*/ + @Test + public void TooFewStarsContradictionRule_Row() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/TooFewStarsContradictionRule/Row", 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,0); + StarBattleCell cell2 = board.getCell(1,0); + StarBattleCell cell3 = board.getCell(2,0); + StarBattleCell cell4 = board.getCell(3,0); + + Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || + point.equals(cell3.getLocation()) || point.equals(cell4.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + } /*Too few stars in region*/ + @Test + public void TooFewStarsContradictionRule_Region() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/TooFewStarsContradictionRule/Region", 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,0); + StarBattleCell cell2 = board.getCell(0,1); + StarBattleCell cell3 = board.getCell(1,0); + StarBattleCell cell4 = board.getCell(1,1); + + Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Point point = new Point(j,i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || + point.equals(cell3.getLocation()) || point.equals(cell4.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } + } /*False contradiction*/ + @Test + public void TooFewStarsContradictionRule_FalseContradiction() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/TooFewStarsContradictionRule/FalseContradiction", starBattle); + TreeNode rootNode = starBattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + + Assert.assertNotNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); + for (int i = 0; i < board.getHeight(); ++i) { + for (int j = 0; j < board.getWidth(); ++j) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); + } + } + } } diff --git a/src/test/resources/puzzles/starbattle/rules/TooFewStarsContradictionRule/Column b/src/test/resources/puzzles/starbattle/rules/TooFewStarsContradictionRule/Column index 6d5d920ca..1d1004b8b 100644 --- a/src/test/resources/puzzles/starbattle/rules/TooFewStarsContradictionRule/Column +++ b/src/test/resources/puzzles/starbattle/rules/TooFewStarsContradictionRule/Column @@ -4,34 +4,34 @@ - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + diff --git a/src/test/resources/puzzles/starbattle/rules/TooFewStarsContradictionRule/FalseContradiction b/src/test/resources/puzzles/starbattle/rules/TooFewStarsContradictionRule/FalseContradiction index 782c1d37d..0c377a58b 100644 --- a/src/test/resources/puzzles/starbattle/rules/TooFewStarsContradictionRule/FalseContradiction +++ b/src/test/resources/puzzles/starbattle/rules/TooFewStarsContradictionRule/FalseContradiction @@ -4,34 +4,34 @@ - - - - + + + + - - - - + + + + - - - + + + - - - + + + diff --git a/src/test/resources/puzzles/starbattle/rules/TooFewStarsContradictionRule/Region b/src/test/resources/puzzles/starbattle/rules/TooFewStarsContradictionRule/Region index 01f9ba680..2594f46e5 100644 --- a/src/test/resources/puzzles/starbattle/rules/TooFewStarsContradictionRule/Region +++ b/src/test/resources/puzzles/starbattle/rules/TooFewStarsContradictionRule/Region @@ -4,33 +4,33 @@ - - - - + + + + - - + + - + - - - - + + + + - - - + + + diff --git a/src/test/resources/puzzles/starbattle/rules/TooFewStarsContradictionRule/Row b/src/test/resources/puzzles/starbattle/rules/TooFewStarsContradictionRule/Row index 70ca07cef..67c36c5e8 100644 --- a/src/test/resources/puzzles/starbattle/rules/TooFewStarsContradictionRule/Row +++ b/src/test/resources/puzzles/starbattle/rules/TooFewStarsContradictionRule/Row @@ -4,34 +4,34 @@ - - - - + + + + - + - - + + - - - + + + - - - - + + + + From 12038600a6e66811f529fb13867a42ca1f46d146 Mon Sep 17 00:00:00 2001 From: summerhenson Date: Tue, 18 Jun 2024 14:53:26 -0400 Subject: [PATCH 2/4] Basic Surround Star direct rule tests --- .../rules/SurroundStarDirectRuleTest.java | 146 ++++++++++++++++++ .../rules/SurroundStarDirectRule/CenterStar | 29 ++++ .../rules/SurroundStarDirectRule/CornerStar | 29 ++++ 3 files changed, 204 insertions(+) create mode 100644 src/test/java/puzzles/starbattle/rules/SurroundStarDirectRuleTest.java create mode 100644 src/test/resources/puzzles/starbattle/rules/SurroundStarDirectRule/CenterStar create mode 100644 src/test/resources/puzzles/starbattle/rules/SurroundStarDirectRule/CornerStar diff --git a/src/test/java/puzzles/starbattle/rules/SurroundStarDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/SurroundStarDirectRuleTest.java new file mode 100644 index 000000000..ae7621b31 --- /dev/null +++ b/src/test/java/puzzles/starbattle/rules/SurroundStarDirectRuleTest.java @@ -0,0 +1,146 @@ +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.SurroundStarDirectRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class SurroundStarDirectRuleTest { + + private static final SurroundStarDirectRule RULE = new SurroundStarDirectRule(); + private static StarBattle starbattle; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + starbattle = new StarBattle(); + } + + @Test + public void SurroundStarDirectRule_CenterStarOneTile() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/SurroundStarDirectRule/CenterStar", 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,1); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(0, 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 SurroundStarDirectRule_CenterStarAllTiles() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/SurroundStarDirectRule/CenterStar", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + for (int i = 0; i < board.getWidth(); i++) { + for (int j = 0; j < board.getHeight(); j++) { + if (i != 1 || j != 1) { + StarBattleCell cell = board.getCell(i,j); + 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.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void SurroundStarDirectRule_CornerStar() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/SurroundStarDirectRule/CornerStar", 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(1,0); + cell2.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell2); + StarBattleCell cell3 = board.getCell(1,1); + cell3.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell3); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location1 = new Point(0, 1); + Point location2 = new Point(1,0); + Point location3 = 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(location1) || point.equals(location2) || point.equals(location3)) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void SurroundStarDirectRule_FalseContradiction() + throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/SurroundStarDirectRule/CornerStar", 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.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/SurroundStarDirectRule/CenterStar b/src/test/resources/puzzles/starbattle/rules/SurroundStarDirectRule/CenterStar new file mode 100644 index 000000000..a22f988df --- /dev/null +++ b/src/test/resources/puzzles/starbattle/rules/SurroundStarDirectRule/CenterStar @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/starbattle/rules/SurroundStarDirectRule/CornerStar b/src/test/resources/puzzles/starbattle/rules/SurroundStarDirectRule/CornerStar new file mode 100644 index 000000000..50558d4c4 --- /dev/null +++ b/src/test/resources/puzzles/starbattle/rules/SurroundStarDirectRule/CornerStar @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From cd42e83f05c4599a5cd90af612b102b24406a161 Mon Sep 17 00:00:00 2001 From: summerhenson Date: Fri, 21 Jun 2024 14:07:06 -0400 Subject: [PATCH 3/4] Added new Surround Star direct rule test --- .../rules/SurroundStarDirectRuleTest.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/test/java/puzzles/starbattle/rules/SurroundStarDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/SurroundStarDirectRuleTest.java index ae7621b31..f6894d6de 100644 --- a/src/test/java/puzzles/starbattle/rules/SurroundStarDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/SurroundStarDirectRuleTest.java @@ -53,6 +53,33 @@ public void SurroundStarDirectRule_CenterStarOneTile() throws InvalidFileFormatE } } + @Test + public void SurroundStarDirectRule_CenterStarOneTileDiagonal() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/SurroundStarDirectRule/CenterStar", 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); + cell.setData(StarBattleCellType.BLACK.value); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + Point location = new Point(0, 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 SurroundStarDirectRule_CenterStarAllTiles() throws InvalidFileFormatException { @@ -136,7 +163,7 @@ public void SurroundStarDirectRule_FalseContradiction() 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))); From ac95969eac247bb05a83078f26ad64257956c671 Mon Sep 17 00:00:00 2001 From: summerhenson Date: Fri, 21 Jun 2024 15:08:32 -0400 Subject: [PATCH 4/4] Make a rule name more accurate --- .../puzzles/starbattle/rules/SurroundStarDirectRuleTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/puzzles/starbattle/rules/SurroundStarDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/SurroundStarDirectRuleTest.java index f6894d6de..db55d0f65 100644 --- a/src/test/java/puzzles/starbattle/rules/SurroundStarDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/SurroundStarDirectRuleTest.java @@ -150,7 +150,7 @@ public void SurroundStarDirectRule_CornerStar() throws InvalidFileFormatExceptio } @Test - public void SurroundStarDirectRule_FalseContradiction() + public void SurroundStarDirectRule_FalseSurroundStar() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/starbattle/rules/SurroundStarDirectRule/CornerStar", starbattle); TreeNode rootNode = starbattle.getTree().getRootNode();