Skip to content

Commit

Permalink
Merge branch 'dev' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
charlestian23 authored Dec 13, 2023
2 parents 51e20db + ca9fef9 commit ec7b4a7
Show file tree
Hide file tree
Showing 102 changed files with 2,626 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions bin/main/edu/rpi/legup/log4j2.properties
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Logging level
# Root logger option
log4j.rootLogger=DEBUG, stdout, file
# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=Legup.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
# Logging level
# Root logger option
log4j.rootLogger=DEBUG, stdout, file
# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=Legup.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
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
Expand Up @@ -30,6 +30,9 @@ public static void setUp() {
nurikabe = new Nurikabe();
}

/**
* Tests the Black Between Regions direct rule for regions that are diagonal to each other (diagonal going from top left to bottom right)
*/
@Test
public void BlackBetweenRegionsDirectRule_DiagonalBlackBetweenRegions1Test() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsDirectRule/DiagonalBlackBetweenRegions1", nurikabe);
Expand Down Expand Up @@ -62,6 +65,9 @@ public void BlackBetweenRegionsDirectRule_DiagonalBlackBetweenRegions1Test() thr
}
}

/**
* Tests the Black Between Regions direct rule for regions that are diagonal to each other (diagonal going from bottom left to top right)
*/
@Test
public void BlackBetweenRegionsDirectRule_DiagonalBlackBetweenRegions2Test() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsDirectRule/DiagonalBlackBetweenRegions2", nurikabe);
Expand Down Expand Up @@ -94,6 +100,9 @@ public void BlackBetweenRegionsDirectRule_DiagonalBlackBetweenRegions2Test() thr
}
}

/**
* Tests the Black Between Regions direct rule for regions that are horizontally opposite each other
*/
@Test
public void BlackBetweenRegionsDirectRule_HorizontalBlackBetweenRegionsTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsDirectRule/HorizontalBlackBetweenRegions", nurikabe);
Expand Down Expand Up @@ -123,6 +132,9 @@ public void BlackBetweenRegionsDirectRule_HorizontalBlackBetweenRegionsTest() th
}
}

/**
* Tests the Black Between Regions direct rule for regions that are vertically opposite each other
*/
@Test
public void BlackBetweenRegionsDirectRule_VerticalBlackBetweenRegionsTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsDirectRule/VerticalBlackBetweenRegions", nurikabe);
Expand Down Expand Up @@ -151,4 +163,28 @@ public void BlackBetweenRegionsDirectRule_VerticalBlackBetweenRegionsTest() thro
}
}
}

/**
* Tests the Black Between Regions direct rule for a false application of the rule, where a black tile is enclosed by one region
*/
@Test
public void BlackBetweenRegionsDirectRule_FalseBlackBetweenRegionsTest() throws InvalidFileFormatException{
TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsDirectRule/FalseBlackBetweenRegions",nurikabe);
TreeNode rootNode = nurikabe.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

NurikabeBoard board = (NurikabeBoard) transition.getBoard();
NurikabeCell cell = board.getCell(1,1);
cell.setData(NurikabeType.BLACK.toValue());
board.addModifiedData(cell);

Assert.assertNotNull(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)));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public static void setUp() {
nurikabe = new Nurikabe();
}

/**
* Tests the Black BottleNeck direct rule for a bottleneck in the center of the board
*/
@Test
public void BlackBottleNeckDirectRule_TwoSurroundBlackTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBottleNeckDirectRule/SimpleBlackBottleNeck", nurikabe);
Expand Down Expand Up @@ -54,4 +57,64 @@ public void BlackBottleNeckDirectRule_TwoSurroundBlackTest() throws InvalidFileF
}
}
}


/**
* Tests the Black BottleNeck direct rule for a bottleneck in the corner of the board
*/
@Test
public void BlackBottleNeckDirectRule_CornerBottleneck() throws InvalidFileFormatException{
TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBottleNeckDirectRule/CornerBottleNeck", nurikabe);
TreeNode rootNode = nurikabe.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

NurikabeBoard board = (NurikabeBoard)transition.getBoard();
NurikabeCell cell = board.getCell(0,1);
cell.setData(NurikabeType.BLACK.toValue());

board.addModifiedData(cell);

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(cell.getLocation())){
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
else {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
}
}
}


