From 515e9222606bbedb1dd760deac5645c9df03be8a Mon Sep 17 00:00:00 2001 From: uykek Date: Sun, 5 Jul 2020 12:52:29 +0200 Subject: [PATCH] Use 'QQWing.hasUniqueSolution()' method instead of 'QQWing.solve()' method for the custom sudoku and import verification --- .../ui/CreateSudokuActivity.java | 25 ++++++------------- .../ui/GameActivity.java | 4 ++- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/CreateSudokuActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/CreateSudokuActivity.java index 9b3df36..7d69953 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/CreateSudokuActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/CreateSudokuActivity.java @@ -26,11 +26,6 @@ import org.secuso.privacyfriendlysudoku.ui.view.CreateSudokuSpecialButtonLayout; import org.secuso.privacyfriendlysudoku.ui.view.R; import org.secuso.privacyfriendlysudoku.ui.view.SudokuFieldLayout; import org.secuso.privacyfriendlysudoku.ui.view.SudokuKeyboardLayout; -import org.secuso.privacyfriendlysudoku.ui.view.SudokuSpecialButtonLayout; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.LinkedList; public class CreateSudokuActivity extends BaseActivity implements IFinalizeDialogFragmentListener { @@ -45,28 +40,18 @@ public class CreateSudokuActivity extends BaseActivity implements IFinalizeDialo super.onCreate(savedInstanceState); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); - if (sharedPref.getBoolean("pref_dark_mode_setting", false )) { - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); - } else { - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); - } - if(sharedPref.getBoolean("pref_keep_screen_on", true)) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } gameController = new GameController(sharedPref, getApplicationContext()); - if(sharedPref.getBoolean("pref_keep_screen_on", true)) { - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - } - Bundle extras = getIntent().getExtras(); GameType gameType = GameType.valueOf(extras.getString("gameType", GameType.Default_9x9.name())); int sectionSize = gameType.getSize(); int boardSize = sectionSize * sectionSize; - GameInfoContainer container = new GameInfoContainer(0, GameDifficulty.Unspecified, + GameInfoContainer container = new GameInfoContainer(0, GameDifficulty.Moderate, gameType, new int [boardSize], new int [boardSize], new boolean [boardSize][sectionSize]); gameController.loadLevel(container); @@ -126,16 +111,20 @@ public class CreateSudokuActivity extends BaseActivity implements IFinalizeDialo GameType gameType = gameController.getGameType(); int boardSize = gameType.getSize() * gameType.getSize(); String boardContent = gameController.getCodeOfField(); + GameInfoContainer container = new GameInfoContainer(0, GameDifficulty.Unspecified, gameType, new int [boardSize], new int [boardSize], new boolean [boardSize][gameType.getSize()]); container.parseFixedValues(boardContent); + //gameController.loadLevel(container); QQWing verifier = new QQWing(gameType, GameDifficulty.Unspecified); verifier.setRecordHistory(true); verifier.setPuzzle(container.getFixedValues()); - boolean solvable = verifier.solve(); + verifier.solve(); - if(solvable) { + boolean distinctlySolvable = verifier.hasUniqueSolution(); + + if(distinctlySolvable) { Toast.makeText(CreateSudokuActivity.this, R.string.finished_verifying_custom_sudoku_toast, Toast.LENGTH_LONG).show(); final Intent intent = new Intent(this, GameActivity.class); intent.setData(Uri.parse(GameActivity.URL_SCHEME_WITHOUT_HOST + "://" + boardContent)); diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java index ad301dc..79237e0 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java @@ -147,7 +147,9 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig difficultyCheck = new QQWing(container.getGameType(), GameDifficulty.Unspecified); difficultyCheck.setRecordHistory(true); difficultyCheck.setPuzzle(container.getFixedValues()); - startGame = difficultyCheck.solve(); + difficultyCheck.solve(); + + startGame = difficultyCheck.hasUniqueSolution(); container.parseDifficulty(difficultyCheck.getDifficulty().toString()); } catch (IllegalArgumentException e) {