return os;
}
-std::shared_ptr<Step> find_path(const std::string& start, const std::string& goal) {
+std::shared_ptr<Step> find_path(const std::string& start, const std::string& goal, unsigned max_frontier) {
std::istringstream iss_start{start}, iss_goal{goal};
Board board_start, board_goal;
iss_start >> board_start;
if (iss_goal.fail() || !iss_goal.eof()) {
throw std::runtime_error("Could not parse the goal board: " + goal);
}
- return find_path(board_start, board_goal);
+ return find_path(board_start, board_goal, max_frontier);
}
-std::shared_ptr<Step> find_path(const Board& start, const Board& goal) {
+std::shared_ptr<Step> find_path(const Board& start, const Board& goal, unsigned max_frontier) {
InvertedBoard invgoal = goal.invert();
std::multimap<int, std::shared_ptr<Step>> todo;
std::set<Board> seen;
}
}
}
+ while (todo.size() > max_frontier) {
+ todo.erase(--todo.end());
+ }
}
throw std::runtime_error("No path from start to goal");
}