Simple implementation to learn Sudoku programming. Separate game and UI classes to check the game logic in the CUI and the game experience in the GUI.
数独プログラミングを学ぶためのシンプルな実装です。ゲームクラスと UI クラスを分離し、CUI でゲームロジックを、GUI でゲーム体験を確認できます。
- CUI repl mode
% java Sudoku repl
-----+-----+-----+
. . 3 . 5 . . 8 9
. . . . 8 9 1 . .
. . . 1 . . . 5 .
. . 4 . . 5 . 9 7
. . . . . 8 . 1 .
. . 7 9 . 4 3 6 .
. . 1 5 . . 9 . .
. . 5 . . 7 2 . 1
9 . . . . . . 4 .
-----+-----+-----+
> set 0 0 1
Set 0 0 1 returns true
-----+-----+-----+
1 . 3 . 5 . . 8 9
. . . . 8 9 1 . .
. . . 1 . . . 5 .
. . 4 . . 5 . 9 7
. . . . . 8 . 1 .
. . 7 9 . 4 3 6 .
. . 1 5 . . 9 . .
. . 5 . . 7 2 . 1
9 . . . . . . 4 .
-----+-----+-----+
> help
Available commands:
1. new
2. reset
3. solve
4. hint
5. set <row> <col> <value>
6. undo
7. quit
- GUI swing mode
$ java Sudoku [repl | swing]
- repl: run in cui repl mode
- swing: run in gui swing mode
Sudoku game logic with the new game, solve the game, provide a hint, undo an action, reset the game.
数独ゲームの、作成、解く、ヒント、アクションを元に戻す、ゲームをリセットを実装しました。
It implemented the following solver strategies.
以下のソルバー戦略を実装した。
-
Nacked Single.
If there is only one candidate, it is assumed to be the solution for that cell.
候補が 1 つしかない場合、そのセルの解とする。
-
Hidden Single reduction.
If a candidate appears only once in a row, column, or block, it can reduce candidates.
候補が行、列、ブロックに 1 回しか出現しない場合、候補を減らすことができる。
-
Nacked Pairs, Triplets reduction.
If the pairs and triples appear in the row, column, and block, it can reduce candidates.
ペア、トリプルが行、列、ブロックに出現していれば、候補を減らすことができる。
-
Box/Line reduction.
If a candidate only appears two or three times in a row or column and is all in the same block, it can reduce candidates.
候補が行や列に 2 ~ 3 回しか登場せず、すべて同じブロックにある場合、候補を減らすことができる。
A rough class diagram is as follows:
classDiagram
SudokuBoard --|> SudokuQuiz
SudokuBoard : -board
SudokuBoard : -cells
SudokuBoard : -numbers
SudokuBoard : -quiz
SudokuBoard : +hint()
SudokuBoard : +newQuiz()
SudokuBoard : +resetQuiz()
SudokuBoard : +setCell()
SudokuBoard : +setValue()
SudokuBoard : +solveQuiz()
SudokuBoard : +undo()
SudokuQuiz : -quiz
SudokuQuiz : -board
SudokuQuiz : +setValue()
SudokuQuiz : +newQuiz()
SudokuQuiz : +resetQuiz()
SudokuQuiz : +solve()
SudokuQuiz : +undo()
SudokuBoard --|> SudokuSolver
SudokuSolver : -quiz
SudokuSolver : -board
SudokuSolver : +getHints()
CommandPanelListener --|> SudokuBoard
CommandPanelListener : +actionPerformed()
BoardPanelListener --|> SudokuBoard
BoardPanelListener : +actionPerformed()
NumberPanelListener --|> SudokuBoard
NumberPanelListener : +actionPerformed()