Add JavaDocs and a few comments to some of the changed controller classes
This commit is contained in:
parent
82297a8367
commit
a0e15e7508
5 changed files with 37 additions and 2 deletions
|
@ -119,8 +119,10 @@ public class GameController implements IModelChangedListener, Parcelable {
|
||||||
public void loadNewDailySudokuLevel() {
|
public void loadNewDailySudokuLevel() {
|
||||||
NewLevelManager newLevelManager = NewLevelManager.getInstance(context, settings);
|
NewLevelManager newLevelManager = NewLevelManager.getInstance(context, settings);
|
||||||
|
|
||||||
|
// generate the daily sudoku
|
||||||
int[] level = newLevelManager.loadDailySudoku();
|
int[] level = newLevelManager.loadDailySudoku();
|
||||||
|
|
||||||
|
// calculate the difficulty of the daily sudoku
|
||||||
QQWing difficultyCheck = new QQWing(GameType.Default_9x9, GameDifficulty.Unspecified);
|
QQWing difficultyCheck = new QQWing(GameType.Default_9x9, GameDifficulty.Unspecified);
|
||||||
difficultyCheck.setRecordHistory(true);
|
difficultyCheck.setRecordHistory(true);
|
||||||
difficultyCheck.setPuzzle(level);
|
difficultyCheck.setPuzzle(level);
|
||||||
|
@ -129,8 +131,6 @@ public class GameController implements IModelChangedListener, Parcelable {
|
||||||
loadLevel(new GameInfoContainer(DAILY_SUDOKU_ID, difficultyCheck.getDifficulty(),
|
loadLevel(new GameInfoContainer(DAILY_SUDOKU_ID, difficultyCheck.getDifficulty(),
|
||||||
GameType.Default_9x9, level, null, null));
|
GameType.Default_9x9, level, null, null));
|
||||||
|
|
||||||
newLevelManager.checkAndRestock();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTime() {
|
public int getTime() {
|
||||||
|
@ -347,19 +347,26 @@ public class GameController implements IModelChangedListener, Parcelable {
|
||||||
fm.saveGameState(this);
|
fm.saveGameState(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save progress on the current daily sudoku
|
||||||
|
* @param context the context in which this method is called
|
||||||
|
*/
|
||||||
public void saveDailySudoku(Context context) {
|
public void saveDailySudoku(Context context) {
|
||||||
int amountOfCells = size * size;
|
int amountOfCells = size * size;
|
||||||
int[] encodedBoard = new int[amountOfCells];
|
int[] encodedBoard = new int[amountOfCells];
|
||||||
|
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
for (int j = 0; j < size; j++) {
|
for (int j = 0; j < size; j++) {
|
||||||
encodedBoard[i * size + j] = gameBoard.getCell(i, j).getValue();
|
encodedBoard[i * size + j] = gameBoard.getCell(i, j).getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// turn the current date into an id
|
||||||
Calendar currentDate = Calendar.getInstance();
|
Calendar currentDate = Calendar.getInstance();
|
||||||
int id = currentDate.get(Calendar.DAY_OF_MONTH) * 1000000
|
int id = currentDate.get(Calendar.DAY_OF_MONTH) * 1000000
|
||||||
+ (currentDate.get(Calendar.MONTH) + 1) * 10000 + currentDate.get(Calendar.YEAR);
|
+ (currentDate.get(Calendar.MONTH) + 1) * 10000 + currentDate.get(Calendar.YEAR);
|
||||||
|
|
||||||
|
// save the sudoku to the database using the previously calculated id
|
||||||
DatabaseHelper db = new DatabaseHelper(context);
|
DatabaseHelper db = new DatabaseHelper(context);
|
||||||
DailySudoku dailySudoku = new DailySudoku(id, difficulty, gameType, encodedBoard, usedHints, GameActivity.timeToString(time));
|
DailySudoku dailySudoku = new DailySudoku(id, difficulty, gameType, encodedBoard, usedHints, GameActivity.timeToString(time));
|
||||||
db.addDailySudoku(dailySudoku);
|
db.addDailySudoku(dailySudoku);
|
||||||
|
|
|
@ -83,9 +83,12 @@ public class NewLevelManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] loadDailySudoku() {
|
public int[] loadDailySudoku() {
|
||||||
|
// create a seed from the current date
|
||||||
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());
|
||||||
QQWingController controller = new QQWingController();
|
QQWingController controller = new QQWingController();
|
||||||
|
|
||||||
|
// generate new sudoku using the previously computed seed
|
||||||
return controller.generateFromSeed(toHash.hashCode(), CHALLENGE_GENERATION_PROBABILITY, CHALLENGE_ITERATIONS);
|
return controller.generateFromSeed(toHash.hashCode(), CHALLENGE_GENERATION_PROBABILITY, CHALLENGE_ITERATIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,10 +54,23 @@ public class QQWingController {
|
||||||
return generated;
|
return generated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a new sudoku based on a given seed regardless of outcome difficulty
|
||||||
|
* @param seed the seed based on which the sudoku should be calculated
|
||||||
|
* @return the generated sudoku
|
||||||
|
*/
|
||||||
public int[] generateFromSeed(int seed) {
|
public int[] generateFromSeed(int seed) {
|
||||||
return generateFromSeed(seed, 1, 1);
|
return generateFromSeed(seed, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a new sudoku based on a given seed, but only accept challenge sudokus with a certain probability
|
||||||
|
* @param seed the seed based on which the sudoku should be calculated
|
||||||
|
* @param challengePermission the probability with which a challenge sudoku is accepted upon calculation
|
||||||
|
* @param challengeIterations the amount of times a challenge sudoku can be rejected in a row before being
|
||||||
|
* accepted with a probability of 100%
|
||||||
|
* @return the generated sudoku
|
||||||
|
*/
|
||||||
public int[] generateFromSeed(int seed, double challengePermission, int challengeIterations) {
|
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);
|
||||||
|
|
|
@ -84,9 +84,15 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||||
return levelList.get(0);
|
return levelList.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of all the daily sudokus that have been solved and thus saved to the database
|
||||||
|
* @return a list of all the daily sudokus that have been solved so far
|
||||||
|
*/
|
||||||
public synchronized List<DailySudoku> getDailySudokus() {
|
public synchronized List<DailySudoku> getDailySudokus() {
|
||||||
List<DailySudoku> dailySudokuList = new LinkedList<>();
|
List<DailySudoku> dailySudokuList = new LinkedList<>();
|
||||||
SQLiteDatabase database = getWritableDatabase();
|
SQLiteDatabase database = getWritableDatabase();
|
||||||
|
|
||||||
|
// order results from most to least recent
|
||||||
String order = DailySudokuColumns._ID + " DESC";
|
String order = DailySudokuColumns._ID + " DESC";
|
||||||
|
|
||||||
// How you want the results sorted in the resulting Cursor
|
// How you want the results sorted in the resulting Cursor
|
||||||
|
@ -125,6 +131,11 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||||
return database.insert(LevelColumns.TABLE_NAME, null, LevelColumns.getValues(level));
|
return database.insert(LevelColumns.TABLE_NAME, null, LevelColumns.getValues(level));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new daily sudoku to the database
|
||||||
|
* @param ds the daily sudoku which is to be added to the database
|
||||||
|
* @return the row id of the newly inserted sudoku (or -1 if an error occurred)
|
||||||
|
*/
|
||||||
public synchronized long addDailySudoku(DailySudoku ds) {
|
public synchronized long addDailySudoku(DailySudoku ds) {
|
||||||
SQLiteDatabase database = getWritableDatabase();
|
SQLiteDatabase database = getWritableDatabase();
|
||||||
return database.insert(DailySudokuColumns.TABLE_NAME, null, DailySudokuColumns.getValues(ds));
|
return database.insert(DailySudokuColumns.TABLE_NAME, null, DailySudokuColumns.getValues(ds));
|
||||||
|
|
|
@ -203,6 +203,7 @@ public class GameInfoContainer {
|
||||||
sb.append("/");
|
sb.append("/");
|
||||||
sb.append(controller.getUsedHints());
|
sb.append(controller.getUsedHints());
|
||||||
|
|
||||||
|
// add additional information to custom sudokus to ensure they can be distinguished from 'regular' sudokus
|
||||||
if (custom) {
|
if (custom) {
|
||||||
sb.append("/");
|
sb.append("/");
|
||||||
sb.append(custom);
|
sb.append(custom);
|
||||||
|
|
Loading…
Reference in a new issue