40 }
while (board_matrix[x][y] !=
' ');
42 cout <<
"\nComputer played at (" << x <<
"," << y <<
")\n";
48 cout <<
"\n" << p->
get_name() <<
" enter row and column [0-3]: ";
51 if (x < 0 || x > 3 || y < 0 || y > 3) {
52 cout <<
"Invalid cell. Please enter values between 0-3.\n";
57 if (board_matrix[x][y] !=
' ') {
58 cout <<
"Box already occupied. Choose another Box.\n";
74 for (
auto& row :
board) {
75 for (
auto& cell : row) {
83 int x = move->
get_x();
84 int y = move->
get_y();
92 if (
board[x][y] !=
' ') {
105 for (
int i = 0; i < 4; i++) {
106 if (
board[i][0] == symbol &&
board[i][1] == symbol &&
107 board[i][2] == symbol &&
board[i][3] == symbol) {
113 for (
int j = 0; j < 4; j++) {
114 if (
board[0][j] == symbol &&
board[1][j] == symbol &&
115 board[2][j] == symbol &&
board[3][j] == symbol) {
121 if (
board[0][0] == symbol &&
board[1][1] == symbol &&
122 board[2][2] == symbol &&
board[3][3] == symbol) {
125 if (
board[0][3] == symbol &&
board[1][2] == symbol &&
126 board[2][1] == symbol &&
board[3][0] == symbol) {
135 for (
int i = 0; i <
rows; i++) {
136 for (
int j = 0; j <
columns; j++) {
137 if (
board[i][j] ==
' ') {
PlayerType
Represents the type of player in the game.
Definition BoardGame_Classes.h:24
@ COMPUTER
A computer-controlled player.
Definition BoardGame_Classes.h:26
int n_moves
Definition BoardGame_Classes.h:45
int rows
Definition BoardGame_Classes.h:42
Board(int rows, int columns)
Definition BoardGame_Classes.h:51
vector< vector< char > > board
Definition BoardGame_Classes.h:44
int columns
Definition BoardGame_Classes.h:43
Represents a single move in a board game.
Definition BoardGame_Classes.h:100
T get_symbol() const
Get the move symbol.
Definition BoardGame_Classes.h:116
int get_y() const
Get column index.
Definition BoardGame_Classes.h:113
int get_x() const
Get row index.
Definition BoardGame_Classes.h:110
Base template for all players (human or AI).
Definition BoardGame_Classes.h:126
char symbol
Definition BoardGame_Classes.h:130
PlayerType get_type() const
Get player type (e.g., 'H' or 'C').
Definition BoardGame_Classes.h:147
Board< T > * get_board_ptr() const
Get a pointer to the game board.
Definition BoardGame_Classes.h:153
PlayerType type
Definition BoardGame_Classes.h:129
Player(string n, char s, PlayerType t)
Definition BoardGame_Classes.h:137
string get_name() const
Get the player's name.
Definition BoardGame_Classes.h:144
string name
Definition BoardGame_Classes.h:128
T get_symbol() const
Get the player's symbol.
Definition BoardGame_Classes.h:150
bool update_board(Move< char > *move) override
Update the board with a new move.
Definition TicTacToe4x4.h:82
bool is_draw(Player< char > *player) override
Check if the game ended in a draw.
Definition TicTacToe4x4.h:133
bool is_lose(Player< char > *player) override
Check if a player has lost.
Definition TicTacToe4x4.h:145
TicTacToe4x4_Board()
Definition TicTacToe4x4.h:72
bool is_win(Player< char > *player) override
Check if a player has won.
Definition TicTacToe4x4.h:101
bool game_is_over(Player< char > *player) override
Check if the game is over.
Definition TicTacToe4x4.h:149
Definition TicTacToe4x4.h:18
TicTacToe4x4_Player(string name, char symbol, PlayerType type)
Definition TicTacToe4x4.h:20
Move< char > * get_move(Player< char > *p) override
Ask the user (or AI) to make a move.
Definition TicTacToe4x4.h:28
Player< char > * create_player(string &name, char symbol, PlayerType type) override
Create a player object based on input name, symbol, and type.
Definition TicTacToe4x4.h:66
TicTacToe4x4_UI()
Definition TicTacToe4x4.h:26
UI(string message, int cell_display_width)
Definition BoardGame_Classes.h:196