Advertisement
Guest User

Untitled

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