Skip to content

Commit

Permalink
Merge branch 'project' of https://github.com/Jimmers2001/LEGUP into J…
Browse files Browse the repository at this point in the history
…immers2001-project
  • Loading branch information
charlestian23 committed Apr 14, 2023
2 parents 83b8c14 + 21e6b17 commit 0039649
Show file tree
Hide file tree
Showing 28 changed files with 797 additions and 161 deletions.
2 changes: 1 addition & 1 deletion bin/main/edu/rpi/legup/legup/config
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<puzzle name="LightUp"
qualifiedClassName="edu.rpi.legup.puzzle.lightup.LightUp"
fileType=".xml"
fileCreationDisabled="true"/>
fileCreationDisabled="false"/>
<puzzle name="Masyu"
qualifiedClassName="edu.rpi.legup.puzzle.masyu.Masyu"
fileType=".xml"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package puzzles.lightup.rules;

import edu.rpi.legup.puzzle.lightup.LightUpBoard;
import legup.MockGameBoardFacade;
import legup.TestUtilities;
import edu.rpi.legup.model.PuzzleImporter;
import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
import org.junit.Assert;
Expand All @@ -17,13 +15,10 @@
public class BulbsInPathContradictionRuleTest {
private static final BulbsInPathContradictionRule RULE = new BulbsInPathContradictionRule();
private static LightUp lightUp;
private static PuzzleImporter importer;

@BeforeClass
public static void setUp() {
MockGameBoardFacade.getInstance();
lightUp = new LightUp();
importer = lightUp.getImporter();
}

@Test
Expand All @@ -34,6 +29,7 @@ public void BulbsInPathContradictionRule_LightInHorizontalPath() throws InvalidF
transition.setRule(RULE);

LightUpBoard board = (LightUpBoard) transition.getBoard();
//confirm there is a contradiction somewhere on the board
Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(0, 0)));
Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(2, 0)));
Expand All @@ -49,6 +45,7 @@ public void BulbsInPathContradictionRule_LightInVerticalPath() throws InvalidFil
transition.setRule(RULE);

LightUpBoard board = (LightUpBoard) transition.getBoard();
//confirm there is a contradiction somewhere on the board
Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(0, 0)));
Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(0, 2)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package puzzles.lightup.rules;

import edu.rpi.legup.puzzle.lightup.LightUpBoard;
import edu.rpi.legup.puzzle.lightup.rules.CannotLightACellContradictionRule;
import legup.MockGameBoardFacade;
import legup.TestUtilities;
import edu.rpi.legup.model.PuzzleImporter;
import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
import org.junit.Assert;
import edu.rpi.legup.puzzle.lightup.LightUp;
import edu.rpi.legup.puzzle.lightup.rules.CannotLightACellContradictionRule;
import edu.rpi.legup.save.InvalidFileFormatException;

import org.junit.BeforeClass;
Expand All @@ -17,43 +15,57 @@
public class CannotLightACellContradictionRuleTest {
private static final CannotLightACellContradictionRule RULE = new CannotLightACellContradictionRule();
private static LightUp lightUp;
private static PuzzleImporter importer;

@BeforeClass
public static void setUp() {
MockGameBoardFacade.getInstance();
lightUp = new LightUp();
importer = lightUp.getImporter();
}

@Test
public void CannotLightACellContradictionRule_CannotFillMiddle() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/lightup/rules/CannotLightACellContradictionRule/CannotFillMiddle", lightUp);
@Test
//extensive full testing of null and non-null in a 5x5 board
public void FullLightTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/lightup/rules/CannotLightACellContradictionRule/FullLightTest", lightUp);
TreeNode rootNode = lightUp.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);
transition.setRule(RULE);

LightUpBoard board = (LightUpBoard) transition.getBoard();
//confirm there is a contradiction somewhere on the board
Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 2)));

Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(1, 1)));
//confirm it is impossible to light up these squares
Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(1, 3)));
Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(3, 3)));

//confirm these are not required to be lit because they are already lit or unable to be
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 1)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(3, 2)));
}

@Test
public void CannotLightACellContradictionRule_CannotFillCorners() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/lightup/rules/CannotLightACellContradictionRule/CannotFillCorners", lightUp);
@Test
//simple contradiction testing for null and non-null in a 3x3 board
public void CannotLightMiddleTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/lightup/rules/CannotLightACellContradictionRule/CannotLight", lightUp);
TreeNode rootNode = lightUp.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);
transition.setRule(RULE);

