11 cout <<
"\nColumns: ";
12 for (
int c = 0; c < (int)b[0].size(); ++c) cout << c <<
' ';
13 cout <<
"\n---------------------\n";
14 for (
int r = 0; r < (int)b.size(); ++r) {
15 for (
int c = 0; c < (int)b[r].size(); ++c) {
17 cout << (ch ==
' ' ?
'.' : ch) <<
' ';
36 vector<int> validCols;
38 if (matrix[0][c] ==
' ') validCols.push_back(c);
41 static std::mt19937 rng((
unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
42 std::uniform_int_distribution<int> dist(0, (
int)validCols.size() - 1);
43 int col = validCols[dist(rng)];
44 cout <<
"Computer " << p->
get_name() <<
" plays column " << col <<
'\n';
51 if (!(cin >> col)) { cin.clear();
string garbage; getline(cin, garbage); cout <<
"Invalid input\n";
continue; }
52 if (col < 0 || col >= bptr->
get_columns()) { cout <<
"Column out of range\n";
continue; }
53 if (matrix[0][col] !=
' ') { cout <<
"Column full. Choose another.\n";
continue; }
PlayerType
Represents the type of player in the game.
Definition BoardGame_Classes.h:24
@ COMPUTER
A computer-controlled player.
Definition BoardGame_Classes.h:26
vector< vector< T > > get_board_matrix() const
Return a copy of the current board as a 2D vector.
Definition BoardGame_Classes.h:82
int get_columns() const
Get number of columns.
Definition BoardGame_Classes.h:90
Move< char > * get_move(Player< char > *p) override
Ask the user (or AI) to make a move.
Definition FourUI.h:23
FourUI()
Definition FourUI.h:9
Player< char > * create_player(string &name, char symbol, PlayerType type) override
Create a player object based on input name, symbol, and type.
Definition FourUI.h:58
void print_board(const vector< vector< char > > &b)
Definition FourUI.h:10
Represents a single move in a board game.
Definition BoardGame_Classes.h:100
Base template for all players (human or AI).
Definition BoardGame_Classes.h:126
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
string get_name() const
Get the player's name.
Definition BoardGame_Classes.h:144
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