Skip to content

Commit fe4f7b8

Browse files
committed
update
1 parent 5a86094 commit fe4f7b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2006
-1445
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2323
hs_err_pid*
2424
.idea/
25-
SudokuGenerator2.iml
25+
*.iml
2626
out/

README.md

Lines changed: 291 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,307 @@
1+
## Puzzle Form
2+
Puzzle form is form of all boxes inside the puzzle. **The first box index is 0**.
3+
4+
For example, the classic form of 9x9 sudoku is
5+
6+
``` json
7+
[
8+
[0, 0, 0, 1, 1, 1, 2, 2, 2],
9+
[0, 0, 0, 1, 1, 1, 2, 2, 2],
10+
[0, 0, 0, 1, 1, 1, 2, 2, 2],
11+
[3, 3, 3, 4, 4, 4, 5, 5, 5],
12+
[3, 3, 3, 4, 4, 4, 5, 5, 5],
13+
[3, 3, 3, 4, 4, 4, 5, 5, 5],
14+
[6, 6, 6, 7, 7, 7, 8, 8, 8],
15+
[6, 6, 6, 7, 7, 7, 8, 8, 8],
16+
[6, 6, 6, 7, 7, 7, 8, 8, 8]
17+
]
18+
```
19+
20+
| `0` | `0` | `0` | 1 | 1 | 1 | `2` | `2` | `2 ` |
21+
|-----|-----|-----|-----|-----|-----|------|-----|------|
22+
| `0` | `0` | `0` | 1 | 1 | 1 | `2` | `2` | `2 ` |
23+
| `0` | `0` | `0` | 1 | 1 | 1 | `2` | `2` | `2 ` |
24+
| 3 | 3 | 3 | `4` | `4` | `4` | 5 | 5 | 5 |
25+
| 3 | 3 | 3 | `4` | `4` | `4` | 5 | 5 | 5 |
26+
| 3 | 3 | 3 | `4` | `4` | `4` | 5 | 5 | 5 |
27+
| `6` | `6` | `6` | 7 | 7 | 7 | `8 ` | `8` | `8` |
28+
| `6` | `6` | `6` | 7 | 7 | 7 | `8 ` | `8` | `8` |
29+
| `6` | `6` | `6` | 7 | 7 | 7 | `8 ` | `8` | `8` |
30+
31+
And one custom form is
32+
33+
``` json
34+
[
35+
[0, 0, 0, 0, 1, 1, 1, 2, 2],
36+
[0, 0, 0, 1, 1, 2, 2, 2, 2],
37+
[3, 0, 3, 1, 1, 1, 1, 2, 2],
38+
[3, 0, 3, 4, 4, 4, 5, 5, 2],
39+
[3, 3, 3, 4, 4, 4, 5, 5, 5],
40+
[6, 3, 3, 4, 4, 4, 5, 8, 5],
41+
[6, 6, 7, 7, 7, 7, 5, 8, 5],
42+
[6, 6, 6, 6, 7, 7, 8, 8, 8],
43+
[6, 6, 7, 7, 7, 8, 8, 8, 8]
44+
]
45+
```
46+
47+
| `0` | `0` | `0` | `0` | _1_ | _1_ | _1_ | `2` | `2 ` |
48+
|-----|-----|-----|-----|-----|-----|------|-----|------|
49+
| `0` | `0` | `0` | _1_ | _1_ | `2` | `2` | `2` | `2 ` |
50+
| 3 | `0` | 3 | _1_ | _1_ | _1_ | _1_ | `2` | `2 ` |
51+
| 3 | `0` | 3 | `4` | `4` | `4` | 5 | 5 | `2` |
52+
| 3 | 3 | 3 | `4` | `4` | `4` | 5 | 5 | 5 |
53+
| `6` | 3 | 3 | `4` | `4` | `4` | 5 | `8` | 5 |
54+
| `6` | `6` | _7_ | _7_ | _7_ | _7_ | 5 | `8` | 5 |
55+
| `6` | `6` | `6` | `6` | _7_ | _7_ | `8 ` | `8` | `8` |
56+
| `6` | `6` | _7_ | _7_ | _7_ | `8` | `8 ` | `8` | `8` |
57+
58+
### Supported Form
59+
60+
#### 4x4
61+
Support Form Register
62+
- Classic
63+
64+
| 0 | 0 | 1 | 1 |
65+
|-----|-----|-----|-----|
66+
| 0 | 0 | 1 | 1 |
67+
| 2 | 2 | 3 | 3 |
68+
| 2 | 2 | 3 | 3 |
69+
70+
- Form 1
71+
72+
| 0 | 0 | 0 | 1 |
73+
|-----|-----|-----|-----|
74+
| 0 | 2 | 1 | 1 |
75+
| 2 | 2 | 1 | 3 |
76+
| 2 | 3 | 3 | 3 |
77+
78+
- Form 2
79+
80+
| 0 | 0 | 0 | 1 |
81+
|-----|-----|-----|-----|
82+
| 0 | 1 | 1 | 1 |
83+
| 2 | 2 | 2 | 3 |
84+
| 2 | 3 | 3 | 3 |
85+
86+
#### 5x5
87+
Support Form Register
88+
- Form 1
89+
90+
| 0 | 0 | 0 | 1 | 1 |
91+
|-----|-----|-----|-----|-----|
92+
| 0 | 0 | 2 | 1 | 1 |
93+
| 3 | 2 | 2 | 2 | 1 |
94+
| 3 | 3 | 2 | 4 | 4 |
95+
| 3 | 3 | 4 | 4 | 4 |
96+
97+
- Form 2
98+
99+
| 0 | 0 | 0 | 0 | 1 |
100+
|-----|-----|-----|-----|-----|
101+
| 3 | 0 | 2 | 1 | 1 |
102+
| 3 | 2 | 2 | 2 | 1 |
103+
| 3 | 3 | 2 | 4 | 1 |
104+
| 3 | 4 | 4 | 4 | 4 |
105+
106+
- Form 3
107+
108+
| 0 | 0 | 0 | 0 | 1 |
109+
|-----|-----|-----|-----|-----|
110+
| 3 | 2 | 2 | 0 | 1 |
111+
| 3 | 3 | 2 | 1 | 1 |
112+
| 3 | 4 | 2 | 2 | 1 |
113+
| 3 | 4 | 4 | 4 | 4 |
114+
115+
116+
#### 6x6
117+
Support Form Register
118+
119+
- Classic
120+
121+
| 0 | 0 | 0 | 1 | 1 | 1 |
122+
|-----|-----|-----|-----|-----|-----|
123+
| 0 | 0 | 0 | 1 | 1 | 1 |
124+
| 2 | 2 | 2 | 3 | 3 | 3 |
125+
| 2 | 2 | 2 | 3 | 3 | 3 |
126+
| 4 | 4 | 4 | 5 | 5 | 5 |
127+
| 4 | 4 | 4 | 5 | 5 | 5 |
128+
129+
- Form 1
130+
131+
| 0 | 0 | 0 | 0 | 1 | 1 |
132+
|-----|-----|-----|-----|-----|-----|
133+
| 0 | 0 | 2 | 1 | 1 | 1 |
134+
| 2 | 2 | 2 | 1 | 3 | 3 |
135+
| 2 | 2 | 4 | 3 | 3 | 3 |
136+
| 4 | 4 | 4 | 3 | 5 | 5 |
137+
| 4 | 4 | 5 | 5 | 5 | 5 |
138+
139+
- Form 2
140+
141+
| 0 | 0 | 0 | 0 | 0 | 1 |
142+
|-----|-----|-----|-----|-----|-----|
143+
| 2 | 0 | 2 | 1 | 1 | 1 |
144+
| 2 | 2 | 2 | 1 | 1 | 3 |
145+
| 2 | 4 | 4 | 3 | 3 | 3 |
146+
| 4 | 4 | 4 | 3 | 5 | 3 |
147+
| 4 | 5 | 5 | 5 | 5 | 5 |
148+
149+
#### 7x7
150+
Support Form Register
151+
152+
- Form 1
153+
154+
| 0 | 0 | 0 | 1 | 1 | 1 | 1 |
155+
|-----|-----|-----|-----|-----|-----|-----|
156+
| 0 | 0 | 0 | 1 | 1 | 1 | 4 |
157+
| 2 | 2 | 0 | 3 | 3 | 4 | 4 |
158+
| 2 | 2 | 3 | 3 | 3 | 4 | 4 |
159+
| 2 | 2 | 3 | 3 | 6 | 4 | 4 |
160+
| 2 | 5 | 5 | 5 | 6 | 6 | 6 |
161+
| 5 | 5 | 5 | 5 | 6 | 6 | 6 |
162+
163+
- Form 2
164+
165+
| 0 | 0 | 1 | 1 | 1 | 1 | 2 |
166+
|-----|-----|-----|-----|-----|-----|-----|
167+
| 0 | 0 | 0 | 1 | 1 | 1 | 2 |
168+
| 3 | 0 | 0 | 4 | 4 | 2 | 2 |
169+
| 3 | 3 | 4 | 4 | 4 | 2 | 2 |
170+
| 3 | 3 | 4 | 4 | 6 | 6 | 2 |
171+
| 3 | 5 | 5 | 5 | 6 | 6 | 6 |
172+
| 3 | 5 | 5 | 5 | 5 | 6 | 6 |
173+
174+
- Form 3
175+
176+
| 0 | 0 | 0 | 1 | 2 | 2 | 2 |
177+
|-----|-----|-----|-----|-----|-----|-----|
178+
| 0 | 0 | 1 | 1 | 1 | 1 | 2 |
179+
| 0 | 0 | 4 | 1 | 4 | 1 | 2 |
180+
| 3 | 3 | 4 | 4 | 4 | 2 | 2 |
181+
| 3 | 5 | 4 | 5 | 4 | 6 | 6 |
182+
| 3 | 5 | 5 | 5 | 5 | 6 | 6 |
183+
| 3 | 3 | 3 | 5 | 6 | 6 | 6 |
184+
185+
- Form 4
186+
187+
| 0 | 0 | 0 | 1 | 1 | 2 | 2 |
188+
|-----|-----|-----|-----|-----|-----|-----|
189+
| 0 | 0 | 1 | 1 | 1 | 2 | 2 |
190+
| 0 | 0 | 3 | 1 | 1 | 2 | 2 |
191+
| 4 | 4 | 3 | 3 | 3 | 2 | 5 |
192+
| 4 | 4 | 3 | 3 | 3 | 5 | 5 |
193+
| 4 | 4 | 6 | 6 | 6 | 5 | 5 |
194+
| 4 | 6 | 6 | 6 | 6 | 5 | 5 |
195+
196+
- Form 5
197+
198+
| 0 | 0 | 0 | 0 | 0 | 0 | 1 |
199+
|-----|-----|-----|-----|-----|-----|-----|
200+
| 2 | 2 | 3 | 3 | 0 | 1 | 1 |
201+
| 2 | 2 | 2 | 3 | 1 | 1 | 4 |
202+
| 2 | 5 | 5 | 3 | 1 | 1 | 4 |
203+
| 2 | 5 | 5 | 3 | 4 | 4 | 4 |
204+
| 5 | 5 | 6 | 3 | 3 | 4 | 4 |
205+
| 5 | 6 | 6 | 6 | 6 | 6 | 6 |
206+
207+
#### 8x8
208+
Support Form Register
209+
- Classic
1210

