-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_printer.h
65 lines (58 loc) · 2.13 KB
/
game_printer.h
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <cstdint>
#include <iostream>
#include <map>
#include <string>
#include <vector>
enum class VictoryStates { winning, losing, unknown };
inline std::map<VictoryStates, std::string> const victory_state_to_string{
{VictoryStates::winning, "W"},
{VictoryStates::losing, "L"},
{VictoryStates::unknown, "unknown"}};
using i32 = std::int32_t;
using u32 = std::uint32_t;
template <class Game, class GameState, u32 NumOfPlayers>
class GamePrinter {
public:
void print_game_graph(GameState game_state, u32 game_depth) {
num_of_player_whos_turn = (num_of_player_whos_turn + 1) % NumOfPlayers;
++indentation_depth;
if (game_depth != 0) {
if (Game::check_winning_conditions(game_state) ==
VictoryStates::unknown) {
print_game_state_with_formatting(game_state);
std::vector<GameState> const possible_states_after_one_move =
Game::generate_states(game_state);
for (GameState const& possible_state_after_one_move :
possible_states_after_one_move) {
print_game_graph(possible_state_after_one_move,
game_depth - 1);
}
} else {
print_constatation_of_victory_state(game_state);
}
}
--indentation_depth;
num_of_player_whos_turn =
(num_of_player_whos_turn + NumOfPlayers - 1) % NumOfPlayers;
}
private:
void print_game_state_with_formatting(GameState const& game_state) {
print_indentation();
std::cout << player_to_string[num_of_player_whos_turn] << " "
<< game_state.to_string() << '\n';
}
void print_indentation() {
for (u32 i = 0; i < indentation_depth; ++i) std::cout << " ";
}
void print_constatation_of_victory_state(GameState const& game_state) {
print_indentation();
std::cout << player_to_string[num_of_player_whos_turn] << " "
<< game_state.to_string() << ' '
<< victory_state_to_string[Game::check_winning_conditions(
game_state)]
<< '\n';
}
u32 indentation_depth = 0xFFFFFFFF;
u32 num_of_player_whos_turn = NumOfPlayers - 1;
std::vector<std::string> const player_to_string{"1st", "2nd", "3rd", "4th"};
};