Hi Clauber,
Please review this post How to get help on the Dynamo forums
There are going to be many strategies available to optimise a pipe network, however going from A to B isn’t always a straight line. A search of Google Scholar will get you some papers to start thinking of strategies
My first thought would be to get a oriented enclosing rectangle of points A & B then use the most suitable horizontal & vertical edges to create your pipes