diff --git a/src/main/java/edu/rpi/legup/puzzle/binary/rules/CompleteRowColumnDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/binary/rules/CompleteRowColumnDirectRule.java index 147d1c2a1..6b4399903 100644 --- a/src/main/java/edu/rpi/legup/puzzle/binary/rules/CompleteRowColumnDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/binary/rules/CompleteRowColumnDirectRule.java @@ -34,42 +34,21 @@ public CompleteRowColumnDirectRule() { */ @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - BinaryBoard initialBoard = (BinaryBoard) transition.getParents().get(0).getBoard(); - BinaryBoard finalBoard = (BinaryBoard) transition.getBoard(); - int elementIndex = puzzleElement.getIndex(); - int boardDim = initialBoard.getWidth(); - int elementRow = elementIndex / boardDim; - int elementCol = elementIndex % boardDim; - - int numColZeros = 0; - int numColOnes = 0; - for (int i = 0; i < boardDim; i++) { - BinaryCell cell = initialBoard.getCell(i, elementCol); - if(cell.getData() == 1){ - numColOnes ++; - } - else if(cell.getData() == 0) { - numColZeros ++; - } + BinaryBoard board = (BinaryBoard) transition.getBoard(); + BinaryBoard origBoard = (BinaryBoard) transition.getParents().get(0).getBoard(); + ContradictionRule contraRule = new UnbalancedRowOrColumnContradictionRule(); + + BinaryCell cell = (BinaryCell) board.getPuzzleElement(puzzleElement); + if (cell.getType() == BinaryType.UNKNOWN) { + return "Only ONE or ZERO cells are allowed for this rule!"; } - int numRowZeros = 0; - int numRowOnes = 0; - for (int i = 0; i < boardDim; i++) { - BinaryCell cell = initialBoard.getCell(elementRow, i); - if(cell.getData() == 1) { - numRowOnes ++; - } - else if(cell.getData() == 0) { - numRowZeros ++; + if(cell.getType() != BinaryType.UNKNOWN){ + if (contraRule.checkContradictionAt(origBoard, puzzleElement) != null) { + return "Balanced row or column found"; } - } - if (numColOnes + numColZeros != boardDim) { - return super.getInvalidUseOfRuleMessage() + ": The column for the specificed element is not complete"; - } - if (numRowOnes + numRowZeros != boardDim) { - return super.getInvalidUseOfRuleMessage() + ": The row for the specified element is not complete"; + } return null; } diff --git a/src/main/java/edu/rpi/legup/puzzle/binary/rules/OneTileGapDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/binary/rules/OneTileGapDirectRule.java index 469d898ab..26f1f1be0 100644 --- a/src/main/java/edu/rpi/legup/puzzle/binary/rules/OneTileGapDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/binary/rules/OneTileGapDirectRule.java @@ -10,6 +10,8 @@ import edu.rpi.legup.puzzle.binary.BinaryCell; import edu.rpi.legup.puzzle.binary.BinaryType; +import java.util.Set; + public class OneTileGapDirectRule extends DirectRule { private final String INVALID_USE_MESSAGE = "Number at cell is incorrect"; public OneTileGapDirectRule() { @@ -21,22 +23,35 @@ public OneTileGapDirectRule() { @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - BinaryBoard board = (BinaryBoard) transition.getBoard(); + BinaryBoard destBoard = (BinaryBoard) transition.getBoard(); BinaryBoard origBoard = (BinaryBoard) transition.getParents().get(0).getBoard(); ContradictionRule contraRule = new ThreeAdjacentContradictionRule(); + Set changedCells = destBoard.getModifiedData(); +// for (PuzzleElement p : changedCells) { +// BinaryCell c = (BinaryCell) destBoard.getPuzzleElement(p); +// if (c.getData() == 0) { +// c.setData(1); +// int cX = c.getLocation().x; +// int cY = c.getLocation().y; +// if ((destBoard.getCell(cX-1, cY).getType() == BinaryType.ONE && destBoard.getCell(cX+1, cY).getType() == BinaryType.ONE) || +// (destBoard.getCell(cX, cY-1).getType() == BinaryType.ONE && destBoard.getCell(cX, cY+1).getType() == BinaryType.ONE)) { +// return "" +// } +// +// } +// else if (c.getData() == 1) +// c.setData(0); +// else if (c.getData() == 2) +// return "Only ONE or ZERO cells are allowed for this rule!"; +// if (c.getLocation().x-1) +// } +// +// if (c.getType() ) +// if (contraRule.checkContradictionAt(destBoard, puzzleElement) != null) { +// return "Grouping of Three Ones or Zeros found"; +// } - BinaryCell cell = (BinaryCell) board.getPuzzleElement(puzzleElement); - if (cell.getType() == BinaryType.UNKNOWN) { - return "Only ONE or ZERO cells are allowed for this rule!"; - } - - if(cell.getType() != BinaryType.UNKNOWN){ - if (contraRule.checkContradictionAt(origBoard, puzzleElement) == null) { - return "Grouping of Three Ones or Zeros found"; - } - - } return null; } diff --git a/src/main/java/edu/rpi/legup/puzzle/binary/rules/SurroundPairDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/binary/rules/SurroundPairDirectRule.java index 732885a2a..d6747b9fa 100644 --- a/src/main/java/edu/rpi/legup/puzzle/binary/rules/SurroundPairDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/binary/rules/SurroundPairDirectRule.java @@ -10,6 +10,9 @@ import edu.rpi.legup.puzzle.binary.BinaryCell; import edu.rpi.legup.puzzle.binary.BinaryType; +import java.util.ArrayList; +import java.util.Set; + public class SurroundPairDirectRule extends DirectRule { public SurroundPairDirectRule() { @@ -21,22 +24,24 @@ public SurroundPairDirectRule() { @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - BinaryBoard board = (BinaryBoard) transition.getBoard(); + BinaryBoard destBoard = (BinaryBoard) transition.getBoard(); BinaryBoard origBoard = (BinaryBoard) transition.getParents().get(0).getBoard(); ContradictionRule contraRule = new ThreeAdjacentContradictionRule(); - - BinaryCell cell = (BinaryCell) board.getPuzzleElement(puzzleElement); - if (cell.getType() == BinaryType.UNKNOWN) { - return "Only ONE or ZERO cells are allowed for this rule!"; - } - - if(cell.getType() != BinaryType.UNKNOWN){ - if (contraRule.checkContradictionAt(origBoard, puzzleElement) == null) { - return "Grouping of Three Ones or Zeros found"; - } - + Set changedCells = destBoard.getModifiedData(); +// for (PuzzleElement p : changedCells) { +// BinaryCell c = (BinaryCell) destBoard.getPuzzleElement(p); +// if (c.getData() == 0) +// c.setData(1); +// else if (c.getData() == 1) +// c.setData(0); +// else if (c.getData() == 2) +// return "Only ONE or ZERO cells are allowed for this rule!"; +// } + if (contraRule.checkContradictionAt(destBoard, puzzleElement) == null) { + return "Grouping of Three Ones or Zeros found"; } + return null; } diff --git a/src/main/java/edu/rpi/legup/puzzle/binary/rules/ThreeAdjacentContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/binary/rules/ThreeAdjacentContradictionRule.java index 69be423d4..8c39900e1 100644 --- a/src/main/java/edu/rpi/legup/puzzle/binary/rules/ThreeAdjacentContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/binary/rules/ThreeAdjacentContradictionRule.java @@ -29,16 +29,22 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { int cellY = cell.getLocation().y; if(cell.getType() == BinaryType.ONE || cell.getType() == BinaryType.ZERO) { - for (int x = cell.getLocation().x - 2; x >= 0 && x < cell.getLocation().x && x < width - 2; x++){ + for (int x = cell.getLocation().x - 2; x < cell.getLocation().x && x < width - 2; x++){ + if (x < 0) + continue; if(binaryBoard.getCell(x, cellY).getType() == binaryBoard.getCell(x + 1, cellY).getType() && binaryBoard.getCell(x + 1, cellY).getType() == binaryBoard.getCell(x + 2, cellY).getType()) { + System.out.println("Contradiction Found because of " + binaryBoard.getCell(x, cellY).getLocation().x + " " + binaryBoard.getCell(x, cellY).getLocation().y + " " + + binaryBoard.getCell(x+1, cellY).getLocation().x + " " + binaryBoard.getCell(x+1, cellY).getLocation().y + " " + + binaryBoard.getCell(x+2, cellY).getLocation().x + " " + binaryBoard.getCell(x+2, cellY).getLocation().y); return null; } } - for (int y = cell.getLocation().y - 2; y >= 0 && y < cell.getLocation().y && y < height - 2; y++){ + for (int y = cell.getLocation().y - 2; y < cell.getLocation().y && y < height - 2; y++){ + if (y < 0) + continue; if(binaryBoard.getCell(cellX, y).getType() == binaryBoard.getCell(cellX, y + 1).getType() && binaryBoard.getCell(cellX, y + 1).getType() == binaryBoard.getCell(cellX, y + 2).getType()) { + System.out.println("Contradiction Found because of " + binaryBoard.getCell(cellX, y+2).getLocation().x + " " + binaryBoard.getCell(cellX, y).getLocation().y + " " + + binaryBoard.getCell(cellX, y+1).getLocation().x + " " + binaryBoard.getCell(cellX, y+1).getLocation().y + " " + + binaryBoard.getCell(cellX, y+2).getLocation().x + " " + binaryBoard.getCell(cellX, y+2).getLocation().y); return null; } }