代写完成–Java GUI: 九宫格游戏
Introduction
In this assignment, you are going to complete a logic-based game called Sudoku. For more details regarding this game, you may check its Wikipedia page here.
There are 2 parts in this assignment: Part A and Part B. Implement ALL routines in part A and in part B.
Fundamentals
A typical Sudoku puzzle has a 9x9 board. The goal of Sudoku is simple: fill in the numbers 1-9 exactly once in every row, column, and 3x3 region. It is common to use pencil-mark to plot in possible numbers in each cell. The image below shows the pencil-mark, indicated by the small numbers in blue color. Your completed program should be able to provide the correct pencil-mark to the user.
In addition, your completed program will be able to solve a Sudoku puzzle by clicking the “Solution” button. The following shows the solution of the above puzzle:
Your completed program will shade the box in grey color if the user input has no conflict. For example, if the user changed the input in box “H-VI” to 8, the corresponding conflicted row, column, and subregion will be unshaded as shown below.
Description: Part A
Subset Class
Open Subset.java and complete the followings of Subset class:
Complete the method isValid(). This method will return a boolean of true if the subset contains 1-9 exactly once. For example, if the subset contains [2,3,6,9,7,1,8,4,5], then isValid() should return true. And it will return false if some numbers are missing or repeated. Complete the method markings(). This method will return a boolean array of size 10, say a, where a[i] is true if the subset didn’t contain i.
For example, if the subset contains [0,0,6,5,8,0,7,0,9], then we should return a=[F,T,T,T,T,F,F,F,F,F]. If the subset contains [1,2,3,4,5,6,7,8,9], then this method will return a=[T,F,F,F,F,F,F,F,F,F].
Complete the method conflict(int n). This method will return true if the subset contains input n.
Hint: you may want to use the method getValue() to obtain the value in cell.
Row Class, Column Class, and Subregion ClassAfter completing Subset.java, there are three methods to check the validity, markings, and conflicts for a subset of size 9. The game of Sudoku requires these conditions to be checked in row, column, and subregion. So we are going to extract it and put it into the subset for checking. Note that the following classes are inherited from the Subset class.
Open Row.java. The constructor of Row class will initialize the variable c, where c is an array of cells of size 9 initialized in subset. This variable c should contain the cells of the given row from the matrix.
Open Column.java. Similarly, the constructor of Column class will initialize the variable c. This variable c should contain the cells of the given column from the matrix.
Open Subregion.java. Again, the constructor of Subregion class will initialize the variable c. This variable c contains the cells of the given subregion from the matrix.
Hint: you may want to use the method setRow(), setColumn(), and setSubregion() of Cell class for this part.Cell Class
Open Cell.java and complete the following methods of Cell class.
Complete the method getPencilMarking(). This method will return a boolean array pencilMarking, where pencilMarking[i] is true if all corresponding row, column, and subregion didn’t contain i.
Hint: Use the method markings() that you completed in Subset.java for this.
Complete the method conflict(). This method will return true if the input value i conflicts with its row, column, or subregion.
Hint: Use the OR operator.Board
Open Board.java and complete the following methods of Board class.
Complete the methods solve() and solve(int k). These two methods are used to solve a Sudoku puzzle. Solving a Sudoku puzzle is quite complicated. You can write your code according to the pseudocode provided in the Appendix.
Complete the method generate(). This method generates a random Sudoku puzzle. Again, we provided the pseudocode for you in the Appendix.
After finishing part A, you can try to build and run main(). The output should look like this:
Note that the program generates a random Sudoku puzzle every time, so your output should look a bit different from the above.
Also, you need to open interfce.java and disable the import/export button if you want to run it before finishing Part B. Otherwise, you will have an error because your IO.java is incomplete.
If your implementation is correct, you should be able to use Generate, Solution, and PencilMarkings. Also, the conflict checking function should work (see Introduction).
Description: Part B
File output
Open IO.java. Complete the method for file output. After you have completed this method, your program should be able to perform Export. For example, the following shows an unfinished Sudoku puzzle:
By clicking the Export button, the following window will show up:
which allow the user to save the puzzle.
There are three parts in the puzzle that you need to save: value, solution, and the given puzzle.
Value: the current value stored in a cell, can be user input or original puzzle generated by the program.
Solution: the solution to this puzzle.
Given: a boolean that describes whether the cell value is generated by the algorithm.
Hint: You may need to use these methods: getBoard(), getValue(), getSolution(), and getGiven(). Note: You can store the puzzle in any way you want as long as you can load it back to the program.
File input
Open IO.java. Complete the method for file input. After you have completed this method, your program should be able to perform Import to input a previously saved puzzle. For example, here is a new puzzle after the Generate button is clicked.
You can click the Import button and the following window will pop up.
Select and open the file “123.data”. Then, the user can continue to play this previously saved puzzle.