Add methods which generate a fixed sudoku based on the current date
This commit is contained in:
parent
01888989a3
commit
88a7f7813e
2 changed files with 26 additions and 0 deletions
|
@ -15,6 +15,9 @@ import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -75,6 +78,15 @@ public class NewLevelManager {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int[] loadDailySudoku() {
|
||||||
|
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
|
||||||
|
Date date = new Date();
|
||||||
|
String toHash = "Sudoku/.PrivacyFriendly/." + dateFormat.format(date);
|
||||||
|
|
||||||
|
QQWingController controller = new QQWingController();
|
||||||
|
return controller.generateFromSeed(toHash.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
public int[] loadLevel(GameType type, GameDifficulty diff) {
|
public int[] loadLevel(GameType type, GameDifficulty diff) {
|
||||||
Level level = dbHelper.getLevel(diff, type);
|
Level level = dbHelper.getLevel(diff, type);
|
||||||
dbHelper.deleteLevel(level.getId());
|
dbHelper.deleteLevel(level.getId());
|
||||||
|
|
|
@ -53,6 +53,20 @@ public class QQWingController {
|
||||||
return generated;
|
return generated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int[] generateFromSeed(int seed) {
|
||||||
|
generated.clear();
|
||||||
|
|
||||||
|
QQWing generator = new QQWing(GameType.Default_9x9, GameDifficulty.Unspecified);
|
||||||
|
generator.setRandom(seed);
|
||||||
|
generator.setRecordHistory(true);
|
||||||
|
generator.generatePuzzle();
|
||||||
|
|
||||||
|
generated.add(generator.getPuzzle());
|
||||||
|
opts.gameType = GameType.Default_9x9;
|
||||||
|
opts.gameDifficulty = generator.getDifficulty();
|
||||||
|
return generated.poll();
|
||||||
|
}
|
||||||
|
|
||||||
public int[] solve(GameBoard gameBoard) {
|
public int[] solve(GameBoard gameBoard) {
|
||||||
|
|
||||||
level = new int[gameBoard.getSize()*gameBoard.getSize()];
|
level = new int[gameBoard.getSize()*gameBoard.getSize()];
|
||||||
|
|
Loading…
Reference in a new issue