Question
Use the following pseudocode for a fully functional c++ program that implements the game of Tic Tac Toe. #include #include void display_board(const std::vector & board)
Use the following pseudocode for a fully functional c++ program that implements the game of Tic Tac Toe.
#include
void display_board(const std::vector
bool check_winner(const std::vector
bool is_full(const std::vector
int main() { std::vector
while (!is_full(board) && !check_winner(board, 'X') && !check_winner(board, 'O')) { display_board(board); std::cout << "Player " << player << ", enter row and column (0-2): "; std::cin >> row >> col;
while (row < 0 || row > 2 || col < 0 || col > 2 || board[row][col] != '-') { std::cout << "Invalid move. Try again: "; std::cin >> row >> col; }
board[row][col] = player; player = (player == 'X') ? 'O' : 'X'; }
display_board(board);
if (check_winner(board, 'X')) { std::cout << "Player X wins!" << std::endl; } else if (check_winner(board, 'O')) { std::cout << "Player O wins!" << std::endl; } else { std::cout << "It's a draw!" << std::endl; }
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started