Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void findPortals(const std::vector<std::vector<char>>& map, std::vector<std::tuple<std::string, Coordinate, Coordinate>>& portals)
- {
- std::vector<std::vector<bool>> visit(1000, std::vector<bool>(1000, false));
- std::tuple<std::string, Coordinate, Coordinate> sa;
- std::string nume;
- Coordinate star;
- Coordinate fini;
- std::string save;
- Coordinate starSave;
- Coordinate finiSave;
- int dirX[] = { -1,0,0,1 };
- int dirY[] = { 0,-1,1,0 };
- int sss = 0;
- int sss2 = 0;
- for (int i = 0; i < map.size(); i++)
- {
- for (int j = 0; j < map[0].size(); j++)
- {
- sss = i;
- sss2 = j;
- if ((map[i][j] >= 'A') && (map[i][j] <= 'Z') && (visit[i][j] == false))
- {
- nume.clear();
- visit[i][j] = true;
- nume += map[i][j];
- fini.x = i;
- fini.y = j;
- if (i + 1 < map.size())
- {
- if ((map[i + 1][j] >= 'A') && (map[i + 1][j] <= 'Z'))
- {
- nume += map[i + 1][j];
- star.x = i + 1;
- star.y = j;
- }
- }
- if (j + 1 < map[0].size())
- {
- if ((map[i][j + 1] >= 'A') && (map[i][j + 1] <= 'Z'))
- {
- nume += map[i][j + 1];
- star.x = i;
- star.y = j + 1;
- }
- }
- if (i - 1 >= 0)
- {
- if ((map[i - 1][j] >= 'A') && (map[i - 1][j] <= 'Z'))
- {
- nume += map[i - 1][j];
- star.x = i - 1;
- star.y = j;
- }
- }
- if (j - 1 >= 0)
- {
- if ((map[i][j - 1] >= 'A') && (map[i][j - 1] <= 'Z'))
- {
- nume += map[i][j - 1];
- star.x = i;
- star.y = j - 1;
- }
- }
- visit[star.x][star.y] = true;
- int check = false;
- for (int k = 0; k < 4; k++)
- {
- if (checkInMap(fini.x + dirX[k], fini.y + dirY[k], map.size(), map[0].size()))
- {
- if (map[fini.x + dirX[k]][fini.y + dirY[k]] == '.')
- {
- star.x = fini.x + dirX[k];
- star.y = fini.y + dirY[k];
- char as = nume[0];
- nume[0] = nume[1];
- nume[1] = as;
- check = true;
- break;
- }
- }
- }
- if (check == false)
- {
- for (int k = 0; k < 4; k++)
- {
- if (checkInMap(star.x + dirX[k], star.y + dirY[k], map.size(), map[0].size()))
- {
- if (map[star.x + dirX[k]][star.y + dirY[k]] == '.')
- {
- star.x = star.x + dirX[k];
- star.y = star.y + dirY[k];
- break;
- }
- }
- }
- }
- if (((nume[0] != 'A') || (nume[1] != 'A')) &&
- ((nume[0] != 'Z') || (nume[1] != 'Z')))
- {
- save = nume;
- starSave = star;
- finiSave = fini;
- nume.clear();
- int i1 = star.x;
- for (int i2 = star.y + 1; i2 < map[0].size(); i2++)
- {
- i = i1;
- j = i2;
- if ((map[i][j] >= 'A') && (map[i][j] <= 'Z') && (!visit[i][j]))
- {
- nume += map[i][j];
- fini.x = i;
- fini.y = j;
- if (i + 1 < map.size())
- {
- if ((map[i + 1][j] >= 'A') && (map[i + 1][j] <= 'Z'))
- {
- nume += map[i + 1][j];
- star.x = i + 1;
- star.y = j;
- }
- }
- if (j + 1 < map[0].size())
- {
- if ((map[i][j + 1] >= 'A') && (map[i][j + 1] <= 'Z'))
- {
- nume += map[i][j + 1];
- star.x = i;
- star.y = j + 1;
- }
- }
- if (i - 1 >= 0)
- {
- if ((map[i - 1][j] >= 'A') && (map[i - 1][j] <= 'Z'))
- {
- nume += map[i - 1][j];
- star.x = i - 1;
- star.y = j;
- }
- }
- if (j - 1 >= 0)
- {
- if ((map[i][j - 1] >= 'A') && (map[i][j - 1] <= 'Z'))
- {
- nume += map[i][j - 1];
- star.x = i;
- star.y = j - 1;
- }
- }
- int check3 = true;
- for (int k = 0; k < 4; k++)
- {
- if (checkInMap(fini.x + dirX[k], fini.y + dirY[k], map.size(), map[0].size()))
- {
- if (map[fini.x + dirX[k]][fini.y + dirY[k]] == '.')
- {
- star.x = fini.x + dirX[k];
- star.y = fini.y + dirY[k];
- char as = nume[0];
- nume[0] = nume[1];
- nume[1] = as;
- check3 = false;
- break;
- }
- }
- }
- if (check3)
- {
- for (int k = 0; k < 4; k++)
- {
- if (checkInMap(star.x + dirX[k], star.y + dirY[k], map.size(), map[0].size()))
- {
- if (map[star.x + dirX[k]][star.y + dirY[k]] == '.')
- {
- star.x = star.x + dirX[k];
- star.y = star.y + dirY[k];
- break;
- }
- }
- }
- }
- if (((save[0] == nume[1]) && (save[1] == nume[0])) ||
- ((save[0] == nume[0]) && (save[1] == nume[1])))
- {
- finiSave = star;
- portals.push_back(std::make_tuple(save, starSave, finiSave));
- i2 = map[0].size();
- }
- }
- }
- for (int i1 = star.x + 1; i1 < map.size(); i1++)
- {
- for (int i2 = 0; i2 < map[0].size(); i2++)
- {
- i = i1;
- j = i2;
- if ((map[i][j] >= 'A') && (map[i][j] <= 'Z') && (!visit[i][j]))
- {
- nume.clear();
- nume += map[i][j];
- fini.x = i;
- fini.y = j;
- if (i + 1 < map.size())
- {
- if ((map[i + 1][j] >= 'A') && (map[i + 1][j] <= 'Z'))
- {
- nume += map[i + 1][j];
- star.x = i + 1;
- star.y = j;
- }
- }
- if (j + 1 < map[0].size())
- {
- if ((map[i][j + 1] >= 'A') && (map[i][j + 1] <= 'Z'))
- {
- nume += map[i][j + 1];
- star.x = i;
- star.y = j + 1;
- }
- }
- if (i - 1 >= 0)
- {
- if ((map[i - 1][j] >= 'A') && (map[i - 1][j] <= 'Z'))
- {
- nume += map[i - 1][j];
- star.x = i - 1;
- star.y = j;
- }
- }
- if (j - 1 >= 0)
- {
- if ((map[i][j - 1] >= 'A') && (map[i][j - 1] <= 'Z'))
- {
- nume += map[i][j - 1];
- star.x = i;
- star.y = j - 1;
- }
- }
- int check4 = true;
- for (int k = 0; k < 4; k++)
- {
- if (checkInMap(fini.x + dirX[k], fini.y + dirY[k], map.size(), map[0].size()))
- {
- if (map[fini.x + dirX[k]][fini.y + dirY[k]] == '.')
- {
- star.x = fini.x + dirX[k];
- star.y = fini.y + dirY[k];
- char as = nume[0];
- nume[0] = nume[1];
- nume[1] = as;
- check4 = false;
- break;
- }
- }
- }
- if (check4)
- {
- for (int k = 0; k < 4; k++)
- {
- if (checkInMap(star.x + dirX[k], star.y + dirY[k], map.size(), map[0].size()))
- {
- if (map[star.x + dirX[k]][star.y + dirY[k]] == '.')
- {
- star.x = star.x + dirX[k];
- star.y = star.y + dirY[k];
- break;
- }
- }
- }
- }
- if (((save[0] == nume[1]) && (save[1] == nume[0])) ||
- ((save[0] == nume[0]) && (save[1] == nume[1])))
- {
- finiSave = star;
- portals.push_back(std::make_tuple(save, starSave, finiSave));
- i1 = map.size();
- i2 = map[0].size();
- }
- }
- }
- }
- }
- }
- i = sss;
- j = sss2;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement