diff --git a/src/main/java/edu/rpi/legup/puzzle/binary/rules/DuplicateRowsOrColumnsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/binary/rules/DuplicateRowsOrColumnsContradictionRule.java index 14960fd5a..f65ccc58c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/binary/rules/DuplicateRowsOrColumnsContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/binary/rules/DuplicateRowsOrColumnsContradictionRule.java @@ -29,7 +29,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { ArrayList row = binaryBoard.getRowTypes(cell.getLocation().y); int size = row.size(); - System.out.println("Row: " + row); + for (int i = 0; i < size; i++) { if (i > cell.getLocation().y) { ArrayList currRow = binaryBoard.getRowTypes(i); @@ -41,7 +41,6 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { ArrayList col = binaryBoard.getColTypes(cell.getLocation().x); - System.out.println("column: " + col); for (int i = 0; i < size; i++) { if (i > cell.getLocation().x) { ArrayList currCol = binaryBoard.getColTypes(i); @@ -51,55 +50,6 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { } } - -// BinaryCell[] rowArray = row.toArray(new BinaryCell[0]); -// -// boolean rowValid = false; -// int size = row.size(); -// int y = cell.getLocation().y; -// for (int i = 0; i < size; i++) { -// if (i != y) { -// Set currRow = binaryBoard.getRow(i); -// BinaryCell[] currRowArray = currRow.toArray(new BinaryCell[0]); -// for (int j = 0; j < size; j++) { -// BinaryCell rowElement = rowArray[j]; -// BinaryCell currRowElement = currRowArray[j]; -// System.out.println("Row: " + i + " Org x: " + rowElement.getLocation().x + " Curr x: " + currRowElement.getLocation().x); -//// if (rowElement.getType() != currRowElement.getType()) { -//// rowValid = true; -//// break; -//// } -// } -//// if (!rowValid) -//// return null; -// } -// } -// return null; -// Set col = binaryBoard.getCol(cell.getLocation().x); -// BinaryCell[] colArray = col.toArray(new BinaryCell[0]); -// size = col.size(); -// int x = cell.getLocation().x; -// for (int i = 0; i < size; i++) { -// if (colValid) { -// break; -// } -// if (i != x) { -// Set currCol = binaryBoard.getCol(i); -// BinaryCell[] currColArray = currCol.toArray(new BinaryCell[0]); -// for (int j = 0; j < size; j++) { -// BinaryCell colElement = colArray[j]; -// BinaryCell currColElement = currColArray[j]; -// if (colElement.getType() != currColElement.getType()) { -// colValid = true; -// } -// } -// } -// } -// if (!colValid) { -// return null; -// } - - //System.out.println(cell.getLocation().x + " " + cell.getLocation().y); return super.getNoContradictionMessage() + ": " + this.NO_CONTRADICTION_MESSAGE; } } 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 daa49c46e..469d898ab 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 @@ -27,11 +27,11 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem BinaryCell cell = (BinaryCell) board.getPuzzleElement(puzzleElement); - if(cell.getType() != BinaryType.UNKNOWN){ - if (cell.getType() == BinaryType.UNKNOWN) { - return "Only ONE or ZERO cells are allowed for this rule!"; - } + 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"; } @@ -39,16 +39,6 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem } return null; } -/* - if ((upOne.getType() == BinaryType.ONE && downOne.getType() == BinaryType.ONE && cell.getType() != BinaryType.ONE) || - (upOne.getType() == BinaryType.ZERO && downOne.getType() == BinaryType.ZERO && cell.getType() != BinaryType.ZERO) || - (leftOne.getType() == BinaryType.ONE && rightOne.getType() == BinaryType.ONE && cell.getType() != BinaryType.ONE) || - (leftOne.getType() == BinaryType.ZERO && downOne.getType() == BinaryType.ZERO && cell.getType() != BinaryType.ZERO)) { - return null; - } - return super.getInvalidUseOfRuleMessage() + ": " + this.INVALID_USE_MESSAGE; - } -*/ @Override public Board getDefaultBoard(TreeNode node) { 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 5ef0566d7..732885a2a 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 @@ -26,12 +26,12 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem ContradictionRule contraRule = new ThreeAdjacentContradictionRule(); - BinaryCell cell = (BinaryCell) board.getPuzzleElement(puzzleElement); + 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 (cell.getType() == BinaryType.UNKNOWN) { - return "Only ONE or ZERO cells are allowed for this rule!"; - } - if (contraRule.checkContradictionAt(origBoard, puzzleElement) == null) { return "Grouping of Three Ones or Zeros found"; } 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 8e1fffaa9..69be423d4 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 @@ -23,29 +23,22 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) { int height = binaryBoard.getHeight(); int width = binaryBoard.getWidth(); - BinaryCell cell = (BinaryCell) binaryBoard.getPuzzleElement(puzzleElement); - int cellX = cell.getLocation().x; int cellY = cell.getLocation().y; - System.out.println("X = " + cellX + ", Y = " + cellY); 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 >= 0 && x < cell.getLocation().x && x < width - 2; x++){ 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("CUR XY fail X= " + cellX + " , " + cellY); 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 >= 0 && y < cell.getLocation().y && y < height - 2; y++){ 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("CUR XY fail Y= " + cellX + " , " + cellY); return null; } } diff --git a/src/main/java/edu/rpi/legup/puzzle/binary/rules/UnbalancedRowOrColumnContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/binary/rules/UnbalancedRowOrColumnContradictionRule.java index b58f9f02e..de18e3b5c 100644 --- a/src/main/java/edu/rpi/legup/puzzle/binary/rules/UnbalancedRowOrColumnContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/binary/rules/UnbalancedRowOrColumnContradictionRule.java @@ -39,9 +39,7 @@ else if(item.getType() == BinaryType.ONE) { rowNumOnes++; } } -// if (rowNumZeros + rowNumOnes != size) { -// return super.getInvalidUseOfRuleMessage() + ": " + this.INVALID_USE_MESSAGE; -// } + if (rowNumZeros > size/2 || rowNumOnes > size/2) { return null; } @@ -60,9 +58,7 @@ else if(item.getType() == BinaryType.ONE) { colNumOnes++; } } -// if (colNumZeros + colNumOnes != size) { -// return super.getInvalidUseOfRuleMessage() + ": " + this.INVALID_USE_MESSAGE; -// } + if (colNumZeros > size/2 || colNumOnes > size/2) { return null; }