Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#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;
bool 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;
return checkWin;
void computerMovebool playEven
int bestScore ;
int bestMoveRow ;
int bestMoveCol ;
for int i ; i ; i
for int j ; j ; j
if boardij
boardij playEven : ; Assuming even numbers represent user and odd numbers represent computer
int score minimaxfalse;
boardij;
if score bestScore
bestScore score;
bestMoveRow i;
bestMoveCol j;
boardbestMoveRowbestMoveCol playEven : ;
usedNumbers.insertbestMoveRow bestMoveCol ;
int evaluate
if checkWin
return boardFull : ;
return ;
int minimaxbool maximizingPlayer
int score evaluate;
if score return score;
if maximizingPlayer
int bestScore ;
for int i ; i ; i
for int j ; j ; j
if boardij
boardij; Computer's move
int currentScore minimaxfalse;
boardij;
bestScore maxbestScore currentScore;
return bestScore;
else
int bestScore ;
for int i ; i ; i
for int j ; j ; j
if boardij
boardij; User's move
int currentScore minimaxtrue;
boardij;
bestScore minbestScore currentScore;
return bestScore;
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;
if userMoveplayEven
cout "Congratulations! You win!" endl;
break;
else
Computer's turn
computerMoveplayEven;
displayBoard;
if checkWin
cout "Computer wins! Better luck next time." endl;
break;
if boardFull
cout "It's a draw!" endl;
break;
userTurn userTurn;
displayBoard;
Welcome to the SumUp Game!
Do you want to play with even numbers? yn: y
Your turn Enter the position ai and value: a
Process finished with exit code interrupted by signal : SIGSEGV
when i run this code i get that outcome, where when i type anything it just stops the code and says exit code could you fix it please
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