Ejemplo n.º 1
0
// method for checking end of game (win or draw)
BOOL Game::CheckEndGame()
{
	if (CheckWinner())
		return TRUE;
	if (CheckDraw())
		return TRUE;
	return FALSE;
}
int CheckStatus(int b[9])
{
	int status;

	status=CheckWin(b);
	if(status==1)
		{
			return 1;
		}

	status=CheckLose(b);
	if(status==(-1))
		{
			return -1;
		}

	status=CheckDraw(b);
	if(status==1)
		{
			return 0;
		}

	return 20;
}
void main()
{
	clrscr();
			 int pos;
			 char choice;
			 int legal;
			 
			 cout<<"Do You Want Me to Start?\nChoice(y/n):";					//Who plays the first move?
			 cin>>choice;

			 DisplayBoard(a);

			 switch(choice)
			 {

				case 'y':
					{

						while(move<5)			//First one to move would make a maximum of 5 moves
						{

								pos=MiniMax(a);
								a[pos]=2;
								DisplayBoard(a);
								
								if(CheckWin(a))
									{
										DisplayBoard(a);
										cout<<"\n\nYou lost!";
										delay(5000);
										break;
									}
								else if(CheckDraw(a))
									{
										DisplayBoard(a);
										cout<<"\n\nIts Draw!";
										delay(5000);
										break;
									}

								enterAgain1:
								cout<<"\n\nEnter position(0-8):";
								cin>>pos;
								legal=CheckLegal(a,pos);
								
								if(legal==0)
									{
										cout<<"\nInvalid Move!";
										goto enterAgain1;
									}
								a[pos]=1;

								DisplayBoard(a);
								
								if(CheckLose(a))
									{
										DisplayBoard(a);
										cout<<"\n\nYou won!";
										delay(5000);
										break;
									}
								else if(CheckDraw(a))
									{
										DisplayBoard(a);
										cout<<"\n\nIts Draw!";
										delay(5000);
										break;
									}
											
								move++;
						}

							break;
					}


				case 'n':
					{

						while(move<5)
						{

							DisplayBoard(a);

							enterAgain2:
							cout<<"\n\nEnter position(0-8):";
							cin>>pos;

							legal=CheckLegal(a,pos);
							if(legal==0)
							{
								cout<<"\nInvalid Move!";
								goto enterAgain2;
							}

							a[pos]=1;

							DisplayBoard(a);

							if(CheckLose(a))
							{
								DisplayBoard(a);
								cout<<"\n\nYou won!";
								delay(5000);
								break;
							}
							else if(CheckDraw(a))
							{
								DisplayBoard(a);
								cout<<"\n\nIts Draw!";
								delay(5000);
								break;
							}


							pos=MiniMax(a);
							a[pos]=2;
							cout<<"\n\t"<<pos;
							DisplayBoard(a);

							if(CheckWin(a))
							{
								DisplayBoard(a);
								cout<<"\n\nYou lost!";
								delay(5000);
								break;
							}
							else if(CheckDraw(a))
							{
								DisplayBoard(a);
								cout<<"\n\nIts Draw!";
								delay(5000);
								break;
							}

																													
							move++;
						}


						break;
					}
					
				default:
					{
						break;
					}

			 }


}