An implementation of Dijkstra's algorithm on a grid