back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/puzzle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'puzzle.cpp')
-rw-r--r--puzzle.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/puzzle.cpp b/puzzle.cpp
index 0e3574b..50b32af 100644
--- a/puzzle.cpp
+++ b/puzzle.cpp
@@ -35,7 +35,7 @@ static void find_path_to_picture(std::string& path, int number)
std::to_string(number % puzzles_per_side) + ".jpg";
}
-void GameParams::CreateNewPuzzles()
+void GameParams::NextUntestedPuzzles()
{
int idx_random_puzzle;
std::unique_ptr<Puzzle> tmp_puzzle;
@@ -65,6 +65,24 @@ void GameParams::CreateNewPuzzles()
tmp_puzzle->callback(press_button_callback, this);
puzzles.push_back(std::move(tmp_puzzle));
}
+ ResetFreePuzzles();
+}
+
+bool GameParams::IsSolvability()
+{
+ int counter = 0;
+ for(size_t i = 0; i < puzzles.size(); ++i)
+ for(size_t j = i+1; j < puzzles.size(); ++j)
+ if(puzzles[i]->sequence_number > puzzles[j]->sequence_number)
+ ++counter;
+ return counter % 2 == 0;
+}
+
+void GameParams::CreateNewPuzzles()
+{
+ do {
+ NextUntestedPuzzles();
+ } while(!IsSolvability());
}
void GameParams::NewGame()