Advertisement
svetlyoek

Radioactive Mutant Vampire Bunnies

May 20th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.19 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Numerics;
  6. using System.Text;
  7. using System.Text.RegularExpressions;
  8. using System.Threading.Tasks;
  9.  
  10. namespace solutions
  11. {
  12. class Program
  13. {
  14. public static void Main()
  15. {
  16. var matrixSize = Console.ReadLine().Split().Select(int.Parse).ToArray();
  17.  
  18. var rows = matrixSize[0];
  19. var cols = matrixSize[1];
  20.  
  21. var matrix = new char[rows, cols];
  22.  
  23. var currentRow = -1;
  24. var currentCol = -1;
  25.  
  26. for (int row = 0; row < rows; row++)
  27. {
  28. var input = Console.ReadLine().ToCharArray();
  29.  
  30. for (int col = 0; col < cols; col++)
  31. {
  32. matrix[row, col] = input[col];
  33.  
  34. if (matrix[row, col] == 'P')
  35. {
  36. currentRow = row;
  37. currentCol = col;
  38. }
  39. }
  40. }
  41.  
  42. matrix[currentRow, currentCol] = '.';
  43.  
  44. var commands = Console.ReadLine().ToCharArray();
  45.  
  46. var queue = new Queue<char>(commands);
  47.  
  48. var newPlayerRow = currentRow;
  49. var newPlayerCol = currentCol;
  50.  
  51. while (queue.Count > 0)
  52. {
  53. switch (queue.Dequeue())
  54. {
  55. case 'U': newPlayerRow -= 1; break;
  56. case 'D': newPlayerRow += 1; break;
  57. case 'L': newPlayerCol -= 1; break;
  58. case 'R': newPlayerCol += 1; break;
  59. }
  60.  
  61. matrix = MultyplyBunnies(matrix, rows, cols);
  62.  
  63. if (newPlayerRow >= 0 && newPlayerRow < matrix.GetLength(0)
  64. && newPlayerCol >= 0 && newPlayerCol < matrix.GetLength(1))
  65. {
  66. currentRow = newPlayerRow;
  67. currentCol = newPlayerCol;
  68.  
  69. if (matrix[currentRow, currentCol] == 'B')
  70. {
  71. PrintMatrix(matrix, rows, cols);
  72. Console.WriteLine($"dead: {currentRow} {currentCol}");
  73. return;
  74. }
  75. }
  76. else
  77. {
  78. PrintMatrix(matrix, rows, cols);
  79. Console.WriteLine($"won: {currentRow} {currentCol}");
  80. return;
  81. }
  82.  
  83. }
  84. }
  85. public static char[,] MultyplyBunnies(char[,] matrix, int rows, int cols)
  86. {
  87. var newMatrix = new char[rows, cols];
  88.  
  89. for (int row = 0; row < rows; row++)
  90. {
  91. for (int col = 0; col < cols; col++)
  92. {
  93. newMatrix[row, col] = matrix[row, col];
  94. }
  95. }
  96.  
  97. for (int row = 0; row < rows; row++)
  98. {
  99. for (int col = 0; col < cols; col++)
  100. {
  101. if (matrix[row, col] == 'B')
  102. {
  103. if (row - 1 >= 0)
  104. {
  105. newMatrix[row - 1, col] = 'B';
  106. }
  107. if (col - 1 >= 0)
  108. {
  109. newMatrix[row, col - 1] = 'B';
  110. }
  111. if (col + 1 < cols)
  112. {
  113. newMatrix[row, col + 1] = 'B';
  114. }
  115. if (row + 1 < rows)
  116. {
  117. newMatrix[row + 1, col] = 'B';
  118. }
  119. }
  120. }
  121. }
  122. return newMatrix;
  123. }
  124. public static void PrintMatrix(char[,] matrix, int rows, int cols)
  125. {
  126. for (int row = 0; row < rows; row++)
  127. {
  128. for (int col = 0; col < cols; col++)
  129. {
  130. Console.Write(matrix[row, col]);
  131. }
  132. Console.WriteLine();
  133. }
  134. }
  135. }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement