Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skyscrapers contradiction tests #628

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions puzzles files/skyscrapers/1646651

This file was deleted.

47 changes: 0 additions & 47 deletions puzzles files/skyscrapers/easy1.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public PuzzleElement importCell(Node node, Board board) throws InvalidFileFormat
if (x >= width || y >= height) {
throw new InvalidFileFormatException("TreeTent Factory: cell location out of bounds");
}
if (value < 0 || value > 3) {
if (value < 0) {
throw new InvalidFileFormatException("TreeTent Factory: cell unknown value");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public DuplicateNumberContradictionRule() {
*/
@Override
public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
//TODO:? Refactor to count each row/col once rather than per cell (override checkContradiction)
SkyscrapersCell cell = (SkyscrapersCell) puzzleElement;
SkyscrapersBoard skyscrapersboard = (SkyscrapersBoard) board;
Point loc = cell.getLocation();
Expand All @@ -40,8 +39,8 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
for (int i = 0; i < skyscrapersboard.getWidth(); i++) {
SkyscrapersCell c = skyscrapersboard.getCell(i, loc.y);
if (i != loc.x && cell.getType() == SkyscrapersType.Number && c.getType() == SkyscrapersType.Number && c.getData() == cell.getData()) {
System.out.print(c.getData());
System.out.println(cell.getData());
//System.out.print(c.getData());
//System.out.println(cell.getData());
return null;
}
}
Expand All @@ -50,8 +49,8 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
for (int i = 0; i < skyscrapersboard.getHeight(); i++) {
SkyscrapersCell c = skyscrapersboard.getCell(loc.x, i);
if (i != loc.y && cell.getType() == SkyscrapersType.Number && c.getType() == SkyscrapersType.Number && c.getData() == cell.getData()) {
System.out.print(c.getData());
System.out.println(cell.getData());
//System.out.print(c.getData());
//System.out.println(cell.getData());
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
Collections.reverse(row);
for (SkyscrapersCell c : row) {
if (c.getData() > max) {
System.out.print(c.getData());
//System.out.print(c.getData());
//System.out.println(cell.getData());
max = c.getData();
count++;
Expand All @@ -83,7 +83,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
max = 0;
count = 0;
for (SkyscrapersCell c : col) {
System.out.println(c.getData());
//System.out.println(c.getData());
if (c.getData() > max) {

//System.out.println(cell.getData());
Expand All @@ -100,7 +100,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
count = 0;
Collections.reverse(col);
for (SkyscrapersCell c : col) {
System.out.println(c.getData());
//System.out.println(c.getData());
if (c.getData() > max) {

//System.out.println(cell.getData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
//from west border
for (SkyscrapersCell c : row) {
if (c.getData() > max) {
System.out.print(c.getData());
//System.out.print(c.getData());
//System.out.println(cell.getData());
max = c.getData();
count++;
Expand All @@ -65,7 +65,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
Collections.reverse(row);
for (SkyscrapersCell c : row) {
if (c.getData() > max) {
System.out.print(c.getData());
//System.out.print(c.getData());
//System.out.println(cell.getData());
max = c.getData();
count++;
Expand All @@ -83,7 +83,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
max = 0;
count = 0;
for (SkyscrapersCell c : col) {
System.out.println(c.getData());
//System.out.println(c.getData());
if (c.getData() > max) {

//System.out.println(cell.getData());
Expand All @@ -100,7 +100,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
count = 0;
Collections.reverse(col);
for (SkyscrapersCell c : col) {
System.out.println(c.getData());
//System.out.println(c.getData());
if (c.getData() > max) {

//System.out.println(cell.getData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class LastSingularCellDirectRule extends DirectRule {

public LastSingularCellDirectRule() {
super("SKYS-BASC-0002", "Last Non-Duplicate Cell",
super("SKYS-BASC-0002", "Last Cell for Number",
"There is only one cell on this row/col for this number that does not create a duplicate contradiction",
"edu/rpi/legup/images/skyscrapers/rules/LastCell.png");
}
Expand Down Expand Up @@ -49,8 +49,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
initialBoard.setDupeFlag(dupeTemp);
initialBoard.setViewFlag(viewTemp);

System.out.println(XCandidates.size());
System.out.println(YCandidates.size());
//System.out.println(XCandidates.size());
//System.out.println(YCandidates.size());

//return null if either pass, both messages otherwise
String xCheck = candidateCheck(XCandidates, puzzleElement, finalCell);
Expand Down Expand Up @@ -96,9 +96,8 @@ private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) {
public Board getDefaultBoard(TreeNode node) {
SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard();
SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy();
System.out.println(lightUpBoard.getPuzzleElements().size());
//System.out.println(lightUpBoard.getPuzzleElements().size());
for (PuzzleElement element : lightUpBoard.getPuzzleElements()) {
System.out.println("123");
SkyscrapersCell cell = (SkyscrapersCell) element;
if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) {
//cell.setData(SkyscrapersType.BULB.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class LastSingularNumberDirectRule extends DirectRule {

public LastSingularNumberDirectRule() {
super("SKYS-BASC-0003", "Last Non-Duplicate Number",
super("SKYS-BASC-0003", "Last Number for Cell",
"There is only one number for this cell that does not create a duplicate contradiction",
"edu/rpi/legup/images/skyscrapers/rules/LastNumber.png");
}
Expand Down Expand Up @@ -79,9 +79,8 @@ private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) {
public Board getDefaultBoard(TreeNode node) {
SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard();
SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy();
System.out.println(lightUpBoard.getPuzzleElements().size());
//System.out.println(lightUpBoard.getPuzzleElements().size());
for (PuzzleElement element : lightUpBoard.getPuzzleElements()) {
System.out.println("123");
SkyscrapersCell cell = (SkyscrapersCell) element;
if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) {
//cell.setData(SkyscrapersType.BULB.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem
initialBoard.setDupeFlag(dupeTemp);
initialBoard.setViewFlag(viewTemp);

System.out.println(XCandidates.size());
System.out.println(YCandidates.size());
//System.out.println(XCandidates.size());
//System.out.println(YCandidates.size());

//return null if either pass, both messages otherwise
String xCheck = candidateCheck(XCandidates, puzzleElement, finalCell);
Expand Down Expand Up @@ -97,16 +97,15 @@ private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) {
public Board getDefaultBoard(TreeNode node) {
SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard();
SkyscrapersBoard modBoard = (SkyscrapersBoard) node.getBoard().copy();
System.out.println(modBoard.getPuzzleElements().size());
//System.out.println(modBoard.getPuzzleElements().size());
for (PuzzleElement element : modBoard.getPuzzleElements()) {
System.out.println("123");
SkyscrapersCell cell = (SkyscrapersCell) element;
if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) {
//cell.setData(SkyscrapersType.BULB.value);
modBoard.addModifiedData(cell);
}
}
System.out.println(modBoard.getModifiedData().isEmpty());
//System.out.println(modBoard.getModifiedData().isEmpty());
if (modBoard.getModifiedData().isEmpty()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) {
public Board getDefaultBoard(TreeNode node) {
SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard();
SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy();
System.out.println(lightUpBoard.getPuzzleElements().size());
//System.out.println(lightUpBoard.getPuzzleElements().size());
for (PuzzleElement element : lightUpBoard.getPuzzleElements()) {
System.out.println("123");
SkyscrapersCell cell = (SkyscrapersCell) element;
if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) {
//cell.setData(SkyscrapersType.BULB.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ private boolean isForced(SkyscrapersBoard board, SkyscrapersCell cell) {
public Board getDefaultBoard(TreeNode node) {
SkyscrapersBoard initialBoard = (SkyscrapersBoard) node.getBoard();
SkyscrapersBoard lightUpBoard = (SkyscrapersBoard) node.getBoard().copy();
System.out.println(lightUpBoard.getPuzzleElements().size());
//System.out.println(lightUpBoard.getPuzzleElements().size());
for (PuzzleElement element : lightUpBoard.getPuzzleElements()) {
System.out.println("123");
SkyscrapersCell cell = (SkyscrapersCell) element;
if (cell.getType() == SkyscrapersType.UNKNOWN && isForced(initialBoard, cell)) {
//cell.setData(SkyscrapersType.BULB.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public ArrayList<Board> getCases(Board board, PuzzleElement puzzleElement) {
public String checkRuleRaw(TreeTransition transition) {
List<TreeTransition> childTransitions = transition.getParents().get(0).getChildren();
if (childTransitions.size() == 0) {
//System.out.println("0");
return "This case rule must have at least one child.";
}
else {
Expand All @@ -104,16 +103,13 @@ public String checkRuleRaw(TreeTransition transition) {
for (int i = 0; i < childTransitions.size(); i++) {
TreeTransition case2 = childTransitions.get(i);
if (case2.getBoard().getModifiedData().size() != 1) {
//System.out.println("1");
return super.getInvalidUseOfRuleMessage() + ": This case rule must have 1 modified cell for each case.";
}
SkyscrapersCell mod2 = (SkyscrapersCell) case2.getBoard().getModifiedData().iterator().next();
if (!mod1.getLocation().equals(mod2.getLocation())) {
//System.out.println("2");
return super.getInvalidUseOfRuleMessage() + ": This case rule must modify the same cell for each case.";
}
if (!(mod2.getType() == SkyscrapersType.Number)) {
//System.out.println("3");
return super.getInvalidUseOfRuleMessage() + ": This case rule must assign a number.";
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/legup/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import puzzles.battleship.rules.*;
import puzzles.lightup.rules.*;
import puzzles.nurikabe.rules.*;
import puzzles.skyscrapers.rules.*;
import puzzles.treetent.rules.*;

/**
Expand Down Expand Up @@ -94,6 +95,21 @@ public static void main(String[] args) {
printTestResults(result34);
Result result35 = JUnitCore.runClasses(TreeForTentDirectRuleTest.class);
printTestResults(result35);

// Skyscrapers Tests
Result result36 = JUnitCore.runClasses(DuplicateNumberContradictionTest.class);
printTestResults(result36);
Result result37 = JUnitCore.runClasses(ExceedingVisibilityContradictionTest.class);
printTestResults(result37);
Result result38 = JUnitCore.runClasses(InsufficientVisibilityContradictionTest.class);
printTestResults(result38);
Result result39 = JUnitCore.runClasses(PreemptiveVisibilityContradictionTest.class);
printTestResults(result39);
Result result40 = JUnitCore.runClasses(UnresolvedCellContradictionTest.class);
printTestResults(result40);
Result result41 = JUnitCore.runClasses(UnresolvedNumberContradictionTest.class);
printTestResults(result41);

}

private static void printTestResults(Result result) {
Expand Down
Loading
Loading