rspeer / dominiate

A simulator for Dominion card game strategies
http://rspeer.github.com/dominiate
MIT License
121 stars 43 forks source link

Fixed trashing bug, Lookout bug. Added Forager #86

Open chadeos opened 9 years ago

chadeos commented 9 years ago

The trashing bug was this: say you included Trade Route on in trashPriority. Imagine you drew a hand with only one Trade Route in it and no other cards you wanted to trash. When the simulator called ai_playValue for Trade Route, ai_playValue would say, "Hey, there's a card in my hand I want to trash (Trade Route), so go ahead and play me." So the bot would play the Trade Route, but at that point there's nothing left in the bot's hand that it wants to trash: Trade Route was the only card in the hand that the bot wanted to trash. So the bot would be stuck trashing some other card it would have rather hung on to. I've pasted a simple bot that demonstrates the bug below.

I am new to Dominiate, Coffeescript, and GitHub, but I think I did everything right. However, I was unsure where to put the line Array::remove = (e) -> @[t..t] = [] if (t = @indexOf(e)) > -1 in basicAI.coffee, so I put it on top. Also, I decided to give Forager ai_playValue one below Upgrade, but am unsure of that as well.

{
  name: 'TradeRouteBug'
  requires: ["Trade Route"]
  gainPriority: (state, my) -> [
    "Trade Route" if my.countInDeck("Trade Route") == 0
  ]

  trashPriority: (state, my) -> [
    "Trade Route"
  ]

  trashValue: (state, card, my) -> [
    # Without this Copper and Curse will get trashed even if they're not
    # in trashPriority
    -1
  ]
}
rspeer commented 9 years ago

I'm starting to review these PRs now. This looks like the right plan to fix it -- I'll just want to change the part involving Array::remove, I think. What you've written would be a destructive operation, which I think would be easy to use incorrectly.

I'd prefer making a copy of a list that excludes the skipCardName, as in:

adjustedHand = hand.filter((card) -> card.name != skipCardName)