public void UndoMove(Position origin, Position destination, Piece capturedPiece) { Piece piece = Board.RemPiece(destination); piece.DecrementQtyMovement(); if (capturedPiece != null) { Board.AddPiece(capturedPiece, destination); CapturedPieces.Remove(capturedPiece); } Board.AddPiece(piece, origin); // Castling if (piece is King && destination.Col == origin.Col + 2) { Position originRook = new Position(origin.Row, origin.Col + 3); Position destinationRook = new Position(origin.Row, origin.Col + 1); Piece rook = Board.RemPiece(destinationRook); rook.DecrementQtyMovement(); Board.AddPiece(rook, originRook); } if (piece is King && destination.Col == origin.Col - 2) { Position originRook = new Position(origin.Row, origin.Col - 4); Position destinationRook = new Position(origin.Row, origin.Col - 1); Piece rook = Board.RemPiece(destinationRook); rook.DecrementQtyMovement(); Board.AddPiece(rook, originRook); } // En Passant if (piece is Pawn) { if (origin.Col != destination.Col && capturedPiece == VulnerableEnPassant) { Piece pawn = Board.RemPiece(destination); Position pawnPos; if (piece.Color == Color.White) { pawnPos = new Position(3, destination.Col); } else { pawnPos = new Position(4, destination.Col); } Board.AddPiece(pawn, pawnPos); } } }