13 int count_SUS_sequences(
char symbol) {
15 string target =
"SUS";
18 for (
int i = 0; i < 3; i++) {
20 for (
int j = 0; j < 3; j++) row +=
board[i][j];
21 if (row == target) count++;
25 for (
int j = 0; j < 3; j++) {
27 for (
int i = 0; i < 3; i++) col +=
board[i][j];
28 if (col == target) count++;
32 string diag1 = string(1,
board[0][0]) + string(1,
board[1][1]) + string(1,
board[2][2]);
33 string diag2 = string(1,
board[0][2]) + string(1,
board[1][1]) + string(1,
board[2][0]);
34 if (diag1 == target) count++;
35 if (diag2 == target) count++;
42 for (
int i = 0; i < 3; i++) {
43 for (
int j = 0; j < 3; j++) {
50 int x = move->
get_x();
51 int y = move->
get_y();
54 if (x < 0 || x >= 3 || y < 0 || y >= 3) {
55 cout <<
"Invalid position! Use 0-2.\n";
59 if (
board[x][y] !=
' ') {
60 cout <<
"Cell already occupied!\n";
64 if (symbol !=
'S' && symbol !=
'U') {
65 cout <<
"Invalid symbol! Use only S or U.\n";
92 int x_score = count_SUS_sequences(
'X');
93 int o_score = count_SUS_sequences(
'O');
94 return make_pair(x_score, o_score);
122 <<
"), enter your move (row, column, and S/U): ";
123 cin >> x >> y >> symbol;
124 symbol = toupper(symbol);
130 char symbol = (rand() % 2 == 0) ?
'S' :
'U';
131 cout << player->
get_name() <<
" chooses position (" << x <<
", " << y
132 <<
") with symbol " << symbol <<
"\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
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 is_win(Player< char > *player) override
Check if a player has won.
Definition SUS.h:74
bool update_board(Move< char > *move) override
Update the board with a new move.
Definition SUS.h:49
bool is_lose(Player< char > *player) override
Check if a player has lost.
Definition SUS.h:79
SUS_Board()
Definition SUS.h:41
pair< int, int > get_scores()
Definition SUS.h:91
bool game_is_over(Player< char > *player) override
Check if the game is over.
Definition SUS.h:87
bool is_draw(Player< char > *player) override
Check if the game ended in a draw.
Definition SUS.h:83
SUS_Player(string name, char symbol)
Definition SUS.h:101
SUS_Random_Player(char symbol)
Definition SUS.h:107
Move< char > * get_move(Player< char > *player) override
Ask the user (or AI) to make a move.
Definition SUS.h:117
SUS_UI()
Definition SUS.h:115
UI(string message, int cell_display_width)
Definition BoardGame_Classes.h:196