16 set<string> dictionary;
18 void load_dictionary() {
19 ifstream file(
"dic.txt");
21 while (file >> word) {
22 transform(word.begin(), word.end(), word.begin(), ::toupper);
23 dictionary.insert(word);
28 string get_word(
int r1,
int c1,
int r2,
int c2,
int r3,
int c3) {
29 return string(1,
board[r1][c1]) +
30 string(1,
board[r2][c2]) +
31 string(1,
board[r3][c3]);
37 for (
int i = 0; i < 3; i++) {
38 for (
int j = 0; j < 3; j++) {
45 int x = move->
get_x();
46 int y = move->
get_y();
49 if (x < 0 || x >= 3 || y < 0 || y >= 3) {
50 cout <<
"Invalid position! Use 0-2.\n";
54 if (
board[x][y] !=
' ') {
55 cout <<
"Cell already occupied!\n";
59 if (!isalpha(symbol)) {
60 cout <<
"Invalid symbol! Use letters only.\n";
64 board[x][y] = toupper(symbol);
71 string lines[8][3] = {
72 {
"00",
"01",
"02"}, {
"10",
"11",
"12"}, {
"20",
"21",
"22"},
73 {
"00",
"10",
"20"}, {
"01",
"11",
"21"}, {
"02",
"12",
"22"},
74 {
"00",
"11",
"22"}, {
"02",
"11",
"20"}
77 for (
int i = 0; i < 8; i++) {
78 int r1 = lines[i][0][0] -
'0', c1 = lines[i][0][1] -
'0';
79 int r2 = lines[i][1][0] -
'0', c2 = lines[i][1][1] -
'0';
80 int r3 = lines[i][2][0] -
'0', c3 = lines[i][2][1] -
'0';
82 string word = get_word(r1, c1, r2, c2, r3, c3);
83 string rev_word = string(word.rbegin(), word.rend());
85 if (dictionary.find(word) != dictionary.end() ||
86 dictionary.find(rev_word) != dictionary.end()) {
131 <<
"), enter your move (row, column, and letter): ";
132 cin >> x >> y >> letter;
133 letter = toupper(letter);
139 char letter =
'A' + rand() % 26;
140 cout << player->
get_name() <<
" chooses position (" << x <<
", " << y
141 <<
") with letter " << letter <<
"\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
UI(string message, int cell_display_width)
Definition BoardGame_Classes.h:196
bool is_draw(Player< char > *player) override
Check if the game ended in a draw.
Definition wordTic_tac_toe.h:98
bool is_win(Player< char > *player) override
Check if a player has won.
Definition wordTic_tac_toe.h:69
bool game_is_over(Player< char > *player) override
Check if the game is over.
Definition wordTic_tac_toe.h:102
bool update_board(Move< char > *move) override
Update the board with a new move.
Definition wordTic_tac_toe.h:44
bool is_lose(Player< char > *player) override
Check if a player has lost.
Definition wordTic_tac_toe.h:94
word_Board()
Definition wordTic_tac_toe.h:35
word_Player(string name, char symbol)
Definition wordTic_tac_toe.h:110
word_Random_Player(char symbol)
Definition wordTic_tac_toe.h:116
word_UI()
Definition wordTic_tac_toe.h:124
Move< char > * get_move(Player< char > *player) override
Ask the user (or AI) to make a move.
Definition wordTic_tac_toe.h:126