Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _10._Radioactive_Mutant_Vampire_Bunnies
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] size = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- int rows = size[0];
- int cols = size[1];
- int playerRow = -1;
- int playerCol = -1;
- char[,] playGraund = new char[rows, cols];
- for (int row = 0; row < rows; row++)
- {
- char[] input = Console.ReadLine().ToCharArray();
- for (int col = 0; col < cols; col++)
- {
- playGraund[row, col] = input[col];
- if (playGraund[row, col] == 'P')
- {
- playerRow = row;
- playerCol = col;
- }
- }
- }
- char[] cmd = Console.ReadLine().ToArray();
- Queue<int[]> bunniesIndexes = new Queue<int[]>();
- for (int c = 0; c < cmd.Length; c++)
- {
- BunniesFinder(rows, cols, playGraund, bunniesIndexes);
- bool won = false;
- char currMove = cmd[c];
- MultiplyBunny(rows, cols, playGraund, bunniesIndexes);
- if (currMove == 'U')
- {
- if (playerRow - 1 >= 0)
- {
- if (playGraund[playerRow - 1, playerCol] == '.')
- {
- playGraund[playerRow, playerCol] = '.';
- playGraund[playerRow - 1, playerCol] = 'P';
- playerRow -= 1;
- }
- else
- {
- if (playGraund[playerRow, playerCol] != 'B')
- {
- playGraund[playerRow, playerCol] = '.';
- }
- PrintPlayground(rows, cols, playGraund);
- Console.WriteLine($"dead: {playerRow - 1} {playerCol}");
- break;
- }
- }
- else
- {
- if (playGraund[playerRow, playerCol] != 'B')
- {
- playGraund[playerRow, playerCol] = '.';
- }
- won = true;
- }
- }
- else if (currMove == 'D')
- {
- if (playerRow + 1 < rows)
- {
- if (playGraund[playerRow + 1, playerCol] == '.')
- {
- playGraund[playerRow, playerCol] = '.';
- playGraund[playerRow + 1, playerCol] = 'P';
- playerRow += 1;
- }
- else
- {
- if (playGraund[playerRow, playerCol] != 'B')
- {
- playGraund[playerRow, playerCol] = '.';
- }
- PrintPlayground(rows, cols, playGraund);
- Console.WriteLine($"dead: {playerRow + 1} {playerCol}");
- break;
- }
- }
- else
- {
- if (playGraund[playerRow, playerCol] != 'B')
- {
- playGraund[playerRow, playerCol] = '.';
- }
- won = true;
- }
- }
- else if (currMove == 'L')
- {
- if (playerCol - 1 >= 0)
- {
- if (playGraund[playerRow, playerCol - 1] == '.')
- {
- playGraund[playerRow, playerCol] = '.';
- playGraund[playerRow, playerCol - 1] = 'P';
- playerCol -= 1;
- }
- else
- {
- if (playGraund[playerRow, playerCol] != 'B')
- {
- playGraund[playerRow, playerCol] = '.';
- }
- PrintPlayground(rows, cols, playGraund);
- Console.WriteLine($"dead: {playerRow} {playerCol - 1}");
- break;
- }
- }
- else
- {
- if (playGraund[playerRow, playerCol] != 'B')
- {
- playGraund[playerRow, playerCol] = '.';
- }
- won = true;
- }
- }
- else if (currMove == 'R')
- {
- if (playerCol + 1 < cols)
- {
- if (playGraund[playerRow, playerCol + 1] == '.')
- {
- playGraund[playerRow, playerCol] = '.';
- playGraund[playerRow, playerCol + 1] = 'P';
- playerCol += 1;
- }
- else
- {
- if (playGraund[playerRow, playerCol] != 'B')
- {
- playGraund[playerRow, playerCol] = '.';
- }
- PrintPlayground(rows, cols, playGraund);
- Console.WriteLine($"dead: {playerRow} {playerCol + 1}");
- break;
- }
- }
- else
- {
- if (playGraund[playerRow, playerCol] != 'B')
- {
- playGraund[playerRow, playerCol] = '.';
- }
- won = true;
- }
- }
- if (won)
- {
- PrintPlayground(rows, cols, playGraund);
- Console.WriteLine($"won: {playerRow} {playerCol}");
- break;
- }
- }
- }
- static void MultiplyBunny(int rows, int cols, char[,] playGraund, Queue<int[]> bunniesIndexes)
- {
- while (bunniesIndexes.Count != 0)
- {
- int[] currBunny = bunniesIndexes.Dequeue();
- int row = currBunny[0];
- int col = currBunny[1];
- if (row - 1 >= 0)
- {
- playGraund[row - 1, col] = 'B';
- }
- if (row + 1 < rows)
- {
- playGraund[row + 1, col] = 'B';
- }
- if (col - 1 >= 0)
- {
- playGraund[row, col - 1] = 'B';
- }
- if (col + 1 < cols)
- {
- playGraund[row, col + 1] = 'B';
- }
- }
- }
- static void PrintPlayground(int rows, int cols, char[,] playGraund)
- {
- for (int row = 0; row < rows; row++)
- {
- for (int col = 0; col < cols; col++)
- {
- Console.Write(playGraund[row, col]);
- }
- Console.WriteLine();
- }
- }
- static void BunniesFinder(int rows, int cols, char[,] playGraund, Queue<int[]> bunniesIndexes)
- {
- for (int row = 0; row < rows; row++)
- {
- for (int col = 0; col < cols; col++)
- {
- if (playGraund[row, col] == 'B')
- {
- bunniesIndexes.Enqueue(new int[] { row, col });
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement