-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.h
65 lines (58 loc) · 1.88 KB
/
game.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
#ifndef GAME_H
#define GAME_H
#include <memory>
#include "board.h"
#include "cell_state.h"
#include "player.h"
/**
* @class Game
* @brief Represents a Hex game.
*
* This class encapsulates a complete Hex game, including the game board and the
* two players. It handles the game loop, player turns, and game state
* transitions.
*/
class Game {
public:
/**
* @brief Constructs a new Game object.
*
* This constructor initializes a new game with a specified board size and two
* unique players. Players are moved into the Game object, ensuring that the
* Game has exclusive ownership of the players.
*
* @param board_size The size of the game board.
* @param player1 Unique pointer to the first player.
* @param player2 Unique pointer to the second player.
*/
Game(int board_size, std::unique_ptr<Player> player_1,
std::unique_ptr<Player> player_2);
/**
* @brief Starts and manages the Hex game.
*
* This function contains the main game loop. It continues until a player
* wins, i.e., when the board's check_winner() function no longer returns
* Cell_state::Empty. On each iteration of the loop, it:
* - Displays the current player's turn,
* - Displays the current state of the board,
* - Asks the current player to choose a move,
* - Makes the chosen move on the board,
* - Switches to the other player.
* Once a player wins, it displays the final state of the board and the
* winner.
*/
void play();
private:
Board board; ///< The Hex game board.
std::unique_ptr<Player>
players[2]; ///< Array of unique pointers to the two players.
int current_player_index; ///< Index of the current player.
/**
* @brief Switches the current player.
*
* This function switches the turn to the other player. It is called after a
* player has made a move.
*/
void switch_player();
};
#endif