This was in the game development section and I think I accidently put it there (or an admin moved it, if so then next time can you let me know, thanks). So I am posting it here (java forum community is of higer quality when giving responses) , I hope this does not break any rules.
I am going to be honest here, I am completley lost on trying to figure this out. I am trying to create a sudoku solver using sat4j for a 9x9 puzzle. I am trying to read a partially filled board and, by using a Satisability solver it finds a legal assignment to the empty squares (if possible). If such an assignment is impossible, the program says so; otherwise, it prints the original board and a solution to the terminal.
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class sudoku {
private int dim;
private int size;
private int [][] box;
// attempt at creating clauses to be stored in an array and then so sat4j can solve it
// I think that is what I should do
public sudoku (int dim){
final int n=3;
final int[][] field = new int[n*n][n*n];
for (int i=0;i<n*n;i++)
for(int j=0;j<n*n;j++)
field[i][j] = (i*n + i/n +j)%(n*n)+1;
/*
this.dim=dim;
size = dim*dim;
box = new int[size][size];
for(int i=0;i<size;i++)//row
for(int j=0;j<size;j++)//column
for(int k = 0;k < size;k++){//box
}
*/
}
public static void main(String []args) throws FileNotFoundException {
// TODO Auto-generated method stub
Scanner fileIn = null;
Scanner input = new Scanner(System.in);
File filename = new File ("solvesampleinput.txt");
try {
fileIn = new Scanner(new FileInputStream(filename));
}
catch (FileNotFoundException e)
{
System.out.println("File Not Found");
System.exit(0);
}
//
System.out.println("opened success");
System.out.println(fileIn.nextLine());
System.out.println(fileIn.nextLine());
System.out.println(fileIn.nextLine());
System.out.println(fileIn.nextLine());
System.out.println(fileIn.nextLine());
System.out.println(fileIn.nextLine());
System.out.println(fileIn.nextLine());
System.out.println(fileIn.nextLine());
}
// }
// }
// }
// public sudoku(Scanner input){
// int [][] board = new int [9][9];
//Another attempt
public static boolean solve(int[][] board) {
// Find a position that's still empty.
for (int x=0; x<9; x++) {
for (int y=0; y<9; y++) {
if (board[x][y] == 0) {
// Try each possibile value in this space
// and see if the rest of the puzzle can be filled in.
for (board[x][y]=1; board[x][y]<=9; board[x][y]++) {
}
}
}
}
return false;
}
}
I greatly appreciate any help. I dont need to understand what Sat4j is doing since I already know it is just coding this is tearing by brain apart.