With all of the corner cases, true optimality probably means not using a script for healing, at least during a run.
I tend to hold to the ideal espoused by Dangerpin back when he was around --
anything you can do in vanilla KoL (including the weighing of options in the decision-making process) can be done in ASH. You evidently have a different view, no doubt influenced by the pragmatic fact that most scripts cut a lot of corners.
I agree that true optimality is outside the scope of most scripts posted on these forums -- but it
is possible. It's one of the things that keeps me scripting.
The problem you mentioned is basically that UR doesn't know where you're going to adventure
next. That can be fixed -- all that needs to happen is for your betweenBattleScript to also call the recovery script. The recovery script could then be made as permissive as possible since it would always have an accurate location for your character, rather than relying strictly on absolute settings. It would run twice: once after adventuring, with your current location, and once before adventuring, with your new location. If the recovery amounts were specified as 0, it would only restore a comfortable minimum HP needed for a safe turn at your location, considering possibilities such as hipster monsters, assassins, and holiday monsters. This might be lower
or higher than your actual restore setting.
Problem solved for automatic adventuring. For relay play, a global override that replaces links to adventure.php with a portal page that sets the location and calls your recovery script before adventuring, transparent with mafia relay settings.
Then, add a setting "strictlyFollowSettings" to let users override location-sensitive recovery with UR's current behavior.
Optimal automation is possible, including corner cases, with a minimum of settings to allow for sub-optimal play. My philosophy is that settings should exist to tweak or override existing scripted optimality; configuring them as you play should not be required to achieve that optimality. I'm not claiming to have accomplished this in any of my scripts, but it's the ideal I have in mind.
Bale, sorry for the rant in your thread.
Although I do think a location-sensitive mode, though challenging to script, would be a ridiculously sweet feature for UR and would save players a chunk of meat each run.