Skip to content

Commit

Permalink
Merge branch 'Rorymar-master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
longj6 committed Oct 17, 2023
2 parents 535a825 + bf4d933 commit ff0024d
Show file tree
Hide file tree
Showing 27 changed files with 975 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import edu.rpi.legup.model.PuzzleExporter;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard;
import org.w3c.dom.Document;

public class FillapixExporter extends PuzzleExporter {
Expand All @@ -15,7 +16,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {
FillapixBoard board;
if (puzzle.getTree() != null) {
board = (FillapixBoard) puzzle.getTree().getRootNode().getBoard();
}
}
else {
board = (FillapixBoard) puzzle.getBoardView().getBoard();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ public static void setUp() {
treetent = new TreeTent();
}

/**
* @throws InvalidFileFormatException
* Tests if a tree is next to only grass in a 2x2 grid triggers the contradiction
*/
@Test
public void NoTentForTreeContradictionRule_() throws InvalidFileFormatException {
public void NoTentForTreeContradictionRule_Basic() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTentForTreeContradictionRule/NoTentForTree", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
Expand All @@ -43,5 +47,65 @@ public void NoTentForTreeContradictionRule_() throws InvalidFileFormatException
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
}

/**
* @throws InvalidFileFormatException
* Tests similarly to above, but now with a tent diagonally next to the tree, which should still contradict
*/
@Test
public void NoTentForTreeContradictionRule_Diagonal() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTentForTreeContradictionRule/NoTentForTreeDiagonal", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
}

/**
* @throws InvalidFileFormatException
* Tests that adjacent trees do not allow a pass
*/
@Test
public void NoTentForTreeContradictionRule_TwoTrees() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTentForTreeContradictionRule/NoTentForTreeTwoTrees", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 1)));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
}

/**
* @throws InvalidFileFormatException
* Tests similarly to above, but now with a tent diagonally next to two trees, which should still contradict on one.
*/
@Test
public void NoTentForTreeContradictionRule_TwoTreesDiagonal() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTentForTreeContradictionRule/NoTentForTreeTwoTreesDiagonal", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@

import edu.rpi.legup.puzzle.treetent.TreeTent;
import edu.rpi.legup.puzzle.treetent.TreeTentBoard;
import edu.rpi.legup.puzzle.treetent.TreeTentCell;
import edu.rpi.legup.puzzle.treetent.TreeTentType;
import edu.rpi.legup.puzzle.treetent.rules.NoTreeForTentContradictionRule;
import edu.rpi.legup.save.InvalidFileFormatException;

import java.awt.*;

public class NoTreeForTentContradictionRuleTest {

private static final NoTreeForTentContradictionRule RULE = new NoTreeForTentContradictionRule();
Expand All @@ -28,9 +24,13 @@ public static void setUp() {
treetent = new TreeTent();
}

/**
* @throws InvalidFileFormatException
* Tests if, in a 2x2 Grid, a Tent in the NW corner has no adjacent trees
*/
@Test
public void NoTreeForTentContradictionRule_() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTent", treetent);
public void NoTreeForTentContradictionRule_NW() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentNW", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);
Expand All @@ -43,5 +43,165 @@ public void NoTreeForTentContradictionRule_() throws InvalidFileFormatException
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
}

/**
* @throws InvalidFileFormatException
* Tests if, in a 2x2 Grid, a Tent in the NE corner has no adjacent trees
*/
@Test
public void NoTreeForTentContradictionRule_NE() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentNE", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 1)));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
}

/**
* @throws InvalidFileFormatException
* Tests if, in a 2x2 Grid, a Tent in the NW corner has no adjacent trees
*/
@Test
public void NoTreeForTentContradictionRule_SW() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentSW", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 0)));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(0, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
}

/**
* @throws InvalidFileFormatException
* Tests if, in a 2x2 Grid, a Tent in the SE corner has no adjacent trees
*/
@Test
public void NoTreeForTentContradictionRule_SE() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentSE", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
}

/**
* @throws InvalidFileFormatException
* Tests if, in a 3x3 Grid with no trees, a Tent in the center cell has no adjacent trees
*/
@Test
public void NoTreeForTentContradictionRule_3x3() throws InvalidFileFormatException{
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTent3x3", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 1)));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 2)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 2)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 2)));
}

