#include<stdio.h>
#include<stdlib.h>
int i,j;
int a[3][3];
void myprint1()
{
printf(" ## TANVIR-JEWEL ##\n");
printf("## WELCOME TO TIC_TAC_TOE ##\n\n");
printf("Enter the index number(i j)\n\n");
printf(" 00 | 01 | 02\n______________\n 10 | 11 | 12\n______________\n 20 | 21 | 22\n\n");
printf("Sign X for player 1\nSign O for player 2 \n\n");
}
// To show the board
void myprint2()
{
system("CLS");
myprint1();
printf("\n\n %c |",a[0][0]);
printf(" %c |",a[0][1]);
printf(" %c ",a[0][2]);
printf("\n______________\n");
printf(" %c |",a[1][0]);
printf(" %c |",a[1][1]);
printf(" %c ",a[1][2]);
printf("\n______________\n");
printf(" %c |",a[2][0]);
printf(" %c |",a[2][1]);
printf(" %c ",a[2][2]);
printf("\n");
}
check()
{
char test= ' ';
// Check Rows
for (i=0; i<3;i++)
if (a[i][0] == a[i] [1] && a[i][0] == a[i] [2] && a[i] [0] != ' ') test= a[i] [0];
// Check Columns
for (i=0; i<3;i++)
if (a[0][i] == a[1] [i] && a[0][i] == a[2] [i] && a[0] [i] != ' ') test= a[0] [i];
// Check Ara-ari
if (a[0][0] == a[1] [1] && a[1][1] == a[2] [2] && a[1] [1] != ' ')
test= a[1] [1];
if (a[0][2] == a[1] [1] && a[1][1] == a[2] [0] && a[1] [1] != ' ') test= a[1] [1];
// Winner if any
if (test== 'X')
{
printf ("\nplayer1 Win\n\n");
exit(0);
}
if (test== 'O')
{
printf ("\nplayer2 Win\n\n");
exit(0);
}
}
void input1()
{
printf ("\nPlayer 1 Turn");
printf ("\nEnter index no. for i: ");
scanf ("%d",&i);
printf ("\nEnter index no. for j: ");
scanf ("%d", &j);
a[i][j] = 'X';
myprint2();
}
void input2()
{
printf ("\nPlayer 2 Turn");
printf ("\nEnter index no for i: ");
scanf ("%d",&i);
printf ("\nEnter index no for j: ");
scanf ("%d", &j);
a[i][j]='O';
myprint2();
}
int main()
{
int x,y;
myprint2();
for(x=0;x<5;x++)
{
input1();
check();
if(x!=4)
{
input2();
check();
}
}
printf ("\n\n GAME DRAW");
return 0;
}
#include<stdlib.h>
int i,j;
int a[3][3];
void myprint1()
{
printf(" ## TANVIR-JEWEL ##\n");
printf("## WELCOME TO TIC_TAC_TOE ##\n\n");
printf("Enter the index number(i j)\n\n");
printf(" 00 | 01 | 02\n______________\n 10 | 11 | 12\n______________\n 20 | 21 | 22\n\n");
printf("Sign X for player 1\nSign O for player 2 \n\n");
}
// To show the board
void myprint2()
{
system("CLS");
myprint1();
printf("\n\n %c |",a[0][0]);
printf(" %c |",a[0][1]);
printf(" %c ",a[0][2]);
printf("\n______________\n");
printf(" %c |",a[1][0]);
printf(" %c |",a[1][1]);
printf(" %c ",a[1][2]);
printf("\n______________\n");
printf(" %c |",a[2][0]);
printf(" %c |",a[2][1]);
printf(" %c ",a[2][2]);
printf("\n");
}
check()
{
char test= ' ';
// Check Rows
for (i=0; i<3;i++)
if (a[i][0] == a[i] [1] && a[i][0] == a[i] [2] && a[i] [0] != ' ') test= a[i] [0];
// Check Columns
for (i=0; i<3;i++)
if (a[0][i] == a[1] [i] && a[0][i] == a[2] [i] && a[0] [i] != ' ') test= a[0] [i];
// Check Ara-ari
if (a[0][0] == a[1] [1] && a[1][1] == a[2] [2] && a[1] [1] != ' ')
test= a[1] [1];
if (a[0][2] == a[1] [1] && a[1][1] == a[2] [0] && a[1] [1] != ' ') test= a[1] [1];
// Winner if any
if (test== 'X')
{
printf ("\nplayer1 Win\n\n");
exit(0);
}
if (test== 'O')
{
printf ("\nplayer2 Win\n\n");
exit(0);
}
}
void input1()
{
printf ("\nPlayer 1 Turn");
printf ("\nEnter index no. for i: ");
scanf ("%d",&i);
printf ("\nEnter index no. for j: ");
scanf ("%d", &j);
a[i][j] = 'X';
myprint2();
}
void input2()
{
printf ("\nPlayer 2 Turn");
printf ("\nEnter index no for i: ");
scanf ("%d",&i);
printf ("\nEnter index no for j: ");
scanf ("%d", &j);
a[i][j]='O';
myprint2();
}
int main()
{
int x,y;
myprint2();
for(x=0;x<5;x++)
{
input1();
check();
if(x!=4)
{
input2();
check();
}
}
printf ("\n\n GAME DRAW");
return 0;
}
No comments:
Post a Comment