8 #ifndef HOG2_ENV_UTIL_PUZZLE_INFERENCE_RULE_H
9 #define HOG2_ENV_UTIL_PUZZLE_INFERENCE_RULE_H
12 #include <unordered_map>
24 template<
class State,
class Action>
28 std::unordered_map<Action, ActionType> &
logics)
const
30 std::for_each(
rules.begin(),
rules.end(), [&](
auto &rule) {
31 std::for_each(logics.begin(), logics.end(), [&](auto &logic) {
32 ActionType t = rule(env, state, logic.first);
35 if (logic.second != UNKNOWN && logic.second != t)
36 logic.second = INVALID;
37 else logic.second = t;
44 std::unordered_map<Action, ActionType>
logics;
47 std::vector<Action> &actions)
50 std::transform(actions.begin(), actions.end(), std::inserter(logics, logics.end()), [](
const Action &action) {
51 return std::make_pair(action, UNKNOWN);
53 UpdateActionLogics(env, state, logics);
54 if (std::count_if(logics.begin(), logics.end(), [](
const auto &logic) {
55 return logic.second == MUST_TAKE;
56 }) > 1 || std::count_if(logics.begin(), logics.end(), [](
const auto &logic) {
57 return logic.second == INVALID;
63 for (
auto it = actions.begin(); it != actions.end(); )
66 switch (logics[action]) {
70 actions.push_back(action);
75 it = actions.erase(it);