Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _01._Dangerous_Floor
- {
- using System;
- public class StartUp
- {
- public static void Main()
- {
- var board = new string[8, 8];
- for (int row = 0; row < board.GetLength(0); row++)
- {
- var currentRow = Console.ReadLine().Split(',');
- for (int col = 0; col < board.GetLength(1); col++)
- {
- board[row,col] = currentRow[col].ToString();
- }
- }
- string command;
- while ((command = Console.ReadLine())!= "END")
- {
- var figure = command[0].ToString();
- var currentRow = int.Parse(command[1].ToString());
- var currentCol = int.Parse(command[2].ToString());
- if (board[currentRow,currentCol] != figure)
- {
- Console.WriteLine("There is no such a piece!");
- }
- else
- {
- var rowToBeMoved = int.Parse(command[4].ToString());
- var colToBeMoved = int.Parse(command[5].ToString());
- if (!IsTheMoveInsideTheBoard(rowToBeMoved, colToBeMoved, board))
- {
- Console.WriteLine("Move go out of board!");
- }
- else
- {
- if (IsMoveCorrect(figure,currentRow, currentCol, rowToBeMoved,colToBeMoved))
- {
- board[rowToBeMoved, colToBeMoved] = figure;
- board[currentRow, currentCol] = "x";
- continue;
- }
- Console.WriteLine("Invalid move!");
- }
- }
- }
- }
- public static bool IsTheMoveInsideTheBoard(int rowToBeMooved, int colToBeMoved, string[,] board)
- {
- return 0 <= rowToBeMooved && rowToBeMooved < board.GetLength(0) && 0 <= colToBeMoved && colToBeMoved < board.GetLength(1);
- }
- public static bool IsMoveCorrect(string figure, int currentRow, int currentCol, int rowToBeMoved, int colToBeMoved)
- {
- switch (figure)
- {
- case "K":
- return currentRow == rowToBeMoved && Math.Abs(currentCol - colToBeMoved) == 1 || currentCol == colToBeMoved && Math.Abs(currentRow - rowToBeMoved) == 1 || Math.Abs(currentRow - rowToBeMoved) == 1 && Math.Abs(currentCol - colToBeMoved) == 1;
- case "R":
- return currentRow == rowToBeMoved || currentCol == colToBeMoved;
- case "B":
- return Math.Abs(currentRow - rowToBeMoved) == Math.Abs(currentCol - colToBeMoved);
- case "Q":
- return Math.Abs(currentRow - rowToBeMoved) == Math.Abs(currentCol - colToBeMoved) || currentRow == rowToBeMoved || currentCol == colToBeMoved;
- case "P":
- return rowToBeMoved == currentRow - 1 && currentCol == colToBeMoved;
- }
- return false;
- }
- }
- }
Add Comment
Please, Sign In to add comment