Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- class Program
- {
- static void Main()
- {
- string[,]board=new string[8,8];
- for (int i = 0; i < board.GetLength(0); i++)
- {
- string[] figures = Console.ReadLine().Split(new [] {','}, StringSplitOptions.RemoveEmptyEntries).ToArray();
- for (int j = 0; j < board.GetLength(1); j++)
- {
- board[i, j] = figures[j];
- }
- }
- // matricata e zaredena
- string input = Console.ReadLine();
- while (input != "END")
- {
- char[] moves = input.ToCharArray();
- char figure = moves[0];
- int row = int.Parse(moves[1].ToString());
- int col = int.Parse(moves[2].ToString());
- int nrow =int.Parse(moves[4].ToString());
- int ncol =int.Parse(moves[5].ToString());
- if (board[row, col] != figure.ToString())
- {
- Console.WriteLine("There is no such a piece!");
- }
- else if (!Isin(board,nrow,ncol))
- {
- Console.WriteLine("Move go out of board!");
- }
- else
- {
- Moves(board,row,col,nrow,ncol,figure);
- }
- input = Console.ReadLine();
- }
- }
- public static void Moves(string[,] board, int row, int col, int nrow, int ncol,char figure)
- {
- switch (figure)
- {
- case 'K':
- if (Math.Abs(row - nrow) != 1 && Math.Abs(col - ncol)!=1)
- {
- Console.WriteLine("Invalid move!");
- break;
- }
- board[nrow, ncol] = 'K'.ToString();
- board[row, col] = "x";
- break;
- case 'P':
- if (row - nrow !=1)
- {
- Console.WriteLine("Invalid move!");
- break;
- }
- board[nrow, ncol] = 'P'.ToString();
- board[row, col] = "x";
- break;
- case 'Q':
- board[nrow, ncol] = 'Q'.ToString();
- board[row, col] = "x";
- break;
- case 'R':
- if (nrow!=row && ncol!=col)
- {
- Console.WriteLine("Invalid move!");
- break;
- }
- board[nrow, ncol] = 'R'.ToString();
- board[row, col] = "x";
- break;
- case 'B':
- if (nrow == row || ncol == col )
- {
- Console.WriteLine("Invalid move!");
- break;
- }
- board[nrow, ncol] = 'B'.ToString();
- board[row, col] = "x";
- break;
- }
- }
- public static bool Isin(string[,] board,int r, int c)
- {
- return r >= 0 && r < board.GetLength(0) && c >= 0 && c < board.GetLength(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment