Advertisement
Guest User

Untitled

a guest
May 24th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.16 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _10._Radioactive_Mutant_Bunnies
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10.  
  11. int[] dimensions = Console.ReadLine()
  12. .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  13. .Select(int.Parse)
  14. .ToArray();
  15.  
  16. int rows = dimensions[0];
  17. int columns = dimensions[1];
  18.  
  19. char[,] matrix = new char[rows, columns];
  20. int currentRow = 0;
  21. int currentCol = 0;
  22. bool isDead = false;
  23. bool isOutside = false;
  24.  
  25. for (int i = 0; i < rows; i++)
  26. {
  27. string values = Console.ReadLine();
  28.  
  29. for (int j = 0; j < columns; j++)
  30. {
  31. matrix[i, j] = values[j];
  32. if (matrix[i, j] == 'P')
  33. {
  34. currentRow = i;
  35. currentCol = j;
  36. }
  37. }
  38. }
  39.  
  40. string commands = Console.ReadLine();
  41.  
  42.  
  43. for (int i = 0; i < commands.Length; i++)
  44. {
  45.  
  46. if (commands[i] == 'U')
  47. {
  48. if (currentRow - 1 >= 0)
  49. {
  50. if (matrix[currentRow - 1, currentCol] == '.')
  51. {
  52. matrix[currentRow, currentCol] = '.';
  53. currentRow = currentRow - 1;
  54. matrix[currentRow, currentCol] = 'P';
  55.  
  56. }
  57. else if (matrix[currentRow - 1, currentCol] == 'B')
  58. {
  59. currentRow = currentRow - 1;
  60. isDead = true;
  61. }
  62. }
  63. else
  64. {
  65. matrix[currentRow, currentCol] = '.';
  66.  
  67. isOutside = true;
  68. }
  69. }
  70.  
  71. if (commands[i] == 'D')
  72. {
  73. if (currentRow + 1 < rows)
  74. {
  75. if (matrix[currentRow + 1, currentCol] == '.')
  76. {
  77. matrix[currentRow, currentCol] = '.';
  78. currentRow = currentRow + 1;
  79. matrix[currentRow, currentCol] = 'P';
  80.  
  81. }
  82. else if (matrix[currentRow + 1, currentCol] == 'B')
  83. {
  84. currentRow = currentRow + 1;
  85. isDead = true;
  86. }
  87. }
  88. else
  89. {
  90. matrix[currentRow, currentCol] = '.';
  91.  
  92. isOutside = true;
  93. }
  94. }
  95.  
  96. if (commands[i] == 'L')
  97. {
  98. if (currentCol - 1 >= 0)
  99. {
  100. if (matrix[currentRow, currentCol - 1] == '.')
  101. {
  102.  
  103. matrix[currentRow, currentCol] = '.';
  104. currentCol = currentCol - 1;
  105. matrix[currentRow, currentCol] = 'P';
  106.  
  107. }
  108. else if (matrix[currentRow, currentCol - 1] == 'B')
  109. {
  110. currentCol = currentCol - 1;
  111. isDead = true;
  112. }
  113. }
  114. else
  115. {
  116. matrix[currentRow, currentCol] = '.';
  117.  
  118. isOutside = true;
  119. }
  120. }
  121.  
  122. if (commands[i] == 'R')
  123. {
  124. if (currentCol + 1 < rows)
  125. {
  126. if (matrix[currentRow, currentCol + 1] == '.')
  127. {
  128.  
  129. matrix[currentRow, currentCol] = '.';
  130. currentCol = currentCol + 1;
  131. matrix[currentRow, currentCol] = 'P';
  132. }
  133. else if (matrix[currentRow, currentCol + 1] == 'B')
  134. {
  135. currentCol = currentCol + 1;
  136. isDead = true;
  137. }
  138. }
  139. else
  140. {
  141. matrix[currentRow, currentCol] = '.';
  142.  
  143. isOutside = true;
  144. }
  145. }
  146.  
  147.  
  148. for (int row = 0; row < rows; row++)
  149. {
  150. for (int col = 0; col < columns; col++)
  151. {
  152. if (matrix[row, col] == 'B')
  153. {
  154. //UP
  155. if (row - 1 >= 0)
  156. {
  157. if (matrix[row - 1, col] == 'P')
  158. {
  159. matrix[row - 1, col] = 'B';
  160. isDead = true;
  161. }
  162. else if (matrix[row - 1, col] == '.')
  163. {
  164. matrix[row - 1, col] = 'A';
  165. }
  166. }
  167.  
  168. //DOWN
  169. if (row + 1 < rows)
  170. {
  171. if (matrix[row + 1, col] == 'P')
  172. {
  173. matrix[row + 1, col] = 'B';
  174. isDead = true;
  175. }
  176. else if (matrix[row + 1, col] == '.')
  177. {
  178. matrix[row + 1, col] = 'A';
  179. }
  180. }
  181.  
  182. //LEFT
  183. if (col - 1 >= 0)
  184. {
  185. if (matrix[row, col - 1] == 'P')
  186. {
  187. matrix[row, col - 1] = 'B';
  188. isDead = true;
  189. }
  190. else if (matrix[row, col - 1] == '.')
  191. {
  192. matrix[row, col - 1] = 'A';
  193. }
  194. }
  195.  
  196. //RIGHT
  197. if (col + 1 < rows)
  198. {
  199. if (matrix[row, col + 1] == 'P')
  200. {
  201. matrix[row, col + 1] = 'B';
  202. isDead = true;
  203. }
  204. else if (matrix[row, col + 1] == '.')
  205. {
  206. matrix[row, col + 1] = 'A';
  207. }
  208. }
  209. }
  210. }
  211. }
  212.  
  213.  
  214. for (int row = 0; row < rows; row++)
  215. {
  216. for (int col = 0; col < columns; col++)
  217. {
  218. if (matrix[row, col] == 'A')
  219. {
  220. matrix[row, col] = 'B';
  221. }
  222. }
  223. }
  224.  
  225. if (isDead == true || isOutside == true)
  226. {
  227. break;
  228. }
  229. }
  230.  
  231.  
  232. for (int i = 0; i < rows; i++)
  233. {
  234.  
  235. for (int j = 0; j < columns; j++)
  236. {
  237. Console.Write($"{matrix[i, j]}");
  238. }
  239. Console.WriteLine();
  240. }
  241.  
  242. if (isDead)
  243. {
  244. Console.WriteLine($"dead: {currentRow} {currentCol}");
  245. }
  246.  
  247. if (isOutside)
  248. {
  249. Console.WriteLine($"won: {currentRow} {currentCol}");
  250. }
  251. }
  252. }
  253. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement