Skip to content

Commit

Permalink
Merge pull request #779 from B-McCusker56/binary
Browse files Browse the repository at this point in the history
Binary
  • Loading branch information
B-McCusker56 authored Mar 28, 2024
2 parents fd0ea65 + 9c0d0b0 commit a38365e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {
ArrayList<BinaryType> 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<BinaryType> currRow = binaryBoard.getRowTypes(i);
Expand All @@ -41,7 +41,6 @@ public String checkContradictionAt(Board board, PuzzleElement puzzleElement) {

ArrayList<BinaryType> col = binaryBoard.getColTypes(cell.getLocation().x);

System.out.println("column: " + col);
for (int i = 0; i < size; i++) {
if (i > cell.getLocation().x) {
ArrayList<BinaryType> currCol = binaryBoard.getColTypes(i);
Expand All @@ -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<BinaryCell> 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<BinaryCell> 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<BinaryCell> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,18 @@ 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";
}

}
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit a38365e

Please sign in to comment.