Add methods which generate a fixed sudoku based on the current date

This commit is contained in:
uykek 2020-05-26 20:15:33 +02:00
parent 01888989a3
commit 88a7f7813e
2 changed files with 26 additions and 0 deletions

View file

@ -15,6 +15,9 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
@ -75,6 +78,15 @@ public class NewLevelManager {
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) {
Level level = dbHelper.getLevel(diff, type);
dbHelper.deleteLevel(level.getId());

View file

@ -53,6 +53,20 @@ public class QQWingController {
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) {
level = new int[gameBoard.getSize()*gameBoard.getSize()];