Last active
April 23, 2016 01:19
-
-
Save Mooophy/60ebbc794486d8d0944e49332e2eb2d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto search(std::string const& source, std::string const& goal) -> void | |
{ | |
// add is_max_depth_reached to stop the for loop | |
bool is_max_depth_reached = false; | |
for (max_depth_ = 0; is_max_depth_reached; ++max_depth_) | |
{ | |
is_max_depth_reached = false; | |
visited_.clear(); | |
q_.clear(); | |
for (q_.push_front(Node(source, "")); !q_.empty(); max_q_length_ = std::max(max_q_length_, q_.size())) | |
{ | |
auto curr = q_.front(); q_.pop_front(); | |
visited_.insert(curr.state); | |
if (goal == curr.state){ final_path_ = curr.path; return; } | |
if (curr.path.size() >= max_depth_) | |
{ | |
is_max_depth_reached = true; //condition for next max_depth_ | |
continue | |
} | |
for (auto make_child : func_dic_.at(curr.state.find('0'))) | |
{ | |
auto child = make_child(curr); | |
if (visited_.end() == visited_.find(child.state)) q_.push_front(child); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment