Skip to content

Commit

Permalink
Merge pull request #832 from summerhenson/star-battle
Browse files Browse the repository at this point in the history
Star battle
  • Loading branch information
summerhenson authored Jul 9, 2024
2 parents 4a1ab37 + 53a0ac6 commit dd6aca0
Show file tree
Hide file tree
Showing 9 changed files with 345 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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.ColumnsWithinRegionsDirectRule;
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 ColumnsWithinRegionsDirectRuleTest {

private static final ColumnsWithinRegionsDirectRule RULE = new ColumnsWithinRegionsDirectRule();
private static StarBattle starbattle;

@BeforeClass
public static void setUp() {
MockGameBoardFacade.getInstance();
starbattle = new StarBattle();
}

//single column w/in single region one square outside


}
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,70 @@ public void TooFewStarsContradictionRule_FalseContradiction()
}
}

@Test
public void TooFewStarsContradictionRule_NotEnoughSpace()
throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/starbattle/rules/TooFewStarsContradictionRule/NotEnoughSpace", starBattle);
TreeNode rootNode = starBattle.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

StarBattleBoard board = (StarBattleBoard) transition.getBoard();

Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard()));
for (int i = 0; i < board.getHeight(); ++i) {
for (int j = 0; j < board.getWidth(); ++j) {
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i)));
}
}
}

@Test
public void TooFewStarsContradictionRule_TwoStarColumn()
throws InvalidFileFormatException {

TestUtilities.importTestBoard("puzzles/starbattle/rules/TooFewStarsContradictionRule/TwoStarColumn", 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)));
}
}
}
}

@Test
public void TooFewStarsContradictionRule_TwoStarFalseContradiction()
throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/starbattle/rules/TooFewStarsContradictionRule/TwoStarFalseContradiction", 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)));
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Legup version="2.0.0">
<puzzle name="StarBattle">
<board size="3" puzzle_num="1">
<region>
<cells>
<cell value="0" x="0" y="0"/>
<cell value="0" x="1" y="0"/>
<cell value="0" x="0" y="1"/>
<cell value="0" x="0" y="2"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="2" y="0"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="2" y="2"/>
<cell value="0" x="1" y="2"/>
<cell value="0" x="2" y="1"/>
<cell value="0" x="1" y="1"/>
</cells>
</region>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Legup version="2.0.0">
<puzzle name="StarBattle">
<board size="3" puzzle_num="1">
<region>
<cells>
<cell value="-1" x="0" y="0"/>
<cell value="0" x="1" y="0"/>
<cell value="0" x="1" y="1"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="0" y="1"/>
<cell value="0" x="0" y="2"/>
<cell value="0" x="1" y="2"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="2" y="2"/>
<cell value="0" x="2" y="0"/>
<cell value="0" x="2" y="1"/>
</cells>
</region>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Legup version="2.0.0">
<puzzle name="StarBattle">
<board size="3" puzzle_num="1">
<region>
<cells>
<cell value="0" x="0" y="0"/>
<cell value="-1" x="1" y="0"/>
<cell value="0" x="2" y="0"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="0" y="1"/>
<cell value="0" x="1" y="1"/>
<cell value="0" x="2" y="1"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="0" y="2"/>
<cell value="-1" x="1" y="2"/>
<cell value="0" x="2" y="2"/>
</cells>
</region>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Legup version="2.0.0">
<puzzle name="StarBattle">
<board size="4" puzzle_num="1">
<region>
<cells>
<cell value="0" x="0" y="0"/>
<cell value="0" x="1" y="0"/>
<cell value="0" x="0" y="1"/>
<cell value="0" x="1" y="1"/>
<cell value="0" x="2" y="1"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="0" y="2"/>
<cell value="0" x="1" y="2"/>
<cell value="0" x="2" y="2"/>
<cell value="0" x="0" y="3"/>
<cell value="0" x="1" y="3"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="2" y="0"/>
<cell value="0" x="3" y="0"/>
<cell value="0" x="3" y="1"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="3" y="2"/>
<cell value="0" x="2" y="3"/>
<cell value="0" x="3" y="3"/>
</cells>
</region>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Legup version="2.0.0">
<puzzle name="StarBattle">
<board size="4" puzzle_num="5">
<region>
<cells>
<cell value="-2" x="0" y="2"/>
<cell value="-1" x="1" y="2"/>
<cell value="-1" x="0" y="3"/>
<cell value="-1" x="1" y="3"/>
</cells>
</region>
<region>
<cells>
<cell value="-1" x="2" y="2"/>
<cell value="-1" x="3" y="2"/>
<cell value="-2" x="2" y="3"/>
<cell value="-1" x="3" y="3"/>
</cells>
</region>
<region>
<cells>
<cell value="-1" x="0" y="0"/>
<cell value="-2" x="1" y="0"/>
<cell value="-1" x="0" y="1"/>
<cell value="0" x="1" y="1"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="2" y="0"/>
<cell value="-1" x="3" y="0"/>
<cell value="-1" x="2" y="1"/>
<cell value="-2" x="3" y="1"/>
</cells>
</region>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Legup version="2.0.0">
<puzzle name="StarBattle">
<board size="4" puzzle_num="2">
<region>
<cells>
<cell value="0" x="0" y="2"/>
<cell value="0" x="1" y="2"/>
<cell value="-1" x="0" y="3"/>
<cell value="0" x="1" y="3"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="2" y="2"/>
<cell value="0" x="3" y="2"/>
<cell value="0" x="2" y="3"/>
<cell value="0" x="3" y="3"/>
</cells>
</region>
<region>
<cells>
<cell value="-1" x="0" y="0"/>
<cell value="0" x="1" y="0"/>
<cell value="-1" x="0" y="1"/>
<cell value="0" x="1" y="1"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="2" y="0"/>
<cell value="0" x="3" y="0"/>
<cell value="0" x="2" y="1"/>
<cell value="0" x="3" y="1"/>
</cells>
</region>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Legup version="2.0.0">
<puzzle name="StarBattle">
<board size="4" puzzle_num="2">
<region>
<cells>
<cell value="-2" x="0" y="2"/>
<cell value="-1" x="1" y="2"/>
<cell value="0" x="0" y="3"/>
<cell value="-1" x="1" y="3"/>
</cells>
</region>
<region>
<cells>
<cell value="-1" x="2" y="2"/>
<cell value="0" x="3" y="2"/>
<cell value="-2" x="2" y="3"/>
<cell value="-1" x="3" y="3"/>
</cells>
</region>
<region>
<cells>
<cell value="-1" x="0" y="0"/>
<cell value="-2" x="1" y="0"/>
<cell value="-1" x="0" y="1"/>
<cell value="0" x="1" y="1"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="2" y="0"/>
<cell value="-1" x="3" y="0"/>
<cell value="-1" x="2" y="1"/>
<cell value="-2" x="3" y="1"/>
</cells>
</region>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>

0 comments on commit dd6aca0

Please sign in to comment.