Tic Tack Toe game

TECHNIQUE:-


A player can play a good game of tic-tac-toe to follow some rule. 
  1. Win: If the player has two sign in a row, they can place a third sign to get three in a row.
  2. Block: If the opponent has two sign in a row, the player must play the third sign themselves to block the opponent.
  3. Fork: Create an opportunity where the player has two way the win. 
  4. play with rules is the major property of the game.

tic



RUN THE CODE IN C++ COMPILER AND ENJOY THE GAME:-

CODE:-

#include<iostream>
using namespace std;
int main()
{
int arr[11],turn2=0,true2,b,s[11],g=1;  for(b=1; b<=9; b++) {  arr[b]=7;  s[b]=17; }   
while(1)
{
int n;
true2=0; int linux=0;
turn2++;
if((turn2%2)!=0){  cout<<endl<<"player 1 turn enter position"<<endl;
uppe: if(linux==1) {
     cout<<endl<<"dyan se"<<endl;  }
cin>>n; for(b=1; b<=9;  b++) if(s[b]==n) {
  linux=1;  goto uppe;  }   s[g]=n; g++;
arr[n]=1;  }
else
{  cout<<endl<<"player 2 turn enter  position"<<endl;
upper: if(linux==1){       cout<<endl<<"dyan se"<<endl;   }
cin>>n;     for(b=1; b<=9;  b++) if(s[b]==n) {
   linux=1;  goto upper;  }  s[g]=n; g++; arr[n]=2;
} cout<<endl; 
for(b=1; b<=9; b++)

cout<<arr[b]<<" ";  if((b)%3==0) cout<<endl;
}
if(arr[1]==1&&arr[2]==1&&arr[3]==1||arr[4]==1&&arr[5]==1&&arr[6]==1||
arr[7]==1&&arr[8]==1&&arr[9]==1||arr[1]==1&&arr[4]==1&&arr[7]==1||
arr[2]==1&&arr[5]==1&&arr[7]==1||arr[3]==1&&arr[6]==1&&arr[9]==1||
arr[1]==1&&arr[5]==1&&arr[9]==1||arr[9]==1&&arr[3]==1&&arr[5]==1&&arr[7]==1)
{ true2=1;  }
if(arr[1]==2&&arr[2]==2&&arr[3]==2||arr[4]==2&&arr[5]==2&&arr[6]==2||
arr[7]==2&&arr[8]==2&&arr[9]==2||arr[1]==2&&arr[4]==2&&arr[6]==2||
arr[2]==2&&arr[5]==2&&arr[7]==2||arr[3]==2&&arr[6]==2&&arr[9]==2||
arr[1]==2&&arr[5]==2&&arr[9]==2||arr[9]==2&&arr[3]==2&&arr[5]==2&&arr[7]==2)
{ true2=1; }
if(true2==1&&turn2%2!=0)   { cout<<"player1"<<endl;    break; }
if(true2==1&&turn2%2==0)    {
cout<<"player2"<<endl;    break;  } }
}


No comments:

Post a Comment