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. --- solution_algorithm.hpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'solution_algorithm.hpp') 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& first, + const std::shared_ptr& second) const { + return *first == *second; + } + }; + friend struct std::hash>; friend class ASearch; }; @@ -48,18 +55,11 @@ struct std::hash> { typedef std::vector> vect_node; // using of // ComputeFreeMoves class ASearch { - struct EqualNode { - bool operator()(const std::shared_ptr& first, - const std::shared_ptr& second) const { - return *first == *second; - } - }; - std::priority_queue, vect_node, Node::Comp> open_queue; std::unordered_set, std::hash>, - 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& n) const; - bool IsNearEmptyBox(const GameParams::coordinates c) const; void ShowSolution(Node *goal); }; -- cgit v1.2.3