Skip to content

Commit

Permalink
TooFewTents Overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
Rorymar committed Dec 1, 2023
1 parent df8d747 commit 51e20db
Show file tree
Hide file tree
Showing 8 changed files with 355 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/test/java/puzzles/treetent/rules/TentOrGrassCaseRuleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package puzzles.treetent.rules;

import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.tree.Tree;
import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
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.FillinRowCaseRule;
import edu.rpi.legup.puzzle.treetent.rules.TentOrGrassCaseRule;
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.*;
import java.util.ArrayList;

public class TentOrGrassCaseRuleTest {
private static final TentOrGrassCaseRule RULE = new TentOrGrassCaseRule();
private static TreeTent treetent;

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

/**
* @throws InvalidFileFormatException
* A temporary test
*/
@Test
public void TentOrGrassCaseRule_Test() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/TentOrGrassCaseRule/TentOrGrassTest", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

TreeTentBoard board = (TreeTentBoard) transition.getBoard();
TreeTentCell testing_cell = board.getCell(1, 0);
ArrayList<Board> cases = RULE.getCases(board, testing_cell);
// assert correct number of cases created
Assert.assertEquals(2, cases.size());
//Store the 0,1 cells from each case
//Assert that the Array of their states match to a an array of the expected.

}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package puzzles.treetent.rules;

import edu.rpi.legup.puzzle.treetent.TreeTentCell;
import legup.MockGameBoardFacade;
import legup.TestUtilities;
import edu.rpi.legup.model.tree.TreeNode;
Expand All @@ -13,6 +14,8 @@
import edu.rpi.legup.puzzle.treetent.rules.TooFewTentsContradictionRule;
import edu.rpi.legup.save.InvalidFileFormatException;

import java.awt.*;

public class TooFewTentsContradictionRuleTest {

private static final TooFewTentsContradictionRule RULE = new TooFewTentsContradictionRule();
Expand Down Expand Up @@ -72,5 +75,177 @@ public void TooFewTentsContradictionRule_DoubleBad() throws InvalidFileFormatExc
Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(0, 0)));
}

/**
* @throws InvalidFileFormatException
* Looks at a 2x2 Board in the format:
* [] Tr
* [] Gr
* Column 2 is checked to have 1 Tent (which is not present, thus producing a contradiction)
*/
@Test
public void TooFewTentsContradictionRule_2x2ColumnOnly() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents2x2Column",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));

TreeTentCell cell1 = board.getCell(1,0);
TreeTentCell cell2 = board.getCell(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(cell1.getLocation()) || point.equals(cell2.getLocation())) {
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
else {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
}
}
}

/**
* @throws InvalidFileFormatException
* Looks at a 2x2 Board in the format:
* Tr Gr
* [] []
* Row 1 is checked to have 1 Tent (which is not present, thus producing a contradiction)
*/
@Test
public void TooFewTentsContradictionRule_2x2RowOnly() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents2x2Row",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));

TreeTentCell cell1 = board.getCell(0,0);
TreeTentCell cell2 = board.getCell(1,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(cell1.getLocation()) || point.equals(cell2.getLocation())) {
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
else {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
}
}
}

/**
* @throws InvalidFileFormatException
* Looks at a 3x3 Board in the format:
* [] Tr []
* [] Gr []
* [] Gr []
* Column 2 is checked to have 1 Tent (which is not present, thus producing a contradiction)
*/
@Test
public void TooFewTentsContradictionRule_3x3OneColumn() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents3x3Column",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));

TreeTentCell cell1 = board.getCell(1,0);
TreeTentCell cell2 = board.getCell(1,1);
TreeTentCell cell3 = board.getCell(1,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(cell1.getLocation()) || point.equals(cell2.getLocation()) || point.equals(cell3.getLocation())) {
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
else {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
}
}
}

/**
* @throws InvalidFileFormatException
* Looks at a 3x3 Board in the format:
* Gr Tr Gr
* Gr [] Gr
* Gr Tr Gr
* Column 1 and 3 are checked to have 1 Tent (which is not present, thus producing a contradiction)
*/
@Test
public void TooFewTentsContradictionRule_3x3TwoColumn() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents3x3DoubleColumn",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));

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

/**
* @throws InvalidFileFormatException
* Looks at a 2x2 Board in the format:
* Tn []
* Tr []
* This should fail the contradiction as it is a legal board.
*/
@Test
public void TooFewTentsContradictionRule_NoContradiction() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsNoContradiction",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));

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)));
}
}
}



}

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Legup>
<puzzle name="TreeTent">
<board height="2" width="2">
<cells>
<cell value="1" x="0" y="0"/>
<cell value="2" x="0" y="1"/>
<cell value="2" x="1" y="1"/>
</cells>
<axis side="east">
<clue index="A" value="1"/>
<clue index="B" value="0"/>
</axis>
<axis side="south">
<clue index="1" value="0"/>
<clue index="2" value="1"/>
</axis>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Legup>
<puzzle name="TreeTent">
<board height="2" width="2">
<cells>
<cell value="1" x="1" y="0"/>
<cell value="2" x="1" y="1"/>
</cells>
<axis side="east">
<clue index="A" value="0"/>
<clue index="B" value="0"/>
</axis>
<axis side="south">
<clue index="1" value="0"/>
<clue index="2" value="1"/>
</axis>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Legup>
<puzzle name="TreeTent">
<board height="2" width="2">
<cells>
<cell value="1" x="0" y="0"/>
<cell value="2" x="1" y="0"/>
</cells>
<axis side="east">
<clue index="A" value="1"/>
<clue index="B" value="0"/>
</axis>
<axis side="south">
<clue index="1" value="0"/>
<clue index="2" value="0"/>
</axis>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Legup>
<puzzle name="TreeTent">
<board height="3" width="3">
<cells>
<cell value="1" x="1" y="0"/>
<cell value="2" x="1" y="1"/>
<cell value="2" x="1" y="2"/>
</cells>
<axis side="east">
<clue index="A" value="0"/>
<clue index="B" value="0"/>
<clue index="C" value="0"/>
</axis>
<axis side="south">
<clue index="1" value="0"/>
<clue index="2" value="1"/>
<clue index="3" value="0"/>
</axis>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Legup>
<puzzle name="TreeTent">
<board height="3" width="3">
<cells>
<cell value="2" x="0" y="0"/>
<cell value="2" x="0" y="1"/>
<cell value="2" x="0" y="2"/>
<cell value="1" x="1" y="0"/>
<cell value="1" x="1" y="2"/>
<cell value="2" x="2" y="0"/>
<cell value="2" x="2" y="1"/>
<cell value="2" x="2" y="2"/>
</cells>
<axis side="east">
<clue index="A" value="0"/>
<clue index="B" value="0"/>
<clue index="C" value="0"/>
</axis>
<axis side="south">
<clue index="1" value="1"/>
<clue index="2" value="0"/>
<clue index="3" value="1"/>
</axis>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Legup>
<puzzle name="TreeTent">
<board height="2" width="2">
<cells>
<cell value="3" x="0" y="0"/>
<cell value="1" x="0" y="1"/>
</cells>
<axis side="east">
<clue index="A" value="1"/>
<clue index="B" value="0"/>
</axis>
<axis side="south">
<clue index="1" value="1"/>
<clue index="2" value="0"/>
</axis>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>

0 comments on commit 51e20db

Please sign in to comment.