Well you are probably overthinking it.
Start (x,y)End (x,y)DistanceToGo = End - Start
Now distance to go is the delta X and the delta Y you need to cover
So inventory your pieces. If you have deltaX worth of horizontal pipes and deltaY worth of vertical pipes just lay out all the horizontal pipes end to end, throw in a connector, do all the vertical pipes end to end, throw a connector and you're done.
(I think the connector actually covers both an X and a Y so probably adjust your deltaX and deltaY accordingly)
So that's the "naive" strategy.
Now for obstacles, you just place each piece and then make checks:
place a "vertical or horizontal depending on which mode we're in"check blockedif blocked, replace current piece with down curve.check blockedif blocked replace current piece with up curvecheck blockedif blocked remove previous piece (it needs to be something different)
throw that in a loop with a mode to indicate if you're currently trying to traverse horizontally or vertically and that's probably close to the solution.
That assumes more or less infinite inventory choices.
If you have too few horizontal or vertical pipes you'll need to cover ground by going curve to curve to curve. I haven't seen any puzzles in the game that require that.
I'm also just throwing out stuff off the top of my head. Haven't thought it through too much but it should be a good place to start.
-me