Grid optimizer for A* algo