How long will it take for the horse to be captured?

Problem: When Farmer Oskar doesn’t watch his cows closely enough, they tend to wander off into the forest to hunt for horse spies. To catch an enemy agent horse, the cows lure it into a cow trail and set up fences at the endpoints of the trail, which are $$L$$ meters apart. Two previously hidden cows then reveal themselves, having concealed themselves in nearby bushes – and the chase is on! The cows are located at positions $$A$$ and $$B$$ meters from the left endpoint.

One particular horse (positioned $$P$$ meters from the left endpoint) who they attempted to catch remembered to bring her walkie-talkie and have now called for backup. The backup will arrive to rescue her very soon, so she wonders for how long she can hold the cows off.

Horse chasing happens in $$1$$ minute steps. During each minute, the following steps happen in order:

1. The cows choose to move either $$0$$ or $$1$$ meters, in any direction.

2. The horse jumps either $$0$$, $$1$$, or $$2$$ meters in any direction. However, if a cow occupies the same position as the horse, she can only jump a single meter since she now must jump over the cow.

3. If there is a cow in the same position as the horse, the cows capture her.

How long will it take for the horse to be captured, assuming both she and the cows move optimally?

Parameters:

$$1 \leq L \leq 1000$$

$$0 \leq A \leq L$$

$$0 \leq B \leq L$$

$$0 \leq P \leq L$$

$$A \neq B \neq P$$

• This looks like it's a programming challenge rather than a puzzle. I'm not sure what you're expecting for a solution, since the answer depends on the parameters of which there are a wide range, and the site intends for you to write code.
– xnor
Feb 29 at 18:45
• @xnor More like a dicussion on what the optimal decisions are for each party involved Mar 1 at 5:59