From 79f3f4bf89e71daaf6a06b545b633eca8f5fab5a Mon Sep 17 00:00:00 2001 From: nguyennd Date: Mon, 16 May 2022 14:23:05 +0700 Subject: [PATCH] add contents --- README.md | 152 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 86 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index 166e8b6..01a7d61 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,80 @@ +## Contents +- [Generator](#generator) +- [Solver](#solver) +- [Puzzle Form](#puzzle-form) + * [Supported Form](#supported-form) + + [4x4](#4x4) + + [5x5](#5x5) + + [6x6](#6x6) + + [7x7](#7x7) + + [8x8](#8x8) + + [9x9](#9x9) + + [12x12](#12x12) + + [16x16](#16x16) + + [25x25](#25x25) +- [Score](#score) + +## Generator + +To generate new puzzle use `Generator.generate(size of puzzle, maximum time, minimum score, maximum score)` +In which `size of puzzle` is length of puzzle edge. Example 9x9 is 9, 25x25 is 25, ..etc. + +Example: +```java +// register new form to generate puzzle +// generator will select random form of registered forms +// and generate a puzzle with that form +Puzzle7.registerForm(new Puzzle7.Form(new int[][]{ + {0, 0, 1, 1, 1, 1, 2}, + {0, 0, 0, 1, 1, 1, 2}, + {3, 0, 0, 4, 4, 2, 2}, + {3, 3, 4, 4, 4, 2, 2}, + {3, 3, 4, 4, 6, 6, 2}, + {3, 5, 5, 5, 6, 6, 6}, + {3, 5, 5, 5, 5, 6, 6} +})); +// generate 7x7 puzzle within 5 seconds with minimum score of 10 and maximum score of 1.000.000 +Game game = Generator.generate(7, 5 * 1000, 10, 1000000); +// score of generated puzzle +System.out.println("Score: " + game.getScore()); +// puzzle +System.out.println("Puzzle"); +System.out.println(game.getQuestion()); +// solved puzzle +System.out.println("Solved"); +System.out.println(game.getAnswer()); +// Form of puzzle (return null if classic form) +// use game.getQuestion().isClassicForm() to check classic form. +game.getQuestion().getForm(); +``` + +## Solver + +To solve a puzzle (example _6x6_) +- create new empty puzzle by `Puzzle6 puzzle = new Puzzle6()` with classic form or `Puzzle6 puzzle = new Puzzle6(Puzzle6.FORM1)` +if use custom form 1 of Puzzle 6. And +- set board for puzzle by `puzzle.setBoard`, if square is empty, set it 0. +- use `PuzzleSolver.solve(puzzle, time)` to solve puzzle and return the solved puzzle. + +Example +```java +Puzzle7 puzzle = new Puzzle7(Puzzle7.FORM2); +puzzle.setBoard(new int[][]{ + {0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 5}, + {0, 0, 0, 0, 0, 7, 0}, + {0, 2, 7, 0, 0, 4, 0}, + {6, 0, 0, 5, 0, 0, 0}, + {0, 0, 2, 3, 0, 0, 0}, +}); + +Puzzle solved = PuzzleSolver.solve(puzzle, 5 * 1000); +System.out.println(solved); +``` + ## Puzzle Form -Puzzle form is form of all boxes inside the puzzle. **The first box index is 0**. +Puzzle form is form of all boxes inside the puzzle. **The first box index is 0**. For example, the classic form of 9x9 sudoku is @@ -85,7 +160,7 @@ Support Form Register #### 5x5 Support Form Register -- Form 1 +- Form 1 | 0 | 0 | 0 | 1 | 1 | |-----|-----|-----|-----|-----| @@ -194,7 +269,7 @@ Support Form Register | 4 | 6 | 6 | 6 | 6 | 5 | 5 | - Form 5 - + | 0 | 0 | 0 | 0 | 0 | 0 | 1 | |-----|-----|-----|-----|-----|-----|-----| | 2 | 2 | 3 | 3 | 0 | 1 | 1 | @@ -205,9 +280,9 @@ Support Form Register | 5 | 6 | 6 | 6 | 6 | 6 | 6 | #### 8x8 -Support Form Register -- Classic - +Support Form Register +- Classic + | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | |-----|-----|-----|-----|-----|-----|-----|-----| | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | @@ -220,7 +295,7 @@ Support Form Register #### 9x9 Support Form Register -- Classic +- Classic | `0` | `0` | `0` | 1 | 1 | 1 | `2` | `2` | `2 ` | |-----|-----|-----|-----|-----|-----|------|-----|------| @@ -234,9 +309,9 @@ Support Form Register | `6` | `6` | `6` | 7 | 7 | 7 | `8 ` | `8` | `8` | #### 12x12 -Support Classic Form Only +Support Classic Form Only -- Classic +- Classic #### 16x16 Support Classic Form Only @@ -244,41 +319,9 @@ Support Classic Form Only #### 25x25 Support Classic Form Only -## Generator +## Score -To generate new puzzle use `Generator.generate(size of puzzle, maximum time, minimum score, maximum score)` -In which `size of puzzle` is length of puzzle edge. Example 9x9 is 9, 25x25 is 25, ..etc. - -Example: -```java -// register new form to generate puzzle -// generator will select random form of registered forms -// and generate a puzzle with that form -Puzzle7.registerForm(new Puzzle7.Form(new int[][]{ - {0, 0, 1, 1, 1, 1, 2}, - {0, 0, 0, 1, 1, 1, 2}, - {3, 0, 0, 4, 4, 2, 2}, - {3, 3, 4, 4, 4, 2, 2}, - {3, 3, 4, 4, 6, 6, 2}, - {3, 5, 5, 5, 6, 6, 6}, - {3, 5, 5, 5, 5, 6, 6} -})); -// generate 7x7 puzzle within 5 seconds with minimum score of 10 and maximum score of 1.000.000 -Game game = Generator.generate(7, 5 * 1000, 10, 1000000); -// score of generated puzzle -System.out.println("Score: " + game.getScore()); -// puzzle -System.out.println("Puzzle"); -System.out.println(game.getQuestion()); -// solved puzzle -System.out.println("Solved"); -System.out.println(game.getAnswer()); -// Form of puzzle (return null if classic form) -// use game.getQuestion().isClassicForm() to check classic form. -game.getQuestion().getForm(); -``` - -###### Score of sudoku puzzle is defined: +Score of sudoku puzzle is defined + `<` **100** : know the rule + `>` **100** and `<` **1000** : know some techniques + `>` **1000** : requires flat-out trial (_`score / 1000`_ is the number of tries) @@ -289,31 +332,8 @@ To show the puzzle as string, use `puzzle.toString()` To get score of a puzzle, use `puzzle.difficultyScore(answer)` where **_answer_** is the solved puzzle. -To solve a puzzle (example _6x6_) -- create new empty puzzle by `Puzzle6 puzzle = new Puzzle6()` with classic form or `Puzzle6 puzzle = new Puzzle6(Puzzle6.FORM1)` -if use custom form 1 of Puzzle 6. And -- set board for puzzle by `puzzle.setBoard`, if square is empty, set it 0. -- use `PuzzleSolver.solve(puzzle, time)` to solve puzzle and return the solved puzzle. - -Example -```java -Puzzle7 puzzle = new Puzzle7(Puzzle7.FORM2); -puzzle.setBoard(new int[][]{ - {0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 5}, - {0, 0, 0, 0, 0, 7, 0}, - {0, 2, 7, 0, 0, 4, 0}, - {6, 0, 0, 5, 0, 0, 0}, - {0, 0, 2, 3, 0, 0, 0}, -}); - -Puzzle solved = PuzzleSolver.solve(puzzle, 5 * 1000); -System.out.println(solved); -``` See Example: https://github.com/dangnguyendota/SudokuGeneratorAndSolver/blob/master/src/vn/com/dangnguyendota/Example.java - Supported: - 4x4