/**
* @throws InvalidFileFormatException
* Tests if, in a 3x3 Grid with diagonal trees, a Tent in the center cell has no adjacent trees
*/
@Test
public void NoTreeForTentContradictionRule_3x3WithDiagonalTrees() throws InvalidFileFormatException{
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentDiagonals", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 1)));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 2)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 2)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 2)));
}

/**
* @throws InvalidFileFormatException
* Tests if, in a 3x3 Grid with an adjacent tree, test does not assert null.
*/
@Test
public void NoTreeForTentContradictionRule_YesTree() throws InvalidFileFormatException{
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentYesTree", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

Assert.assertNotNull(RULE.checkContradiction(board));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 2)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 2)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 2)));
}

/**
* @throws InvalidFileFormatException
* Tests if, in a 3x3 Grid with touching tents, a Tent in the center cell has no adjacent trees
*/
@Test
public void NoTreeForTentContradictionRule_JustTent() throws InvalidFileFormatException{
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentJustTent", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 0)));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(0, 1)));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 2)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 2)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 2)));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public static void setUp() {
treetent = new TreeTent();
}

/**
* @throws InvalidFileFormatException
* Test to check if all adjacent and diagonals not filled with a tree are filled with grass
*/
@Test
public void SurroundTentWithGrassBasicRuleTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/SurroundTentWithGrassDirectRule/SurroundTentWithGrass", treetent);
Expand Down Expand Up @@ -58,6 +62,90 @@ public void SurroundTentWithGrassBasicRuleTest() throws InvalidFileFormatExcepti
}
}
}

/**
* @throws InvalidFileFormatException
*
* Test with a 3x3 board with an absolutely empty area aside from a tent in the middle
* While such a situation is an illegal treetent setup, this direct rule doesn't consider that aspect, so its ok in this context
*/
@Test
public void SurroundTentWithGrassBasicRuleTest_BadBoard() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/SurroundTentWithGrassDirectRule/SurroundTentWithGrassBad", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

TreeTentCell cell1 = board.getCell(0, 0);
cell1.setData(TreeTentType.GRASS);
TreeTentCell cell2 = board.getCell(1, 0);
cell2.setData(TreeTentType.GRASS);
TreeTentCell cell3 = board.getCell(2, 0);
cell3.setData(TreeTentType.GRASS);
TreeTentCell cell4 = board.getCell(0, 1);
cell4.setData(TreeTentType.GRASS);
//Skip (1,1) due to being the Tent
TreeTentCell cell5 = board.getCell(2, 1);
cell5.setData(TreeTentType.GRASS);
TreeTentCell cell6 = board.getCell(0, 2);
cell6.setData(TreeTentType.GRASS);
TreeTentCell cell7 = board.getCell(1, 2);
cell7.setData(TreeTentType.GRASS);
TreeTentCell cell8 = board.getCell(2, 2);
cell8.setData(TreeTentType.GRASS);

board.addModifiedData(cell1);
board.addModifiedData(cell2);
board.addModifiedData(cell3);
//board.addModifiedData(cell4);
board.addModifiedData(cell5);
board.addModifiedData(cell6);
board.addModifiedData(cell7);
board.addModifiedData(cell8);

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

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(cell1.getLocation()) || point.equals(cell2.getLocation()) ||
point.equals(cell3.getLocation()) || //point.equals(cell4.getLocation()) ||
point.equals(cell5.getLocation()) || point.equals(cell6.getLocation()) ||
point.equals(cell7.getLocation()) || point.equals(cell8.getLocation())
) {
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
else {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
}
}
}

/**
* @throws InvalidFileFormatException
*
* Test to see if the rule passes even if no grass was able to be placed due to the presence of trees.
*/
@Test
public void SurroundTentWithGrassBasicRuleTest_FullBoard() throws InvalidFileFormatException{
TestUtilities.importTestBoard("puzzles/treetent/rules/SurroundTentWithGrassDirectRule/SurroundTentWithGrassTrees", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

Assert.assertNull(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)));
}
}
}
}


Expand Down
Loading

0 comments on commit ff0024d

Please sign in to comment.