From f2aa3460ff3f03fb7ae17db65928a07296a5f34c Mon Sep 17 00:00:00 2001 From: uykek Date: Wed, 17 Jun 2020 18:33:59 +0200 Subject: [PATCH 1/2] Modify NewLevelManager's loadDailySudoku() method so that the probability of the daily sudoku's difficulty being 'challenge' is only 10% --- .../controller/NewLevelManager.java | 17 +++++++++++++---- .../controller/QQWingController.java | 18 +++++++++++++----- 2 files changed, 26 insertions(+), 9 deletions(-) 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 b656bb5..7aca04a 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/NewLevelManager.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/NewLevelManager.java @@ -40,6 +40,9 @@ public class NewLevelManager { public static int PRE_SAVES_MIN = 3; public static int PRE_SAVES_MAX = 10; + private final double CHALLENGE_GENERATION_PROBABILITY = 0.9; + + public static NewLevelManager getInstance(Context context, SharedPreferences settings) { if(instance == null) { instance = new NewLevelManager(context, settings); @@ -80,11 +83,17 @@ public class NewLevelManager { public int[] loadDailySudoku() { DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); - Date date = new Date(); - String toHash = "Sudoku/.PrivacyFriendly/." + dateFormat.format(date); - + String toHash = "Sudoku/.PrivacyFriendly/." + dateFormat.format(new Date()); + boolean generateChallenge = new Random(toHash.hashCode()).nextDouble() >= CHALLENGE_GENERATION_PROBABILITY; QQWingController controller = new QQWingController(); - return controller.generateFromSeed(toHash.hashCode()); + int[] result; + + if (generateChallenge) { + result = controller.generateFromSeed(toHash.hashCode(), GameDifficulty.Challenge); + } else { + result = controller.generateFromSeed(toHash.hashCode(), GameDifficulty.Unspecified); + } + return result; } public int[] loadLevel(GameType type, GameDifficulty diff) { 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 2f44929..44697fa 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/QQWingController.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/QQWingController.java @@ -53,13 +53,21 @@ public class QQWingController { return generated; } - public int[] generateFromSeed(int seed) { + public int[] generateFromSeed(int seed, GameDifficulty difficulty) { generated.clear(); - QQWing generator = new QQWing(GameType.Default_9x9, GameDifficulty.Unspecified); - generator.setRandom(seed); - generator.setRecordHistory(true); - generator.generatePuzzle(); + boolean havePuzzle = false; + + while(!havePuzzle) { + seed++; + generator.setRandom(seed); + generator.setRecordHistory(true); + generator.generatePuzzle(); + + if (difficulty == GameDifficulty.Unspecified || difficulty == generator.getDifficulty()) { + havePuzzle = true; + } + } generated.add(generator.getPuzzle()); opts.gameType = GameType.Default_9x9; From 0f5ef95c018e2d6a57f9850793216af56e60b8d0 Mon Sep 17 00:00:00 2001 From: uykek Date: Mon, 22 Jun 2020 10:22:04 +0200 Subject: [PATCH 2/2] Fix problem with previously added method that caused the generation of a challenge sudoku as the daily sudoku to be more, rather than less, likely --- .../privacyfriendlysudoku/controller/QQWingController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 44697fa..eb78863 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/QQWingController.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/QQWingController.java @@ -64,7 +64,8 @@ public class QQWingController { generator.setRecordHistory(true); generator.generatePuzzle(); - if (difficulty == GameDifficulty.Unspecified || difficulty == generator.getDifficulty()) { + if (difficulty == GameDifficulty.Unspecified && generator.getDifficulty() != GameDifficulty.Challenge + || difficulty == generator.getDifficulty()) { havePuzzle = true; } }