Help with Soduku Solver

Discussion in 'Java' started by coder7, Dec 21, 2015.

  1. coder7

    coder7

    Joined:
    Dec 21, 2015
    Messages:
    1
    Likes Received:
    0
    I'm trying to make a Java Soduku solver. I have some errors in my code, any help would be great. I have some errors on cells, fields, array list, integer generate numbers, and a couple errors with brackets. Thanks for your time and help!

    package random;

    import java.util.Collections;

    public class Soduku {
    static short row;



    boolean check()
    {
    if(row==9)
    {

    }
    return true;

    }
    boolean check2() {
    if(cells[row[col]] != 0)
    {
    if(solve(col==8? (row+1): row, (col+1) % 9 ))
    {
    return true;
    }
    }
    else {

    Integer[] random = generateNumbers();

    for(int i=0; i<9; i++)
    {
    if(!containedInRowCol(row, col, random && !containedIn3x3Box(row, col, random)))
    {
    cells[row] [col] = random;
    fields[row] [col].setText(String.valueOf(random));

    if(solve(col==8? (row +1) : row, (col +1) % 9))
    return true;
    else
    {
    cells[row] [col] = 0;
    fields[row] [col].setText("");
    }




    }
    }

    }
    }

    return false;

    private boolean containedIn3x3Box(int row, int col, int value)
    {
    int startRow = row/3 * 3;
    int startCol= col/3 *3;



    for(int i=startRow; i<startRow +3; i++)
    for(int q=startCol; q<startCol +3; q++)
    {
    if(!(i==row && q==col))
    {
    if(cells [q] ==value)
    {
    return true;
    }
    }
    }
    return false;
    }


    private Integer[] generateNumbers()
    {
    ArrayList<Integer> random = new ArrayList<Integer>();
    for(int i=0; i<9; i++)
    random.add(i+1);
    Collections.shuffle(random);


    return random.toArray(new Integer[9]);
    }







    public static void main(String[] args) {



















    }
     
    coder7, Dec 21, 2015
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.