2-
Map map = Generator.generateRandomMap(size of puzzle (example: 9x9 is 9), time(ms) (maximum thinking time), minScore (minimum score of generated map), maxScore (maximum score of generated map));
3-
Example: Generate sudoku 9x9 in maximum 5 seconds and get score between 1 to 5000.
211+
| 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |
212+
|-----|-----|-----|-----|-----|-----|-----|-----|
213+
| 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |
214+
| 2 | 2 | 2 | 2 | 3 | 3 | 3 | 3 |
215+
| 2 | 2 | 2 | 2 | 3 | 3 | 3 | 3 |
216+
| 4 | 4 | 4 | 4 | 5 | 5 | 5 | 5 |
217+
| 4 | 4 | 4 | 4 | 5 | 5 | 5 | 5 |
218+
| 6 | 6 | 6 | 6 | 7 | 7 | 7 | 7 |
219+
| 6 | 6 | 6 | 6 | 7 | 7 | 7 | 7 |
220+
221+
#### 9x9
222+
Support Form Register
223+
- Classic
224+
225+
| `0` | `0` | `0` | 1 | 1 | 1 | `2` | `2` | `2 ` |
226+
|-----|-----|-----|-----|-----|-----|------|-----|------|
227+
| `0` | `0` | `0` | 1 | 1 | 1 | `2` | `2` | `2 ` |
228+
| `0` | `0` | `0` | 1 | 1 | 1 | `2` | `2` | `2 ` |
229+
| 3 | 3 | 3 | `4` | `4` | `4` | 5 | 5 | 5 |
230+
| 3 | 3 | 3 | `4` | `4` | `4` | 5 | 5 | 5 |
231+
| 3 | 3 | 3 | `4` | `4` | `4` | 5 | 5 | 5 |
232+
| `6` | `6` | `6` | 7 | 7 | 7 | `8 ` | `8` | `8` |
233+
| `6` | `6` | `6` | 7 | 7 | 7 | `8 ` | `8` | `8` |
234+
| `6` | `6` | `6` | 7 | 7 | 7 | `8 ` | `8` | `8` |
235+
236+
#### 12x12
237+
Support Classic Form Only
238+
239+
- Classic
240+
241+
#### 16x16
242+
Support Classic Form Only
4243

