Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.5 kB
3
Indexable
Never
namespace dz;

class Program
{
    enum Chessmen { bishop, knight, rook, queen, king }
    static bool IsCorrect(Chessmen figure, char charStart, byte yStart, char charEnd, byte yEnd)
    {
        int xStart = (int)charStart - 96;
        int xEnd = (int)charEnd - 96;
        bool diagonal = Math.Abs(xStart - xEnd) == Math.Abs(yStart - yEnd);
        bool horisontalAndVertical = (xStart == xEnd) || (yStart == yEnd);
        if (xEnd == xStart && yEnd == yStart) { return false; }
        if (xEnd > 8 || xEnd < 1 || yEnd > 8 || yEnd < 1) { return false; }
        if (figure == Chessmen.bishop)
        {
            return diagonal;
        }
        else if (figure == Chessmen.knight)
        {
            return (Math.Abs(xStart - xEnd) == 1) && (Math.Abs(yStart - yEnd) == 2) || (Math.Abs(xStart - xEnd) == 2) && (Math.Abs(yStart - yEnd) == 1);
        }
        else if (figure == Chessmen.rook)
        {
            return horisontalAndVertical;
        }
        else if (figure == Chessmen.queen)
        {
            return horisontalAndVertical ||  diagonal;
        }
        else if (figure == Chessmen.king)
        {
            return (Math.Abs(xStart - xEnd) == 1 && yStart == yEnd) || (Math.Abs(yStart - yEnd) == 1 && xStart == xEnd)
                || (diagonal && (Math.Abs(xEnd - xStart) == 1));
        }
        return true;
    }
    static void Main(string[] args)
    {
        Console.WriteLine(IsCorrect(Chessmen.king, 'd', 4, 'd', 5));
        Console.ReadLine();
    }

}