From 88a7f7813e02fbfdcb2175f4285dda08920cb17d Mon Sep 17 00:00:00 2001 From: uykek Date: Tue, 26 May 2020 20:15:33 +0200 Subject: [PATCH] Add methods which generate a fixed sudoku based on the current date --- .../controller/NewLevelManager.java | 12 ++++++++++++ .../controller/QQWingController.java | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/NewLevelManager.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/NewLevelManager.java index b74319b..b656bb5 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/NewLevelManager.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/NewLevelManager.java @@ -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()); diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/QQWingController.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/QQWingController.java index 2a2f1d4..2f44929 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/QQWingController.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/QQWingController.java @@ -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()];