Optimal strategy to capture a skittish lamb wandering near a precipice