Пример #1
0
        private void UndoMovement(Position origin, Position destination, Piece capturedPiece)
        {
            Piece piece = Board.RemovePiece(destination);

            piece.DecreaseMovementCount();
            if (capturedPiece != null)
            {
                Board.AddPiece(capturedPiece, destination);
                Captured.Remove(capturedPiece);
            }
            Board.AddPiece(piece, origin);

            //Special move: Castling
            if ((piece is King) && (destination.Column == origin.Column + 2))
            {
                Position originR      = new Position(origin.Row, origin.Column + 3);
                Position destinationR = new Position(origin.Row, origin.Column + 1);
                Piece    R            = Board.RemovePiece(destinationR);
                R.DecreaseMovementCount();
                Board.AddPiece(R, originR);
            }

            if ((piece is King) && (destination.Column == origin.Column - 2))
            {
                Position originR      = new Position(origin.Row, origin.Column - 4);
                Position destinationR = new Position(origin.Row, origin.Column - 1);
                Piece    R            = Board.RemovePiece(destinationR);
                R.DecreaseMovementCount();
                Board.AddPiece(R, originR);
            }

            //Special move: En Passant
            if (piece is Pawn)
            {
                if ((origin.Column != destination.Column) && (capturedPiece == VulnerableToEnPassant))
                {
                    Piece    pawn = Board.RemovePiece(destination);
                    Position positionP;
                    if (piece.Color == Color.White)
                    {
                        positionP = new Position(3, destination.Column);
                    }
                    else
                    {
                        positionP = new Position(4, destination.Column);
                    }
                    Board.AddPiece(pawn, positionP);
                }
            }
        }