Loading slide
That rule you just used has a name. It is called greedy: at every step, take whatever looks closest to the goal right now.
In the first maze, greedy worked. In the second, it walked you straight into the trap. The exit was sitting right there, just past a wall, and the only way around was to head off in the wrong direction first. Greedy never does that. It cannot bring itself to step away from the goal, even when stepping away is the only path that reaches it.
That is the catch hiding inside search. Following the closest-looking option is a fine instinct until the right answer asks you to move away from it first.
And real problems are full of moments like that. The winning move often looks, at the time, exactly like a wrong one.
Did you know?