Create algorithm.java

There's an issue regarding finding the best path because direction takes priority. If you test this code on your computer, you will see what I mean.