Stephan van Hulst wrote:Normally you pass arguments to tasks by creating a new type for the task, and providing the arguments via constructor parameters. You can refactor your NaiveSolver by passing the board and the row index in its constructor, and then have the call() method just do whatever the runNaiveSolver() method is doing now.
Please don't use raw types, you should implement Callable<Boolean>, not Callable.
lewis manuel wrote:1.) I changed the name because I want to compare both classes and see how long it takes for solver to finish the puzzle.
2.) I explained with very good reason(at least I think) why I chose to make numberOfSteps static. If I don't make it static, then there would be several tasks run by N threads and thus they would have their own instance of the variable numberOfSteps. This does not make sense as there should only be one instance of this variable so that once we are done, we can see the total number of steps it took to solve the puzzle.
3.) Why make the board or the row final if some of the values in the board, that ones that are not predefined, are going to be changing constantly. If I declare it as final, I won't be able to change any of the cells that are 0.
4.) There is no way it could be null at this point because in a another class I instantiate the sudokuBoard class with some values such as how many rows and columns does the board have.
lewis manuel wrote:Well the way I have set up it has to be. The whole point is that a thread will be given a row to work on. If there are 4 rows, then there are 4 threads. So the number of threads are dictated by the size of the problem. So using one thread would not work because it would only check the first row.
2.) Impossible because I already checked that before starting the game. It is guaranteed that all the values will be between 1 and N because I explicitly checked for that.
6.) because row and column are actually the subgrid size. GridSize * GridSize is the true size of the grid.
lewis manuel wrote:Edit2: I made some additional changes so that it would work with one thread and it worked perfectly. Once I added another thread, then it returned false. Meaning it could not solve the puzzle.
lewis manuel wrote:Because I assume that the board they have given me is valid from the start. Only once I start solving do I check if it's invalid. I'm doing this for simplicity sake.
lewis manuel wrote:After a lot of pain and struggling, I finally it got to work.
Don't get me started about those stupid light bulbs. |