13 bool is_valid_position(
int x,
int y) {
14 if (x < 0 || x >= 3 || y < 0 || y >= 5)
return false;
15 int start = (5 - (2 * x + 1)) / 2;
16 int end = start + (2 * x + 1);
17 return (y >= start && y < end);
22 for (
int i = 0; i < 3; i++) {
23 for (
int j = 0; j < 5; j++) {
24 if (is_valid_position(i, j)) {
35 int x = move->
get_x();
36 int y = move->
get_y();
39 if (!is_valid_position(x, y)) {
40 cout <<
"Invalid position! Not in pyramid shape.\n";
44 if (
board[x][y] !=
'.') {
45 cout <<
"Cell already occupied!\n";
58 if (
board[0][2] == symbol &&
board[1][2] == symbol &&
board[2][2] == symbol)
62 for (
int i = 0; i < 3; i++) {
63 int start = (5 - (2 * i + 1)) / 2;
64 int end = start + (2 * i + 1);
65 for (
int j = start; j <= end - 3; j++) {
66 if (
board[i][j] == symbol &&
board[i][j + 1] == symbol &&
board[i][j + 2] == symbol)
72 if (
board[0][2] == symbol &&
board[1][1] == symbol &&
board[2][0] == symbol)
74 if (
board[0][2] == symbol &&
board[1][3] == symbol &&
board[2][4] == symbol)
89 for (
int i = 0; i < 3; i++) {
90 for (
int j = 0; j < 5; j++) {
91 if (
board[i][j] !=
'#') {
93 if (
board[i][j] !=
'.') {
100 return (filled_cells == valid_cells && !
is_win(player));
131 <<
"), enter your move (row 0-2, column 0-4 in pyramid shape): ";
140 }
while (!is_valid_pyramid_position(x, y));
142 cout << player->
get_name() <<
" chooses position (" << x <<
", " << y <<
")\n";
148 bool is_valid_pyramid_position(
int x,
int y) {
149 int start = (5 - (2 * x + 1)) / 2;
150 int end = start + (2 * x + 1);
151 return (x >= 0 && x < 3 && y >= start && y < end);
PlayerType
Represents the type of player in the game.
Definition BoardGame_Classes.h:24
@ HUMAN
A human player.
Definition BoardGame_Classes.h:25
@ COMPUTER
A computer-controlled player.
Definition BoardGame_Classes.h:26
int n_moves
Definition BoardGame_Classes.h:45
Board(int rows, int columns)
Definition BoardGame_Classes.h:51
vector< vector< char > > board
Definition BoardGame_Classes.h:44
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
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 game_is_over(Player< char > *player) override
Check if the game is over.
Definition Pyramic_XO.h:103
bool update_board(Move< char > *move) override
Update the board with a new move.
Definition Pyramic_XO.h:34
Pyramic_XO_Board()
Definition Pyramic_XO.h:21
bool is_lose(Player< char > *player) override
Check if a player has lost.
Definition Pyramic_XO.h:80
bool is_win(Player< char > *player) override
Check if a player has won.
Definition Pyramic_XO.h:54
bool is_draw(Player< char > *player) override
Check if the game ended in a draw.
Definition Pyramic_XO.h:84
Pyramic_XO_Player(string name, char symbol)
Definition Pyramic_XO.h:111
Pyramic_XO_RandomPlayer(char symbol)
Definition Pyramic_XO.h:117
Pyramic_XO_UI()
Definition Pyramic_XO.h:125
Move< char > * get_move(Player< char > *player) override
Ask the user (or AI) to make a move.
Definition Pyramic_XO.h:127
UI(string message, int cell_display_width)
Definition BoardGame_Classes.h:196