Well you could start with a simple depth-first pathfinding algorithm so you can see which squares you need to take to get to the end points. After that you would have to come up with your own...