Each city is modelled as an unweighted planar graph. Every zone (neighbourhood) is a node; two nodes are connected by an edge if and only if their geographic boundaries share a physical border segment — i.e. the zones are neighbours on the map.
Bologna's zones are the 18 official "zone storiche" published by the Comune di Bologna open-data portal. Barcelona's and Vienna's zones come directly from OpenStreetMap administrative polygons (admin levels 10 and 9).
Because every edge has the same cost (one hop), the shortest path is found with Breadth-First Search (BFS). BFS explores the graph in expanding "waves": first all zones reachable in 1 hop, then 2 hops, and so on. The first time it reaches the destination it is guaranteed to have found the minimum number of hops — no shorter route can exist.
A second BFS runs backwards from the destination at every guess, computing the distance from every zone to the target. This is what powers the Last dist. counter you see while playing.
Each new game samples random pairs until it finds one whose shortest path length falls between 3 and 12 hops — short enough to be solvable, long enough to be interesting.