5-
Map map = Generator.generateRandomMap(9, 5000, 1, 5000);
244+
#### 25x25
245+
Support Classic Form Only
246+
247+
## Generator
248+
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 generate 8x8 puzzle within 5 seconds with minimum score of 10 and maximum score of 1.000.000:
253+
```java
254+
Game game = Generator.generate(8, 5 * 1000, 10, 1000000);
255+
// score of generated puzzle
256+
System.out.println("Score: " + game.getScore());
257+
// puzzle
258+
System.out.println("Puzzle");
259+
System.out.println(game.getQuestion());
260+
// solved puzzle
261+
System.out.println("Solved");
262+
System.out.println(game.getAnswer());
263+
// Form of puzzle (return null if classic form)
264+
// use game.getQuestion().isClassicForm() to check classic form.
265+
game.getQuestion().getForm();
266+
```
6267

7268
###### Score of sudoku puzzle is defined:
8269
+ `<` **100** : know the rule
9270
+ `>` **100** and `<` **1000** : know some techniques
10-
+ `>` **1000** : requires flat-out trial (_`score / 1000`_ is the number of tries)
271+
+ `>` **1000** : requires flat-out trial (_`score / 1000`_ is the number of tries)
272+
273+
The Puzzle with higher score is harder to solve.
274+
275+
To show the puzzle as string, use `puzzle.toString()`
276+
277+
To get score of a puzzle, use `puzzle.difficultyScore(answer)` where **_answer_** is the solved puzzle.
11278

