From 90bd5ca05bea4dbeaaeff5cbe13b5671da420c82 Mon Sep 17 00:00:00 2001 From: scratko Date: Fri, 25 Jul 2025 17:04:21 +0300 Subject: July update Added const qualifiers is_next_to_empty_box() became visible to other files(). The size of the main window has been changed. Checking whether the A* algorithm has been launched before starting a new game or the same A* algorithm. Fixed indentation in lambda expressions. The initial node is added to open_queue without additional creation of dynamic memory (the address of the object field is taken). Fixed PQ_cont.erase(). IsNearEmptyBox was removed(). EqualNode moved to the Node class. --- puzzle.hpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'puzzle.hpp') diff --git a/puzzle.hpp b/puzzle.hpp index 09660c8..88f13ac 100644 --- a/puzzle.hpp +++ b/puzzle.hpp @@ -17,15 +17,21 @@ enum { }; class Puzzle : public Fl_Button{ -public: - unsigned char sequence_number; +private: + unsigned char sequence_number{}; + // Path for file access error handling (ERR_FILE_ACCESS) std::string path; Fl_PNG_Image *stored_img_pointer; +public: Puzzle(int x, int y) : Fl_Button(x, y, puzzle_size, puzzle_size), - stored_img_pointer(nullptr) { - } + stored_img_pointer(nullptr) + { + } ~Puzzle() { delete stored_img_pointer; } + friend class GameParams; + friend class PuzzleGame; + friend class ASearch; }; class GameParams { @@ -43,9 +49,9 @@ private: coordinates empty_box; std::vector> puzzles; Fl_Window *win; - /* - * selecting the current directory where the user image is stored - */ + // True while A* is solving the puzzle; blocks new game and solving again + bool is_a_star_active = false; + // selecting the current directory where the user image is stored std::string cur_directory; GameParams(Fl_Window *a_win = nullptr) @@ -53,14 +59,17 @@ private: {} void CalculateStandardPuzzlePos(); void ResetFreePuzzles(); + void ResetAStarActive() { is_a_star_active = false; } + void SetAStarActive() { is_a_star_active = true; } void NextUntestedPuzzles(); bool IsSolvability(); void CreateNewPuzzles(); void SelectRandomPicture(); Fl_PNG_Image *LoadPictureParts(std::unique_ptr& tmp_puzzle); -public: void SetXYEmptyBox(int x, int y) { empty_box.x = x; empty_box. y = y; } coordinates GetXYEmptyBox() { return empty_box; } +public: + bool GetAStarActive() { return is_a_star_active; } static GameParams *SetUpParams(Fl_Window *win) { if(instance) return instance; -- cgit v1.2.3