Advertisement
haufont

Untitled

Aug 29th, 2016
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.81 KB | None | 0 0
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <set>
  6. #include <string>
  7. #include <map>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <string>
  11. #include <queue>
  12. #include <time.h>
  13. #include <stack>
  14. #include <iostream>
  15. #include <fstream>
  16. using namespace std;
  17.  
  18. char matrix[100][100];
  19. deque <pair<int,int>> rest;
  20. bool used[100][100];
  21.  
  22. int dx[4] = { 1, -1, 0, 0 };
  23. int dy[4] = { 0, 0, -1, 1 };
  24. int n, m;
  25.  
  26. bool bfs(int x, int y)
  27. {
  28. used[x][y] = 1;
  29. rest.push_back(make_pair(x, y));
  30. while (rest.size())
  31. {
  32. pair<int, int>t = rest.front();
  33. rest.pop_front();
  34. x = t.first;
  35. y = t.second;
  36. for (int i = 0; i < 4; i++)
  37. {
  38. if (-1 < x + dx[i] < n && -1 < y + dy[i] < m && !used[x + dx[i]][y + dy[i]])
  39. {
  40. if (matrix[x + dx[i]][y + dy[i]] == '.' || matrix[x + dx[i]][y + dy[i]] == 'O')
  41. {
  42. used[x + dx[i]][y + dy[i]] = 1;
  43. rest.push_back(make_pair(x + dx[i], y + dy[i]));
  44. }
  45. else
  46. {
  47. if (matrix[x + dx[i]][y + dy[i]] == 'X')
  48. {
  49. return true;
  50. }
  51. }
  52. }
  53. }
  54. }
  55. return false;
  56. }
  57. int main()
  58. {
  59. srand(time(NULL));
  60. cin >> n >> m;
  61. if (n > 100 || m > 100)
  62. {
  63. cout << "Build error";
  64. return 0;
  65. }
  66. matrix[1][1] = 'O';
  67. used[1][1] = true;
  68. int ty = 0;
  69. for (int i = 0; i < n; i++)
  70. {
  71. for (int j = 0; j < m; j++)
  72. {
  73. if (!used[i][j] && rand() % 10 == 0)
  74. {
  75. double f = (ty + 1) / n*m;
  76. if (f < 0.2)
  77. {
  78. matrix[i][j] = 'X';
  79. ty++;
  80. used[i][j] = true;
  81. }
  82. }
  83. if (!used[i][j])
  84. {
  85. matrix[i][j] = '.';
  86. used[i][j] = true;
  87. }
  88. }
  89. }
  90. int x1 = 1, y1 = 1;
  91. if (ty == 0)
  92. {
  93. cout << "Randow victory";
  94. return 0;
  95. }
  96. while (ty != 0)
  97. {
  98. for (int i = 0; i < n; i++)
  99. {
  100. for (int j = 0; j < m; j++)
  101. {
  102. cout << matrix[i][j];
  103. }
  104. cout << endl;
  105. }
  106. char s, t;
  107. bool ryt = false;
  108. cin >> s >> t;
  109. bool gt = false;
  110. bool tr = false;
  111. tr = (s == 'q');
  112. int h;
  113. if (t == 'w')
  114. h = 1;
  115. if (t == 'd')
  116. h = 3;
  117. if (t == 's')
  118. h = 0;
  119. if (t == 'a')
  120. h = 2;
  121. if (tr)
  122. {
  123. for (int i = 0; i < 4; i++)
  124. {
  125. if (h == i)
  126. {
  127. if (-1 < x1 + dx[i] < n && -1 < y1 + dy[i] < m && matrix[x1 + dx[i]][y1 + dy[i]] == '.')
  128. {
  129. matrix[x1][y1] = '.';
  130. x1 += dx[i];
  131. y1 += dy[i];
  132. matrix[x1][y1] = 'O';
  133. }
  134. else
  135. {
  136. cout << "impossible" << endl;
  137. gt = true;
  138. break;
  139. }
  140. }
  141. }
  142. if (gt)
  143. continue;
  144. }
  145. else
  146. {
  147. int x2 = x1;
  148. int y2 = y1;
  149. for (int i = 0; i < 4; i++)
  150. {
  151. if (h == i)
  152. {
  153. while ((-1 < x1 + dx[i]) && (x1 + dx[i] < n) && (-1 < y1 + dy[i]) && (y1 + dy[i] < m) && matrix[x1 + dx[i]][y1 + dy[i]] != '#')
  154. {
  155. x1 += dx[i];
  156. y1 += dy[i];
  157. if (matrix[x1][y1] == 'X')
  158. {
  159. ty--;
  160. matrix[x1][y1] = '.';
  161. break;
  162. }
  163. if (matrix[x1][y1] == '#')
  164. {
  165. break;
  166. }
  167. matrix[x1][y1] = '-';
  168. for (int i = 0; i < n; i++)
  169. {
  170. for (int j = 0; j < m; j++)
  171. {
  172. cout << matrix[i][j];
  173. }
  174. cout << endl;
  175. }
  176. if (matrix[x1][y1] == '-')
  177. {
  178. matrix[x1][y1] = '.';
  179. }
  180. Sleep(1000);
  181. }
  182. }
  183. }
  184. x1 = x2;
  185. y1 = y2;
  186. }
  187. for (int i = 0; i < n; i++)
  188. {
  189. for (int j = 0; j < m; j++)
  190. {
  191. if (matrix[i][j] == 'X')
  192. {
  193. int y = rand();
  194. for (int v = 0; v < 4; v++)
  195. {
  196. if (y % 8 == v)
  197. {
  198. if ((-1 < i + dx[v]) && (i + dx[v]) < n && (-1 < j + dy[v]) && (j + dy[v] < m) && matrix[i + dx[v]][j + dy[v]] == '.')
  199. {
  200. matrix[i][j] = '.';
  201. matrix[i + dx[v]][j + dy[v]] = 'X';
  202. }
  203. }
  204. if (y % 8 == v + 4)
  205. {
  206. if ((-1 < i + dx[v]) && (i + dx[v]) < n && (-1 < j + dy[v]) && (j + dy[v] < m) && matrix[i + dx[v]][j + dy[v]] == '.')
  207. {
  208. matrix[i + dx[v]][j + dy[v]] = '#';
  209. }
  210. }
  211. }
  212. if (y % 200 == 199)
  213. {
  214. cout << "AllllllaxAkbaaar" << endl;
  215. for (int sd = 0; sd < m; sd++)
  216. {
  217. if (matrix[sd][j] == 'O')
  218. {
  219. cout << "FFFFFFFFFFFFFFFFFFatality" << endl;
  220. ryt = true;
  221. }
  222. if (matrix[sd][j] == 'X')
  223. ty--;
  224. if (sd != i)
  225. {
  226. matrix[sd][j] = '#';
  227. }
  228. else
  229. {
  230. matrix[sd][j] = '.';
  231. ty--;
  232. }
  233. }
  234. }
  235. }
  236. }
  237. }
  238. bool g = bfs(x1, y1);
  239. if (ryt && !g)
  240. {
  241. for (int i = 0; i < n; i++)
  242. {
  243. for (int j = 0; j < m; j++)
  244. {
  245. cout << matrix[i][j];
  246. }
  247. cout << endl;
  248. }
  249. cout << "GameOver" << endl;
  250. return 0;
  251. }
  252. }
  253. for (int i = 0; i < n; i++)
  254. {
  255. for (int j = 0; j < m; j++)
  256. {
  257. cout << matrix[i][j];
  258. }
  259. cout << endl;
  260. }
  261. cout << "Izi vin";
  262. return 0;
  263. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement