X_0

Run Settings
LanguageC++
Language Version
Run Command
///////////////////////////////////////////////////////////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; }
Editor Settings
Theme
Key bindings
Full width
Lines