-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3e401c
commit 4b2b704
Showing
19 changed files
with
492 additions
and
639 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
#ifndef BOARD_H | ||
#define BOARD_H | ||
|
||
class Board | ||
{ | ||
private: | ||
int **grid; | ||
int boardSize; | ||
int turn; | ||
vector <Cell> emptyCells{}; | ||
|
||
public: | ||
explicit Board(int bs) | ||
{ | ||
boardSize = bs; | ||
grid = new int *[boardSize]; | ||
for (int i = 0; i < boardSize; i++) | ||
grid[i] = new int[boardSize]; | ||
|
||
for (int i = 0; i < boardSize; i++) | ||
for (int j = 0; j < boardSize; j++) | ||
{ | ||
grid[i][j] = 0; | ||
} | ||
turn = 1; | ||
} | ||
|
||
virtual ~Board() | ||
{ | ||
|
||
for (int i = 0; i < boardSize; i++) | ||
delete[] grid[i]; | ||
|
||
delete[] grid; | ||
} | ||
|
||
Board(Board &cboard) | ||
{ | ||
boardSize = cboard.GetBoardSize(); | ||
|
||
grid = new int *[boardSize]; | ||
for (int i = 0; i < boardSize; i++) | ||
grid[i] = new int[boardSize]; | ||
|
||
for (int i = 0; i < boardSize; i++) | ||
for (int j = 0; j < boardSize; j++) | ||
grid[i][j] = 0; | ||
|
||
for (int i = 0; i < boardSize; i++) | ||
{ | ||
for (int j = 0; j < boardSize; j++) | ||
{ | ||
grid[i][j] = cboard.GridValue(i, j); | ||
} | ||
} | ||
|
||
turn = cboard.GetTurn(); | ||
emptyCells = cboard.emptyCells; | ||
} | ||
|
||
//SECTION - Spots | ||
void addCells(); | ||
|
||
void PrintCells(vector <Cell> cells); | ||
|
||
vector <Cell> GetEmpty() | ||
{ | ||
return emptyCells; | ||
} | ||
|
||
int EmptySize() | ||
{ | ||
return emptyCells.size(); | ||
} | ||
|
||
void RemoveEmptyCell(int x, int y); | ||
|
||
|
||
//SECTION - Board | ||
int GetBoardSize() | ||
{ | ||
return boardSize; | ||
} | ||
|
||
void PrintBoard(); | ||
|
||
bool isBoardFull(); | ||
|
||
|
||
//SECTION - Grid | ||
int GridValue(int x, int y) | ||
{ | ||
return grid[x][y]; | ||
} | ||
|
||
int **GetGrid() | ||
{ | ||
return grid; | ||
} | ||
|
||
|
||
//SECTION - Neighbours | ||
stack <Cell> CheckNeighbours(int target, int x, int y); | ||
|
||
bool isInVector(vector <Cell> v, Cell e); | ||
|
||
bool isInVector(vector <PathCell> v, PathCell e); | ||
|
||
void PrintNeighbours(stack <Cell> s); | ||
|
||
|
||
//SECTION - Moving | ||
bool AddTestMove(int playerIndex, int x, int y); | ||
|
||
bool AddMove(int playerIndex, int x, int y); | ||
|
||
bool IsValidInput(int x, int y); | ||
|
||
|
||
//SECTION - Win Checking | ||
int Evaluation(int player, int opponent); | ||
|
||
bool CheckForWin(int playerType); | ||
|
||
bool CheckLine(int playerType); | ||
|
||
bool DepthFirstSearch(int playerType); | ||
|
||
|
||
//SECTION - Other | ||
int MoveNumber() | ||
{ return (((boardSize * boardSize) - EmptySize()) + 1); } | ||
|
||
bool SetTurn(int playerType) | ||
{ | ||
turn = playerType; | ||
return true; | ||
} | ||
|
||
bool CanWin() | ||
{ | ||
if ((EmptySize() + (boardSize * 2 - 1)) <= (boardSize * boardSize)) | ||
return true; | ||
return false; | ||
} | ||
|
||
void printCoord(int x, int y, bool el); | ||
|
||
int GetTurn() | ||
{ | ||
return turn; | ||
} | ||
|
||
}; | ||
|
||
#endif //BOARD_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.