167#include <unordered_set>
176#include <type_traits>
179namespace aitoolkit::goap {
180 template <
typename T>
182 { a == b } -> std::convertible_to<bool>;
183 { std::hash<T>{}(a) } -> std::convertible_to<size_t>;
201 template <blackboard_trait T>
209 virtual float cost(
const T& blackboard)
const = 0;
225 template <blackboard_trait T>
226 using action_ptr = std::unique_ptr<action<T>>;
228 template <
typename A,
typename T>
231 template <blackboard_trait T, action_trait<T>... Actions>
232 std::vector<action_ptr<T>> action_list(Actions... actions) {
233 auto action_list = std::vector<action_ptr<T>>{};
234 action_list.reserve(
sizeof...(Actions));
235 (action_list.push_back(std::make_unique<Actions>(std::move(actions))), ...);
244 template <blackboard_trait T>
253 return m_plan.size();
259 operator bool()
const {
260 return !m_plan.empty();
267 if (!m_plan.empty()) {
268 auto action_idx = m_plan.top();
271 auto&
action = m_actions[action_idx];
277 std::stack<size_t> m_plan;
278 std::vector<action_ptr<T>> m_actions;
281 std::vector<action_ptr<T>>
actions,
303 template <blackboard_trait T>
305 std::vector<action_ptr<T>>
actions,
315 std::shared_ptr<node_type>
parent;
318 using node_ptr = std::shared_ptr<node_type>;
321 bool operator()(
const node_ptr&
a,
const node_ptr&
b)
const {
322 return a->cost >
b->cost;
332 .action_taken_idx = std::nullopt,
plan< T > planner(std::vector< action_ptr< T > > actions, T initital_blackboard, T goal_blackboard, size_t max_iterations=0)
Create a plan.
Definition goap.hpp:304