Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _8.RadioActiveBunnies
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] input = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- int rows = input[0];
- int columns = input[1];
- char[,] lair = new char[rows, columns];
- string winOrLose = string.Empty;
- bool deadPlayer = false;
- for (int i = 0; i < rows; i++)
- {
- char[] symbols = Console.ReadLine().ToCharArray();
- for (int j = 0; j < columns; j++)
- {
- lair[i, j] = symbols[j];
- }
- }
- char[] directions = Console.ReadLine().ToCharArray();
- int endRow = -1;
- int endColumn = -1;
- for (int i = 0; i < directions.Length; i++)
- {
- int playerRow = -1;
- int playerColumn = -1;
- if (directions[i] == 'L')
- {
- for (int k = 0; k < lair.GetLength(0); k++)
- {
- for (int l = 0; l < lair.GetLength(1); l++)
- {
- if (lair[k, l] == 'P')
- {
- playerRow = k;
- playerColumn = l;
- break;
- }
- }
- if (playerRow != -1)
- {
- break;
- }
- }
- lair[playerRow, playerColumn] = '.';
- if (playerColumn - 1 < 0)
- {
- endRow = playerRow;
- endColumn = playerColumn;
- winOrLose = "won";
- }
- else
- {
- if (lair[playerRow, playerColumn - 1] == 'B' || lair[playerRow, playerColumn - 1] == 'N')
- {
- winOrLose = "dead";
- endRow = playerRow;
- endColumn = playerColumn - 1;
- deadPlayer = true;
- }
- else
- {
- lair[playerRow, playerColumn - 1] = 'P';
- }
- }
- }
- if (directions[i] == 'R')
- {
- for (int k = 0; k < lair.GetLength(0); k++)
- {
- for (int l = 0; l < lair.GetLength(1); l++)
- {
- if (lair[k, l] == 'P')
- {
- playerRow = k;
- playerColumn = l;
- break;
- }
- }
- if (playerRow != -1)
- {
- break;
- }
- }
- lair[playerRow, playerColumn] = '.';
- if (playerColumn + 1 > lair.GetLength(1) - 1)
- {
- endRow = playerRow;
- endColumn = playerColumn;
- winOrLose = "won";
- }
- else
- {
- if (lair[playerRow, playerColumn + 1] == 'B' || lair[playerRow, playerColumn - 1] == 'N')
- {
- winOrLose = "dead";
- endRow = playerRow;
- endColumn = playerColumn + 1;
- deadPlayer = true;
- }
- else
- {
- lair[playerRow, playerColumn + 1] = 'P';
- }
- }
- }
- if (directions[i] == 'U')
- {
- for (int k = 0; k < lair.GetLength(0); k++)
- {
- for (int l = 0; l < lair.GetLength(1); l++)
- {
- if (lair[k, l] == 'P')
- {
- playerRow = k;
- playerColumn = l;
- break;
- }
- }
- if (playerRow != -1)
- {
- break;
- }
- }
- lair[playerRow, playerColumn] = '.';
- if (playerRow - 1 < 0)
- {
- endRow = playerRow;
- endColumn = playerColumn;
- winOrLose = "won";
- }
- else
- {
- if (lair[playerRow - 1, playerColumn] == 'B' || lair[playerRow, playerColumn - 1] == 'N')
- {
- winOrLose = "dead";
- endRow = playerRow - 1;
- endColumn = playerColumn;
- deadPlayer = true;
- }
- else
- {
- lair[playerRow - 1, playerColumn] = 'P';
- }
- }
- }
- if (directions[i] == 'D')
- {
- for (int k = 0; k < lair.GetLength(0); k++)
- {
- for (int l = 0; l < lair.GetLength(1); l++)
- {
- if (lair[k, l] == 'P')
- {
- playerRow = k;
- playerColumn = l;
- break;
- }
- }
- if (playerRow != -1)
- {
- break;
- }
- }
- lair[playerRow, playerColumn] = '.';
- if (playerRow + 1 > lair.GetLength(0) - 1)
- {
- endRow = playerRow;
- endColumn = playerColumn;
- winOrLose = "won";
- }
- else
- {
- if (lair[playerRow + 1, playerColumn] == 'B' || lair[playerRow, playerColumn - 1] == 'N')
- {
- winOrLose = "dead";
- endRow = playerRow + 1;
- endColumn = playerColumn;
- deadPlayer = true;
- }
- else
- {
- lair[playerRow + 1, playerColumn] = 'P';
- }
- }
- }
- bool checkerForPlayer = false;
- for (int p = 0; p < lair.GetLength(0); p++)
- {
- for (int b = 0; b < lair.GetLength(1); b++)
- {
- if (lair[p, b] == 'B')
- {
- int bunnyRow = p;
- int bunnyColumn = b;
- if (bunnyRow - 1 >= 0)
- {
- if (lair[bunnyRow - 1, bunnyColumn] == 'P')
- {
- checkerForPlayer = true;
- endRow = bunnyRow - 1;
- endColumn = bunnyColumn;
- winOrLose = "dead";
- }
- lair[bunnyRow - 1, bunnyColumn] = 'N';
- }
- if (bunnyRow + 1 < lair.GetLength(0))
- {
- if (lair[bunnyRow + 1, bunnyColumn] == 'P')
- {
- checkerForPlayer = true;
- endRow = bunnyRow + 1;
- endColumn = bunnyColumn;
- winOrLose = "dead";
- }
- lair[bunnyRow + 1, bunnyColumn] = 'N';
- }
- if (bunnyColumn - 1 >= 0)
- {
- if (lair[bunnyRow, bunnyColumn - 1] == 'P')
- {
- checkerForPlayer = true;
- endRow = bunnyRow;
- endColumn = bunnyColumn - 1;
- winOrLose = "dead";
- }
- lair[bunnyRow, bunnyColumn - 1] = 'N';
- }
- if (bunnyColumn + 1 < lair.GetLength(1))
- {
- if (lair[bunnyRow, bunnyColumn + 1] == 'P')
- {
- checkerForPlayer = true;
- endRow = bunnyRow;
- endColumn = bunnyColumn + 1;
- winOrLose = "dead";
- }
- lair[bunnyRow, bunnyColumn + 1] = 'N';
- }
- }
- }
- }
- for (int a = 0; a < lair.GetLength(0); a++)
- {
- for (int s = 0; s < lair.GetLength(1); s++)
- {
- if (lair[a, s] == 'N')
- {
- lair[a, s] = 'B';
- }
- }
- }
- if (checkerForPlayer == true)
- {
- break;
- }
- if (deadPlayer)
- {
- break;
- }
- if (winOrLose == "won" || winOrLose == "dead")
- {
- break;
- }
- }
- for (int i = 0; i < lair.GetLength(0); i++)
- {
- for (int j = 0; j < lair.GetLength(1); j++)
- {
- Console.Write(lair[i, j]);
- }
- Console.WriteLine();
- }
- Console.WriteLine($"{winOrLose}: {endRow} {endColumn}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement