#include "Strategy.hpp" Strategy::Strategy(const std::vector<std::string_view> & lines) { if (!util::doIfNameMatch(std::regex("Strategy : ((incremental)|(sequential))"), lines[0], [this](auto sm) {type = sm[1] == "sequential" ? Type::Sequential : Type::Incremental;})) util::myThrow(fmt::format("Invalid strategy identifier '{}'", lines[0])); for (unsigned int i = 1; i < lines.size(); i++) { auto splited = util::split(lines[i], ' '); if (splited.size() == 2) edges[std::pair<std::string,std::string>(splited[0], "")] = splited[1]; else if (splited.size() == 3) edges[std::pair<std::string,std::string>(splited[0], splited[1])] = splited[2]; else util::myThrow(fmt::format("Invalid strategy line '{}'", lines[i])); } } std::pair<std::string, int> Strategy::getMovement(const Config & c, const std::string & transition) { auto foundSpecific = edges.find(std::make_pair(c.getState(), transition)); auto foundGeneric = edges.find(std::make_pair(c.getState(), "")); if (foundSpecific != edges.end()) return {foundSpecific->second, 1}; if (foundGeneric != edges.end()) return {foundGeneric->second, 1}; util::myThrow(fmt::format("no suitable movement found for current state '{}' and transition '{}'", c.getState(), transition)); return {"", 0}; }