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;
- class RadioactiveBunnies
- {
- static void Main()
- {
- int[] dimensions = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- int n = dimensions[0];
- int m = dimensions[1];
- char[,] board = new char[n, m];
- bool isDead = false;
- bool shouldContinue = true;
- int[] endIndex = new int[2];
- int playerRow = 0, playerCol = 0;
- for (int i = 0; i < n; i++)
- {
- char[] cells = Console.ReadLine().ToCharArray();
- for (int j = 0; j < m; j++)
- {
- board[i, j] = cells[j];
- if (cells[j] == 'P')
- {
- playerRow = i;
- playerCol = j;
- }
- }
- }
- char[] directions = Console.ReadLine().ToCharArray();
- foreach (var direction in directions)
- {
- while (shouldContinue)
- {
- switch (direction)
- {
- case 'U':
- if (playerRow - 1 == -1)
- {
- Console.WriteLine("won {0} {1}", playerRow, playerCol);
- shouldContinue = false;
- break;
- }
- playerRow = Math.Max(0, playerRow - 1);
- PrintBoard(board);
- if (board[playerRow, playerCol] == 'B')
- {
- isDead = true;
- shouldContinue = false;
- }
- break;
- case 'D':
- if (playerRow + 1 == n)
- {
- Console.WriteLine("won {0} {1}", playerRow, playerCol);
- shouldContinue = false;
- break;
- }
- playerRow = Math.Min(n - 1, playerRow + 1);
- if (playerRow == n)
- {
- Console.WriteLine("won {0} {1}", playerRow, playerCol);
- }
- if (board[playerRow, playerCol] == 'B')
- {
- isDead = true;
- shouldContinue = false;
- }
- break;
- case 'L':
- if (playerCol - 1 == -1)
- {
- Console.WriteLine("won {0} {1}", playerRow, playerCol);
- shouldContinue = false;
- break;
- }
- playerCol = Math.Max(0, playerCol - 1);
- if (board[playerRow, playerCol] == 'B')
- {
- isDead = true;
- shouldContinue = false;
- }
- break;
- case 'R':
- if (playerCol + 1 == m)
- {
- Console.WriteLine("won {0} {1}", playerRow, playerCol);
- shouldContinue = false;
- break;
- }
- playerCol = Math.Min(m - 1, playerCol + 1);
- if (board[playerRow, playerCol] == 'B')
- {
- isDead = true;
- shouldContinue = false;
- }
- break;
- }
- for (int i = 0; i < board.GetLength(0); i++)
- {
- for (int j = 0; j < board.GetLength(1); j++)
- {
- if (board[i, j] == 'B')
- {
- int startRow = Math.Max(0, i - 1);
- int startCol = Math.Max(0, j - 1);
- int endRow = Math.Min(board.GetLength(0) - 1, i + 1);
- int endCol = Math.Min(board.GetLength(1) - 1, j + 1);
- for (int k = startRow; k <= endRow; k++)
- {
- for (int l = startCol; l <= endCol; l++)
- {
- board[k, l] = 'B';
- }
- }
- }
- }
- }
- if (board[playerRow, playerCol] == 'B')
- {
- isDead = true;
- shouldContinue = false;
- }
- if (isDead == true)
- {
- PrintBoard(board);
- Console.WriteLine("won: {0} {1}", playerRow, playerCol);
- break;
- }
- }
- }
- }
- private static void PrintBoard(char[,] board)
- {
- for (int i = 0; i < board.GetLength(0); i++)
- {
- for (int j = 0; j < board.GetLength(1); j++)
- {
- Console.Write("{0} ", board[i, j]);
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement