Question: #include #include #include #include #include using namespace std; vector > board = { { 0 , 0 , 0 } , { 0 , 0
#include
#include
#include
#include
#include
using namespace std;
vector board
;
unorderedset usedNumbers;
void displayBoard
for const auto& row : board
for int value : row
cout value ;
cout endl;
bool checkWin
Check rows and columns
for int i ; i ; i
int rowSum ;
int colSum ;
for int j ; j ; j
rowSum boardij;
colSum boardji;
if rowSum colSum
return true;
Check diagonals
int diag board board board;
int diag board board board;
if diag diag
return true;
return false;
bool boardFull
for const auto& row : board
for int value : row
if value
return false;
return true;
void userMovebool playEven
char rowLetter;
int value;
bool validInput false;
while validInput
cout "Your turn Enter the position ai and value: ;
cin rowLetter value;
if usedNumberscountvalue rowLetter a rowLetter i value value playEven && value playEven && value
cout "Invalid move. Please try again." endl;
else
int row rowLetter a;
int col rowLetter a;
if boardrowcol
cout "Spot already occupied. Please try again." endl;
else
boardrowcol value;
usedNumbers.insertvalue;
validInput true;
void computerMovebool playEven
int value;
bool validMove false;
while validMove
value rand; Random number between and
if usedNumberscountvalue && playEven && value playEven && value
int row, col;
do
row rand;
col rand;
while boardrowcol;
boardrowcol value;
usedNumbers.insertvalue;
validMove true;
int main
srandtime;
cout "Welcome to the SumUp Game!" endl;
char playerChoice;
cout Do you want to play with even numbers? yn: ;
cin playerChoice;
bool playEven playerChoice y playerChoice Y;
bool userTurn true;
while true
Player's turn
if userTurn
displayBoard;
userMoveplayEven; If playEven is true, user should play odd numbers, and vice versa
if checkWin
cout "Congratulations! You win!" endl;
break;
else Computer's turn
computerMoveplayEven; If playEven is true, computer should play odd numbers, and vice versa
if checkWin
cout "Computer wins! Better luck next time." endl;
break;
if boardFull
cout "It's a draw!" endl;
break;
userTurn userTurn;
displayBoard;
return ;
modify this code by adding an AI algorith so that the code plays the best move rather than a random move. you can use stuufs like minimax algorithm. C
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
