#pragma once #include #include "matrix.hpp" #include #include #include #include #include "config.hpp" namespace ai { // ZED: I don't know if this is the best place for this using AIProfile = std::unordered_map; constexpr const int SCORE_MAX = std::numeric_limits::max() / 2; constexpr const size_t STATE_MAX = 32; using State = std::bitset; const State ALL_ZERO; const State ALL_ONES = ~ALL_ZERO; struct Action { std::string name; int cost = 0; State $positive_preconds; State $negative_preconds; State $positive_effects; State $negative_effects; Action() {} Action(std::string name, int cost) : name(name), cost(cost) { } void needs(int name, bool val); void effect(int name, bool val); void ignore(int name); bool can_effect(State& state); State apply_effect(State& state); bool operator==(const Action& other) const { return other.name == name; } }; using Script = std::deque; const Action FINAL_ACTION("END", SCORE_MAX); struct ActionState { Action action; State state; ActionState(Action action, State state) : action(action), state(state) {} ActionState() : action(FINAL_ACTION), state(0) {} bool operator==(const ActionState& other) const { return other.action == action && other.state == state; } }; struct ActionPlan { bool complete = false; Script script; }; bool is_subset(State& source, State& target); int distance_to_goal(State from, State to); ActionPlan plan_actions(std::vector& actions, State start, State goal); } template<> struct std::hash { size_t operator()(const ai::Action& p) const { return std::hash{}(p.name); } }; template<> struct std::hash { size_t operator()(const ai::ActionState& p) const { return std::hash{}(p.action) ^ std::hash{}(p.state); } };