In this assignment, you implement a recursive method to find a solution to a given Sudoku problem.
A Sudoku is a 9x9 grid of integers, each with values 1..9.
A Sudoku is valid when each of the 9 rows, each of the 9 columns, and each of the 9 3x3 boxes in the grid has exactly one each of the possible values 1..9, without any duplicates.
A Sudoku problem is a Sudoku grid with some of the grid cells already filled. The solution fills the remaining cells to give a valid Sudoku.
A recursive strategy for finding a solution to a Sudoku problem is as follows:
If a solution is found for at least one legal value, set the Sudoku to reflect this solution, and return that a solution was found.
If no solution is found for any legal value, reset this cell to the value it had when this method was called, and report that this Sudoku does not have a solution.
This algorithm is an example of backtracking: at any point in the search, try any one of the available options. If that option doesn't work, return to that point, and try a different option, until all the available options have been tried.
Most of the code you will need has been provided at Sudoku.java and SudokuTest.java. In particular, the method CheckSudoku returns true if a Sudoku is valid, and false otherwise (it can also print where a Sudoku is invalid). The method toString will convert a Sudoku to a printable form, again with an option to check the validity of the Sudoku and provide more information.
SudokuTest.java also provides some test Sudoku with solutions.
All this code assumes that a Sudoku is represented as a 9-element array of rows, where each row is a 9-element array of ints. Each of the ints must have a value in 1..9. The value 0 represents an empty cell.
You must implement the public static boolean fillSudoku (int [] [] sudoku) method to fill all the empty Sudoku cells with values in 1..9. Your method should return true if a solution exists, and return false otherwise. If the method returns true, it must fill in the Sudoku with a valid solution. If it returns false, it must leave the Sudoku unchanged.
Your solution must be recursive. You may want to write a recursive helper method rather than making the fillSudoku method recursive, but this choice is up to you.
Your fillSudoku code may use a for loop to test each of the legal values for one cell. However, it must use recursion to try to find values for all the other empty cells.
Note that CheckSudoku doesn't verify that all cells are filled -- it just verifies that none of the Sudoku rules are broken.
Also note that people do not generally use backtracking to solve Sudoku. That means that the AI Escargot problem in SudokuTest, which is hard for humans to solve, should not be particularly challenging for a backtracking solver.
To turn in your assignment, turn in your modified Sudoku.java class, with your implemented fillSudoku method.
The TAs will test your solvers with the Sudoko in SudokuTest, and also with other Sudoku.