So I think I will reevaluate the putting back of treasures
# A) Look what you would gain if you just put back as if you discard (that is the fallback if everything we try now fails)
# B) For each unique treasure, test if the gain changes if we just put this treasure back
# C) Extraconditions like Potions for Alchemist, Royal Seal which have effects other than gaining
# D) Put the "best" treasure back that does not change the gain or was excluded in C).
This should also be able to handle Quarry, Talisman, HoP.
Now we just have to evaluate what "best" means, first idea would just be by price. What I don't like there
Harem > HoP, Royal Seal
Harem, Royal Seal, Stash > Quarry, Talisman, Potion
Diadem < all
Harem should be more or less rated like silver, perhaps an epsilon higher to defend against attacks. But that's only a small chance in the turn just before the reshuffle, which can more or less be ignored. But when you bought HoP, a reasonable AI should want to gain something with it in the end, so it should be more valuable than silver and thus as Harem.
Same should be true for Royal Seal, Stash vs. Quarry, Talisman, Potion while here maybe in the endgame it is shifted again in Royal Seals favour.
Second idea would be a new function treasurePriority2(state) (which exists, but for other means), which has just a defaultList (without much thought and probably forgotten something)
Bank>Platinum>Gold>HoP>Quarry>Talisman>Potion>Diadem>Royal Seal>Stash>Harem>Silver>Copper
and which of course could be costumized then if someone wants something more fancy. Most of the inequalities are not so important anyway, you seldomly want to play say Talisman and Potion in the same strat.
Royal Seal then also needs some extra considerration if we want to put it back at all , but that is a different point similar to "do not put back Potions when Alchemists are in play".
Edit: Contraband I forgot. And Hoard. Hoard should work with this, Contraband is difficult anyway.