Advertisement
Guest User

Untitled

a guest
Dec 20th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.21 KB | None | 0 0
  1. void findPortals(const std::vector<std::vector<char>>& map, std::vector<std::tuple<std::string, Coordinate, Coordinate>>& portals)
  2. {
  3. std::vector<std::vector<bool>> visit(1000, std::vector<bool>(1000, false));
  4. std::tuple<std::string, Coordinate, Coordinate> sa;
  5. std::string nume;
  6. Coordinate star;
  7. Coordinate fini;
  8.  
  9. std::string save;
  10. Coordinate starSave;
  11. Coordinate finiSave;
  12.  
  13. int dirX[] = { -1,0,0,1 };
  14. int dirY[] = { 0,-1,1,0 };
  15. int sss = 0;
  16. int sss2 = 0;
  17. for (int i = 0; i < map.size(); i++)
  18. {
  19. for (int j = 0; j < map[0].size(); j++)
  20. {
  21. sss = i;
  22. sss2 = j;
  23. if ((map[i][j] >= 'A') && (map[i][j] <= 'Z') && (visit[i][j] == false))
  24. {
  25. nume.clear();
  26. visit[i][j] = true;
  27. nume += map[i][j];
  28. fini.x = i;
  29. fini.y = j;
  30.  
  31. if (i + 1 < map.size())
  32. {
  33. if ((map[i + 1][j] >= 'A') && (map[i + 1][j] <= 'Z'))
  34. {
  35. nume += map[i + 1][j];
  36. star.x = i + 1;
  37. star.y = j;
  38. }
  39. }
  40. if (j + 1 < map[0].size())
  41. {
  42. if ((map[i][j + 1] >= 'A') && (map[i][j + 1] <= 'Z'))
  43. {
  44. nume += map[i][j + 1];
  45. star.x = i;
  46. star.y = j + 1;
  47. }
  48. }
  49. if (i - 1 >= 0)
  50. {
  51. if ((map[i - 1][j] >= 'A') && (map[i - 1][j] <= 'Z'))
  52. {
  53. nume += map[i - 1][j];
  54. star.x = i - 1;
  55. star.y = j;
  56. }
  57. }
  58. if (j - 1 >= 0)
  59. {
  60. if ((map[i][j - 1] >= 'A') && (map[i][j - 1] <= 'Z'))
  61. {
  62. nume += map[i][j - 1];
  63. star.x = i;
  64. star.y = j - 1;
  65. }
  66. }
  67.  
  68. visit[star.x][star.y] = true;
  69. int check = false;
  70. for (int k = 0; k < 4; k++)
  71. {
  72. if (checkInMap(fini.x + dirX[k], fini.y + dirY[k], map.size(), map[0].size()))
  73. {
  74. if (map[fini.x + dirX[k]][fini.y + dirY[k]] == '.')
  75. {
  76. star.x = fini.x + dirX[k];
  77. star.y = fini.y + dirY[k];
  78. char as = nume[0];
  79. nume[0] = nume[1];
  80. nume[1] = as;
  81. check = true;
  82. break;
  83. }
  84. }
  85. }
  86. if (check == false)
  87. {
  88. for (int k = 0; k < 4; k++)
  89. {
  90. if (checkInMap(star.x + dirX[k], star.y + dirY[k], map.size(), map[0].size()))
  91. {
  92. if (map[star.x + dirX[k]][star.y + dirY[k]] == '.')
  93. {
  94. star.x = star.x + dirX[k];
  95. star.y = star.y + dirY[k];
  96. break;
  97. }
  98. }
  99. }
  100. }
  101. if (((nume[0] != 'A') || (nume[1] != 'A')) &&
  102. ((nume[0] != 'Z') || (nume[1] != 'Z')))
  103. {
  104. save = nume;
  105. starSave = star;
  106. finiSave = fini;
  107. nume.clear();
  108.  
  109. int i1 = star.x;
  110. for (int i2 = star.y + 1; i2 < map[0].size(); i2++)
  111. {
  112. i = i1;
  113. j = i2;
  114. if ((map[i][j] >= 'A') && (map[i][j] <= 'Z') && (!visit[i][j]))
  115. {
  116. nume += map[i][j];
  117. fini.x = i;
  118. fini.y = j;
  119.  
  120. if (i + 1 < map.size())
  121. {
  122. if ((map[i + 1][j] >= 'A') && (map[i + 1][j] <= 'Z'))
  123. {
  124. nume += map[i + 1][j];
  125. star.x = i + 1;
  126. star.y = j;
  127. }
  128. }
  129. if (j + 1 < map[0].size())
  130. {
  131. if ((map[i][j + 1] >= 'A') && (map[i][j + 1] <= 'Z'))
  132. {
  133. nume += map[i][j + 1];
  134. star.x = i;
  135. star.y = j + 1;
  136. }
  137. }
  138. if (i - 1 >= 0)
  139. {
  140. if ((map[i - 1][j] >= 'A') && (map[i - 1][j] <= 'Z'))
  141. {
  142. nume += map[i - 1][j];
  143. star.x = i - 1;
  144. star.y = j;
  145. }
  146. }
  147. if (j - 1 >= 0)
  148. {
  149. if ((map[i][j - 1] >= 'A') && (map[i][j - 1] <= 'Z'))
  150. {
  151. nume += map[i][j - 1];
  152. star.x = i;
  153. star.y = j - 1;
  154. }
  155. }
  156. int check3 = true;
  157. for (int k = 0; k < 4; k++)
  158. {
  159. if (checkInMap(fini.x + dirX[k], fini.y + dirY[k], map.size(), map[0].size()))
  160. {
  161. if (map[fini.x + dirX[k]][fini.y + dirY[k]] == '.')
  162. {
  163. star.x = fini.x + dirX[k];
  164. star.y = fini.y + dirY[k];
  165. char as = nume[0];
  166. nume[0] = nume[1];
  167. nume[1] = as;
  168. check3 = false;
  169. break;
  170. }
  171. }
  172. }
  173. if (check3)
  174. {
  175. for (int k = 0; k < 4; k++)
  176. {
  177. if (checkInMap(star.x + dirX[k], star.y + dirY[k], map.size(), map[0].size()))
  178. {
  179. if (map[star.x + dirX[k]][star.y + dirY[k]] == '.')
  180. {
  181. star.x = star.x + dirX[k];
  182. star.y = star.y + dirY[k];
  183. break;
  184. }
  185. }
  186. }
  187. }
  188.  
  189. if (((save[0] == nume[1]) && (save[1] == nume[0])) ||
  190. ((save[0] == nume[0]) && (save[1] == nume[1])))
  191. {
  192. finiSave = star;
  193. portals.push_back(std::make_tuple(save, starSave, finiSave));
  194. i2 = map[0].size();
  195. }
  196.  
  197. }
  198. }
  199.  
  200. for (int i1 = star.x + 1; i1 < map.size(); i1++)
  201. {
  202. for (int i2 = 0; i2 < map[0].size(); i2++)
  203. {
  204. i = i1;
  205. j = i2;
  206. if ((map[i][j] >= 'A') && (map[i][j] <= 'Z') && (!visit[i][j]))
  207. {
  208. nume.clear();
  209. nume += map[i][j];
  210. fini.x = i;
  211. fini.y = j;
  212.  
  213. if (i + 1 < map.size())
  214. {
  215. if ((map[i + 1][j] >= 'A') && (map[i + 1][j] <= 'Z'))
  216. {
  217. nume += map[i + 1][j];
  218. star.x = i + 1;
  219. star.y = j;
  220. }
  221. }
  222. if (j + 1 < map[0].size())
  223. {
  224. if ((map[i][j + 1] >= 'A') && (map[i][j + 1] <= 'Z'))
  225. {
  226. nume += map[i][j + 1];
  227. star.x = i;
  228. star.y = j + 1;
  229. }
  230. }
  231. if (i - 1 >= 0)
  232. {
  233. if ((map[i - 1][j] >= 'A') && (map[i - 1][j] <= 'Z'))
  234. {
  235. nume += map[i - 1][j];
  236. star.x = i - 1;
  237. star.y = j;
  238. }
  239. }
  240. if (j - 1 >= 0)
  241. {
  242. if ((map[i][j - 1] >= 'A') && (map[i][j - 1] <= 'Z'))
  243. {
  244. nume += map[i][j - 1];
  245. star.x = i;
  246. star.y = j - 1;
  247. }
  248. }
  249. int check4 = true;
  250. for (int k = 0; k < 4; k++)
  251. {
  252. if (checkInMap(fini.x + dirX[k], fini.y + dirY[k], map.size(), map[0].size()))
  253. {
  254. if (map[fini.x + dirX[k]][fini.y + dirY[k]] == '.')
  255. {
  256. star.x = fini.x + dirX[k];
  257. star.y = fini.y + dirY[k];
  258. char as = nume[0];
  259. nume[0] = nume[1];
  260. nume[1] = as;
  261. check4 = false;
  262. break;
  263. }
  264. }
  265. }
  266. if (check4)
  267. {
  268. for (int k = 0; k < 4; k++)
  269. {
  270. if (checkInMap(star.x + dirX[k], star.y + dirY[k], map.size(), map[0].size()))
  271. {
  272. if (map[star.x + dirX[k]][star.y + dirY[k]] == '.')
  273. {
  274. star.x = star.x + dirX[k];
  275. star.y = star.y + dirY[k];
  276. break;
  277. }
  278. }
  279. }
  280. }
  281.  
  282. if (((save[0] == nume[1]) && (save[1] == nume[0])) ||
  283. ((save[0] == nume[0]) && (save[1] == nume[1])))
  284. {
  285. finiSave = star;
  286. portals.push_back(std::make_tuple(save, starSave, finiSave));
  287. i1 = map.size();
  288. i2 = map[0].size();
  289. }
  290. }
  291.  
  292. }
  293. }
  294. }
  295. }
  296. i = sss;
  297. j = sss2;
  298. }
  299. }
  300. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement