Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _02.Bunnies
- {
- class Bunnies
- {
- public static List<char[]> list = new List<char[]>();
- static void Main(string[] args)
- {
- int[] dimensions = Console.ReadLine().Split().Select(int.Parse).ToArray();
- List<char[]> array = new List<char[]>();
- for (int i = 0; i < dimensions[0]; i++)
- {
- char[] input = Console.ReadLine().ToCharArray();
- array.Add(input);
- list.Add(input);
- }
- int xHero = 0;
- int yHero = 0;
- for (int i = 0; i < dimensions[0]; i++)
- {
- for (int j = 0; j < dimensions[1]; j++)
- {
- if (array[i][j] == 'P')
- {
- xHero = i;
- yHero = j;
- break;
- }
- }
- }
- char[] commands = Console.ReadLine().ToCharArray();
- foreach(char command in commands)
- {
- int lastX = xHero;
- int lastY = yHero;
- switch(command)
- {
- case 'U':
- xHero += -1;
- break;
- case 'R':
- yHero += 1;
- break;
- case 'D':
- xHero += 1;
- break;
- case 'L':
- yHero += -1;
- break;
- }
- MultiplyBunnies(array);
- if(EndCheck(array, xHero, yHero))
- {
- foreach(var line in array)
- {
- Console.WriteLine(string.Join("",line));
- }
- Console.WriteLine("dead: {0} {1}", lastX, lastY);
- break;
- }
- if(WinState(array,xHero,yHero))
- {
- foreach (var line in array)
- {
- Console.WriteLine(string.Join("", line));
- }
- Console.WriteLine("won: {0} {1}", lastX, lastY);
- break;
- }
- }
- }
- private static bool WinState(List<char[]> array, int xHero, int yHero)
- {
- if (xHero < 0 || xHero >= array.Count || yHero < 0 || yHero >= array[xHero].Length) return true;
- return false;
- }
- private static bool EndCheck(List<char[]> array, int xHero, int yHero)
- {
- if (array[xHero][yHero] == 'B') return true;
- return false;
- }
- private static void MultiplyBunnies(List<char[]> array)
- {
- for (int i = 0; i < array.Count; i++)
- {
- for (int j = 0; j < array[i].Length; j++)
- {
- if (array[i][j] == 'B') //if current place on main array is 'B' - multiply them on list
- {
- if ((i - 1) >= 0) list[i - 1][j] = 'B';
- if ((i + 1) < array.Count) list[i + 1][j] = 'B';
- if ((j - 1) >= 0) list[i][j - 1] = 'B';
- if ((j + 1) < array[i].Length) list[i][j + 1] = 'B';
- }
- }
- }
- for (int i = 0; i < array.Count; i++) //copy list into main array
- {
- for (int j = 0; j < array[i].Length; j++)
- {
- array[i][j] = list[i][j];
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement