Hello!
This task looks totally doable, although I should wipe the dust from my prolog knowledge for a bit.
The best strategy will be write a breadth-first-search algorithm (using Prolog backtracing ability) and navigate for the nearest target at time, if any (or move spiral, if latter somehow is impossible).
The second version adds some "stone obstacles", mentioned in the code, but not in the task.
Should I do simple version or both?