Skip to content

Commit

Permalink
added functions to eliminate the impossible (still wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
ContemporaryNietzsche committed Jun 25, 2024
1 parent 7049e9f commit 6e5dc78
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 26 deletions.
13 changes: 13 additions & 0 deletions .settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -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
24 changes: 21 additions & 3 deletions src/main/java/edu/rpi/legup/puzzle/binary/BinaryBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ public Set<BinaryCell> getRowCells(int rowNum) {
return row;
}

public ArrayList<BinaryType> getRowTypes(int rowNum) {
ArrayList<BinaryType> row = new ArrayList<BinaryType>();
public ArrayList<BinaryCell> listRowCells(int rowNum) {
ArrayList<BinaryCell> 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<BinaryType> getColTypes(int colNum) {
ArrayList<BinaryType> col = new ArrayList<BinaryType>();
for (int i = 0; i < size; i++) {
Expand All @@ -59,6 +60,15 @@ public ArrayList<BinaryType> getColTypes(int colNum) {
return col;
}

public ArrayList<BinaryType> getRowTypes(int rowNum) {
ArrayList<BinaryType> row = new ArrayList<BinaryType>();
for (int i = 0; i < size; i++) {
BinaryCell cell = getCell(i, rowNum);
row.add(cell.getType());
}
return row;
}

public Set<BinaryCell> getColCells(int colNum) {
Set<BinaryCell> col = new HashSet<>();
for (int i = 0; i < size; i++) {
Expand All @@ -67,6 +77,14 @@ public Set<BinaryCell> getColCells(int colNum) {
return col;
}

public ArrayList<BinaryCell> listColCells(int colNum) {
ArrayList<BinaryCell> 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()");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -26,26 +28,30 @@ public EliminateTheImpossibleDirectRule() {

// Function to generate all binary strings
void generatePossibilitites(int spots, ArrayList<String> 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<String> q = new LinkedList<String>();
q.add("1");
Expand All @@ -57,54 +63,89 @@ void generatePossibilitites(int spots, ArrayList<String> 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<String> result = new ArrayList<String>();
ArrayList<String> rowResult = new ArrayList<String>();

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<BinaryCell> row = origBoard.listRowCells(binaryCell.getLocation().y);

for(BinaryCell t : row){
System.out.println(t.getType());
// if(t.equals(BinaryType.UNKNOWN));
}

// ArrayList<ArrayList<BinaryType>> rowCopies = new ArrayList<>();
// for(int i = 0; i < rowResult.size(); i++){
// rowCopies.add( new ArrayList<BinaryType>(row) );
// }

// for(ArrayList<BinaryType> 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
Expand Down

0 comments on commit 6e5dc78

Please sign in to comment.