Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- string board[9] = { " ", " ", " ", " ", " ", " ", " ", " ", " " };
- void desk(string s = "What's your move, first player: ") {
- system("cls");
- cout << "~~KRESTIKI NOLIKI~~" << endl;
- cout << "Make your move, enter number of cell" << endl;
- cout << "~~~~~~~~~~~~~~~~~" << endl;
- cout << " " << board[0] << " | " << board[1] << " | " << board[2] << endl;
- cout << "~~~~~~~~~~~~~~~~~" << endl;
- cout << " " << board[3] << " | " << board[4] << " | " << board[5] << endl;
- cout << "~~~~~~~~~~~~~~~~~" << endl;
- cout << " " << board[6] << " | " << board[7] << " | " << board[8] << endl;
- cout << "~~~~~~~~~~~~~~~~~" << endl;
- cout << s;
- }
- int pobeda() {
- if ((board[0] == board[1] && board[1] == board[2] && board[0] != " ") ||
- (board[3] == board[4] && board[4] == board[5] && board[3] != " ") ||
- (board[6] == board[7] && board[7] == board[8] && board[6] != " ") ||
- (board[0] == board[3] && board[3] == board[6] && board[0] != " ") ||
- (board[1] == board[4] && board[4] == board[7] && board[1] != " ") ||
- (board[2] == board[5] && board[5] == board[8] && board[2] != " ") ||
- (board[0] == board[4] && board[4] == board[8] && board[0] != " ") ||
- (board[6] == board[4] && board[4] == board[2] && board[6] != " ")) {
- return 1;
- }
- if (board[0] != " " && board[1] != " " && board[2] != " " && board[3] != " " && board[4] != " " && board[5] != " " && board[6] != " " && board[7] != " " && board[8] != " ") {
- return -1;
- }
- else {
- return 0;
- }
- }
- int main() {
- int a, n = 0, v = 0;
- desk();
- while (n != 9) {
- cin >> a;
- if (n % 2 == 0 && board[a - 1] == " " && a <= 9 && a >= 0) {
- board[a - 1] = "X";
- n++;
- }
- else if (n%2 != 0 && board[a-1] == " " && a <= 9 && a >= 0) {
- board[a - 1] = "O";
- n++;
- }
- else {
- desk("error, enter again: ");
- continue;
- }
- v++;
- if (v % 2 == 0) {
- desk("What's your move, first player: ");
- }
- if (v % 2 != 0) {
- desk("What's your move, second player: ");
- }
- int g = pobeda();
- if (g != 0) {
- if (g == 1 && v%2 != 0) {
- desk("WIN 1 PLAYER");
- }
- if (g == 1 && v % 2 == 0) {
- desk("WIN 2 PLAYER");
- }
- if (g == -1) {
- desk("TIE");
- }
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement