-
Notifications
You must be signed in to change notification settings - Fork 0
/
OthelloBoard.h
74 lines (59 loc) · 2.18 KB
/
OthelloBoard.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
#ifndef __OTHELLOBOARD_H
#define __OTHELLOBOARD_H
#include <vector>
#include "OthelloMove.h"
#include "GameBoard.h"
#include "GameMove.h"
const int BOARD_SIZE = 8;
/*
An OthelloBoard encapsulates data needed to represent a single game of Othello.
This includes the state of the board, tracking the current player, and keeping
a history of moves on the board.
*/
class OthelloBoard : public GameBoard {
public:
enum Player {EMPTY = 0, BLACK = 1, WHITE = -1};
// Default constructor initializes the board to its starting "new game" state
OthelloBoard();
/*
Fills in a vector with all possible moves on the current board state for
the current player. The moves should be ordered based first on row, then on
column. Example ordering: (0, 5) (0, 7) (1, 0) (2, 0) (2, 2) (7, 7).
If no moves are possible, then a single OthelloMove representing a Pass is
put in the vector.
Precondition: the vector is empty.
Postcondition: the vector contains all valid moves for the current player.
*/
virtual void GetPossibleMoves(std::vector<GameMove *> *list) const;
/*
Applies a valid move to the board, updating the board state accordingly.
You may assume that this move is valid, and is consistent with the list
of possible moves returned by GetAllMoves.
*/
virtual void ApplyMove(GameMove *move);
/*
Undoes the last move applied to the board, restoring it to the state it was
in prior to the most recent move.
*/
virtual void UndoLastMove();
/*
Creates an OthelloMove object on the heap. Whoever calls this method is
responsible for managing the move's lifetime (or transferring that task to
someone else.)
*/
virtual GameMove *CreateMove() const {return new OthelloMove;}
inline static bool InBounds(GameMove *m) {
OthelloMove *move = (OthelloMove*)m;
return (move->mRow < 0 || move->mCol < 0 || move->mRow > BOARD_SIZE || move->mCol > BOARD_SIZE);
}
// Returns true if the game is finished.
virtual bool IsFinished() const {
return mPassCount == 2;
}
private:
friend class OthelloView;
char mBoard[BOARD_SIZE][BOARD_SIZE];
static char mWeights[BOARD_SIZE][BOARD_SIZE];
int mPassCount;
};
#endif