Exemple #1
0
        /// <summary>
        ///     Updates the board after En Passant. Does not check legality.
        /// </summary>
        /// <param name="attacker">Pawn that is passing</param>
        /// <param name="capture">Capture to make</param>
        /// <param name="lostPiece">Pawn being captured</param>
        private void UpdateBoardForEnPassant(IPawn attacker, ICapture capture, IPawn lostPiece)
        {
            GameBoard.Remove(attacker.Location);
            attacker.MoveTo(capture.EndingPosition);
            GameBoard.Add(capture.EndingPosition);

            GameBoard.Remove(lostPiece.Location);
            lostPiece.Location = ChessPosition.None;

            MoveHistory.Add(attacker, capture);
        }
Exemple #2
0
        /// <summary>
        ///     Executes a normal capture. Does not check for legality.
        /// </summary>
        /// <param name="capture"></param>
        /// <returns>Point value of piece being captured</returns>
        private int ExecuteCapture(ICapture capture)
        {
            IPiece movingPiece = GetPiece(ActivePlayerColor, capture.StartingPosition);
            IPiece lostPiece   = GetPiece(InactivePlayerColor, capture.EndingPosition);

            movingPiece.MoveTo(capture.EndingPosition);
            lostPiece.Location = ChessPosition.None;

            GameBoard.Execute(capture);
            MoveHistory.Add(movingPiece, capture);

            return(lostPiece.Value);
        }
Exemple #3
0
        /// <summary>
        ///     Updates board for Castle. Does not check legality.
        /// </summary>
        /// <param name="king"></param>
        /// <param name="move"></param>
        /// <param name="rook"></param>
        private void UpdateBoardForCastle(IKing king, IMove move, IRook rook)
        {
            ChessPosition newRookLocation = ModelLocator.CastlingHelper.GetEndingPositionForCastlingRook(king, rook);

            GameBoard.Remove(king.Location);    // remove King from board
            king.MoveTo(move.EndingPosition);   // move King, update location
            GameBoard.Add(move.EndingPosition); // place King on board at update location

            GameBoard.Remove(rook.Location);    // remove Rook from board
            rook.MoveTo(newRookLocation);       // move Rook, update location
            GameBoard.Add(rook.Location);       // place Rook on board at updated location

            MoveHistory.Add(king, move);
        }
Exemple #4
0
        /// <summary>
        ///     Executes a move. Does not check legality.
        /// </summary>
        /// <param name="move"></param>
        private void ExecuteMove(IMove move)
        {
            IPiece movingPiece = GetPiece(ActivePlayerColor, move.StartingPosition);

            movingPiece.MoveTo(move.EndingPosition);

            if (movingPiece is IPawn pawn && pawn.IsPromotable)
            {
                PromotePawn(movingPiece);
            }

            GameBoard.Execute(move);

            MoveHistory.Add(movingPiece, move);
        }