It doesn't think. It tries every pour, skips boards it has seen, and traces back the shortest route. That's breadth-first search.