More specifically it’s a generalisation of the Hamiltonian path problem, which is known to be NP-complete even for the grid graphs we’re dealing with here. Interestingly however, if the grid graph has no holes in it (in our case: no walls that aren’t connected to the edge of the map by other walls) then there is a polynomial time algorithm for finding Hamiltonian cycles[*]. I can’t immediately tell if it would adapt to our gold-maximising problem (ie. what exactly it outputs when there is no Hamiltonian cycle) but it looks promising. Perhaps there is a hard puzzle in this problem waiting to get out ![]()
[*] C. Umans and W. Lenhart, “Hamiltonian cycles in solid grid graphs,” Proceedings 38th Annual Symposium on Foundations of Computer Science, 1997