-
Notifications
You must be signed in to change notification settings - Fork 0
/
TicTacToeBoard.h
44 lines (31 loc) · 989 Bytes
/
TicTacToeBoard.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
#ifndef __TICTACTOEBOARD_H
#define __TICTACTOEBOARD_H
#include <vector>
#include "TicTacToeMove.h"
#include "GameBoard.h"
#include "GameMove.h"
const int TBOARD_SIZE = 3;
class TicTacToeBoard : public GameBoard {
public:
enum Player { EMPTY = 0, X = 1, O = -1 };
// Default constructor initializes the board to its starting "new game" state
TicTacToeBoard();
virtual void GetPossibleMoves(std::vector<GameMove *> *list) const;
virtual void ApplyMove(GameMove *move);
virtual void UndoLastMove();
virtual GameMove *CreateMove() const { return new TicTacToeMove; }
inline static bool InBounds(int row, int col) { return row >= 0 && row < TBOARD_SIZE && col >= 0 && col < TBOARD_SIZE; }
// Returns true if the game is finished.
virtual bool IsFinished() const {
if (mHistory.size() == 9)
return true;
else if(gameOver)
return true;
else return false;
}
private:
friend class TicTacToeView;
bool gameOver;
char mBoard[TBOARD_SIZE][TBOARD_SIZE];
};
#endif