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/main/java/edu/rpi/legup/puzzle/starbattle/rules/ColumnsWithinRegionsDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/ColumnsWithinRegionsDirectRule.java index 6e4830138..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 @@ -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,67 +51,45 @@ 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!"; } - // 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); + 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 += origBoard.columnStars(c); + for (StarBattleCell ce: origBoard.getCol(c)) { + if (ce.getType() == StarBattleCellType.UNKNOWN) { + if (regions.add(ce.getGroupIndex())) { + regionStars += origBoard.getRegion(ce.getGroupIndex()).numStars(); + } + if (ce.getGroupIndex() == region) { + containsRegion = true; + } } } - 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)!"; + if (containsRegion && board.getPuzzleNumber() * columnSubset.size() - columnStars + >= board.getPuzzleNumber() * regions.size() - regionStars) { + return null; } } - */ - return null; + 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/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/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/ColumnsWithinRegionsDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/ColumnsWithinRegionsDirectRuleTest.java index 2f9ed2596..185d31f5c 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); @@ -269,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(); @@ -281,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/ColumnsWithinRowsDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/ColumnsWithinRowsDirectRuleTest.java index a0906c3cf..8f9c938cb 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 { @@ -192,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(); @@ -204,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))); + } } } } 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..a45f7455f --- /dev/null +++ b/src/test/java/puzzles/starbattle/rules/RegionsWithinColumnsDirectRuleTest.java @@ -0,0 +1,353 @@ +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(); + } + + @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.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++) { + 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/java/puzzles/starbattle/rules/RegionsWithinRowsDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/RegionsWithinRowsDirectRuleTest.java new file mode 100644 index 000000000..3ffaa82fd --- /dev/null +++ b/src/test/java/puzzles/starbattle/rules/RegionsWithinRowsDirectRuleTest.java @@ -0,0 +1,258 @@ +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(); + } + + @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))); + } + } + } + } + + @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/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/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/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 diff --git a/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsStarOverlap b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsStarOverlap new file mode 100644 index 000000000..e7495cabf --- /dev/null +++ b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsStarOverlap @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsTwoCells b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsTwoCells new file mode 100644 index 000000000..cea670809 --- /dev/null +++ b/src/test/resources/puzzles/starbattle/rules/RegionsWithinColumnsDirectRule/TwoRegionsTwoCells @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file 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 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 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 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