This currently runs quite slowly, but it can be sped up a lot, by precomputing the route costs and not running the whole depth search each time.