There were two problems. First, coinLossMargin was using State#coins rather than PlayerState#coins. The former is undefined, so coinLossMargin was incorrectly returning 0. Second, the treasure sorting in putOnDeckPriority was reversed, so the AI would put back the lowest valued treasure it could, rather than the highest.
There were two problems. First, coinLossMargin was using State#coins rather than PlayerState#coins. The former is undefined, so coinLossMargin was incorrectly returning 0. Second, the treasure sorting in putOnDeckPriority was reversed, so the AI would put back the lowest valued treasure it could, rather than the highest.
These are now fixed. Fixes #53.