The puzzle is solved if none of the cells have WRONG_GUESS // need to guess - wrong guess TO_GUESS, // need to guess - not attempted yetĬORRECT_GUESS, // need to guess - correct guess * An enumeration of constants to represent the status Save the file as " CellStatus.java" just like a class. We define an enum called CellStatus as follows (in Eclipse File ⇒ New ⇒ Enum). Instead of using a string (such as "correct-guess", "wrong-guess", "to-guess") or an int (1 for correct, 2 for wrong, 3 for to-guess) to represent the status of a cell, JDK 5 introduces a feature known as enumeration ( enum) to efficiently maintain a set of constants in a type-safe manner. } The CellStatus Enumeration ( enum) of Constants Public static final int SUBGRID_SIZE = 3 * Define the named constants used in many classes. To refer to these static constants, use SudokuConstants.GRID_SIZE. This class defines the named constants used by many classes, e.g. If you are using JDK/TextEditor, create a sub-directory called sudoku and place the classes under the sub-directory.You can then create the classes under the sudoku package. In Eclipse/NetNeans/VSCode, first create a "Java Project" called "sudoku" then create a new package (new ⇒ package) also called sudoku.The method newPuzzle() can be used to generate a new puzzle for a new game.Īll the classes are kept in a package called sudoku. Puzzle: A class called Puzzle is designed to model the number puzzle, which holds the numbers and clues in 9x9 int array numbers and boolean array isGiven.SudokuMain: We further customize the JFrame, by creating a subclass called SudokuMain, to hold the GameBoardPanel ( JPanel) in its ContentPane. Similar to Cell, the GameBoardPanel has its own methods to paint() itself. GameBoardPanel: We also customize the JPanel, by creating a subclass called GameBoardPanel, to hold the grid of 9x9 Cells ( JTextFields).CellStatus: An enumeration ( enum) called CellStatus is designed to hold the status constants, including GIVEN, CORRECT_GUESS, WRONG_GUESS and TO_GUESS.The Cell has its own methods to paint() itself. Cell: We customize the JTextField, by creating a subclass called Cell, with additional variables row, col, number and status, to model each cell of the grid.SudokuConstants: To store the named constants such as GRID_SIZE - to be referred to as SudokuConstants.GRID_SIZE.However, it is hard to identify the row and column of the JTextField triggering an event.įor better OO and modular design, we design SIX classes (in a package called sudoku) as shown in the above class diagram: We could simply use 9x9 JTextFields (for entering guesses) arranged in 9x9 GridLayout on a JPanel/ JFrame's ContentPane. There is no known fast polynomial algorithm for solving the puzzle. Mathematically, Sudoku is a NP-complete problem. The One Rule can be compactly stated as: "Each digit appears once in each group." Rows, columns and boxes can be collectively referred to as groups, of which the grid has 27. The initially defined values are clues or givens. A grid has 9 rows, 9 columns and 9 boxes (or blocks or regions), each having 9 cells (or squares), for a total of 81 cells. the puzzle) is a partially completed grid. You could wiki "Sudoku" to understand the rules of the game. Do TODO 1 and run the program (2/10 points).The pre-requsite for this assignment is: You shall be able to program "SwingPhoneApp" in the "Exercises: Graphics Programming". Unfortunately, you have only little time to complete this mini-assignment.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |