TicTacToe.cpp
// This function is used to assign the values
/*
Arbitary value usage:
since I have used maps it would need an iterator to access those X and O characters
which would make code lengthy so I have came with a mathematical approach for solving this TicTacToe
by assuming an arbitary values to the players
Player1 = 20
Player2 = 10
*/
This function is used to assign the values
Arbitary value usage:
since I have used maps it would need an iterator to access those X and O characters
which would make code lengthy so I have came with a mathematical approach for solving this TicTacToe
by assuming an arbitary values to the players
Player1 = 20
Player2 = 10
This function is used to assign the values Arbitary value usage : since I have used maps it would need an iterator to access those X and O characters which would make code lengthy so I have came with a mathematical approach for solving this TicTacToe by assuming an arbitary values to the players Player1 = 20 Player2 = 10
void TicTacToe::assign()
{
	for (int i = 0; i < 9; i++)
	{
		int tempVariable;
		bool surity1 = false; 
		bool surity2 = false;
		while (surity1 != true) {
			cout << "Player 1: Enter your no" << endl;
			cin >> tempVariable;
			bool add = check(tempVariable, choice1);
			if (add == true)
			{
				player_choices[tempVariable] = 20; 
				surity1 = true;
			}
		}
		cout << endl << endl << "Player 2\'s Choice" << endl;
		while (surity2 != true) {
			cout << "Player 2: Enter your no" << endl;
			cin >> tempVariable;
			bool add = check(tempVariable, choice2);
			if (add == true) {
				player_choices[tempVariable] = 10; 
				surity2 = true;
			}
		}
		if ((player_choices[0] == 20) && (player_choices[1] == 20) && (player_choices[2] == 20))
		{
			cout << "Player 1 is the Winner";
			winp1 = true;
			break;
		}
		else if ((player_choices[3] == 20) && (player_choices[4] == 20) && (player_choices[5] == 20))
		{
			cout << "Player 1 is the Winner";
			winp1 = true;
			break;
		}
		else if ((player_choices[6] == 20) && (player_choices[7] == 20) && (player_choices[8] == 20))
		{
			cout << "Player 1 is the Winner";
			winp1 = true;
			break;
		}
		else if ((player_choices[0] == 20) && (player_choices[3] == 20) && (player_choices[6] == 20))
		{
			cout << "Player 1 is the Winner";
			winp1 = true;
			break;
		}
		else if ((player_choices[1] == 20) && (player_choices[4] == 20) && (player_choices[7] == 20))
		{
			cout << "Player 1 is the Winner";
			winp1 = true;
			break;
		}
		else if ((player_choices[2] == 20) && (player_choices[7] == 20) && (player_choices[8] == 20))
		{
			cout << "Player 1 is the Winner";
			winp1 = true;
			break;
		}
		else if ((player_choices[0] == 20) && (player_choices[4] == 20) && (player_choices[8] == 20))
		{
			cout << "Player 1 is the Winner";
			winp1 = true;
			break;
		}
		else if ((player_choices[2] == 20) && (player_choices[4] == 20) && (player_choices[6] == 20))
		{
			cout << "Player 1 is the Winner";
			winp1 = true;
			break;
		}
		else
		{
			cout << endl;
		}
		if ((player_choices[0] == 10) && (player_choices[1] == 10) && (player_choices[2] == 10))
		{
			cout << "Player 2 is the Winner";
			winp2 = true;
			break;
		}
		else if ((player_choices[3] == 10) && (player_choices[4] == 10) && (player_choices[5] == 10))
		{
			cout << "Player 2 is the Winner";
			winp2 = true;
			break;
		}
		else if ((player_choices[6] == 10) && (player_choices[7] == 10) && (player_choices[8] == 10))
		{
			cout << "Player 2 is the Winner";
			winp2 = true;
			break;
		}
		else if ((player_choices[0] == 10) && (player_choices[3] == 10) && (player_choices[6] == 10))
		{
			cout << "Player 2 is the Winner";
			winp2 = true;
			break;
		}
		else if ((player_choices[1] == 10) && (player_choices[4] == 10) && (player_choices[7] == 10))
		{
			cout << "Player 2 is the Winner";
			winp2 = true;
			break;
		}
		else if ((player_choices[2] == 10) && (player_choices[5] == 10) && (player_choices[8] == 10))
		{
			cout << "Player 2 is the Winner";
			winp2 = true;
			break;
		}
		else if ((player_choices[0] == 10) && (player_choices[4] == 10) && (player_choices[8] == 10))
		{
			cout << "Player 2 is the Winner";
			winp2 = true;
			break;
		}
		else if ((player_choices[2] == 10) && (player_choices[4] == 10) && (player_choices[6] == 10))
		{
			cout << "Player 2 is the Winner";
			winp2 = true;
			break;
		}
		else
		{
			cout << endl;
		}
		if (i == 8) {
			if ((winp1 == false) && (winp2 == false))
			{
				cout << "Draw match!" << endl;
			}
		}
	}
}
void TicTacToe :: assign ( ) { for ( int i = 0 ; i < 9 ; i ++ ) { int tempVariable ; bool surity1 = false ; bool surity2 = false ; while ( surity1 != true ) { cout << " " << endl ; cin >> tempVariable ; bool add = check ( tempVariable , choice1 ) ; if ( add == true ) { player_choices [ tempVariable ] = 20 ; surity1 = true ; } } cout << endl << endl << " \' " << endl ; while ( surity2 != true ) { cout << " " << endl ; cin >> tempVariable ; bool add = check ( tempVariable , choice2 ) ; if ( add == true ) { player_choices [ tempVariable ] = 10 ; surity2 = true ; } } if ( ( player_choices [ 0 ] == 20 ) && ( player_choices [ 1 ] == 20 ) && ( player_choices [ 2 ] == 20 ) ) { cout << " " ; winp1 = true ; break ; } else if ( ( player_choices [ 3 ] == 20 ) && ( player_choices [ 4 ] == 20 ) && ( player_choices [ 5 ] == 20 ) ) { cout << " " ; winp1 = true ; break ; } else if ( ( player_choices [ 6 ] == 20 ) && ( player_choices [ 7 ] == 20 ) && ( player_choices [ 8 ] == 20 ) ) { cout << " " ; winp1 = true ; break ; } else if ( ( player_choices [ 0 ] == 20 ) && ( player_choices [ 3 ] == 20 ) && ( player_choices [ 6 ] == 20 ) ) { cout << " " ; winp1 = true ; break ; } else if ( ( player_choices [ 1 ] == 20 ) && ( player_choices [ 4 ] == 20 ) && ( player_choices [ 7 ] == 20 ) ) { cout << " " ; winp1 = true ; break ; } else if ( ( player_choices [ 2 ] == 20 ) && ( player_choices [ 7 ] == 20 ) && ( player_choices [ 8 ] == 20 ) ) { cout << " " ; winp1 = true ; break ; } else if ( ( player_choices [ 0 ] == 20 ) && ( player_choices [ 4 ] == 20 ) && ( player_choices [ 8 ] == 20 ) ) { cout << " " ; winp1 = true ; break ; } else if ( ( player_choices [ 2 ] == 20 ) && ( player_choices [ 4 ] == 20 ) && ( player_choices [ 6 ] == 20 ) ) { cout << " " ; winp1 = true ; break ; } else { cout << endl ; } if ( ( player_choices [ 0 ] == 10 ) && ( player_choices [ 1 ] == 10 ) && ( player_choices [ 2 ] == 10 ) ) { cout << " " ; winp2 = true ; break ; } else if ( ( player_choices [ 3 ] == 10 ) && ( player_choices [ 4 ] == 10 ) && ( player_choices [ 5 ] == 10 ) ) { cout << " " ; winp2 = true ; break ; } else if ( ( player_choices [ 6 ] == 10 ) && ( player_choices [ 7 ] == 10 ) && ( player_choices [ 8 ] == 10 ) ) { cout << " " ; winp2 = true ; break ; } else if ( ( player_choices [ 0 ] == 10 ) && ( player_choices [ 3 ] == 10 ) && ( player_choices [ 6 ] == 10 ) ) { cout << " " ; winp2 = true ; break ; } else if ( ( player_choices [ 1 ] == 10 ) && ( player_choices [ 4 ] == 10 ) && ( player_choices [ 7 ] == 10 ) ) { cout << " " ; winp2 = true ; break ; } else if ( ( player_choices [ 2 ] == 10 ) && ( player_choices [ 5 ] == 10 ) && ( player_choices [ 8 ] == 10 ) ) { cout << " " ; winp2 = true ; break ; } else if ( ( player_choices [ 0 ] == 10 ) && ( player_choices [ 4 ] == 10 ) && ( player_choices [ 8 ] == 10 ) ) { cout << " " ; winp2 = true ; break ; } else if ( ( player_choices [ 2 ] == 10 ) && ( player_choices [ 4 ] == 10 ) && ( player_choices [ 6 ] == 10 ) ) { cout << " " ; winp2 = true ; break ; } else { cout << endl ; } if ( i == 8 ) { if ( ( winp1 == false ) && ( winp2 == false ) ) { cout << " " << endl ; } } } }
This function is used to assign the values
Arbitary value usage:
since I have used maps it would need an iterator to access those X and O characters
which would make code lengthy so I have came with a mathematical approach for solving this TicTacToe
by assuming an arbitary values to the players
Player1 = 20
Player2 = 10
This function is used to assign the values Arbitary value usage : since I have used maps it would need an iterator to access those X and O characters which would make code lengthy so I have came with a mathematical approach for solving this TicTacToe by assuming an arbitary values to the players Player1 = 20 Player2 = 10
// This will make sure non-duplicated entry is enterd!
 // arbitary value
 // arbitary value
 //For each entry there may be winning or loosing and it must be announted!
 //Linear lines - Vertical
 // Diagonal
 /*
		============================For Player 2======================================
		*/ //Linear lines - Vertical
 // Diagonal
