-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.h
73 lines (47 loc) · 1.35 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
66
67
68
69
70
71
72
73
#ifndef GAME_H
#define GAME_H
/*
* Class to model the game. Holds sets of human moves, computer
* moves and free spaces.
*
*/
#include <stdexcept>
#include <set>
#include "Player.h"
using namespace std;
typedef set<int> IntSet;
class Game
{
public:
Game();
Game(const Game& other);
~Game();
Game& operator=(Game other);
bool operator==(const Game& other);
void reset() throw();
void addHumanMove(int move) throw (invalid_argument);
void addComputerMove(int move) throw (invalid_argument);
const Player* getHuman() { return &human_m; };
const Player* getComputer() { return &computer_m; };
// Returns whether any move is available
bool moveAvailable() const;
// Returns whether the given move is available
bool moveAvailable(int) const;
// Returns a copy of the set of available moves
const IntSet& getAvailable() const;
// Returns whether a player has won or the game is a draw
bool isLeaf() const;
// Returns value of the game
int getValue();
// Returns number of possible moves in the game
int getSize() const { return game_size_m; };
private:
IntSet available_moves_m;
Player human_m;
Player computer_m;
int game_value_m;
// Throws an exception if the move is not available
void checkAvailableMoves(int move) throw (invalid_argument);
const static int game_size_m = 9;
};
#endif // GAME_H