Advertisement
Guest User

hi cherrymatt

a guest
Oct 22nd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. def succAndProbReward(self, state, action):
  2. # BEGIN_YOUR_CODE (our solution is 53 lines of code, but don't worry if you deviate from this)
  3. totalCardValue = state[0]
  4. peekIndex = state[1]
  5. deckCardCounts = state[2]
  6. possibleStates = []
  7. if deckCardCounts is None:
  8. return possibleStates #deck is empty, game is over
  9. if action == "Quit":
  10. possibleStates.append(((totalCardValue, None, None), 1.0, totalCardValue))
  11. totalCardCount = sum(val for val in deckCardCounts)
  12. if action == "Peek": #look through each available card in deck
  13. if peekIndex is not None:
  14. return possibleStates
  15. for idx, val in enumerate(deckCardCounts):
  16. if val > 0:
  17. possibleStates.append(((totalCardValue, idx, deckCardCounts), val / float(totalCardCount), -1))
  18. if action == "Take":
  19. lstCounts = list(deckCardCounts)
  20. if peekIndex is not None: #peeked last round
  21. lstCounts[peekIndex] -= 1
  22. newCardSum = totalCardValue + self.cardValues[peekIndex]
  23. if newCardSum > self.threshold:
  24. possibleStates.append(((newCardSum, None, None), 1.0, 0))
  25. elif totalCardCount == 1:
  26. possibleStates.append(((newCardSum, None, None), 1.0, newCardSum))
  27. else:
  28. possibleStates.append(((newCardSum, None, tuple(lstCounts)), 1.0, 0))
  29.  
  30. else:
  31. for idx, val in enumerate(deckCardCounts):
  32. if val > 0:
  33. lstCounts[idx] -= 1
  34. newCardSum = totalCardValue + self.cardValues[idx]
  35. if newCardSum > self.threshold: #bust
  36. possibleStates.append(((newCardSum, None, None), val / float(totalCardCount), 0))
  37. elif totalCardCount == 1:
  38. possibleStates.append(((newCardSum, None, None), val / float(totalCardCount), newCardSum))
  39. else:
  40. possibleStates.append(((newCardSum, None, tuple(lstCounts)), val / float(totalCardCount), 0))
  41. lstCounts[idx] += 1
  42. return possibleStates
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement