kookoo but functional version of a* pathfinding in place