Consider an $N \times N$ ($1 \le N \le 100$) square field made of $1 \times 1$ tiles. Some tiles cannot be crossed by cows and are marked with x. Below is one such $5 \times 5$ field:
. . B x .
. x x A .
. . . x .
. x . . .
. . x . .
Bessie the cow starts on the tile marked A and wants to reach the tile marked B to lick the salt block there. Cows dislike turning and may only move parallel to the edges of the field, that is, up, down, left, or right by one tile at a time. Bessie may face any direction when she starts and when she finishes. Determine the minimum number of $90$-degree turns on any path from A to B. It is guaranteed that B is reachable from A.
., x, A, or B, with no spaces.A to B.In the first example the cow needs at least $2$ turns. For instance, it can face south and move south one tile, turn to face west and move west two tiles, then turn to face south and move south one tile onto B.