Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Radioactive_Mutant_Vampire_Bunnies
- {
- class Program
- {
- static int rows;
- static int cols;
- static List<int> list = new List<int>();
- static char[][] matrix;
- static int pRow;
- static int pCol;
- static bool live = true;
- static bool win = false;
- static void Main()
- {
- var nxm = Console.ReadLine()
- .Split(' ', StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- rows = nxm[0];
- cols = nxm[1];
- matrix = new char[rows][];
- for (int row = 0; row < rows; row++)
- {
- matrix[row] = new char[cols];
- var input = Console.ReadLine()
- .ToCharArray();
- for (int col = 0; col < cols; col++)
- {
- matrix[row][col] = input[col];
- if (matrix[row][col] == 'P')
- {
- pRow = row;
- pCol = col;
- }
- else if (matrix[row][col] == 'B')
- {
- list.Add(row);
- list.Add(col);
- }
- }
- }
- var comm= Console.ReadLine();
- foreach (var cha in comm)
- {
- Move(cha);
- Spare();
- if (win)
- {
- Print();
- Console.WriteLine($"won: {pRow} {pCol}");
- break;
- }
- if (!live)
- {
- Print();
- Console.WriteLine($"dead: {pRow} {pCol}");
- break;
- }
- }
- }
- private static void Spare()
- {
- var n = list.Count;
- for (int i = 0; i < n; i += 2)
- {
- for (int row = -1; row < 2; row++)
- {
- for (int col = -1; col < 2; col++)
- {
- var r = list[i];
- var c = list[i + 1];
- if (!((row == 0 && col == 0) ||
- (row == -1 && col == -1) ||
- (row == -1 && col == 1) ||
- (row == 1 && col == 1) ||
- (row == 1 && col == -1)))
- {
- if (IsIn(r + row, c + col))
- {
- if (matrix[r + row][c + col] == 'P') live = false;
- matrix[r + row][c + col] = 'B';
- list.Add(r + row);
- list.Add(c + col);
- }
- }
- }
- }
- }
- }
- private static void Move(char ch)
- {
- switch (ch)
- {
- case 'U': Direkt(pRow - 1, pCol - 0); break;
- case 'D': Direkt(pRow + 1, pCol - 0); break;
- case 'R': Direkt(pRow - 0, pCol + 1); break;
- case 'L': Direkt(pRow - 0, pCol - 1); break;
- }
- }
- private static void Direkt(int r, int c)
- {
- matrix[pRow][pCol] = '.';
- if (IsIn(r, c))
- {
- if (matrix[r][c] == 'B')
- live = false;
- else
- matrix[r][c] = 'P';
- pRow = r;
- pCol = c;
- }
- else
- win = true;
- }
- static bool IsIn(int r, int c)
- {
- if (r >= 0 && r < rows && c >= 0 && c < cols)
- return true;
- else
- return false;
- }
- private static void Print()
- {
- foreach (var row in matrix)
- {
- if (row.Any())
- Console.WriteLine(string.Join("", row));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement