Results 1 to 9 of 9
  1. #1
    judas is offline Member
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

    Default Sudoku solver with threads

    ............
    Last edited by judas; 06-06-2010 at 04:42 PM. Reason: school project

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default

    Try debugging the code with some println statements to show execution flow and how variable values are changing.

    Or to get help here, can you strip your code down and post all of the code so we can see what is happening.
    Last edited by Norm; 05-26-2010 at 03:08 AM.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default

    I see three calls to new Brett( .. but only two of them call the start() method afterwards.

    Where in your code does it find a solution to the first row?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default

    Sorry, I don't understand your language. So I can't read your variable names or comments.

    Was there a missing start() call?

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default

    What about this one?

    //lager et nytt board
    board = new Board(str, numberOfRowsInBox, numberOfColumnsInBox, squares);
    }
    Have you tried adding debugging println statements so you can see how the execution flows? When I did, the code created and started 2 threads.
    Last edited by Norm; 05-26-2010 at 11:24 PM.

  6. #6
    judas is offline Member
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

    Default

    if i only use brett.copy() when it finds a solution to first row on this board:

    6
    2
    3
    ..1..3
    ......
    ....2.
    26....
    ...3..
    3..1.2

    i get:

    421563
    000000
    000020
    260000
    000300
    300102

    421653
    000000
    000020
    260000
    000300
    300102

    451263
    000000
    000020
    260000
    000300
    300102

    521463
    000000
    000020
    260000
    000300
    300102

    521643
    000000
    000020
    260000
    000300
    300102

    541263
    000000
    000020
    260000
    000300
    300102

    621453
    000000
    000020
    260000
    000300
    300102

    621543
    000000
    000020
    260000
    000300
    300102

    641253
    000000
    000020
    260000
    000300
    300102

    651243
    000000
    000020
    260000
    000300
    300102

    but when i use this in
    Board b = new Board(str, numberOfRowsInBox, numberOfColumnsInBox, board.copy());
    it will only start this first thread, but not the rest. It should start 10 threads, and from those 10 it should find 28 solutions

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default

    should start 10 threads
    Why do you think that?
    Have you tried adding debugging println statements so you can see how the execution flows? When I did, the code created and started 2 threads.
    Put in some println() statements to show when and why the program creates threads.

  8. #8
    judas is offline Member
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

    Default

    I guess because there are 10 solution like this:

    421563
    000000
    000020
    260000
    000300
    300102

    and whenever it finds one of this it is supposed make a new board and start(); which will call the recursive method from (1, 0) and continue solving the board.

    After adding println statements I found out it stopped after making a new board() in the recursive method. So i wonder if the threads are trying to work on the same board. Have I missed any pointers to the new board or something?

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default

    wonder if the threads are trying to work on the same board.
    Use println() to display what board a thread is working on.
    Have I missed any pointers to the new board or something?
    Again use some println() to display what is seen at different points in the program.

Similar Threads

  1. Error from sudoku class
    By hongi in forum New To Java
    Replies: 4
    Last Post: 05-08-2010, 02:08 PM
  2. Sudoku randomizer help
    By mochibon in forum New To Java
    Replies: 0
    Last Post: 04-07-2010, 03:05 AM
  3. How to best design a calculus solver
    By xcallmejudasx in forum New To Java
    Replies: 4
    Last Post: 06-25-2009, 05:27 AM
  4. SUDOKU game problem
    By bumblyb33 in forum AWT / Swing
    Replies: 2
    Last Post: 05-05-2009, 11:18 PM
  5. Rubiks Cube Solver
    By sufs2000 in forum Advanced Java
    Replies: 0
    Last Post: 06-03-2008, 03:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •