Skip to content

Commit

Permalink
Merge pull request #73 from bilts/fix-buy-causes-loss-performance
Browse files Browse the repository at this point in the history
Improve performance of checking whether a buy causes a loss
  • Loading branch information
Rob Speer committed Feb 14, 2012
2 parents d503bb3 + 797a171 commit 396cfb0
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions gameState.coffee
Expand Up @@ -669,11 +669,21 @@ class State
total

buyCausesToLose: (player, state, card) ->
if (state.gainsToEndGame() > 1)
if not card? || @supply[card] > 1 || state.gainsToEndGame() > 1
return false
if (not card?)

# Check to see if the player would be in the lead after buying this card
maxOpponentScore = -Infinity
for status in this.getFinalStatus()
[name, score, turns] = status
if name == player.ai.toString()
myScore = score + card.getVP(player)
else if score > maxOpponentScore
maxOpponentScore = score

if myScore > maxOpponentScore
return false

# One level of recursion is enough for first
if (this.depth==0)
[hypState, hypMy] = state.hypothetical(player.ai)
Expand Down

0 comments on commit 396cfb0

Please sign in to comment.