Adjust generation of the daily sudoku so that challenges have a lesser probability of being generated than other sudokus, but generating them on the days they do appear won't take as long as before
This commit is contained in:
parent
a4b80b9ecc
commit
3db3110618
2 changed files with 22 additions and 17 deletions
|
@ -40,7 +40,8 @@ public class NewLevelManager {
|
||||||
public static int PRE_SAVES_MIN = 3;
|
public static int PRE_SAVES_MIN = 3;
|
||||||
public static int PRE_SAVES_MAX = 10;
|
public static int PRE_SAVES_MAX = 10;
|
||||||
|
|
||||||
private final double CHALLENGE_GENERATION_PROBABILITY = 0.9;
|
private final double CHALLENGE_GENERATION_PROBABILITY = 0.25;
|
||||||
|
private final int CHALLENGE_ITERATIONS = 4;
|
||||||
|
|
||||||
|
|
||||||
public static NewLevelManager getInstance(Context context, SharedPreferences settings) {
|
public static NewLevelManager getInstance(Context context, SharedPreferences settings) {
|
||||||
|
@ -84,16 +85,8 @@ public class NewLevelManager {
|
||||||
public int[] loadDailySudoku() {
|
public int[] loadDailySudoku() {
|
||||||
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
|
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
|
||||||
String toHash = "Sudoku/.PrivacyFriendly/." + dateFormat.format(new Date());
|
String toHash = "Sudoku/.PrivacyFriendly/." + dateFormat.format(new Date());
|
||||||
boolean generateChallenge = new Random(toHash.hashCode()).nextDouble() >= CHALLENGE_GENERATION_PROBABILITY;
|
|
||||||
QQWingController controller = new QQWingController();
|
QQWingController controller = new QQWingController();
|
||||||
int[] result;
|
return controller.generateFromSeed(toHash.hashCode(), CHALLENGE_GENERATION_PROBABILITY, CHALLENGE_ITERATIONS);
|
||||||
|
|
||||||
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) {
|
public int[] loadLevel(GameType type, GameDifficulty diff) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.os.Parcelable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -53,20 +54,27 @@ public class QQWingController {
|
||||||
return generated;
|
return generated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] generateFromSeed(int seed, GameDifficulty difficulty) {
|
public int[] generateFromSeed(int seed) {
|
||||||
|
return generateFromSeed(seed, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] generateFromSeed(int seed, double challengePermission, int challengeIterations) {
|
||||||
generated.clear();
|
generated.clear();
|
||||||
QQWing generator = new QQWing(GameType.Default_9x9, GameDifficulty.Unspecified);
|
QQWing generator = new QQWing(GameType.Default_9x9, GameDifficulty.Unspecified);
|
||||||
boolean havePuzzle = false;
|
boolean continueSearch = true;
|
||||||
|
Random random = new Random(seed);
|
||||||
|
int seedFactor = 2;
|
||||||
|
|
||||||
while(!havePuzzle) {
|
while(continueSearch && challengeIterations > 0) {
|
||||||
seed++;
|
seed *= seedFactor;
|
||||||
generator.setRandom(seed);
|
generator.setRandom(seed);
|
||||||
generator.setRecordHistory(true);
|
generator.setRecordHistory(true);
|
||||||
generator.generatePuzzle();
|
generator.generatePuzzle();
|
||||||
|
|
||||||
if (difficulty == GameDifficulty.Unspecified && generator.getDifficulty() != GameDifficulty.Challenge
|
if (generator.getDifficulty() != GameDifficulty.Challenge || random.nextDouble() < challengePermission) {
|
||||||
|| difficulty == generator.getDifficulty()) {
|
continueSearch = false;
|
||||||
havePuzzle = true;
|
} else {
|
||||||
|
challengeIterations--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,6 +231,10 @@ public class QQWingController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isImpossible() {
|
||||||
|
return solveImpossible;
|
||||||
|
}
|
||||||
|
|
||||||
private static class QQWingOptions {
|
private static class QQWingOptions {
|
||||||
// defaults for options
|
// defaults for options
|
||||||
boolean needNow = false;
|
boolean needNow = false;
|
||||||
|
|
Loading…
Reference in a new issue