summaryrefslogtreecommitdiff
path: root/2023/02/src/game.h
diff options
context:
space:
mode:
Diffstat (limited to '2023/02/src/game.h')
-rw-r--r--2023/02/src/game.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/2023/02/src/game.h b/2023/02/src/game.h
new file mode 100644
index 0000000..1c8002a
--- /dev/null
+++ b/2023/02/src/game.h
@@ -0,0 +1,45 @@
1#ifndef GAME_H
2#define GAME_H
3
4#include <stdexcept>
5#include <string>
6#include <tuple>
7#include <vector>
8
9template<const char* keyword, typename CharT, typename Traits>
10std::basic_istream<CharT, Traits>& skip(std::basic_istream<CharT, Traits>& stream)
11{
12 std::string word;
13 stream >> word;
14 if (word != keyword)
15 {
16 throw std::invalid_argument("Malformed input");
17 }
18
19 return stream;
20}
21
22class Game
23{
24 int id_;
25 std::vector<std::vector<int>> draws{};
26
27 static constexpr char game_t[] = "Game";
28
29 public:
30 Game(int id);
31
32 inline int id() const
33 {
34 return id_;
35 }
36
37 bool is_valid(int blue, int red, int green) const;
38 int power() const;
39 void push_back(const std::vector<int>& draw);
40 std::string to_string() const;
41
42 static Game from_string(const std::string& line);
43};
44
45#endif //GAME_H