-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.cpp
More file actions
33 lines (28 loc) · 921 Bytes
/
action.cpp
File metadata and controls
33 lines (28 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//
// Created by Łukasz Stachowicz on 01/09/2022.
//
#include "action.hpp"
#include <map>
RPSGame::Action RPSGame::fromString(const std::string& action)
{
static std::map<std::string, Action> string_to_action = {
{"unknown", Action::Unknown}
, {"paper", Action::Paper}
, {"rock", Action::Rock}
, {"scissors", Action::Scissors}
, {"lizard", Action::Lizard}
, {"spock", Action::Spock}
};
return [&](const std::string& action) {
std::string lower_action(action);
std::transform(lower_action.begin(), lower_action.end()
, lower_action.begin()
, [](unsigned char c) { return std::tolower(c); });
auto val = string_to_action.find(lower_action);
if (val == string_to_action.end())
{
return Action::Unknown;
}
return val->second;
}(action);
}