diff options
author | scratko <m@scratko.xyz> | 2025-07-25 17:04:21 +0300 |
---|---|---|
committer | scratko <m@scratko.xyz> | 2025-07-25 17:46:22 +0300 |
commit | 90bd5ca05bea4dbeaaeff5cbe13b5671da420c82 (patch) | |
tree | 05757ed9b9ea0c007f4b4e86cfd8402fea4c6a5d /solution_algorithm.hpp | |
parent | ac9a06b04144023e87d1a504cfe5598e7cf3d7b4 (diff) | |
download | picture-puzzle-90bd5ca05bea4dbeaaeff5cbe13b5671da420c82.tar.gz picture-puzzle-90bd5ca05bea4dbeaaeff5cbe13b5671da420c82.tar.bz2 picture-puzzle-90bd5ca05bea4dbeaaeff5cbe13b5671da420c82.zip |
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.
Diffstat (limited to 'solution_algorithm.hpp')
-rw-r--r-- | solution_algorithm.hpp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/solution_algorithm.hpp b/solution_algorithm.hpp index f182aa8..792c270 100644 --- a/solution_algorithm.hpp +++ b/solution_algorithm.hpp @@ -28,6 +28,13 @@ public: return first->evaluation > second->evaluation; } }; + struct EqualNode { + bool operator()(const std::shared_ptr<Node>& first, + const std::shared_ptr<Node>& second) const { + return *first == *second; + } + }; + friend struct std::hash<std::shared_ptr<Node>>; friend class ASearch; }; @@ -48,18 +55,11 @@ struct std::hash<std::shared_ptr<Node>> { typedef std::vector<std::shared_ptr<Node>> vect_node; // using of // ComputeFreeMoves class ASearch { - struct EqualNode { - bool operator()(const std::shared_ptr<Node>& first, - const std::shared_ptr<Node>& second) const { - return *first == *second; - } - }; - std::priority_queue<std::shared_ptr<Node>, vect_node, Node::Comp> open_queue; std::unordered_set<std::shared_ptr<Node>, std::hash<std::shared_ptr<Node>>, - EqualNode> close_set; + Node::EqualNode> close_set; Node initial; Node goal; GameParams *gp; @@ -70,7 +70,6 @@ public: Node *FindSolution(); void ApplyFairEvaluator(Node &n) const; vect_node ComputeFreeMoves(const std::shared_ptr<Node>& n) const; - bool IsNearEmptyBox(const GameParams::coordinates c) const; void ShowSolution(Node *goal); }; |