예제 #1
0
        public bool CanMove(FigureMoving fm)
        {
            this.fm = fm;

            return(CanMoveFrom() &&
                   CanMoveTo() &&
                   CanFigureMove());
        }
예제 #2
0
        void EnPassantAttack(FigureMoving fm)
        {
            Square midSquare = new Square(enPassant);
            Figure pawn      = moveColor == Color.white ? Figure.whitePawn : Figure.blackPawn;

            if (fm.to == midSquare && fm.figure == pawn)// en passant
            {
                InsertFigure(new Square(midSquare.x, fm.from.y), Figure.none);
            }
        }
예제 #3
0
 void SetEnPassant(FigureMoving fm)
 {
     if (fm.figure == Figure.whitePawn || fm.figure == Figure.blackPawn)
     {
         if (fm.AbsDeltaY == 2)// jump is only possible if a pawn moves from Y:1 or Y:6
         {
             int    y         = fm.to.y - fm.SignDeltaY;
             Square midSquare = new Square(fm.to.x, y);
             enPassant = midSquare.ToString();
             return;
         }
     }
     enPassant = "-";// en passant only has power during one move
 }
예제 #4
0
        void MoveCastleRook(FigureMoving fm)
        {
            if ((fm.figure == Figure.whiteKing || fm.figure == Figure.blackKing) &&
                fm.AbsDeltaX == 2 && fm.AbsDeltaY == 0)
            {
                Figure rook = fm.figure == Figure.whiteKing ? Figure.whiteRook : Figure.blackRook;

                if (fm.SignDeltaX == 1)// kingside castle
                {
                    InsertFigure(new Square(7, fm.from.y), Figure.none);
                    InsertFigure(new Square(fm.to.x + (fm.SignDeltaX * -1), fm.to.y), rook);
                }
                else if (fm.SignDeltaX == -1)// queenside castle
                {
                    InsertFigure(new Square(0, fm.from.y), Figure.none);
                    InsertFigure(new Square(fm.to.x + (fm.SignDeltaX * -1), fm.to.y), rook);
                }
            }
        }
예제 #5
0
        void UpdateCastleFlags(FigureMoving fm)
        {
            // we move our king or rook
            Figure king = moveColor == Color.white ? Figure.whiteKing : Figure.blackKing;
            Figure rook = moveColor == Color.white ? Figure.whiteRook : Figure.blackRook;

            if (fm.figure == king)
            {
                DisableQueensideCastle(moveColor);
                DisableKingsideCastle(moveColor);
            }
            else if (fm.figure == rook)
            {
                if (fm.from.x == 0)
                {
                    DisableQueensideCastle(moveColor);
                }
                else if (fm.from.x == 7)
                {
                    DisableKingsideCastle(moveColor);
                }
            }
        }
예제 #6
0
        public Board Move(FigureMoving fm)
        {
            Board nextBoard = new Board(fen);

            nextBoard.InsertFigure(fm.from, Figure.none);
            nextBoard.InsertFigure(fm.to, fm.promotion == Figure.none ? fm.figure : fm.promotion);

            nextBoard.EnPassantAttack(fm);
            nextBoard.SetEnPassant(fm);

            nextBoard.MoveCastleRook(fm);
            nextBoard.UpdateCastleFlags(fm);

            if (moveColor == Color.black)
            {
                nextBoard.moveNumber++;
            }

            nextBoard.moveColor = moveColor.FlipColor(); // end of the move

            nextBoard.GenerateFen();                     //apply the move to current board state
            return(nextBoard);
        }
예제 #7
0
        public bool IsCheckAfterMove(FigureMoving fm)
        {
            Board afterBoard = Move(fm);

            return(afterBoard.CanAttackEnemyKing());
        }