-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.h
110 lines (101 loc) · 4.26 KB
/
player.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef PLAYER_H
#define PLAYER_H
#include <chrono>
#include <utility>
#include "board.h"
/**
* @brief Player serves as an abstract base class providing a contract for all
* derived player types in a game. It encapsulates the generic behaviors and
* attributes of a player. All specific types of players (like Human_player,
* Mcts_player etc.) must inherit from this class and define their unique
* behaviors by implementing the abstract methods.
*
* A Player's primary responsibility is to choose a move based on the current
* state of the game board. This interaction is modelled via the pure virtual
* function choose_move().
*/
class Player {
public:
/**
* @brief Abstract function for choosing a move on the game board.
* @param board Current state of the game board (Board).
* @param player The player who is making the move (Cell_state).
* @return The chosen move as a pair of integers, row first, column second.
*/
virtual std::pair<int, int> choose_move(const Board& board,
Cell_state player) = 0;
};
/**
* @brief Human_player is a concrete class derived from the Player base class.
* It represents a human player in a game, implementing the necessary behaviors
* for move selection and interaction with the game.
*
* The choose_move() function is implemented to accept input directly from the
* user. The input is then checked for validity before being accepted as a
* legitimate move.
*/
class Human_player : public Player {
public:
/**
* @brief Implementation of the choose_move function for the Human_player
* class. This function prompts the user to input a row and column for their
* move. It checks if the move is valid and, if not, prompts the user to try
* again.
*
* @param board The current state of the game board (Board).
* @param player The current player (Cell_state).
* @return The chosen move as a pair of integers, row first, column second.
*/
std::pair<int, int> choose_move(const Board& board,
Cell_state player) override;
};
/**
* @brief Mcts_player is a concrete class derived from the Player base class,
* embodying a player that utilizes the Monte Carlo Tree Search (MCTS) algorithm
* for decision making during a game.
*
* The choose_move() function is implemented to utilize an MCTS agent for
* determining the best move. This is based on the exploration factor, maximum
* decision time, and whether computations are parallelized and verbose logging
* is enabled. All these parameters are customizable during the instantiation
* of a Mcts_player.
*/
class Mcts_player : public Player {
public:
/**
* @brief Constructor for the Mcts_player class.
* It initializes the exploration factor, maximum decision time, whether
* computations are parallelized, and whether verbose logging is enabled.
*
* @param exploration_factor The exploration factor used in MCTS.
* @param max_decision_time The maximum time allowed for decision making.
* @param is_parallelized If true, MCTS computations are parallelized.
* @param is_verbose If true, verbose logging is enabled.
*/
Mcts_player(double exploration_factor,
std::chrono::milliseconds max_decision_time,
bool is_parallelized = false, bool is_verbose = false);
/**
* @brief Implementation of the choose_move function for the Mcts_player
* class. This function uses the MCTS agent to choose a move. New instances of
* the agent are created for each move, so the agent's tree is not preserved.
*
* @param board The current state of the game board.
* @param player The current player.
* @return The chosen move as a pair of integers.
*/
std::pair<int, int> choose_move(const Board& board,
Cell_state player) override;
/**
* @brief Getter for the is_verbose private member of the Mcts_player class.
*
* @return The value of is_verbose.
*/
bool get_is_verbose() const;
private:
double exploration_factor; // The exploration factor used in MCTS.
std::chrono::milliseconds max_decision_time; // Maximum decision-making time.
bool is_parallelized; // If true, MCTS computations are parallelized.
bool is_verbose; // If true, enables verbose logging to console.
};
#endif