12-
To show the map as string, use `map.toString()`
279+
To solve a puzzle (example _6x6_)
280+
- create new empty puzzle by `Puzzle6 puzzle = new Puzzle6()` with classic form or `Puzzle6 puzzle = new Puzzle6(Puzzle6.FORM1)`
281+
if use custom form 1 of Puzzle 6. And
282+
- set board for puzzle by `puzzle.setBoard`, if square is empty, set it 0.
283+
- use `PuzzleSolver.solve(puzzle, time)` to solve puzzle and return the solved puzzle.
13284

14-
To get score of a puzzle, use `map.difficultyScore(answer)` where **_answer_** is the solved puzzle, and **_map_** is the puzzle.
285+
Example
286+
```java
287+
Puzzle7 puzzle = new Puzzle7(Puzzle7.FORM2);
288+
puzzle.setBoard(new int[][]{
289+
{0, 0, 0, 0, 0, 0, 0},
290+
{0, 0, 0, 0, 0, 0, 0},
291+
{0, 0, 0, 0, 0, 0, 5},
292+
{0, 0, 0, 0, 0, 7, 0},
293+
{0, 2, 7, 0, 0, 4, 0},
294+
{6, 0, 0, 5, 0, 0, 0},
295+
{0, 0, 2, 3, 0, 0, 0},
296+
});
15297

16-
To solve a puzzle use:
298+
Puzzle solved = PuzzleSolver.solve(puzzle, 5 * 1000);
299+
System.out.println(solved);
300+
```
17301

18-
int size = <your size of sudoku puzzle, example: 9x9 is 9, 7x7 is 7>;
19-
int[][] puzzle = <your puzzle, minus numbers in all your puzzle's squares 1, for example: empty square 0 becomes -1, 1 becomes 0>;
20-
// init puzzle
21-
Map map = MapFactory.get(size);
22-
map.setMap(puzzle);
23-
// create a solver
24-
PseudoMap pseudo = new PseudoMap(map);
25-
pseudo.solve();
26-
// print solved puzzle
27-
System.out.println(pseudo.getResult());
28302

29303

30304
Supported:
31-
- ~~3x3~~
32305
- 4x4
33306
- 5x5
34307
- 6x6
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)