Question
You must use the GIVEN code and ADD onto it the following four instructions in BOLD. Using the code below, fix or add the following
You must use the GIVEN code and ADD onto it the following four instructions in BOLD.
Using the code below, fix or add the following four steps:
1. (bug) A tie game does NOT finish the game. Correct this.
2. (feature) Transform the game from player vs. player (PvP) only to player vs. player and player vs. a machine (PvM). The user can have an option to select which type before a game starts. The machine runs at least as smart as a random function on picking the next move (i.e. random spot selection)
3. (feature) A game ends when the user enters quit or whoever wins three consecutive games. A user can select to play again, a new fresh start. Each time someone wins they recieve $100,000 The winner can cash a $300,000, for three consecutive wins, then stop, or continue and cash $600,000 at six consecutive wins, stop or continue to nine consecutive wins and cash $900,000, and win $1,000,000 at ten wins. Game will end at ten consecutive wins, no more.
4. (feature) Add wins and ties counters for each player (PvP or PvM).
-------tic-tac-toe.cpp----------------------------------------------------------------------------------------------
/** Simple Tic Tac Toe tictactoe-v0.9.cpp Source: http://paste4btc.com/enVArEWu */ #includeusing namespace std; char matrix[3][3] = { '1', '2', '3', '4', '5', '6', '7', '8', '9' }; char player = 'X'; char Win() { int x = 0; if(x == 0){ //first player if (matrix[0][0] == 'X' && matrix[0][1] == 'X' && matrix[0][2] == 'X') return 'X'; if (matrix[1][0] == 'X' && matrix[1][1] == 'X' && matrix[1][2] == 'X') return 'X'; if (matrix[2][0] == 'X' && matrix[2][1] == 'X' && matrix[2][2] == 'X') return 'X'; if (matrix[0][0] == 'X' && matrix[1][0] == 'X' && matrix[2][0] == 'X') return 'X'; if (matrix[0][1] == 'X' && matrix[1][1] == 'X' && matrix[2][1] == 'X') return 'X'; if (matrix[0][2] == 'X' && matrix[1][2] == 'X' && matrix[2][2] == 'X') return 'X'; if (matrix[0][0] == 'X' && matrix[1][1] == 'X' && matrix[2][2] == 'X') return 'X'; if (matrix[2][0] == 'X' && matrix[1][1] == 'X' && matrix[0][2] == 'X') return 'X'; //second player if (matrix[0][0] == 'O' && matrix[0][1] == 'O' && matrix[0][2] == 'O') return 'O'; if (matrix[1][0] == 'O' && matrix[1][1] == 'O' && matrix[1][2] == 'O') return 'O'; if (matrix[2][0] == 'O' && matrix[2][1] == 'O' && matrix[2][2] == 'O') return 'O'; if (matrix[0][0] == 'O' && matrix[1][0] == 'O' && matrix[2][0] == 'O') return 'O'; if (matrix[0][1] == 'O' && matrix[1][1] == 'O' && matrix[2][1] == 'O') return 'O'; if (matrix[0][2] == 'O' && matrix[1][2] == 'O' && matrix[2][2] == 'O') return 'O'; if (matrix[0][0] == 'O' && matrix[1][1] == 'O' && matrix[2][2] == 'O') return 'O'; if (matrix[2][0] == 'O' && matrix[1][1] == 'O' && matrix[0][2] == 'O') return 'O'; else x = 1; } if(x == 1){ return 'N'; } return '/'; } int main() { //Draw cout << string( 100, ' ' ); cout << "TicTacToe v0.9" << endl; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cout << matrix[i][j] << " "; } cout << endl; } while (1) { //Input int a; cout << "Press the number of the field: "; cin >> a; // if(a != 1 || a != 2|| a != 3|| a != 4|| a != 5|| a != 6|| a != 7|| a != 8|| a != 9){ //return 0; //} if (a == 1){ if(matrix[0][0] == 'X' || matrix[0][0] == 'O'){ cout << "Cannot move there. Player already exists, choose again." << endl; if (player == 'X') player = 'X'; else player = 'O'; } else{ matrix[0][0] = player; if (player == 'X') player = 'O'; else player = 'X'; } } else if (a == 2) if(matrix[0][1] == 'X' || matrix[0][1] == 'O'){ cout << "Cannot move there. Player already exists, choose again." << endl; if (player == 'X') player = 'X'; else player = 'O'; } else{ matrix[0][1] = player; if (player == 'X') player = 'O'; else player = 'X'; } else if (a == 3) if(matrix[0][2] == 'X' || matrix[0][2] == 'O'){ cout << "Cannot move there. Player already exists, choose again." << endl; if (player == 'X') player = 'X'; else player = 'O'; } else{ matrix[0][2] = player; if (player == 'X') player = 'O'; else player = 'X'; } else if (a == 4) if(matrix[1][0] == 'X' || matrix[1][0] == 'O'){ cout << "Cannot move there. Player already exists, choose again." << endl; if (player == 'X') player = 'X'; else player = 'O'; } else{ matrix[1][0] = player; if (player == 'X') player = 'O'; else player = 'X'; } else if (a == 5) if(matrix[1][1] == 'X' || matrix[1][1] == 'O'){ cout << "Cannot move there. Player already exists, choose again." << endl; if (player == 'X') player = 'X'; else player = 'O'; } else{ matrix[1][1] = player; if (player == 'X') player = 'O'; else player = 'X'; } else if (a == 6) if(matrix[1][2] == 'X' || matrix[1][2] == 'O'){ cout << "Cannot move there. Player already exists, choose again." << endl; if (player == 'X') player = 'X'; else player = 'O'; } else{ matrix[1][2] = player; if (player == 'X') player = 'O'; else player = 'X'; } else if (a == 7) if(matrix[2][0] == 'X' || matrix[2][0] == 'O'){ cout << "Cannot move there. Player already exists, choose again." << endl; if (player == 'X') player = 'X'; else player = 'O'; } else{ matrix[2][0] = player; if (player == 'X') player = 'O'; else player = 'X'; } else if (a == 8) if(matrix[2][1] == 'X' || matrix[2][1] == 'O'){ cout << "Cannot move there. Player already exists, choose again." << endl; if (player == 'X') player = 'X'; else player = 'O'; } else{ matrix[2][1] = player; if (player == 'X') player = 'O'; else player = 'X'; } else if (a == 9) if(matrix[2][2] == 'X' || matrix[2][2] == 'O'){ cout << "Cannot move there. Player already exists, choose again." << endl; if (player == 'X') player = 'X'; else player = 'O'; } else{ matrix[2][2] = player; if (player == 'X') player = 'O'; else player = 'X'; } //Draw cout << string( 100, ' ' ); cout << "tictactoe v0.9" << endl; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cout << matrix[i][j] << " "; } cout << endl; } if (Win() == 'X') { cout << "X wins!" << endl; break; } else if (Win() == 'O') { cout << "O wins!" << endl; break; } else if(Win() == 'N'){ cout << "It was a tie!" << endl; break; } //TogglePlayer /* if (player == 'X') player = 'O'; else player = 'X'; */ } 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