Skip to content

Commit 79f3f4b

Browse files
committed
add contents
1 parent 6e9e162 commit 79f3f4b

File tree

1 file changed

+86
-66
lines changed

1 file changed

+86
-66
lines changed

README.md

Lines changed: 86 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,80 @@
1+
## Contents
2+
- [Generator](#generator)
3+
- [Solver](#solver)
4+
- [Puzzle Form](#puzzle-form)
5+
* [Supported Form](#supported-form)
6+
+ [4x4](#4x4)
7+
+ [5x5](#5x5)
8+
+ [6x6](#6x6)
9+
+ [7x7](#7x7)
10+
+ [8x8](#8x8)
11+
+ [9x9](#9x9)
12+
+ [12x12](#12x12)
13+
+ [16x16](#16x16)
14+
+ [25x25](#25x25)
15+
- [Score](#score)
16+
17+
## Generator
18+
19+
To generate new puzzle use `Generator.generate(size of puzzle, maximum time, minimum score, maximum score)`
20+
In which `size of puzzle` is length of puzzle edge. Example 9x9 is 9, 25x25 is 25, ..etc.
21+
22+
Example:
23+
```java
24+
// register new form to generate puzzle
25+
// generator will select random form of registered forms
26+
// and generate a puzzle with that form
27+
Puzzle7.registerForm(new Puzzle7.Form(new int[][]{
28+
{0, 0, 1, 1, 1, 1, 2},
29+
{0, 0, 0, 1, 1, 1, 2},
30+
{3, 0, 0, 4, 4, 2, 2},
31+
{3, 3, 4, 4, 4, 2, 2},
32+
{3, 3, 4, 4, 6, 6, 2},
33+
{3, 5, 5, 5, 6, 6, 6},
34+
{3, 5, 5, 5, 5, 6, 6}
35+
}));
36+
// generate 7x7 puzzle within 5 seconds with minimum score of 10 and maximum score of 1.000.000
37+
Game game = Generator.generate(7, 5 * 1000, 10, 1000000);
38+
// score of generated puzzle
39+
System.out.println("Score: " + game.getScore());
40+
// puzzle
41+
System.out.println("Puzzle");
42+
System.out.println(game.getQuestion());
43+
// solved puzzle
44+
System.out.println("Solved");
45+
System.out.println(game.getAnswer());
46+
// Form of puzzle (return null if classic form)
47+
// use game.getQuestion().isClassicForm() to check classic form.
48+
game.getQuestion().getForm();
49+
```
50+
51+
## Solver
52+
53+
To solve a puzzle (example _6x6_)
54+
- create new empty puzzle by `Puzzle6 puzzle = new Puzzle6()` with classic form or `Puzzle6 puzzle = new Puzzle6(Puzzle6.FORM1)`
55+
if use custom form 1 of Puzzle 6. And
56+
- set board for puzzle by `puzzle.setBoard`, if square is empty, set it 0.
57+
- use `PuzzleSolver.solve(puzzle, time)` to solve puzzle and return the solved puzzle.
58+
59+
Example
60+
```java
61+
Puzzle7 puzzle = new Puzzle7(Puzzle7.FORM2);
62+
puzzle.setBoard(new int[][]{
63+
{0, 0, 0, 0, 0, 0, 0},
64+
{0, 0, 0, 0, 0, 0, 0},
65+
{0, 0, 0, 0, 0, 0, 5},
66+
{0, 0, 0, 0, 0, 7, 0},
67+
{0, 2, 7, 0, 0, 4, 0},
68+
{6, 0, 0, 5, 0, 0, 0},
69+
{0, 0, 2, 3, 0, 0, 0},
70+
});
71+
72+
Puzzle solved = PuzzleSolver.solve(puzzle, 5 * 1000);
73+
System.out.println(solved);
74+
```
75+
176
## Puzzle Form
2-
Puzzle form is form of all boxes inside the puzzle. **The first box index is 0**.
77+
Puzzle form is form of all boxes inside the puzzle. **The first box index is 0**.
378

479
For example, the classic form of 9x9 sudoku is
580

@@ -85,7 +160,7 @@ Support Form Register
85160

86161
#### 5x5
87162
Support Form Register
88-
- Form 1
163+
- Form 1
89164

90165
| 0 | 0 | 0 | 1 | 1 |
91166
|-----|-----|-----|-----|-----|
@@ -194,7 +269,7 @@ Support Form Register
194269
| 4 | 6 | 6 | 6 | 6 | 5 | 5 |
195270

196271
- Form 5
197-
272+
198273
| 0 | 0 | 0 | 0 | 0 | 0 | 1 |
199274
|-----|-----|-----|-----|-----|-----|-----|
200275
| 2 | 2 | 3 | 3 | 0 | 1 | 1 |
@@ -205,9 +280,9 @@ Support Form Register
205280
| 5 | 6 | 6 | 6 | 6 | 6 | 6 |
206281

207282
#### 8x8
208-
Support Form Register
209-
- Classic
210-
283+
Support Form Register
284+
- Classic
285+
211286
| 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |
212287
|-----|-----|-----|-----|-----|-----|-----|-----|
213288
| 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |
@@ -220,7 +295,7 @@ Support Form Register
220295

221296
#### 9x9
222297
Support Form Register
223-
- Classic
298+
- Classic
224299

225300
| `0` | `0` | `0` | 1 | 1 | 1 | `2` | `2` | `2 ` |
226301
|-----|-----|-----|-----|-----|-----|------|-----|------|
@@ -234,51 +309,19 @@ Support Form Register
234309
| `6` | `6` | `6` | 7 | 7 | 7 | `8 ` | `8` | `8` |
235310

236311
#### 12x12
237-
Support Classic Form Only
312+
Support Classic Form Only
238313

239-
- Classic
314+
- Classic
240315

241316
#### 16x16
242317
Support Classic Form Only
243318

244319
#### 25x25
245320
Support Classic Form Only
246321

247-
## Generator
322+
## Score
248323

249-
To generate new puzzle use `Generator.generate(size of puzzle, maximum time, minimum score, maximum score)`
250-
In which `size of puzzle` is length of puzzle edge. Example 9x9 is 9, 25x25 is 25, ..etc.
251-
252-
Example:
253-
```java
254-
// register new form to generate puzzle
255-
// generator will select random form of registered forms
256-
// and generate a puzzle with that form
257-
Puzzle7.registerForm(new Puzzle7.Form(new int[][]{
258-
{0, 0, 1, 1, 1, 1, 2},
259-
{0, 0, 0, 1, 1, 1, 2},
260-
{3, 0, 0, 4, 4, 2, 2},
261-
{3, 3, 4, 4, 4, 2, 2},
262-
{3, 3, 4, 4, 6, 6, 2},
263-
{3, 5, 5, 5, 6, 6, 6},
264-
{3, 5, 5, 5, 5, 6, 6}
265-
}));
266-
// generate 7x7 puzzle within 5 seconds with minimum score of 10 and maximum score of 1.000.000
267-
Game game = Generator.generate(7, 5 * 1000, 10, 1000000);
268-
// score of generated puzzle
269-
System.out.println("Score: " + game.getScore());
270-
// puzzle
271-
System.out.println("Puzzle");
272-
System.out.println(game.getQuestion());
273-
// solved puzzle
274-
System.out.println("Solved");
275-
System.out.println(game.getAnswer());
276-
// Form of puzzle (return null if classic form)
277-
// use game.getQuestion().isClassicForm() to check classic form.
278-
game.getQuestion().getForm();
279-
```
280-
281-
###### Score of sudoku puzzle is defined:
324+
Score of sudoku puzzle is defined
282325
+ `<` **100** : know the rule
283326
+ `>` **100** and `<` **1000** : know some techniques
284327
+ `>` **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()`
289332

290333
To get score of a puzzle, use `puzzle.difficultyScore(answer)` where **_answer_** is the solved puzzle.
291334

292-
To solve a puzzle (example _6x6_)
293-
- create new empty puzzle by `Puzzle6 puzzle = new Puzzle6()` with classic form or `Puzzle6 puzzle = new Puzzle6(Puzzle6.FORM1)`
294-
if use custom form 1 of Puzzle 6. And
295-
- set board for puzzle by `puzzle.setBoard`, if square is empty, set it 0.
296-
- use `PuzzleSolver.solve(puzzle, time)` to solve puzzle and return the solved puzzle.
297-
298-
Example
299-
```java
300-
Puzzle7 puzzle = new Puzzle7(Puzzle7.FORM2);
301-
puzzle.setBoard(new int[][]{
302-
{0, 0, 0, 0, 0, 0, 0},
303-
{0, 0, 0, 0, 0, 0, 0},
304-
{0, 0, 0, 0, 0, 0, 5},
305-
{0, 0, 0, 0, 0, 7, 0},
306-
{0, 2, 7, 0, 0, 4, 0},
307-
{6, 0, 0, 5, 0, 0, 0},
308-
{0, 0, 2, 3, 0, 0, 0},
309-
});
310-
311-
Puzzle solved = PuzzleSolver.solve(puzzle, 5 * 1000);
312-
System.out.println(solved);
313-
```
314335

315336
See Example: https://github.com/dangnguyendota/SudokuGeneratorAndSolver/blob/master/src/vn/com/dangnguyendota/Example.java
316-
317337

318338
Supported:
319339
- 4x4

0 commit comments

Comments
 (0)