Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace _10_Radio_Active_Mutant_Vampire_Bunnies
- {
- class Program
- {
- static char[,] matrix;
- static void Main(string[] args)
- {
- var input = Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- matrix = new char[input[0], input[1]];
- (int rowCheck, int colCheck) = MatrixLoading();
- string moves = Console.ReadLine();
- bool IsSuccessMove = false;
- bool IsLive = false;
- bool playerDead = false;
- for (int i = 0; i < moves.Length; i++)
- {
- if (moves[i] == 'R')
- {
- if (IsValid(rowCheck, colCheck + 1) == true)
- {
- if (matrix[rowCheck, colCheck + 1] == '.')
- {
- matrix[rowCheck, colCheck] = '.';
- IsSuccessMove = true;
- }
- else if (matrix[rowCheck, colCheck + 1] == 'B')
- {
- playerDead = true;
- }
- colCheck = colCheck + 1;
- }
- else
- {
- matrix[rowCheck, colCheck] = '.';
- BonneyMoves();
- MatrixPrint();
- Console.WriteLine($"won: {rowCheck} {colCheck}");
- return;
- }
- }
- else if (moves[i] == 'L')
- {
- if (IsValid(rowCheck, colCheck - 1) == true)
- {
- if (matrix[rowCheck, colCheck - 1] == '.')
- {
- matrix[rowCheck, colCheck] = '.';
- IsSuccessMove = true;
- }
- else if (matrix[rowCheck, colCheck - 1] == 'B')
- {
- playerDead = true;
- }
- colCheck = colCheck - 1;
- }
- else
- {
- matrix[rowCheck, colCheck] = '.'; matrix[rowCheck, colCheck] = '.';
- BonneyMoves();
- MatrixPrint();
- Console.WriteLine($"won: {rowCheck} {colCheck}");
- return;
- }
- }
- else if (moves[i] == 'U')
- {
- if (IsValid(rowCheck - 1, colCheck) == true)
- {
- if (matrix[rowCheck - 1, colCheck] == '.')
- {
- matrix[rowCheck, colCheck] = '.';
- IsSuccessMove = true;
- }
- else if (matrix[rowCheck - 1, colCheck] == 'B')
- {
- playerDead = true;
- }
- rowCheck = rowCheck - 1;
- }
- else
- {
- matrix[rowCheck, colCheck] = '.';
- BonneyMoves();
- MatrixPrint();
- Console.WriteLine($"won: {rowCheck} {colCheck}");
- return;
- }
- }
- else if (moves[i] == 'D')
- {
- if (IsValid(rowCheck + 1, colCheck) == true)
- {
- if (matrix[rowCheck + 1, colCheck] == '.')
- {
- matrix[rowCheck, colCheck] = '.';
- IsSuccessMove = true;
- }
- else if (matrix[rowCheck + 1, colCheck] == 'B')
- {
- playerDead = true;
- }
- rowCheck = rowCheck + 1;
- }
- else
- {
- matrix[rowCheck, colCheck] = '.';
- BonneyMoves();
- MatrixPrint();
- Console.WriteLine($"won: {rowCheck} {colCheck}");
- return;
- }
- }
- if (playerDead)
- {
- BonneyMoves();
- MatrixPrint();
- Console.WriteLine($"dead: {rowCheck} {colCheck}");
- return;
- }
- else if (IsSuccessMove)
- {
- matrix[rowCheck, colCheck] = 'P';
- BonneyMoves();
- foreach (var items in matrix)
- {
- if (items == 'P')
- {
- IsLive = true;
- }
- }
- if (IsLive == false)
- {
- MatrixPrint();
- Console.WriteLine($"dead: {rowCheck} {colCheck}");
- return;
- }
- }
- IsSuccessMove = false;
- }
- }
- private static (int, int) MatrixLoading()
- {
- int rowCheck = 0;
- int colCheck = 0;
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- string items = Console.ReadLine();
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- matrix[row, col] = items[col];
- if (matrix[row, col] == 'P')
- {
- rowCheck = row;
- colCheck = col;
- }
- }
- }
- return (rowCheck, colCheck);
- }
- private static bool IsValid(int rowCheck, int colCheck)
- {
- if ((rowCheck >= 0 && rowCheck < matrix.GetLength(0)) && (colCheck >= 0 && colCheck < matrix.GetLength(1)))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- private static void MatrixPrint()
- {
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- Console.Write(matrix[row, col]);
- }
- Console.WriteLine();
- }
- }
- private static void BonneyMoves()
- {
- var indexBunnies = new Dictionary<int, List<int>>();
- int count = 0;
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- if (matrix[row, col] == 'B')
- {
- indexBunnies.Add(count, new List<int>());
- indexBunnies[count].Add(row);
- indexBunnies[count].Add(col);
- count++;
- }
- }
- }
- for (int i =0;i<indexBunnies.Count;i++)
- {
- int row = indexBunnies[i][0];
- int col = indexBunnies[i][1];
- if (IsValid(row - 1, col) == true && matrix[row - 1, col] != 'B')
- {
- matrix[row - 1, col] = 'B';
- }
- if (IsValid(row + 1, col) == true && matrix[row + 1, col] != 'B')
- {
- matrix[row + 1, col] = 'B';
- }
- if (IsValid(row, col - 1) == true && matrix[row, col - 1] != 'B')
- {
- matrix[row, col - 1] = 'B';
- }
- if (IsValid(row, col + 1) == true && matrix[row, col + 1] != 'B')
- {
- matrix[row, col + 1] = 'B';
- }
- }
- indexBunnies.Clear();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement