Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _02.Bunnies
  8. {
  9. class Bunnies
  10. {
  11. public static List<char[]> list = new List<char[]>();
  12. static void Main(string[] args)
  13. {
  14. int[] dimensions = Console.ReadLine().Split().Select(int.Parse).ToArray();
  15. List<char[]> array = new List<char[]>();
  16. for (int i = 0; i < dimensions[0]; i++)
  17. {
  18. char[] input = Console.ReadLine().ToCharArray();
  19. array.Add(input);
  20. list.Add(input);
  21. }
  22. int xHero = 0;
  23. int yHero = 0;
  24. for (int i = 0; i < dimensions[0]; i++)
  25. {
  26. for (int j = 0; j < dimensions[1]; j++)
  27. {
  28. if (array[i][j] == 'P')
  29. {
  30. xHero = i;
  31. yHero = j;
  32. break;
  33. }
  34. }
  35. }
  36.  
  37. char[] commands = Console.ReadLine().ToCharArray();
  38. foreach(char command in commands)
  39. {
  40. int lastX = xHero;
  41. int lastY = yHero;
  42. switch(command)
  43. {
  44. case 'U':
  45. xHero += -1;
  46. break;
  47. case 'R':
  48. yHero += 1;
  49. break;
  50. case 'D':
  51. xHero += 1;
  52. break;
  53. case 'L':
  54. yHero += -1;
  55. break;
  56. }
  57. MultiplyBunnies(array);
  58. if(EndCheck(array, xHero, yHero))
  59. {
  60. foreach(var line in array)
  61. {
  62. Console.WriteLine(string.Join("",line));
  63. }
  64. Console.WriteLine("dead: {0} {1}", lastX, lastY);
  65. break;
  66. }
  67. if(WinState(array,xHero,yHero))
  68. {
  69. foreach (var line in array)
  70. {
  71. Console.WriteLine(string.Join("", line));
  72. }
  73. Console.WriteLine("won: {0} {1}", lastX, lastY);
  74. break;
  75. }
  76. }
  77. }
  78.  
  79. private static bool WinState(List<char[]> array, int xHero, int yHero)
  80. {
  81.  
  82. if (xHero < 0 || xHero >= array.Count || yHero < 0 || yHero >= array[xHero].Length) return true;
  83. return false;
  84. }
  85.  
  86. private static bool EndCheck(List<char[]> array, int xHero, int yHero)
  87. {
  88. if (array[xHero][yHero] == 'B') return true;
  89. return false;
  90. }
  91.  
  92. private static void MultiplyBunnies(List<char[]> array)
  93. {
  94. for (int i = 0; i < array.Count; i++)
  95. {
  96. for (int j = 0; j < array[i].Length; j++)
  97. {
  98. if (array[i][j] == 'B') //if current place on main array is 'B' - multiply them on list
  99. {
  100. if ((i - 1) >= 0) list[i - 1][j] = 'B';
  101. if ((i + 1) < array.Count) list[i + 1][j] = 'B';
  102. if ((j - 1) >= 0) list[i][j - 1] = 'B';
  103. if ((j + 1) < array[i].Length) list[i][j + 1] = 'B';
  104. }
  105. }
  106. }
  107. for (int i = 0; i < array.Count; i++) //copy list into main array
  108. {
  109. for (int j = 0; j < array[i].Length; j++)
  110. {
  111. array[i][j] = list[i][j];
  112. }
  113. }
  114. }
  115. }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement