diff --git a/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 000000000..ea640e792 --- /dev/null +++ b/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,13 @@ +arguments=--init-script /home/gamma/.cache/jdtls/config/org.eclipse.osgi/55/0/.cp/gradle/init/init.gradle +auto.sync=false +build.scans.enabled=false +connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) +connection.project.dir= +eclipse.preferences.version=1 +gradle.user.home= +java.home=/usr/lib/jvm/java-21-openjdk-amd64 +jvm.arguments= +offline.mode=false +override.workspace.settings=true +show.console.view=true +show.executions.view=true diff --git a/src/main/java/edu/rpi/legup/puzzle/binary/BinaryBoard.java b/src/main/java/edu/rpi/legup/puzzle/binary/BinaryBoard.java index 6bc2b98f1..543736f42 100644 --- a/src/main/java/edu/rpi/legup/puzzle/binary/BinaryBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/binary/BinaryBoard.java @@ -41,15 +41,16 @@ public Set getRowCells(int rowNum) { return row; } - public ArrayList getRowTypes(int rowNum) { - ArrayList row = new ArrayList(); + public ArrayList listRowCells(int rowNum) { + ArrayList row = new ArrayList<>(); for (int i = 0; i < size; i++) { BinaryCell cell = getCell(i, rowNum); - row.add(cell.getType()); + row.add(cell); } return row; } + public ArrayList getColTypes(int colNum) { ArrayList col = new ArrayList(); for (int i = 0; i < size; i++) { @@ -59,6 +60,15 @@ public ArrayList getColTypes(int colNum) { return col; } + public ArrayList getRowTypes(int rowNum) { + ArrayList row = new ArrayList(); + for (int i = 0; i < size; i++) { + BinaryCell cell = getCell(i, rowNum); + row.add(cell.getType()); + } + return row; + } + public Set getColCells(int colNum) { Set col = new HashSet<>(); for (int i = 0; i < size; i++) { @@ -67,6 +77,14 @@ public Set getColCells(int colNum) { return col; } + public ArrayList listColCells(int colNum) { + ArrayList col = new ArrayList<>(); + for (int i = 0; i < size; i++) { + col.add(getCell(colNum, i)); + } + return col; + } + @Override public BinaryBoard copy() { System.out.println("BinaryBoard copy()"); 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 75bd4633d..f938e3119 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 @@ -7,10 +7,12 @@ import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.binary.BinaryBoard; import edu.rpi.legup.puzzle.binary.BinaryCell; +import edu.rpi.legup.puzzle.binary.BinaryType; import java.util.LinkedList; import java.util.Queue; import java.lang.Math.*; +import java.lang.reflect.Array; import java.util.ArrayList; public class EliminateTheImpossibleDirectRule extends DirectRule { @@ -26,26 +28,30 @@ public EliminateTheImpossibleDirectRule() { // Function to generate all binary strings void generatePossibilitites(int spots, ArrayList possibilities, int zeroCount, int oneCount) - // This function generates all the possible combinations of 0s and 1s for a certain size, it does this - // by basically just counting from 0 to the number - 1, so if you want all the possible combinations for 3 - // spots, you can just count in binary from 0 to 7 (taking 3 spots, so from 000 to 111). To be practical, - // the function does not return an array with all the possibilities as an array, but populates the + // This function generates all the possible combinations of 0s and 1s for a + // certain size, it does this + // by basically just counting from 0 to the number - 1, so if you want all the + // possible combinations for 3 + // spots, you can just count in binary from 0 to 7 (taking 3 spots, so from 000 + // to 111). To be practical, + // the function does not return an array with all the possibilities as an array, + // but populates the // arraylist you pass in (possibilities) { - if(zeroCount + oneCount != spots){ + if (zeroCount + oneCount != spots) { System.out.println("INVALID INPUT"); return; } - if(zeroCount == spots){ + if (zeroCount == spots) { String zero = ""; - for(int i = 0; i < spots; i++){ + for (int i = 0; i < spots; i++) { zero = zero + "0"; } possibilities.add(zero); } - int count = (int)Math.pow(2,spots) -1; + int count = (int) Math.pow(2, spots) - 1; int finalLen = spots; Queue q = new LinkedList(); q.add("1"); @@ -57,54 +63,89 @@ void generatePossibilitites(int spots, ArrayList possibilities, int zero String newS1 = s1; int curLen = newS1.length(); int runFor = spots - curLen; - if(curLen < finalLen){ - for(int i = 0; i < runFor; i++){ + if (curLen < finalLen) { + for (int i = 0; i < runFor; i++) { newS1 = "0" + newS1; } } int curZeros = 0; int curOnes = 0; - for(int i = 0; i < spots; i++){ - if(newS1.charAt(i) == '0'){ + for (int i = 0; i < spots; i++) { + if (newS1.charAt(i) == '0') { curZeros++; } - if(newS1.charAt(i) == '1'){ + if (newS1.charAt(i) == '1') { curOnes++; } } - if(zeroCount == curZeros && oneCount == curOnes){ + if (zeroCount == curZeros && oneCount == curOnes) { possibilities.add(newS1); } String s2 = s1; q.add(s1 + "0"); q.add(s2 + "1"); - } + } } @Override public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElement) { - // This function should first check if there are three open spaces, if so, continue, else figure out - // how many spots are open, all the possible binary combinations that could be put there, and by - // analyzing the common factors, logically determine which number has a set spot, meaning that we know + // This function should first check if there are three open spaces, if so, + // continue, else figure out + // how many spots are open, all the possible binary combinations that could be + // put there, and by + // analyzing the common factors, logically determine which number has a set + // spot, meaning that we know // that a certain spot must be a zero or a one BinaryBoard origBoard = (BinaryBoard) transition.getParents().get(0).getBoard(); BinaryCell binaryCell = (BinaryCell) puzzleElement; - ArrayList result = new ArrayList(); + ArrayList rowResult = new ArrayList(); int zerosLeft = 3; int onesLeft = 1; - generatePossibilitites(4, result, zerosLeft, onesLeft); - System.out.println("printing result"); - for(String s : result){ - System.out.println(s); + // To call generatePossibilitites(), you must call it and pass in the amount of + // spots left, + // an ArrayList that will be populated with the possible results (in String + // form), the amount of zeros left and ones left + generatePossibilitites(4, rowResult, zerosLeft, onesLeft); + + //Getting the row and col where the user clicked + ArrayList row = origBoard.listRowCells(binaryCell.getLocation().y); + + for(BinaryCell t : row){ + System.out.println(t.getType()); + // if(t.equals(BinaryType.UNKNOWN)); } + // ArrayList> rowCopies = new ArrayList<>(); + // for(int i = 0; i < rowResult.size(); i++){ + // rowCopies.add( new ArrayList(row) ); + // } + + // for(ArrayList curRow : rowCopies){ + // int idx = 0; + // for(int i = 0; i < curRow.size(); i++ ){ + // if(curRow.get(i).getType().equals(BinaryType.UNKNOWN)){ + // curRow.get(i).setType(); + // } + // + // } + // + // } + + + + // System.out.println("printing result"); + // for (String s : rowResult) { + // System.out.println(s); + // } + return "Grouping of Three Ones or Zeros not found TEST"; + } @Override