Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- vector <string> cort;
- int cnt_white = 0, cnt_black = 0;
- void re_count() {
- for (int i = 1; i <= 8; i++) {
- for (int j = 1; j <= 8; j++) {
- if (cort[i][j] == 'w' || cort[i][j] == 'W') {
- cnt_white++;
- }
- if (cort[i][j] == 'b' || cort[i][j] == 'B') {
- cnt_black++;
- }
- }
- }
- for (int j = 1; j <= 8; j++) {
- if (cort[1][j] == 'w') {
- cort[1][j] = 'W';
- }
- if (cort[8][j] == 'b') {
- cort[8][j] = 'B';
- }
- }
- }
- void print() {
- for (int i = 0; i <= 9; i++) {
- for (int j = 0; j <= 9; j++) {
- cout << cort[i][j] << " ";
- }
- cout << endl;
- }
- }
- void gen() {
- int i;
- cort[0][0] = ' ';
- cort[0][9] = ' ';
- cort[9][0] = ' ';
- cort[9][9] = ' ';
- for (i = 1; i <= 8; i++) {
- cort[i][0] = '9' - i;
- cort[i][9] = '9' - i;
- cort[0][i] = 'a' + (i - 1);
- cort[9][i] = 'a' + (i - 1);
- }
- for (i = 2; i <= 8; i += 2) {
- cort[1][i] = 'b';
- }
- for (i = 1; i <= 8; i += 2) {
- cort[2][i] = 'b';
- }
- for (i = 2; i <= 8; i += 2) {
- cort[3][i] = 'b';
- }
- for (i = 1; i <= 8; i += 2) {
- cort[6][i] = 'w';
- }
- for (i = 2; i <= 8; i += 2) {
- cort[7][i] = 'w';
- }
- for (i = 1; i <= 8; i += 2) {
- cort[8][i] = 'w';
- }
- }
- pair <int, int> get(int color) {
- while (true) {
- string action;
- cin >> action;
- //cout << action << endl;
- int x, y;
- while (action.size() != 2 || action[0] < 'a' || action[0] > 'h' || action[1] < '1' || action[1] > '8') {
- cout << "Проверьте правильность ввода!" << endl;
- cin >> action;
- }
- y = action[0] - 'a' + 1;
- x = 8 - (action[1] - '1');
- //cout << x << " " << y << endl;
- if (color == 0) {
- if (cort[x][y] != 'w' && cort[x][y] != 'W') {
- cout << "Выберите клетку, в которой находится ваша фигура!" << endl;
- }
- else {
- return { x, y };
- }
- }
- else {
- if (cort[x][y] != 'b' && cort[x][y] != 'B') {
- cout << "Выберите клетку, в которой находится ваша фигура!" << endl;
- }
- else {
- return { x, y };
- }
- }
- }
- }
- bool go(int x, int y, int x2, int y2, int color) {
- char start = cort[x][y];
- cort[x][y] = '.';
- bool res = false;
- if (x2 >= x && y2 >= y) {
- while (x != x2 && y != y2) {
- if (color == 0 && cort[x][y] != 'W' && cort[x][y] != 'w' && cort[x][y] != '.') {
- cort[x][y] = '.';
- res = true;
- }
- else if (color == 1 && cort[x][y] != 'B' && cort[x][y] != 'b' && cort[x][y] != '.') {
- cort[x][y] = '.';
- res = true;
- }
- x++;
- y++;
- }
- }
- else if (x2 >= x && y2 <= y) {
- while (x != x2 && y != y2) {
- if (color == 0 && cort[x][y] != 'W' && cort[x][y] != 'w' && cort[x][y] != '.') {
- cort[x][y] = '.';
- res = true;
- }
- else if (color == 1 && cort[x][y] != 'B' && cort[x][y] != 'b' && cort[x][y] != '.') {
- cort[x][y] = '.';
- res = true;
- }
- x++;
- y--;
- }
- }
- else if (x2 <= x && y2 >= y) {
- while (x != x2 && y != y2) {
- if (color == 0 && cort[x][y] != 'W' && cort[x][y] != 'w' && cort[x][y] != '.') {
- cort[x][y] = '.';
- res = true;
- }
- else if (color == 1 && cort[x][y] != 'B' && cort[x][y] != 'b' && cort[x][y] != '.') {
- cort[x][y] = '.';
- res = true;
- }
- x--;
- y++;
- }
- }
- else {
- while (x != x2 && y != y2) {
- if (color == 0 && cort[x][y] != 'W' && cort[x][y] != 'w' && cort[x][y] != '.') {
- cort[x][y] = '.';
- res = true;
- }
- else if (color == 1 && cort[x][y] != 'B' && cort[x][y] != 'b' && cort[x][y] != '.') {
- cort[x][y] = '.';
- res = true;
- }
- x--;
- y--;
- }
- }
- cort[x2][y2] = start;
- return res;
- }
- bool get2(int color, int x, int y) {
- if (color == 0) {
- bool flag = (cort[x][y] == 'W');
- while (true) {
- string action;
- cin >> action;
- int x2, y2;
- while (action.size() != 2 || action[0] < 'a' || action[0] > 'h' || action[1] < '1' || action[1] > '8') {
- cout << "Проверьте правильность ввода!" << endl;
- cin >> action;
- }
- y2 = action[0] - 'a' + 1;
- x2 = 8 - (action[1] - '1');
- if (abs(x2 - x) == abs(y2 - y) && abs(x2 - x) > 0 && cort[x2][y2] == '.') {
- if (flag) {
- if (cort[x2][y2] == '.') {
- return go(x, y, x2, y2, 0);
- }
- else {
- cout << "Вы не можете попасть в эту клетку" << endl;
- }
- }
- else {
- if (abs(x2 - x) == 1) {
- if (cort[x2][y2] == '.' && x2 < x) {
- return go(x, y, x2, y2, 0);
- }
- else {
- cout << "Вы не можете попасть в эту клетку" << endl;
- }
- }
- else if (abs(x2 - x) == 2) {
- if (x2 >= x && y2 >= y) {
- if ((cort[x + 1][y + 1] == 'b' || cort[x + 1][y + 1] == 'B') && cort[x2][y2] == '.') {
- return go(x, y, x2, y2, 0);
- }
- else {
- cout << "Вы не можете попасть в эту клетку" << endl;
- }
- }
- else if (x2 >= x && y2 <= y) {
- if ((cort[x + 1][y - 1] == 'b' || cort[x + 1][y - 1] == 'B') && cort[x2][y2] == '.') {
- return go(x, y, x2, y2, 0);
- }
- else {
- cout << "Вы не можете попасть в эту клетку" << endl;
- }
- }
- else if (x2 <= x && y2 >= y) {
- if ((cort[x - 1][y + 1] == 'b' || cort[x - 1][y + 1] == 'B') && cort[x2][y2] == '.') {
- return go(x, y, x2, y2, 0);
- }
- else {
- cout << "Вы не можете попасть в эту клетку" << endl;
- }
- }
- else {
- if ((cort[x - 1][y - 1] == 'b' || cort[x - 1][y - 1] == 'B') && cort[x2][y2] == '.') {
- return go(x, y, x2, y2, 0);
- }
- else {
- cout << "Вы не можете попасть в эту клетку" << endl;
- }
- }
- }
- else {
- cout << "Вы не можете попасть в эту клетку" << endl;
- }
- }
- }
- else {
- cout << "Вы не можете попасть в эту клетку" << endl;
- }
- }
- }
- else {
- bool flag = (cort[x][y] == 'B');
- while (true) {
- string action;
- cin >> action;
- int x2, y2;
- while (action.size() != 2 || action[0] < 'a' || action[0] > 'h' || action[1] < '1' || action[1] > '8') {
- cout << "Проверьте правильность ввода!" << endl;
- cin >> action;
- }
- y2 = action[0] - 'a' + 1;
- x2 = 8 - (action[1] - '1');
- if (abs(x2 - x) == abs(y2 - y) && abs(x2 - x) > 0 && cort[x2][y2] == '.') {
- if (flag) {
- if (cort[x2][y2] == '.') {
- return go(x, y, x2, y2, 1);
- }
- else {
- cout << "Вы не можете попасть в эту клетку" << endl;
- }
- }
- else {
- if (abs(x2 - x) == 1) {
- if (cort[x2][y2] == '.' && x2 > x) {
- return go(x, y, x2, y2, 1);
- }
- else {
- cout << "Вы не можете попасть в эту клетку" << endl;
- }
- }
- else if (abs(x2 - x) == 2) {
- if (x2 >= x && y2 >= y) {
- if ((cort[x + 1][y + 1] == 'w' || cort[x + 1][y + 1] == 'W') && cort[x2][y2] == '.') {
- return go(x, y, x2, y2, 1);
- }
- else {
- cout << "Вы не можете попасть в эту клетку" << endl;
- }
- }
- else if (x2 >= x && y2 <= y) {
- if ((cort[x + 1][y - 1] == 'w' || cort[x + 1][y - 1] == 'W') && cort[x2][y2] == '.') {
- return go(x, y, x2, y2, 1);
- }
- else {
- cout << "Вы не можете попасть в эту клетку" << endl;
- }
- }
- else if (x2 <= x && y2 >= y) {
- if ((cort[x - 1][y + 1] == 'w' || cort[x - 1][y + 1] == 'W') && cort[x2][y2] == '.') {
- return go(x, y, x2, y2, 1);
- }
- else {
- cout << "Вы не можете попасть в эту клетку" << endl;
- }
- }
- else {
- if ((cort[x - 1][y - 1] == 'w' || cort[x - 1][y - 1] == 'W') && cort[x2][y2] == '.') {
- return go(x, y, x2, y2, 1);
- }
- else {
- cout << "Вы не можете попасть в эту клетку" << endl;
- }
- }
- }
- else {
- cout << "Вы не можете попасть в эту клетку" << endl;
- }
- }
- }
- else {
- cout << "Вы не можете попасть в эту клетку" << endl;
- }
- }
- }
- }
- int main() {
- setlocale(LC_ALL, "Russian");
- string name1, name2;
- cout << "Введите имя первого игрока" << endl;
- getline(cin, name1);
- cout << "Введите имя второго игрока" << endl;
- getline(cin, name2);
- int i, j, x, y;
- pair <int, int> res;
- long long player = 0;
- cort.resize(10, string("........."));
- gen();
- cout << "Правила:" << endl;
- cout << "Стандартные правила шашек" << endl;
- cout << "w - белая шашка, W - белая дамка" << endl;
- cout << "b - чёрная шашка, B - чёрная дамка" << endl;
- cout << "Во время хода, введите слитно координаты выбранной вами фигуры, принадлежащей вам, напрмер a3" << endl;
- cout << "В следующей строке выведите координату, куда вы хотите переставить, выбранную вами фигуру" << endl;
- print();
- while (true) {
- if (player % 2 == 0) {
- cout << "Ход игрока" << " " << name1 << " " << "(белые)" << endl;
- res = get(0);
- x = res.first;
- y = res.second;
- if (!get2(0, x, y)) player++;
- }
- else {
- cout << "Ход игрока" << " " << name2 << " " << "(чёрные)" << endl;
- res = get(1);
- x = res.first;
- y = res.second;
- if (!get2(1, x, y)) player++;
- }
- re_count();
- print();
- cout << cnt_white << " " << cnt_black << endl;
- if (cnt_black == 0) {
- cout << "Победитель" << " " << name1 << " " << "(белые)" << endl;
- return 0;
- }
- else if (cnt_white == 0) {
- cout << "Победитель" << " " << name2 << " " << "(чёрные)" << endl;
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement