Advertisement
Guest User

Untitled

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