1#ifndef OBSTACLESTICTACTOE_H
2#define OBSTACLESTICTACTOE_H
14 vector<pair<int, int>> obstacles;
15 int moves_since_last_obstacle = 0;
17 void add_random_obstacle() {
22 }
while (
board[x][y] !=
' ' || is_obstacle(x, y));
24 obstacles.push_back({ x, y });
28 bool is_obstacle(
int x,
int y) {
29 for (
auto& obs : obstacles) {
30 if (obs.first == x && obs.second == y)
38 for (
int i = 0; i < 6; i++) {
39 for (
int j = 0; j < 6; j++) {
47 int x = move->
get_x();
48 int y = move->
get_y();
51 if (x < 0 || x >= 6 || y < 0 || y >= 6) {
52 cout <<
"Invalid position! Use 0-5.\n";
56 if (is_obstacle(x, y)) {
57 cout <<
"Cell is an obstacle!\n";
61 if (
board[x][y] !=
' ') {
62 cout <<
"Cell already occupied!\n";
68 moves_since_last_obstacle++;
71 if (moves_since_last_obstacle >= 2) {
72 for (
int i = 0; i < 2; i++) {
73 add_random_obstacle();
75 moves_since_last_obstacle = 0;
76 cout <<
"Two new obstacles added!\n";
87 for (
int i = 0; i < 6; i++) {
88 for (
int j = 0; j < 3; j++) {
89 if (
board[i][j] == symbol &&
board[i][j + 1] == symbol &&
90 board[i][j + 2] == symbol &&
board[i][j + 3] == symbol)
96 for (
int j = 0; j < 6; j++) {
97 for (
int i = 0; i < 3; i++) {
98 if (
board[i][j] == symbol &&
board[i + 1][j] == symbol &&
99 board[i + 2][j] == symbol &&
board[i + 3][j] == symbol)
105 for (
int i = 0; i < 3; i++) {
106 for (
int j = 0; j < 3; j++) {
107 if (
board[i][j] == symbol &&
board[i + 1][j + 1] == symbol &&
108 board[i + 2][j + 2] == symbol &&
board[i + 3][j + 3] == symbol)
113 for (
int i = 0; i < 3; i++) {
114 for (
int j = 3; j < 6; j++) {
115 if (
board[i][j] == symbol &&
board[i + 1][j - 1] == symbol &&
116 board[i + 2][j - 2] == symbol &&
board[i + 3][j - 3] == symbol)
130 for (
int i = 0; i < 6; i++) {
131 for (
int j = 0; j < 6; j++) {
132 if (
board[i][j] ==
' ') {
168 <<
"), enter your move (row and column 0-5): ";
175 cout << player->
get_name() <<
" chooses position (" << x <<
", " << y <<
")\n";
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
ObstaclesTicTacToe_Player(string name, char symbol)
Definition ObstaclesTicTacToe.h:148
ObstaclesTicTacToe_RandomPlayer(char symbol)
Definition ObstaclesTicTacToe.h:154
ObstaclesTicTacToe_UI()
Definition ObstaclesTicTacToe.h:162
Move< char > * get_move(Player< char > *player) override
Ask the user (or AI) to make a move.
Definition ObstaclesTicTacToe.h:164
bool is_win(Player< char > *player) override
Check if a player has won.
Definition ObstaclesTicTacToe.h:82
bool is_lose(Player< char > *player) override
Check if a player has lost.
Definition ObstaclesTicTacToe.h:124
bool game_is_over(Player< char > *player) override
Check if the game is over.
Definition ObstaclesTicTacToe.h:140
bool update_board(Move< char > *move) override
Update the board with a new move.
Definition ObstaclesTicTacToe.h:46
ObstaclesTicTacToeBoard()
Definition ObstaclesTicTacToe.h:37
bool is_draw(Player< char > *player) override
Check if the game ended in a draw.
Definition ObstaclesTicTacToe.h:128
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
UI(string message, int cell_display_width)
Definition BoardGame_Classes.h:196