Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
#include <iostream>
#include<conio.h>
if (y == 300)
return 2; //User Won
else if (y == 30)
return 1; //Computer Won
}
//Condition for checking the first diagonal condition for the winner
x = a[1][1] + a[0][0] + a[2][2];
if (x == 300)
return 2; //User Won
else if (x == 30)
return 1; //Computer Won
//Condition for checking the second diagonal condition for the winner
x = a[1][1] + a[0][2] + a[2][0];
if (x == 300)
return 2; //User Won
else if (x == 30)
return 1;
return 0;
}
int x = 0, y = 0, count = 0;
for (int i = 0; i < 3; i++)
{
x = 0;
y = 0;
for (int j = 0; j < 3; j++)
{
x = b[i][j] + x;
y = b[j][i] + y;
}
if (x == n * 3)
count++;
if (y == n * 3)
count++;
}
x = b[0][0] + b[1][1] + b[2][2];
y = b[0][2] + b[1][1] + b[2][0];
if (x == n * 3)
count++;
if (y == n * 3)
count++;
return count;
int min = 8, p, q, x, y;
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
{
if (a[i][j] == 0)
{
a[i][j] = 10;
x = count(a, 10);
y = count(a, 100);
if (min > x - y)
{
p = i;
q = j;
min = x - y;
}
a[i][j] = 100;
x = whowon(a);
if (x == 2)
{
a[i][j] = 10;
return;
}
a[i][j] = 0;
}
}
a[p][q] = 10;
}
x = whowon(a);
if (x == 2)
{
a[i][j] = 10;
return;
}
a[i][j] = 10;
x = whowon(a);
if (x == 1)
{
a[i][j] = 10;
return;
}
//restoring the previous matrix
a[i][j] = 0;
}
}
}
else
if (a[i][j] == 10)
x++;
}
if (y>1 && x >= 1)
{
a[k][p] = 10;
return;
}
}
else
if (a[j][i] == 10)
x++;
}
if (y>1 && x >= 1)
{
a[k][p] = 10;
return;
}
}
int main()
{
cout << "A Program in C++ for playing Tic Tac Toe using AI technique\n\n";
cout << "A Program by Anirudh Polawar and Tanay Rajwal.\n\n";
//By default computer started playing from the center location of the grid
a[1][1] = 10;
int p, q, x,flag;
}
print(a);
}
print(a);
return 0;
}
//output