Skip to content

Commit 1148721

Browse files
committed
#
1 parent 8489236 commit 1148721

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/com/ndn/Run.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,42 @@
11
package com.ndn;
22

3+
import com.google.api.detect.Detect;
4+
import com.google.api.detect.DetectResult;
5+
import com.google.api.translate.Language;
6+
import com.google.api.translate.Translate;
37
import com.ndn.map.*;
8+
import com.sun.java.accessibility.util.Translator;
9+
import org.apache.http.HttpEntity;
10+
import org.apache.http.HttpResponse;
11+
import org.apache.http.NameValuePair;
12+
import org.apache.http.client.HttpClient;
13+
import org.apache.http.client.entity.UrlEncodedFormEntity;
14+
import org.apache.http.client.methods.HttpGet;
15+
import org.apache.http.client.methods.HttpPost;
16+
import org.apache.http.impl.client.HttpClients;
17+
import org.apache.http.message.BasicNameValuePair;
418

519
import java.io.*;
620
import java.nio.charset.StandardCharsets;
721
import java.util.ArrayList;
822
import java.util.Comparator;
23+
import java.util.List;
924

1025
// generates sudoku puzzles and print to file text.
1126
public class Run {
1227

1328
static void randomAndSaveToFile(){
1429
// properties
1530
int level = 16;
16-
int numberOfLessons = 300;
31+
int numberOfLessons = 100;
1732
int minScore = 1;
1833
int maxScore = 10000000;
19-
String path = "result/sudoku16x16/Level_5.txt";
34+
String path = "result/sudoku16x16/Gen.txt";
2035

2136
//cac cac cac
2237
ArrayList<Map> maps = new ArrayList<>();
2338
while (numberOfLessons > 0) {
24-
Map map = Generator.generateRandomMap(level, 30000, minScore, maxScore);
39+
Map map = Generator.generateRandomMap(level, 5000, minScore, maxScore);
2540
System.out.println(map.getScore());
2641
System.out.println(map);
2742
if(map.getScore() >= minScore && map.getScore() <= maxScore) {
@@ -54,7 +69,7 @@ static void randomAndSaveToFile(){
5469
e.printStackTrace();
5570
}
5671
}
57-
public static void main(String... args) {
72+
public static void main(String... args) throws Exception {
5873
randomAndSaveToFile();
5974
}
6075
}

src/com/ndn/map/BacktrackingSolution.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public boolean checkForOneSolution(Map map) {
2626
public boolean checkForOneSolution(int r, int c, Map map) {
2727
counter++;
2828
if (numberOfSolutions >= 2) {
29-
return true;
29+
return false;
3030
}
3131

3232
if(System.currentTimeMillis() - start >= maxTime) {
@@ -60,14 +60,15 @@ public boolean checkForOneSolution(int r, int c, Map map) {
6060

6161
if (checkSquare(r, c, num, map) && checkRow(r, num, map) && checkColumn(c, num, map)) {
6262
map.set(r, c, num);
63-
checkForOneSolution(r, c + 1, map);
63+
boolean flag = checkForOneSolution(r, c + 1, map);
64+
if(!flag) return false;
6465
}
6566
}
6667
}
6768

6869
public boolean randomNewMap(int r, int c, Map map){
6970
if (numberOfSolutions >= 1) {
70-
return true;
71+
return false;
7172
}
7273
counter++;
7374
if (r >= map.size()) {
@@ -91,7 +92,8 @@ public boolean randomNewMap(int r, int c, Map map){
9192
}
9293
if (checkSquare(r, c, shuffle[num], map) && checkRow(r, shuffle[num], map) && checkColumn(c, shuffle[num], map)) {
9394
map.set(r, c, shuffle[num]);
94-
randomNewMap(r, c + 1, map);
95+
boolean flag = randomNewMap(r, c + 1, map);
96+
if(!flag) return false;
9597
}
9698
}
9799
}

0 commit comments

Comments
 (0)