Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::unique_ptr<Strategy> StrategyFactory::create(const std::string &className) {
- std::map<std::string, std::unique_ptr<Strategy>> strategiesMap;
- strategiesMap.try_emplace("random", unique_ptr<Strategy>(new AlwaysRandom));
- strategiesMap.try_emplace("always_defect", unique_ptr<Strategy>(new AlwaysDefect));
- strategiesMap.try_emplace("always_collude", unique_ptr<Strategy>(new AlwaysCollude));
- strategiesMap.try_emplace("grudger", unique_ptr<Strategy>(new Grudger));
- strategiesMap.try_emplace("copycat", unique_ptr<Strategy>(new CopyCat));
- strategiesMap.try_emplace("detective", unique_ptr<Strategy>(new Detective));
- auto it = strategiesMap.find(className);
- if (it != strategiesMap.end()) {
- return std::move(it->second);
- }
- throw std::runtime_error("no strategy found with this name: " + className);
- }
Advertisement
Add Comment
Please, Sign In to add comment