Advertisement
Guest User

Untitled

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