示例#1
0
        static bool IsCanMove(int x1, int y1, int x2, int y2, TypeOfFigure figure)
        {
            if (figure == TypeOfFigure.King)
            {
                return(Math.Abs(x2 - x1) <= 1 && Math.Abs(y2 - y1) <= 1);                              //король всегда ходит на одну клетку
            }
            if (figure == TypeOfFigure.Queen)
            {
                return(x2 - x1 == 0 || y2 - y1 == 0 || (Math.Abs(x2 - x1) == Math.Abs(y2 - y1)));
            }
            if (figure == TypeOfFigure.Rook)
            {
                return(x2 - x1 == 0 || y2 - y1 == 0);
            }
            if (figure == TypeOfFigure.Bishop)
            {
                return(Math.Abs(x2 - x1) == Math.Abs(y2 - y1));
            }
            if (figure == TypeOfFigure.Knight)
            {
                return((Math.Abs(x2 - x1) == 2 && Math.Abs(y2 - y1) == 1) || (Math.Abs(x2 - x1) == 1 && Math.Abs(y2 - y1) == 2));
            }

            return(false);
        }
示例#2
0
        public Board(BoardStateData board)
        {
            // Start from empty rules
            Fields        = new Field[Rules.DEFAULT_FIELDS.Length];
            PlayerOptions = (PlayerOption[])Rules.DEFAULT_PLAYER_OPTIONS.Clone();

            // ACTIVE PLAYER:
            IsWhiteToMove = board.ActivePlayerColor == "White";

            // EN PASSANT
            if (board.EnPassantSquare != "")
            {
                // get col number (EnPassantSquare is for example "c6")
                int colNumber = board.EnPassantSquare[0] - 'a';

                PlayerOptions[CurrentPlayerId()].GiveEnpassantOnCol(colNumber);
            }

            // CASTLING
            PlayerOptions[PlayerId(isWhite: true)].KingsideCastle  = board.WhiteCanKingsideCastle;
            PlayerOptions[PlayerId(isWhite: true)].QueensideCastle = board.WhiteCanQueensideCastle;

            PlayerOptions[PlayerId(isWhite: false)].KingsideCastle  = board.BlackCanKingsideCastle;
            PlayerOptions[PlayerId(isWhite: false)].QueensideCastle = board.BlackCanQueensideCastle;

            // MOVE NUMBERS
            HalfmoveCounter = board.HalfMoveCounter;
            MoveCounter     = board.FullMoveNumber;

            // FIELDS
            for (int rowReversed = 0; rowReversed < 8; rowReversed++)
            {
                // get to actual row (rank) number
                int row = 7 - rowReversed;

                for (int col = 0; col < 8; col++)
                {
                    var fenField = board.Ranks[rowReversed][col];

                    // Hacky whacky isupper? method
                    bool isWhite = fenField.ToUpperInvariant() == fenField;

                    TypeOfFigure figure = fenField.ToUpperInvariant() switch
                    {
                        "K" => TypeOfFigure.King,
                        "Q" => TypeOfFigure.Queen,
                        "R" => TypeOfFigure.Rook,
                        "N" => TypeOfFigure.Knight,
                        "B" => TypeOfFigure.Bishop,
                        "P" => TypeOfFigure.Pawn,
                        " " => TypeOfFigure.EMPTY,
                        _ => throw new NotImplementedException()
                    };

                    int index = new ColRowCoord(col, row).Index;
                    Fields[index].IsWhite = isWhite;
                    Fields[index].Figure  = figure;
                }
            }
        }
示例#3
0
 public static double Weighting(TypeOfFigure type)
 {
     return(type switch
     {
         TypeOfFigure.EMPTY => 0,
         TypeOfFigure.Rook => 5,
         TypeOfFigure.Knight => 3,
         TypeOfFigure.Bishop => 3,
         TypeOfFigure.Queen => 9,
         TypeOfFigure.King => 50,
         TypeOfFigure.Pawn => 1,
         _ => throw new NotImplementedException(),
     });
示例#4
0
        static void Main(string[] args)
        {
            //Начало цикла
            string end = "";

            do
            {
                Console.WriteLine("START");

                int x1 = Convert.ToInt32(Console.ReadLine());
                int y1 = Convert.ToInt32(Console.ReadLine());
                int x2 = Convert.ToInt32(Console.ReadLine());
                int y2 = Convert.ToInt32(Console.ReadLine());

                TypeOfFigure figure = (TypeOfFigure)Convert.ToInt32(Console.ReadLine());

                //Вывод результата и конец цикла
                Console.WriteLine("RESULT: {0} {1}\n\n", figure.ToString(), IsCanMove(x1, y1, x2, y2, figure));
                Console.WriteLine("#Любой символ для завершения");
                end = Console.ReadLine();
            } while (end == "" || end.Length > 1);
        }
示例#5
0
 public Field(bool isWhite, TypeOfFigure type)
 {
     IsWhite = isWhite;
     Figure  = type;
 }