back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/puzzle.hpp
diff options
context:
space:
mode:
authorscratko <m@scratko.xyz>2024-11-16 14:59:17 +0300
committerscratko <m@scratko.xyz>2024-11-16 21:26:41 +0300
commit22d4fdabf17aebebfcb73c7d86b5bbc81b6530f4 (patch)
tree8c86594705005c380560e87b68b01993fc1928ef /puzzle.hpp
parent060fe2ebc6f5ed26c445f95b3cd6c9ee5bc24e28 (diff)
downloadpicture-puzzle-22d4fdabf17aebebfcb73c7d86b5bbc81b6530f4.tar.gz
picture-puzzle-22d4fdabf17aebebfcb73c7d86b5bbc81b6530f4.tar.bz2
picture-puzzle-22d4fdabf17aebebfcb73c7d86b5bbc81b6530f4.zip
Added A* solution algorithm
Diffstat (limited to 'puzzle.hpp')
-rw-r--r--puzzle.hpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/puzzle.hpp b/puzzle.hpp
index e8d85d6..9370763 100644
--- a/puzzle.hpp
+++ b/puzzle.hpp
@@ -9,7 +9,7 @@
#include <memory>
enum {
- puzzle_pieces = 8,
+ puzzle_pieces = 9,
puzzles_per_side = 3,
puzzle_size = 100,
spacing = 5
@@ -27,8 +27,12 @@ class GameParams {
public:
struct coordinates {
int x, y;
+ bool operator==(const coordinates& v) const {
+ return this->x == v.x && this->y == v.y;
+ }
};
private:
+ static GameParams *instance;
coordinates standard_puzzle_coordinates[puzzle_pieces];
char free_puzzles[puzzle_pieces];
coordinates empty_box;
@@ -42,15 +46,19 @@ private:
void NextUntestedPuzzles();
bool IsSolvability();
void CreateNewPuzzles();
+
friend class PuzzleGame;
+ friend class ASearch;
friend void press_button_callback(Fl_Widget*, void*);
+ friend void solve_problem_callback(Fl_Widget*, void*);
public:
void SetXYEmptyBox(int x, int y) { empty_box.x = x; empty_box. y = y; }
coordinates GetXYEmptyBox() { return empty_box; }
static GameParams *SetUpParams(Fl_Window *win) {
+ if(instance)
+ return instance;
GameParams *gi = new GameParams(win);
gi->CalculateStandardPuzzlePos();
- gi->SetXYEmptyBox(215, 245);
return gi;
}
};