-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplayer.hpp
65 lines (50 loc) · 1.38 KB
/
player.hpp
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
/*------------------------------------------------------------------------------
Player class implementation
player.hpp
------------------------------------------------------------------------------*/
#ifndef PLAYER_HPP_INCLUDED
#define PLAYER_HPP_INCLUDED
#include <iostream>
using namespace std;
enum class player_e {
NONE,
X,
O // This is capital letter o.
};
class Player {
public:
Player(const player_e p = player_e::NONE): current(p) {}
void set(const player_e p) {
current = p;
}
player_e get() const {
return current;
}
player_e other() const {
if (current == player_e::O) {
return player_e::X;
} else if (current == player_e::X) {
return player_e::O;
} else {
cerr << __func__ << ": erroneous value of current player." << endl;
exit(1);
}
}
bool is_player() const {
return current != player_e::NONE;
}
void swap() {
current = other();
}
bool operator==(const Player& other) {
return other.current == current;
}
bool operator!=(const Player& other) {
return !(*this == other);
}
friend std::ostream& operator<<(std::ostream& os, const Player& player);
private:
player_e current;
};
std::ostream& operator<<(std::ostream& os, const Player& player);
#endif // PLAYER_HPP_INCLUDED