Skip to content

Commit 8489236

Browse files
committed
Add results for 12x12
1 parent 4768717 commit 8489236

File tree

7 files changed

+19019
-7
lines changed

7 files changed

+19019
-7
lines changed

result/sudoku12x12/Level_1.txt

Lines changed: 3800 additions & 0 deletions
Large diffs are not rendered by default.

result/sudoku12x12/Level_2.txt

Lines changed: 3800 additions & 0 deletions
Large diffs are not rendered by default.

result/sudoku12x12/Level_3.txt

Lines changed: 3800 additions & 0 deletions
Large diffs are not rendered by default.

result/sudoku12x12/Level_4.txt

Lines changed: 3800 additions & 0 deletions
Large diffs are not rendered by default.

result/sudoku12x12/Level_5.txt

Lines changed: 3800 additions & 0 deletions
Large diffs are not rendered by default.

src/com/ndn/Run.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@
99

1010
// generates sudoku puzzles and print to file text.
1111
public class Run {
12-
public static void main(String... args) throws UnsupportedEncodingException {
12+
13+
static void randomAndSaveToFile(){
1314
// properties
14-
int level = 9;
15-
int numberOfLessons = 100;
16-
int minScore = 21;
17-
int maxScore = 100;
18-
String path = "result/sudoku9x9/Level_2.txt";
15+
int level = 16;
16+
int numberOfLessons = 300;
17+
int minScore = 1;
18+
int maxScore = 10000000;
19+
String path = "result/sudoku16x16/Level_5.txt";
1920

2021
//cac cac cac
2122
ArrayList<Map> maps = new ArrayList<>();
2223
while (numberOfLessons > 0) {
23-
Map map = Generator.generateRandomMap(level, 10000, minScore, maxScore);
24+
Map map = Generator.generateRandomMap(level, 30000, minScore, maxScore);
25+
System.out.println(map.getScore());
26+
System.out.println(map);
2427
if(map.getScore() >= minScore && map.getScore() <= maxScore) {
2528
maps.add(map);
2629
numberOfLessons--;
@@ -51,4 +54,7 @@ public static void main(String... args) throws UnsupportedEncodingException {
5154
e.printStackTrace();
5255
}
5356
}
57+
public static void main(String... args) {
58+
randomAndSaveToFile();
59+
}
5460
}

src/com/ndn/map/BacktrackingSolution.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,25 @@ public boolean checkForOneSolution(int r, int c, Map map) {
3939
this.solution = map.cloneMap();
4040
return false;
4141
}
42+
4243
if (c >= map.size()) {
4344
return checkForOneSolution(r + 1, 0, map);
4445
}
46+
4547
if (map.get(r, c) != -1) {
4648
return checkForOneSolution(r, c + 1, map);
4749
}
50+
4851
int num = -1;
4952
while (true) {
5053
map.set(r, c, -1);
5154
num++;
5255
if (num >= map.size()) {
5356
return true;
5457
}
58+
59+
if(numberOfSolutions >= 2) return false;
60+
5561
if (checkSquare(r, c, num, map) && checkRow(r, num, map) && checkColumn(c, num, map)) {
5662
map.set(r, c, num);
5763
checkForOneSolution(r, c + 1, map);

0 commit comments

Comments
 (0)