A* pathfinding for Grid masks