Question
JAVA Sudoku is a popular logic puzzle that uses a 9 by 9 array of squares that are organized into 3 by 3 subarrays. The
JAVA
Sudoku is a popular logic puzzle that uses a 9 by 9 array of squares that are organized into 3 by 3 subarrays. The puzzle solver must fill in the squares with the digits 1 to 9 such that no digit is repeated in any row, any column, or any of the nine 3 by 3 subgroups of squares. Initially, some squares are filled in already and cannot be changed. For example, the following might be a starting configuration for a Sudoku puzzle:
1 | 2 | 3 | 4 | 9 | 7 | 8 | 6 | 5 |
4 | 5 | 9 | ||||||
6 | 7 | 8 | ||||||
3 | 1 | |||||||
2 | ||||||||
9 | 5 | |||||||
8 | ||||||||
7 | ||||||||
5 | 9 |
Create a class SudokuPuzzle that has the attributes boarda 9 by 9 array of integers that represents the current state of the puzzle, where 0 indicates a blank square starta 9 by 9 array of boolean values that indicates which squares in board are given values that cannot be changed and the following methods: SudokuPuzzlea constructor that creates an empty puzzle toStringreturns a string representation of the puzzle that can be printed addInitial(row, col, value)sets the given square to the given value as an initial value that cannot be changed by the puzzle solver addGuess(row, col, value)sets the given square to the given value; the value can be changed later by another call to addGuess checkPuzzlereturns true if the values in the puzzle do not violate the restrictions getValueIn(row, col)returns the value in the given square getAllowedValues(row, col)returns a one-dimensional array of nine booleans, each of which corresponds to a digit and is true if the digit can be placed in the given square without violating the restrictions isFullreturns true if every square has a value resetchanges all of the nonpermanent squares back to blanks (0s) Write a main method in the class Sudoku that creates a SudokuPuzzle object and sets its initial configuration. Then use a loop to allow someone to play Sudoku. Display the current configuration and ask for a row, column, and value. Update the game board and display it again. If the configuration does not satisfy the restrictions, let the user know. Indicate when the puzzle has been solved correctly. In that case, both checkPuzzle and isFull would return true. You should also allow options for resetting the puzzle and displaying the values that can be placed in a given square.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started