From b527b9a999295c13f100f241b28fd0bb400f49a7 Mon Sep 17 00:00:00 2001 From: Zachary Bonagura Date: Tue, 9 Jul 2024 14:59:39 -0400 Subject: [PATCH] Added row functionality for eliminate the impossible --- .../EliminateTheImpossibleDirectRule.java | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/binary/rules/EliminateTheImpossibleDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/binary/rules/EliminateTheImpossibleDirectRule.java index 724edf113..cb4aab59a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/binary/rules/EliminateTheImpossibleDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/binary/rules/EliminateTheImpossibleDirectRule.java @@ -136,11 +136,12 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem System.out.println("Number of possible binary combinations: " + rowCopies.size()); + ArrayList> nonContraRows = new ArrayList<>(); int rowIdx = 0; for(ArrayList curRow : rowCopies){ int charIdx = 0; System.out.println(rowResult.get(rowIdx)); - for(int i = 0; i < curRow.size(); i++ ) { + for(int i = 0; i < curRow.size(); i++) { if (curRow.get(i).getData() == 2) { if (rowResult.get(rowIdx).charAt(charIdx) == '0') { curRow.get(i).setData(0); @@ -152,10 +153,43 @@ else if (rowResult.get(rowIdx).charAt(charIdx) == '1') { } System.out.print(curRow.get(i).getData() + " "); } + + boolean threeAdjacent = false; + int count = 1; + for(int i = 1; i < curRow.size(); i++) { + if (curRow.get(i).getData() == curRow.get(i-1).getData()) { + count++; + if (count == 3) { + threeAdjacent = true; + break; + } + } else { + count = 1; + } + } + + if (!threeAdjacent) { + nonContraRows.add(curRow); + } + rowIdx++; System.out.println(); } + System.out.println("Number of non contradiction rows: " + nonContraRows.size()); + int colNum = binaryCell.getLocation().x; + boolean invalid = false; + for(int i = 0; i < nonContraRows.size(); i++) { + if (nonContraRows.get(i).get(colNum).getData() != binaryCell.getData()) { + invalid = true; + break; + } + } + + if (!invalid) { + return null; + } + return "Grouping of Three Ones or Zeros not found"; }