C Program TIC TAC TOE using vectors Implement a tictactoe ga

C++ Program TIC TAC TOE using vectors

Implement a tic-tac-toe game. At the bottom of these specifications you will see a template you must copy and paste to cloud9. Do not change the provided complete functions, or the function stub headers / return values.

Currently, if the variables provided in main are commented out, the program will compile. Complete the specifications for each function. As you develop the program, implement one function at a time, and test that function. The provided comments provide hints as to what each function should do and when each should be called. Add variables where you see fit.

Implementation Strategies:

The template has variables and two global constants for you to utilize.

The template has string literals for winning or tie game output in comments with provided file.

The template has comments to help you develop the necessary algorithm for 2 users playing tic-tac-toe on a computer. Use these comments along with the function descriptions below to help develop your program. One or more lines of your code should exist below each comment. Remove the TODO part when you have completed that step.

DO NOT try to implement the entire game at once. Instead, develop and test one function at a time. Understand how to walk through your code by hand as well as executing it in unit tests.

The system will test your functions as you attempt to complete each. Use the feedback and walk through your code to fix problems.

Submit and achieve a full score on each function before implementing the main game algorithm.

Tie Game Example:

Starting Template:

Solution

Answer:

#include <iostream>

using namespace std;

char input[10] = {\'o\',\'1\',\'2\',\'3\',\'4\',\'5\',\'6\',\'7\',\'8\',\'9\'};

int checkwinner();
void displayboard();

int main()
{
int player = 1,i,option;

char enable;
do
{
displayboard();
player=(player%2)?1:2;

cout << \"Player \" << player << \", enter a number: \";
cin >> option;

enable=(player == 1) ? \'X\' : \'O\';

if (option == 1 && input[1] == \'1\')

input[1] = enable;
else if (option == 2 && input[2] == \'2\')

input[2] = enable;
else if (option == 3 && input[3] == \'3\')

input[3] = enable;
else if (option == 4 && input[4] == \'4\')

input[4] = enable;
else if (option == 5 && input[5] == \'5\')

input[5] = enable;
else if (option == 6 && input[6] == \'6\')

input[6] = enable;
else if (option == 7 && input[7] == \'7\')

input[7] = enable;
else if (option == 8 && input[8] == \'8\')

input[8] = enable;
else if (option == 9 && input[9] == \'9\')

input[9] = enable;
else
{
cout<<\"Invalid move \";

player--;
cin.ignore();
cin.get();
}
i=checkwinner();

player++;
}while(i==-1);
displayboard();
if(i==1)

cout<<\"==>\\aPlayer \"<<--player<<\" win \";
else
cout<<\"==>\\aGame draw\";

cin.ignore();
cin.get();
return 0;
}


int checkwinner()
{
if (input[1] == input[2] && input[2] == input[3])

return 1;
else if (input[4] == input[5] && input[5] == input[6])

return 1;
else if (input[7] == input[8] && input[8] == input[9])

return 1;
else if (input[1] == input[4] && input[4] == input[7])

return 1;
else if (input[2] == input[5] && input[5] == input[8])

return 1;
else if (input[3] == input[6] && input[6] == input[9])

return 1;
else if (input[1] == input[5] && input[5] == input[9])

return 1;
else if (input[3] == input[5] && input[5] == input[7])

return 1;
else if (input[1] != \'1\' && input[2] != \'2\' && input[3] != \'3\'
&& input[4] != \'4\' && input[5] != \'5\' && input[6] != \'6\'
&& input[7] != \'7\' && input[8] != \'8\' && input[9] != \'9\')

return 0;
else
return -1;
}

void displayboard()
{
system(\"cls\");
cout << \"\ \ \\tTic Tac Toe\ \ \";

cout << \"Player 1 (X) - Player 2 (O)\" << endl << endl;
cout << endl;

cout << \" | | \" << endl;
cout << \" \" << input[1] << \" | \" << input[2] << \" | \" << input[3] << endl;

cout << \"_____|_____|_____\" << endl;
cout << \" | | \" << endl;

cout << \" \" << input[4] << \" | \" << input[5] << \" | \" << input[6] << endl;

cout << \"_____|_____|_____\" << endl;
cout << \" | | \" << endl;

cout << \" \" << input[7] << \" | \" << input[8] << \" | \" << input[9] << endl;

cout << \" | | \" << endl << endl;
}

C++ Program TIC TAC TOE using vectors Implement a tic-tac-toe game. At the bottom of these specifications you will see a template you must copy and paste to clo
C++ Program TIC TAC TOE using vectors Implement a tic-tac-toe game. At the bottom of these specifications you will see a template you must copy and paste to clo
C++ Program TIC TAC TOE using vectors Implement a tic-tac-toe game. At the bottom of these specifications you will see a template you must copy and paste to clo

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site