From 3206f46310f93aa40be70e83c7ab813597afdae9 Mon Sep 17 00:00:00 2001 From: Jose Barbiere <117523329+ContemporaryNietzsche@users.noreply.github.com> Date: Tue, 18 Jun 2024 18:59:25 -0400 Subject: [PATCH 1/6] test committ --- .../rpi/legup/puzzle/binary/rules/EliminateTheImpossible.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/binary/rules/EliminateTheImpossible.java b/src/main/java/edu/rpi/legup/puzzle/binary/rules/EliminateTheImpossible.java index 311057f94..9dc1c0445 100644 --- a/src/main/java/edu/rpi/legup/puzzle/binary/rules/EliminateTheImpossible.java +++ b/src/main/java/edu/rpi/legup/puzzle/binary/rules/EliminateTheImpossible.java @@ -25,7 +25,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem BinaryBoard origBoard = (BinaryBoard) transition.getParents().get(0).getBoard(); BinaryCell binaryCell = (BinaryCell) puzzleElement; - return "Grouping of Three Ones or Zeros not found"; + return "Grouping of Three Ones or Zeros not found TEST"; } @Override From 58ff2bf500260f496fd5b06f0a3ae1bcd80fa539 Mon Sep 17 00:00:00 2001 From: Jose Barbiere <117523329+ContemporaryNietzsche@users.noreply.github.com> Date: Thu, 20 Jun 2024 15:23:25 -0400 Subject: [PATCH 2/6] t --- .../puzzle/binary/rules/EliminateTheImpossibleDirectRule.java | 2 ++ 1 file changed, 2 insertions(+) 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 f7cbbacc9..6b525312f 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 @@ -11,6 +11,8 @@ import java.util.ArrayList; +// dont mind me + public class EliminateTheImpossibleDirectRule extends DirectRule { private final String INVALID_USE_MESSAGE = "Number at cell is incorrect"; From ec8e1d3803ce3b9c06a48be36d31e305f1c4f099 Mon Sep 17 00:00:00 2001 From: ContemporaryNietzsche Date: Fri, 21 Jun 2024 11:44:30 -0400 Subject: [PATCH 3/6] commented before implementation --- .../binary/rules/EliminateTheImpossibleDirectRule.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 6b525312f..6f8ee3ea9 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 @@ -1,6 +1,5 @@ package edu.rpi.legup.puzzle.binary.rules; - import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.rules.DirectRule; @@ -11,8 +10,6 @@ import java.util.ArrayList; -// dont mind me - public class EliminateTheImpossibleDirectRule extends DirectRule { private final String INVALID_USE_MESSAGE = "Number at cell is incorrect"; @@ -58,6 +55,11 @@ public ArrayList binaryCombiniations(int numEmpty) { } @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 + // that a certain spot must be a zero or a one + BinaryBoard origBoard = (BinaryBoard) transition.getParents().get(0).getBoard(); BinaryCell binaryCell = (BinaryCell) puzzleElement; From 4db09f95c39234b52f93656a15683da8fb0859ef Mon Sep 17 00:00:00 2001 From: ContemporaryNietzsche Date: Fri, 21 Jun 2024 15:03:22 -0400 Subject: [PATCH 4/6] added generateAllBinaryStrings functions(pair programmed with Zach) --- .../EliminateTheImpossibleDirectRule.java | 64 +++++++++++-------- 1 file changed, 38 insertions(+), 26 deletions(-) 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 6f8ee3ea9..2898ed084 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 @@ -8,6 +8,9 @@ import edu.rpi.legup.puzzle.binary.BinaryBoard; import edu.rpi.legup.puzzle.binary.BinaryCell; +import java.util.LinkedList; +import java.util.Queue; +import java.lang.Math.*; import java.util.ArrayList; public class EliminateTheImpossibleDirectRule extends DirectRule { @@ -22,37 +25,39 @@ public EliminateTheImpossibleDirectRule() { } // Function to generate all binary strings - static String generateAllBinaryStrings(int n, String arr, int i) + void generateAllBinaryStrings(double x, int poss, ArrayList possibilities) { - if (i == n) - { - return arr; + int count = (int)x; + int finalLen = poss; + + Queue q = new LinkedList(); + q.add("1"); + while (count-- > 0) { + String s1 = q.peek(); + q.remove(); + + String newS1 = s1; + int curLen = newS1.length(); + + int runFor = poss - curLen; + if(curLen < finalLen){ + + + for(int i = 0; i < runFor; i++){ + newS1 = "0" + newS1; + } + + } + + System.out.println(newS1); + possibilities.add(newS1); + String s2 = s1; + q.add(s1 + "0"); + q.add(s2 + "1"); } - // First assign "0" at ith position - // and try for all other permutations - // for remaining positions - arr = arr + "0"; - generateAllBinaryStrings(n, arr, i + 1); - - // And then assign "1" at ith position - // and try for all other permutations - // for remaining positions - arr = arr + "1"; - generateAllBinaryStrings(n, arr, i + 1); - - return null; } - public ArrayList binaryCombiniations(int numEmpty) { - - ArrayList possibilities = new ArrayList<>(); - String arr = ""; - if (generateAllBinaryStrings(numEmpty, arr, 0) != null) { - possibilities.add(arr); - } - return null; - } @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 @@ -63,6 +68,13 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem BinaryBoard origBoard = (BinaryBoard) transition.getParents().get(0).getBoard(); BinaryCell binaryCell = (BinaryCell) puzzleElement; + ArrayList result = new ArrayList(); + generateAllBinaryStrings(10,4,result); + + for(String s : result){ + System.out.println(s); + } + return "Grouping of Three Ones or Zeros not found TEST"; } From c3265d3e0c49c9bc0577919cbc8d9d431479bbc2 Mon Sep 17 00:00:00 2001 From: ContemporaryNietzsche Date: Fri, 21 Jun 2024 15:20:33 -0400 Subject: [PATCH 5/6] fixed some variables (extra 0 bug found) and commented/explained some code --- .../rules/EliminateTheImpossibleDirectRule.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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 2898ed084..0b215d547 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 @@ -25,10 +25,15 @@ public EliminateTheImpossibleDirectRule() { } // Function to generate all binary strings - void generateAllBinaryStrings(double x, int poss, ArrayList possibilities) + void generateAllBinaryStrings(double countTo, int spots, ArrayList possibilities) + // 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) { - int count = (int)x; - int finalLen = poss; + int count = (int)countTo; + int finalLen = spots; Queue q = new LinkedList(); q.add("1"); @@ -39,7 +44,7 @@ void generateAllBinaryStrings(double x, int poss, ArrayList possibilitie String newS1 = s1; int curLen = newS1.length(); - int runFor = poss - curLen; + int runFor = spots - curLen; if(curLen < finalLen){ @@ -69,7 +74,7 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem BinaryCell binaryCell = (BinaryCell) puzzleElement; ArrayList result = new ArrayList(); - generateAllBinaryStrings(10,4,result); + generateAllBinaryStrings(16,4,result); for(String s : result){ System.out.println(s); From 7049e9f76c1e6f16cf716128415b2ab62859c089 Mon Sep 17 00:00:00 2001 From: ContemporaryNietzsche Date: Sat, 22 Jun 2024 03:46:21 -0400 Subject: [PATCH 6/6] finished the generate possibilites function for ETP --- .../EliminateTheImpossibleDirectRule.java | 52 ++++++++++++++----- 1 file changed, 38 insertions(+), 14 deletions(-) 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 0b215d547..75bd4633d 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 @@ -25,42 +25,62 @@ public EliminateTheImpossibleDirectRule() { } // Function to generate all binary strings - void generateAllBinaryStrings(double countTo, int spots, ArrayList possibilities) + 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 // arraylist you pass in (possibilities) { - int count = (int)countTo; + if(zeroCount + oneCount != spots){ + System.out.println("INVALID INPUT"); + return; + } + + if(zeroCount == spots){ + String zero = ""; + for(int i = 0; i < spots; i++){ + zero = zero + "0"; + } + possibilities.add(zero); + + } + int count = (int)Math.pow(2,spots) -1; int finalLen = spots; - Queue q = new LinkedList(); q.add("1"); + while (count-- > 0) { String s1 = q.peek(); q.remove(); - + String newS1 = s1; int curLen = newS1.length(); - int runFor = spots - curLen; if(curLen < finalLen){ - - for(int i = 0; i < runFor; i++){ newS1 = "0" + newS1; } - } - - System.out.println(newS1); - possibilities.add(newS1); + int curZeros = 0; + int curOnes = 0; + + for(int i = 0; i < spots; i++){ + if(newS1.charAt(i) == '0'){ + curZeros++; + } + if(newS1.charAt(i) == '1'){ + curOnes++; + } + } + + if(zeroCount == curZeros && oneCount == curOnes){ + possibilities.add(newS1); + } String s2 = s1; q.add(s1 + "0"); q.add(s2 + "1"); - } - + } } @Override @@ -74,8 +94,12 @@ public String checkRuleRawAt(TreeTransition transition, PuzzleElement puzzleElem BinaryCell binaryCell = (BinaryCell) puzzleElement; ArrayList result = new ArrayList(); - generateAllBinaryStrings(16,4,result); + int zerosLeft = 3; + int onesLeft = 1; + generatePossibilitites(4, result, zerosLeft, onesLeft); + + System.out.println("printing result"); for(String s : result){ System.out.println(s); }