X_0
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
///////////////////////////////////////////////////////////THIS IS BETA VERSION OF X_0///////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include<ctime>
using namespace std;
char mass[3][3];
char result()
{
int y = 0;
for (int i = 0; i < 3; i++)
{
int m = 0, n = 0, q = 0, r = 0, t = 0, s = 0, h = 0, d = 0;
for (int j = 0; j < 3; j++)
{
if (mass[i][j] == 'x')
{
m++;
if (m == 3)
{
system("cls");
cout << "Player1 WIN!!" << endl;
system("PAUSE");
exit(1);
}
}
else if (mass[0][2] == 'x' && mass[1][1] == 'x' && mass[2][0] == 'x')
{
s++;
if (s == 3)
{
system("cls");
cout << "Player1 WIN!!" << endl;
system("PAUSE");
exit(1);
}
}
else if (mass[0][0] == 'x' && mass[1][1] == 'x' && mass[2][2] == 'x')
{
t++;
if (t == 3)
{
system("cls");
cout << "Player1 WIN!!" << endl;
system("PAUSE");
exit(1);
}
}
else if (mass[j][i] == 'x')
{
q++;
if (q == 3)
{
system("cls");
cout << "Player1 WIN!!" << endl;
system("PAUSE");
exit(1);
}
}
else if (mass[i][j] == 'o')
{
n++;
if (n == 3)
{
system("cls");
cout << "Player2 WIN!!" << endl;
system("PAUSE");
exit(1);
}
}
else if (mass[0][0] == 'o' && mass[1][1] == 'o' && mass[2][2] == 'o')
{
h++;
if (h == 3)
{
system("cls");
cout << "Player2 WIN!!" << endl;
system("PAUSE");
exit(1);
}
}
else if (mass[0][2] == 'o' && mass[1][1] == 'o' && mass[2][0] == 'o')
{
d++;
if (d == 3)
{
system("cls");
cout << "Player2 WIN!!" << endl;
system("PAUSE");
exit(1);
}
}
else if (mass[j][i] == 'o')
{
r++;
if (r == 3)
{
system("cls");
cout << "Player2 WIN!!" << endl;
system("PAUSE");
exit(1);
}
}
else if ((mass[i][j] == 'o' || mass[i][j] == 'x') || (mass[j][i] == 'x' || mass[j][i] == 'o'))
{
y++;
if (y == 9)
{
system("cls");
cout << "Nobody WIN!!" << endl;
system("PAUSE");
exit(1);
}
}
}
}
}
void firsround()
{
for (int f = 0; f < 3; f++)
cout << " _______________";
for (int i = 0; i < 3; i++)
{
cout << endl << "|" << "\t" << "\t" << "|" << "\t" << "\t" << "|" << "\t" << "\t" << "|" << endl;
for (int j = 0; j < 3; j++)
{
mass[i][j] = ' ';
cout << "|" << "\t" << mass[i][j] << "\t";
}
cout << "|" << endl << "|";
for (int f = 0; f < 3; f++)
cout << "_______________|";
}
}
int main()
{
srand(time(NULL));
setlocale(LC_ALL, "ru");
int k, l, a, b;
int P;
cout << "If you want to play with computer press 0, but if you want to play with another living being press 1 : ";
cin >> P;
cout << endl;
if (P == 0)
{
firsround();
//INPUTING
for (;;)
{
cout << endl << "input X" << endl;
cin >> k;
cout << "Input Y" << endl;
cin >> l;
k = k - 1;
l = l - 1;
if ((mass[k][l] == 'x') || (mass[k][l] == 'o'))//replace blocker
{
cout << "You can not change this value!" << endl;
continue;
}
else
{
mass[k][l] = 'x';
system("cls");
result();
// "artificial intelligance"
a = rand() % 3;
b = rand() % 3;
cout << endl << a << "\t" << b << endl;
if ((mass[a][b] == 'x') || (mass[a][b] == 'o'))
{
for (; ;)
{
a = rand() % 3;
b = rand() % 3;
if ((mass[a][b] == 'x') || (mass[a][b] == 'o') || (a < 0) || (b < 0))
{
}
else
{
break;
}
}
}
mass[a][b] = 'o';
system("cls");
result();
// SKORE
for (int f = 0; f < 3; f++)
cout << " _______________";
for (int i = 0; i < 3; i++)
{
cout << endl << "|" << "\t" << "\t" << "|" << "\t" << "\t" << "|" << "\t" << "\t" << "|" << endl;
for (int j = 0; j < 3; j++)
{
cout << "|" << "\t" << mass[i][j] << "\t";
}
cout << "|" << endl << "|";
for (int f = 0; f < 3; f++)
cout << "_______________|";
}
}
}
cout << endl;
system("PAUSE");
return 0;
}
if (P == 1)
{
firsround();
for (;;)
{
//Player1
cout << endl << "input X" << endl;
cin >> k;
cout << "Input Y" << endl;
cin >> l;
k = k - 1;
l = l - 1;
if ((mass[k][l] == 'x') || (mass[k][l] == 'o'))//replace blocker
{
cout << "You can not change this value!" << endl;
continue;
}
else
{
mass[k][l] = 'x';
system("cls");
for (int u = 0; u < 3; u++)
cout << " _______________";
for (int f = 0; f < 3; f++)
{
cout << endl << "|" << "\t" << "\t" << "|" << "\t" << "\t" << "|" << "\t" << "\t" << "|" << endl;
for (int j = 0; j < 3; j++)
{
cout << "|" << "\t" << mass[f][j] << "\t";
}
cout << "|" << endl << "|";
for (int f = 0; f < 3; f++)
cout << "_______________|";
}
result();
// Another living being
for (;;)
{
cout << endl << "input X" << endl;
cin >> k;
cout << "Input Y" << endl;
cin >> l;
k = k - 1;
l = l - 1;
if ((mass[k][l] == 'x') || (mass[k][l] == 'o'))//replace blocker
{
cout << "You can not change this value!" << endl;
continue;
}
else
{
mass[k][l] = 'o';
system("cls");
for (int u = 0; u < 3; u++)
cout << " _______________";
for (int f = 0; f < 3; f++)
{
cout << endl << "|" << "\t" << "\t" << "|" << "\t" << "\t" << "|" << "\t" << "\t" << "|" << endl;
for (int j = 0; j < 3; j++)
{
cout << "|" << "\t" << mass[f][j] << "\t";
}
cout << "|" << endl << "|";
for (int f = 0; f < 3; f++)
cout << "_______________|";
}
result();
break;
}
}
}
}
}
else
cout << "WHAT?";
cout << endl;
system("PAUSE");
return 0;
}
Cpp
INFO