forked from prannayk/ACA_Haskell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathticTacToeInC
97 lines (75 loc) · 1.13 KB
/
ticTacToeInC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include<stdio.h>
int arr[3][3];
int options[9];
int choice;
int x[9];
int y[9];
int pass=1;
void initialize()
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
arr[i][j]=0;
}
}
}
void printing()
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{ if(arr[i][j]==1)
printf(" 0 ");
else if(arr[i][j]==2)
printf(" X ");
else
printf(" ");
}
printf("\n\n");
}
}
void displayoptions()
{
int c=1,i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if((arr[i][j]!=1)&&(arr[i][j]!=2))
{
printf("%d.(%d,%d)\n",c,i+1,j+1);
x[c-1]=i;
y[c-1]=j;
options[c-1]=c++;
}
}
}
printf("Enter Your Choice ");
scanf("%d",&choice);
pass++;
}
int update()
{
if(pass%2==0)
arr[x[choice-1]][y[choice-1]]=1;
else
arr[x[choice-1]][y[choice-1]]=2;
}
int main()
{
printf(" *-*-*-*-*-*-*- O has First turn *-*-*-*-*-*-*-*\n");
int i=0;
initialize();
printing();
while(i<10)
{
displayoptions();
update();
printing();
i++;
}
}