Skip to content

Commit

Permalink
Bug fix for X Within Y direct rules
Browse files Browse the repository at this point in the history
  • Loading branch information
summerhenson committed Jul 16, 2024
1 parent f32fe76 commit 2e62d41
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
for (int i = 0; i < regionsToCheck.size(); ++i) {
int r = regionsToCheck.get(i);
regionStars += board.getRegion(r).numStars();
for (PuzzleElement c : board.getRegion(r).getCells()) {
for (StarBattleCell c : board.getRegion(r).getCells()) {
int column = ((StarBattleCell) c).getLocation().x;
if (column != cell.getLocation().x && ((StarBattleCell) c).getType() == StarBattleCellType.UNKNOWN && columns.add(column)) {
if (column != cell.getLocation().x && c.getType() == StarBattleCellType.UNKNOWN && columns.add(column)) {
columnsToCheck.add(column);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
for (int i = 0; i < rowsToCheck.size(); ++i) {
int r = rowsToCheck.get(i);
rowStars += board.rowStars(r);
for (PuzzleElement c : board.getRow(r)) {
int column = ((StarBattleCell) c).getLocation().x;
if (columns.add(column)) {
for (StarBattleCell c : board.getRow(r)) {
int column = c.getLocation().x;
if (c.getType() == StarBattleCellType.UNKNOWN && columns.add(column)) {
columnsToCheck.add(column);
}
}
Expand All @@ -73,9 +73,9 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
for (int i = 0; i < columnsToCheck.size(); ++i) {
int c = columnsToCheck.get(i);
columnStars += board.columnStars(c);
for (PuzzleElement r : board.getCol(c)) {
int row = ((StarBattleCell) r).getLocation().y;
if (rows.add(row)) {
for (StarBattleCell r : board.getCol(c)) {
int row = r.getLocation().y;
if (r.getType() == StarBattleCellType.UNKNOWN && rows.add(row)) {
rowsToCheck.add(row);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
for (int i = 0; i < regionsToCheck.size(); ++i) {
int r = regionsToCheck.get(i);
regionStars += board.getRegion(r).numStars();
for (PuzzleElement ro : board.getRegion(r).getCells()) {
int row = ((StarBattleCell) ro).getLocation().y;
if (rows.add(row)) {
for (StarBattleCell ro : board.getRegion(r).getCells()) {
int row = ro.getLocation().y;
if (ro.getType() == StarBattleCellType.UNKNOWN && rows.add(row)) {
rowsToCheck.add(row);
}
}
Expand All @@ -72,7 +72,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
rowStars += board.rowStars(r);
for (int i = 0; i < board.getSize(); ++i) {
int region = board.getCell(i, r).getGroupIndex();
if (regions.add(region)) {
if (board.getCell(i,r).getType() == StarBattleCellType.UNKNOWN && regions.add(region)) {
regionsToCheck.add(region);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,34 @@ public void ColumnsWithinRegionsDirectRule_TwoColumns()
}
}

@Test
public void ColumnsWithinRegionsDirectRule_TwoColumnsWaitAMinute()
throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/starbattle/rules/ColumnsWithinRegionsDirectRule/TwoColumns", 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,1);
cell1.setData(StarBattleCellType.BLACK.value);
board.addModifiedData(cell1);

Assert.assertNull(RULE.checkRule(transition));

Point location1 = new Point(2, 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)) {
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
} else {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
}
}
}

@Test
public void ColumnsWithinRegionsDirectRule_TwoColumnsStarOverlap()
throws InvalidFileFormatException {
Expand Down

0 comments on commit 2e62d41

Please sign in to comment.