Merge branch 'Sudoku-v3.0' of https://github.com/SecUSo/privacy-friendly-sudoku into Sudoku-v3.0
This commit is contained in:
commit
8d72312575
2 changed files with 27 additions and 9 deletions
|
@ -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) {
|
||||
|
|
|
@ -53,14 +53,23 @@ 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);
|
||||
boolean havePuzzle = false;
|
||||
|
||||
while(!havePuzzle) {
|
||||
seed++;
|
||||
generator.setRandom(seed);
|
||||
generator.setRecordHistory(true);
|
||||
generator.generatePuzzle();
|
||||
|
||||
if (difficulty == GameDifficulty.Unspecified && generator.getDifficulty() != GameDifficulty.Challenge
|
||||
|| difficulty == generator.getDifficulty()) {
|
||||
havePuzzle = true;
|
||||
}
|
||||
}
|
||||
|
||||
generated.add(generator.getPuzzle());
|
||||
opts.gameType = GameType.Default_9x9;
|
||||
opts.gameDifficulty = generator.getDifficulty();
|
||||
|
|
Loading…
Reference in a new issue