LightUpBoard board = (LightUpBoard) transition.getBoard();
//confirm there is a contradiction somewhere on the board
Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 1)));
Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(0, 0)));
Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(0, 2)));
Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(2, 0)));
Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(2, 2)));

//confirm it is impossible to light up the center square
Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(1, 1)));

//every square except the center
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 0)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 1)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 2)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 2)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 1)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@
import org.junit.BeforeClass;
import org.junit.Test;
import edu.rpi.legup.puzzle.lightup.LightUp;
import edu.rpi.legup.puzzle.lightup.rules.FinishWithEmptyBasicRule;
import edu.rpi.legup.save.InvalidFileFormatException;
import legup.TestUtilities;
import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
import edu.rpi.legup.puzzle.lightup.LightUpBoard;
import edu.rpi.legup.puzzle.lightup.LightUpCell;
import edu.rpi.legup.puzzle.lightup.LightUpCellType;
import org.junit.Assert;

public class EmptyCellinLightDirectRuleTest {
public class FinishWithEmptyBasicRuleTest {
private static final FinishWithEmptyBasicRule RULE = new FinishWithEmptyBasicRule();
private static LightUp lightUp;

@BeforeClass
Expand All @@ -13,7 +23,80 @@ public static void setUp() {
}

@Test
public void simpleCaseTest() {
public void FinishWithEmptyWithThreeTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/lightup/rules/FinishWithEmptyBasicRule/FinishWithEmptyWithThree", lightUp);
TreeNode rootNode = lightUp.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

//get board state
LightUpBoard board = (LightUpBoard) transition.getBoard();

//change the board's cells considering the FinishWithEmpty rule to empty
LightUpCell cell1 = board.getCell(1,2);
cell1.setData(LightUpCellType.EMPTY.value);
board.addModifiedData(cell1);

//confirm there is a logical following of the FinishWithBulbs rule
Assert.assertNull(RULE.checkRule(transition));

//only the cell listed above should change following the rule
LightUpCell c;
for (int i = 0; i < board.getHeight(); i++) {
for (int j = 0; j < board.getWidth(); j++) {
c = board.getCell(j, i);
if (i == 2 && j == 1){
//logically follows
Assert.assertNull(RULE.checkRuleAt(transition, c));
}
else {
//does not use the rule to logically follow
Assert.assertNotNull(RULE.checkRuleAt(transition, c));
}
}
}
}

@Test
public void FinishWithEmptyTestWithOne() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/lightup/rules/FinishWithEmptyBasicRule/FinishWithEmptyWithOne", lightUp);
TreeNode rootNode = lightUp.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

//get board state
LightUpBoard board = (LightUpBoard) transition.getBoard();

//change the board's cells considering the FinishWithEmpty rule to empty
LightUpCell cell1 = board.getCell(0,1);
cell1.setData(LightUpCellType.EMPTY.value);
board.addModifiedData(cell1);

LightUpCell cell2 = board.getCell(2,1);
cell2.setData(LightUpCellType.EMPTY.value);
board.addModifiedData(cell2);

LightUpCell cell3 = board.getCell(1,2);
cell3.setData(LightUpCellType.EMPTY.value);
board.addModifiedData(cell3);

//confirm there is a logical following of the FinishWithBulbs rule
Assert.assertNull(RULE.checkRule(transition));

//only the three cells listed above should change following the rule
LightUpCell c;
for (int i = 0; i < board.getHeight(); i++) {
for (int j = 0; j < board.getWidth(); j++) {
c = board.getCell(j, i);
if ((i == 1 && j == 0) || (i == 1 && j == 2) || (i == 2 && j == 1)){
//logically follows
Assert.assertNull(RULE.checkRuleAt(transition, c));
}
else {
//does not use the rule to logically follow
Assert.assertNotNull(RULE.checkRuleAt(transition, c));
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,61 @@
import org.junit.BeforeClass;
import org.junit.Test;
import edu.rpi.legup.puzzle.lightup.LightUp;
import edu.rpi.legup.puzzle.lightup.rules.EmptyCornersBasicRule;
import edu.rpi.legup.save.InvalidFileFormatException;
import legup.TestUtilities;
import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
import edu.rpi.legup.puzzle.lightup.LightUpBoard;
import edu.rpi.legup.puzzle.lightup.LightUpCell;
import edu.rpi.legup.puzzle.lightup.LightUpCellType;
import org.junit.Assert;

public class EmptyCornersDirectRuleTest {
public class EmptyCornersBasicRuleTest {
private static final EmptyCornersBasicRule RULE = new EmptyCornersBasicRule();
private static LightUp lightUp;


@BeforeClass
public static void setUp() {
lightUp = new LightUp();
}

@Test
public void simpleCaseTest() {
public void EmptyCornersTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/lightup/rules/EmptyCornersBasicRule/EmptyCorners", lightUp);
TreeNode rootNode = lightUp.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

//get board state
LightUpBoard board = (LightUpBoard) transition.getBoard();

//change the board's cells considering the EmptyCorners rule to empty
LightUpCell cell1 = board.getCell(2,2);
cell1.setData(LightUpCellType.EMPTY.value);
board.addModifiedData(cell1);

LightUpCell cell2 = board.getCell(0,2);
cell2.setData(LightUpCellType.EMPTY.value);
board.addModifiedData(cell2);

//confirm there is a logical following of the EmptyCorners rule
Assert.assertNull(RULE.checkRule(transition));

//confirm the two expected cells are emptied USING THE RULE
// and none of the rest are (others can be empty just not by the same rule)
LightUpCell c;
for (int i = 0; i < board.getHeight(); i++) {
for (int j = 0; j < board.getWidth(); j++) {
c = board.getCell(j, i);
if ((i == 2 && j == 0) || (i == 2 && j == 2)){
Assert.assertNull(RULE.checkRuleAt(transition, c));
}
else {
Assert.assertNotNull(RULE.checkRuleAt(transition, c));
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@
import org.junit.BeforeClass;
import org.junit.Test;
import edu.rpi.legup.puzzle.lightup.LightUp;
import edu.rpi.legup.puzzle.lightup.rules.EmptyCellinLightBasicRule;
import edu.rpi.legup.save.InvalidFileFormatException;
import legup.TestUtilities;
import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
import edu.rpi.legup.puzzle.lightup.LightUpBoard;
import edu.rpi.legup.puzzle.lightup.LightUpCell;
import edu.rpi.legup.puzzle.lightup.LightUpCellType;
import org.junit.Assert;

public class FinishWithBulbsDirectRuleTest {
public class EmptyCellinLightBasicRuleTest {
private static final EmptyCellinLightBasicRule RULE = new EmptyCellinLightBasicRule();
private static LightUp lightUp;

@BeforeClass
Expand All @@ -13,7 +23,58 @@ public static void setUp() {
}

@Test
public void simpleCaseTest() {
//tests a 3x3 board with with a 0 black tile in the center and lightbulbs in top left and bototm right
//confirms the rest of the tiles must be empty
public void EmptyCellinLightBasicRule() throws InvalidFileFormatException{
TestUtilities.importTestBoard("puzzles/lightup/rules/EmptyCellinLightBasicRule/EmptyCells", lightUp);
TreeNode rootNode = lightUp.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

//get board state
LightUpBoard board = (LightUpBoard) transition.getBoard();

//change the board's cells considering the emptycellinlight rule
LightUpCell cell2 = board.getCell(1,0);
cell2.setData(LightUpCellType.EMPTY.value);
board.addModifiedData(cell2);

LightUpCell cell3 = board.getCell(0,1);
cell3.setData(LightUpCellType.EMPTY.value);
board.addModifiedData(cell3);

LightUpCell cell4 = board.getCell(2,0);
cell4.setData(LightUpCellType.EMPTY.value);
board.addModifiedData(cell4);

LightUpCell cell5 = board.getCell(0,2);
cell5.setData(LightUpCellType.EMPTY.value);
board.addModifiedData(cell5);

LightUpCell cell6 = board.getCell(1,2);
cell6.setData(LightUpCellType.EMPTY.value);
board.addModifiedData(cell6);

LightUpCell cell7 = board.getCell(2,1);
cell7.setData(LightUpCellType.EMPTY.value);
board.addModifiedData(cell7);

//confirm there is a logical following of the EmptyCellinLight rule
Assert.assertNull(RULE.checkRule(transition));

//cells (0,0) and (2,2) are not empty because they have lightbulbs, and (1,1)
//because it is a black tile. Confirm the rest are empty
LightUpCell c;
for (int i = 0; i < board.getHeight(); i++) {
for (int j = 0; j < board.getWidth(); j++) {
c = board.getCell(j, i);
if ((i == 0 && j == 0) || (i == 2 && j == 2) || (i == 1 && j == 1)){
Assert.assertNotNull(RULE.checkRuleAt(transition, c));
}
else {
Assert.assertNull(RULE.checkRuleAt(transition, c));
}
}
}
}
}
Loading

0 comments on commit 0039649

Please sign in to comment.