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/SurroundStarDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/SurroundStarDirectRuleTest.java
new file mode 100644
index 000000000..db55d0f65
--- /dev/null
+++ b/src/test/java/puzzles/starbattle/rules/SurroundStarDirectRuleTest.java
@@ -0,0 +1,173 @@
+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_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 {
+ 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_FalseSurroundStar()
+ 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/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/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
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 @@
- |
- |
- |
- |
+ |
+ |
+ |
+ |
- |
+ |
|
- |
- |
+ |
+ |
- |
- |
- |
+ |
+ |
+ |
|
- |
- |
- |
- |
+ |
+ |
+ |
+ |