/**
* Tests the Black BottleNeck direct rule for a false bottleneck
*/
@Test
public void BlackBottleNeckDirectRule_FalseBottleneck() throws InvalidFileFormatException{
TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBottleNeckDirectRule/FalseBottleNeck", nurikabe);
TreeNode rootNode = nurikabe.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

NurikabeBoard board = (NurikabeBoard)transition.getBoard();
NurikabeCell cell = board.getCell(0,1);
cell.setData(NurikabeType.BLACK.toValue());

board.addModifiedData(cell);

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


50 changes: 37 additions & 13 deletions src/test/java/puzzles/nurikabe/rules/BlackOrWhiteCaseRuleTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package puzzles.nurikabe.rules;

import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
import edu.rpi.legup.puzzle.nurikabe.rules.BlackOrWhiteCaseRule;
import legup.MockGameBoardFacade;
import legup.TestUtilities;
import edu.rpi.legup.model.tree.TreeNode;
Expand All @@ -12,11 +16,13 @@
import edu.rpi.legup.puzzle.nurikabe.rules.TooFewSpacesContradictionRule;
import edu.rpi.legup.save.InvalidFileFormatException;

import java.util.ArrayList;

import java.awt.*;

public class BlackOrWhiteCaseRuleTest {

private static final TooFewSpacesContradictionRule RULE = new TooFewSpacesContradictionRule();
private static final BlackOrWhiteCaseRule RULE = new BlackOrWhiteCaseRule();
private static Nurikabe nurikabe;

@BeforeClass
Expand All @@ -25,27 +31,45 @@ public static void setUp() {
nurikabe = new Nurikabe();
}

/**
* Tests the Black Or White case rule by ensuring that it results in two children, that contain a modified cell that is either black or white
*/
@Test
public void TooFewSpacesContradictionRule_TwoSurroundBlackTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/TooFewSpacesContradictionRule/TwoSurroundBlack", nurikabe);
TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackOrWhiteCaseRule/SimpleBlackOrWhite", nurikabe);
TreeNode rootNode = nurikabe.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

Assert.assertNull(RULE.checkContradiction((NurikabeBoard) transition.getBoard()));

NurikabeBoard board = (NurikabeBoard) transition.getBoard();
Point location = new Point(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(location)) {
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
else {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
NurikabeCell cell = board.getCell(0,0);
ArrayList<Board> cases = RULE.getCases(board,cell);

Assert.assertEquals(2,cases.size());

NurikabeBoard caseBoard = (NurikabeBoard) cases.get(0);
NurikabeBoard caseBoard2 = (NurikabeBoard) cases.get(1);

NurikabeType board1Type = caseBoard.getCell(0,0).getType();
NurikabeType board2Type = caseBoard2.getCell(0,0).getType();

Assert.assertTrue((board1Type.equals(NurikabeType.BLACK) || board1Type.equals(NurikabeType.WHITE)) &&
(board2Type.equals(NurikabeType.BLACK) || board2Type.equals(NurikabeType.WHITE)));
Assert.assertFalse(board1Type.equals(board2Type));

Assert.assertEquals(caseBoard.getHeight(),caseBoard2.getHeight(), board.getHeight());
Assert.assertEquals(caseBoard.getWidth(),caseBoard2.getWidth(), board.getWidth());

for(int i=0; i<caseBoard.getHeight(); i++){
for(int k=0; k<caseBoard.getWidth(); k++){
Point point = new Point(k,i);
if(point.equals(caseBoard.getCell(k,i).getLocation())){
continue;
}
Assert.assertTrue(caseBoard.getCell(k,i).equals(caseBoard2.getCell(k,i)));
}
}


}
}
Loading

0 comments on commit ec7b4a7

Please sign in to comment.