Skip to content

Commit

Permalink
Merge branch 'dev' into treeTentLink
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin-771 authored Dec 2, 2023
2 parents a992b88 + ca9fef9 commit 2c06c38
Show file tree
Hide file tree
Showing 52 changed files with 1,330 additions and 7 deletions.
37 changes: 31 additions & 6 deletions src/main/java/edu/rpi/legup/model/gameboard/GridBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,40 @@ public void setCell(int x, int y, Element e, MouseEvent m) {
if (this instanceof TreeTentBoard && ((y == dimension.height && 0 <= x && x < dimension.width) || (x == dimension.width && 0 <= y && y < dimension.height))) {
TreeTentBoard treeTentBoard = ((TreeTentBoard) this);
TreeTentClue clue = treeTentBoard.getClue(x, y);
if (y == dimension.height && clue.getData() < dimension.width) {
clue.setData(clue.getData() + 1);
if (y == dimension.height) {
if (m.getButton() == MouseEvent.BUTTON1) {
if (clue.getData() < dimension.height) {
clue.setData(clue.getData() + 1);
}
else {
clue.setData(0);
}
}
else {
if (clue.getData() > 0) {
clue.setData(clue.getData() - 1);
}
else {
clue.setData(dimension.height);
}
}
}
else {
if (x == dimension.width && clue.getData() < dimension.height) {
clue.setData(clue.getData() + 1);
else { //x == dimension.width
if (m.getButton() == MouseEvent.BUTTON1) {
if (clue.getData() < dimension.width) {
clue.setData(clue.getData() + 1);
}
else {
clue.setData(0);
}
}
else {
clue.setData(0);
if (clue.getData() > 0) {
clue.setData(clue.getData() - 1);
}
else {
clue.setData(dimension.width);
}
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,31 @@ public TreeTentType getType() {
return data;
}

public int getValue() {
switch (data) {
case TREE:
return 1;
case GRASS:
return 2;
case TENT:
return 3;
default:
return 0;
}
}

@Override
public void setType(Element e, MouseEvent m) {
switch (e.getElementName()) {
case "Unknown Tile":
this.data = TreeTentType.UNKNOWN;
break;
case "Tree Tile":
this.data = TreeTentType.TREE;
break;
case "Grass Tile":
this.data = TreeTentType.GRASS;
break;
case "Tent Tile":
this.data = TreeTentType.TENT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleEle
TreeTentCell cell = (TreeTentCell) puzzleElement;
Point loc = cell.getLocation();

cellElement.setAttribute("value", String.valueOf(cell.getData()));
cellElement.setAttribute("value", String.valueOf(cell.getValue()));
cellElement.setAttribute("x", String.valueOf(loc.x));
cellElement.setAttribute("y", String.valueOf(loc.y));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package puzzles.shorttruthtable.rules;

import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTable;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCell;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType;
import edu.rpi.legup.puzzle.shorttruthtable.rules.basic.introduction.DirectRuleAndIntroduction;
import edu.rpi.legup.save.InvalidFileFormatException;
import legup.MockGameBoardFacade;
import legup.TestUtilities;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

public class AndIntroductionDirectRuleTest {
private static final DirectRuleAndIntroduction RULE = new DirectRuleAndIntroduction();
private static ShortTruthTable stt;

@BeforeClass
public static void setup() {
MockGameBoardFacade.getInstance();
stt = new ShortTruthTable();
}

/**
* Given a statement: A ^ B
*
* Asserts that if at least 1 of A or B is false, then this is a valid application
* of the rule if and only if ^ is false.
*
* @param filePath The file path for test board setup.
* @throws InvalidFileFormatException
*/
@Test
public void FalseAndTest() throws InvalidFileFormatException {
String path = "puzzles/shorttruthtable/rules/AndIntroductionDirectRule/";
falseAndTestHelper(path + "FUF");
falseAndTestHelper(path + "FUU");
falseAndTestHelper(path + "UUF");
falseAndTestHelper(path + "FUT");
falseAndTestHelper(path + "TUF");
}

private void falseAndTestHelper(String filePath) throws InvalidFileFormatException {
TestUtilities.importTestBoard(filePath, stt);
TreeNode rootNode = stt.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard();
ShortTruthTableCell and = board.getCell(1, 0);

and.setData(ShortTruthTableCellType.TRUE);
board.addModifiedData(and);
Assert.assertNotNull(RULE.checkRule(transition));

and.setData(ShortTruthTableCellType.FALSE);
board.addModifiedData(and);
Assert.assertNull(RULE.checkRule(transition));
}

/**
* Given a statement: A ^ B
*
* Asserts that setting ^ to true is a valid application of the rule if
* and only if both A and B are true.
*
* @param filePath The file path for test board setup.
* @throws InvalidFileFormatException
*/
@Test
public void FalseOrTest() throws InvalidFileFormatException {
String path = "puzzles/shorttruthtable/rules/AndIntroductionDirectRule/";
String[] letters = {"T", "F", "U"};
for (String first : letters) {
for (String second : letters) {
trueAndTestHelper(path + first + "U" + second);
}
}
}

private void trueAndTestHelper(String filePath) throws InvalidFileFormatException {
TestUtilities.importTestBoard(filePath, stt);
TreeNode rootNode = stt.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard();
ShortTruthTableCell a = board.getCell(0, 0);
ShortTruthTableCell b = board.getCell(2, 0);
ShortTruthTableCell and = board.getCell(1, 0);

and.setData(ShortTruthTableCellType.TRUE);
board.addModifiedData(and);

if (a.getType() == ShortTruthTableCellType.TRUE && b.getType() == ShortTruthTableCellType.TRUE) {
Assert.assertNull(RULE.checkRule(transition));
}
else {
Assert.assertNotNull(RULE.checkRule(transition));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package puzzles.shorttruthtable.rules;

import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTable;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCell;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType;
import edu.rpi.legup.puzzle.shorttruthtable.rules.basic.introduction.DirectRuleBiconditionalIntroduction;
import edu.rpi.legup.save.InvalidFileFormatException;
import legup.MockGameBoardFacade;
import legup.TestUtilities;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

public class BiconditionalIntroductionTest {
private static final DirectRuleBiconditionalIntroduction RULE = new DirectRuleBiconditionalIntroduction();
private static ShortTruthTable stt;

@BeforeClass
public static void setup() {
MockGameBoardFacade.getInstance();
stt = new ShortTruthTable();
}

/**
* Given a statement: A <-> B
*
* Asserts that if setting <-> to false is a valid application of this rule if and
* only if A and B do not match.
*
* @throws InvalidFileFormatException
*/
@Test
public void FalseConditionalTest() throws InvalidFileFormatException {
String path = "puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/";

String[] letters = {"T", "F", "U"};
for (String a : letters) {
for (String b : letters) {
System.out.println(a + b);
falseConditionalHelper(path + a + "U" + b);
}
}
}

private void falseConditionalHelper(String filePath) throws InvalidFileFormatException {
TestUtilities.importTestBoard(filePath, stt);
TreeNode rootNode = stt.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard();
ShortTruthTableCell conditional = board.getCell(1, 0);

conditional.setData(ShortTruthTableCellType.FALSE);
board.addModifiedData(conditional);

ShortTruthTableCell a = board.getCell(0, 0);
ShortTruthTableCell b = board.getCell(2, 0);
if (a.getType() != b.getType()) {
// Not valid if they don't match but at least one of the values of A or B is unknown
if (a.getType() == ShortTruthTableCellType.UNKNOWN || b.getType() == ShortTruthTableCellType.UNKNOWN) {
Assert.assertNotNull(RULE.checkRule(transition));
}
else {
Assert.assertNull(RULE.checkRule(transition));
}
}
else {
Assert.assertNotNull(RULE.checkRule(transition));
}
}

/**
* Given a statement: A <-> B
*
* Asserts that if setting <-> to true is a valid application of this rule if and
* only if A and B match.
*
* @throws InvalidFileFormatException
*/
@Test
public void TrueConditionalTest() throws InvalidFileFormatException {
String path = "puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/";

String[] letters = {"T", "F", "U"};
for (String a : letters) {
for (String b : letters) {
System.out.println(a + b);
trueConditionalHelper(path + a + "U" + b);
}
}
}

private void trueConditionalHelper(String filePath) throws InvalidFileFormatException {
TestUtilities.importTestBoard(filePath, stt);
TreeNode rootNode = stt.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard();
ShortTruthTableCell conditional = board.getCell(1, 0);

conditional.setData(ShortTruthTableCellType.TRUE);
board.addModifiedData(conditional);

ShortTruthTableCell a = board.getCell(0, 0);
ShortTruthTableCell b = board.getCell(2, 0);
if (a.getType() == b.getType() && a.getType() != ShortTruthTableCellType.UNKNOWN) {
Assert.assertNull(RULE.checkRule(transition));
}
else {
Assert.assertNotNull(RULE.checkRule(transition));
}
}
}
Loading

0 comments on commit 2c06c38

Please sign in to comment.