def simulate(filename = "postriver_values", trials = 0):
  #mat = []
  #for j in range(16):
  #  mat.append([0,0,0])

  mat = pickle.load(open(filename, "rb"))

  for i in range(trials):
    theDeck = cards.Deck()
    theDeck.shuffle()
    herohand = cards.Hand()
    adversaryhand = cards.Hand()
    table = cards.Hand()

    for j in range(2):
      herohand.add_card(theDeck.deal_card())
      adversaryhand.add_card(theDeck.deal_card())

    for j in range(5):
      table.add_card(theDeck.deal_card())

    handscore = getHandCode(herohand, table)

    result = hands.compare_hands(herohand, adversaryhand, table)

    if result == 'left':
      mat[handscore][0] += 1
    elif result == 'none':
      mat[handscore][1] += 1
    elif result == 'right':
      mat[handscore][2] += 1

  print mat
  pickle.dump(mat, open(filename, "wb"))
예제 #2
0
    def end_game(self):
        while len(self.state.table.cards) < 5:
            self.state.table.add_card(self.state.deck.deal_card())

        res, reason = hands.compare_hands(
            self.human.hand, self.hero.hand, self.state.table)
        winner = None
        if res == 'left':
            winner = self.human
        elif res == 'right':
            winner = self.hero
        else:
            self.human += self.state.pot / 2.0
            self.hero += self.state.pot / 2.0
            print bcolors.FAIL + 'The game was a tie.' + bcolors.ENDC
            print 'Hero had', self.hero.hand
            return

        loser = self.other_player(winner)
        print bcolors.FAIL + winner.name + ' has won the round with a ' + reason + bcolors.ENDC
        print 'Hero had', self.hero.hand
        winner.stack += loser.escrow
        winner.stack += winner.escrow
        winner.stack += self.state.pot
        logging.info(('hi', str(self.state)))
예제 #3
0
def simulate(filename = "preflop_values", trials = 0):
  # holds card combos and results in a vector of [#wins, #ties, #losses]
  #mat = []
  #for i in range(13):
  #  tmat = []
  #  for j in range(13):
  #    tmat.append([0,0,0])
  #  mat.append(tmat)

  mat = pickle.load(open(filename, "rb"))

  for i in range(trials):
    theDeck = cards.Deck()
    theDeck.shuffle()
    herohand = cards.Hand()
    adversaryhand = cards.Hand()

    for j in range(2):
      herohand.add_card(theDeck.deal_card())
      adversaryhand.add_card(theDeck.deal_card())

    indices = getIndicesFromHand(herohand)
  
    table = cards.Hand()
    # 5 cards on table
    for j in range(5):
      table.add_card(theDeck.deal_card())

    result = hands.compare_hands(herohand, adversaryhand, table)

    if result == 'left':
      mat[indices[0]][indices[1]][0] += 1
    elif result == 'none':
      mat[indices[0]][indices[1]][1] += 1
    elif result == 'right':
      mat[indices[0]][indices[1]][2] += 1
      
  pickle.dump(mat, open(filename, "wb"))