JavaScript implementation of A* pathfinding