Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- using namespace std;
- char h[9] = { '-', '-', '-', '-', '-', '-', '-', '-', '-' };
- void board_numbers()
- {
- cout << "***********" << endl;
- cout << "-7-|-8-|-9-" << endl;
- cout << "-4-|-5-|-6-" << endl;
- cout << "-1-|-2-|-3-" << endl;
- cout << "***********" << endl;
- }
- void board()
- {
- cout << "\n";
- cout << "***********" << endl;
- cout << "-" << h[6] << "-|-" << h[7] << "-|-" << h[8] << "-" << endl;
- cout << "-" << h[3] << "-|-" << h[4] << "-|-" << h[5] << "-" << endl;
- cout << "-" << h[0] << "-|-" << h[1] << "-|-" << h[2] << "-" << endl;
- cout << "***********" << endl;
- }
- int get_move()
- {
- int move;
- cin >> move;
- while (move > 9 || move < 1 || h[move - 1] != '-')
- {
- cout << "ERROR!!!!" << endl;
- cin >> move;
- }
- return move;
- }
- int endgame_check(char h[])
- {
- if ((h[0] == 'X') && (h[1] == 'X') && (h[2] == 'X'))
- {
- cout << "Победа! X" << endl;
- exit (0);
- }
- if ((h[3] == 'X') && (h[4] == 'X') && (h[5] == 'X'))
- {
- cout << "Победа! X" << endl;
- exit(0);
- }
- if ((h[6] == 'X') && (h[7] == 'X') && (h[8] == 'X'))
- {
- cout << "Победа! X" << endl;
- exit(0);
- }
- if ((h[0] == 'X') && (h[3] == 'X') && (h[6] == 'X'))
- {
- cout << "Победа! X" << endl;
- exit(0);
- }
- if ((h[1] == 'X') && (h[4] == 'X') && (h[7] == 'X'))
- {
- cout << "Победа! X" << endl;
- exit(0);
- }
- if ((h[2] == 'X') && (h[5] == 'X') && (h[8] == 'X'))
- {
- cout << "Победа! X" << endl;
- exit(0);
- }
- if ((h[0] == 'X') && (h[4] == 'X') && (h[8] == 'X'))
- {
- cout << "Победа! X" << endl;
- exit(0);
- }
- if ((h[2] == 'X') && (h[4] == 'X') && (h[6] == 'X'))
- {
- cout << "Победа! X" << endl;
- exit(0);
- }
- if ((h[0] == 'O') && (h[1] == 'O') && (h[2] == 'O'))
- {
- cout << "Победа! O" << endl;
- exit(0);
- }
- if ((h[3] == 'O') && (h[4] == 'O') && (h[5] == 'O'))
- {
- cout << "Победа! O" << endl;
- exit(0);
- }
- if ((h[6] == 'O') && (h[7] == 'O') && (h[8] == 'O'))
- {
- cout << "Победа! O" << endl;
- exit(0);
- }
- if ((h[0] == 'O') && (h[3] == 'O') && (h[6] == 'O'))
- {
- cout << "Победа! O" << endl;
- exit(0);
- }
- if ((h[1] == 'O') && (h[4] == 'O') && (h[7] == 'O'))
- {
- cout << "Победа! O" << endl;
- exit(0);
- }
- if ((h[2] == 'O') && (h[5] == 'O') && (h[8] == 'O'))
- {
- cout << "Победа! O" << endl;
- exit(0);
- }
- if ((h[0] == 'O') && (h[4] == 'O') && (h[8] == 'O'))
- {
- cout << "Победа! O" << endl;
- exit(0);
- }
- if ((h[2] == 'O') && (h[4] == 'O') && (h[6] == 'O'))
- {
- cout << "Победа! O" << endl;
- exit(0);
- }
- }
- int main()
- {
- srand(time(NULL));
- setlocale(LC_ALL,"Russian");
- int choice;
- cout << "Кем будете играть? 1 - крестики, 2 - нолики" << endl;
- cin >> choice;
- for (int i = 0; i < 10; i++)
- {
- board_numbers();
- board();
- if (i == 9)
- {
- cout << "Ничья";
- return 0;
- }
- int move = get_move();
- cout << "Hod: " << i << endl;
- if (choice == 1)
- {
- if (i % 2 == 0)
- {
- h[move - 1] = 'X';
- }
- else h[move - 1] = 'O';
- }
- if (choice == 2)
- {
- if (i % 2 == 0)
- {
- h[move - 1] = 'O';
- }
- else h[move - 1] = 'X';
- }
- endgame_check(h);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement