Beispiel #1
0
def test_evaluator10():
    """Hand evaluator test"""
    cards = [['7C', '5S', '3S', 'JD', '8H', '2S', 'KH'],
             ['AD', '3D', '3S', '5D', '9H', '8S', 'KH']]
    expected = 1
    winner, _ = eval_best_hand(cards)
    assert winner == cards[expected]
Beispiel #2
0
def test_evaluator1():
    """Hand evaluator test"""
    cards = [['3H', '3S', '4H', '4S', '8S', '8C', 'QH'],
             ['KH', '6C', '4H', '4S', '8S', '8C', 'QH']]
    expected = 1
    winner, _ = eval_best_hand(cards)
    assert winner == cards[expected]
Beispiel #3
0
def test_evaluator9():
    """Hand evaluator test"""
    cards = [['2C', '2D', '4S', '4D', '4H', '8S', 'KH'],
             ['7C', '7S', '7D', '7H', '8H', '8S', 'JH']]
    expected = 1
    winner, _ = eval_best_hand(cards)
    assert winner == cards[expected]
Beispiel #4
0
def test_evaluator6b():
    """Hand evaluator test"""
    cards = [['7C', '7C', 'AC', 'AC', '8C', '8S', '7H'],
             ['2C', '3C', '4C', '5C', '6C', '8S', 'KH']]
    expected = 1
    winner, _ = eval_best_hand(cards)
    assert winner == cards[expected]
Beispiel #5
0
def test_evaluator5():
    """Hand evaluator test"""
    cards = [['2D', '2H', 'AS', 'AD', 'AH', '8S', '7H'],
             ['7C', '7S', '7H', 'AD', 'AS', '8S', '8H']]
    expected = 0
    winner, _ = eval_best_hand(cards)
    assert winner == cards[expected]
Beispiel #6
0
def test_evaluator6():
    """Hand evaluator test"""
    cards = [['7C', '7S', '7H', 'AD', 'KS', '5S', '8H'],
             ['2D', '3H', 'AS', '4D', '5H', '8S', '7H']]
    expected = 1
    winner, _ = eval_best_hand(cards)
    assert winner == cards[expected]
Beispiel #7
0
def test_evaluator4():
    """Hand evaluator test"""
    cards = [['8S', 'TS', '8H', 'KS', '9S', 'TH', 'KH'],
             ['TD', '7S', '8H', 'KS', '9S', 'TH', 'KH']]
    expected = 0
    winner, _ = eval_best_hand(cards)
    assert winner == cards[expected]
Beispiel #8
0
def test_evaluator3():
    """Hand evaluator test"""
    cards = [['AS', 'KS', 'TS', '9S', '7S', '2H', '2H'],
             ['AS', 'KS', 'TS', '9S', '8S', '2H', '2H']]
    expected = 1
    winner, _ = eval_best_hand(cards)
    assert winner == cards[expected]
Beispiel #9
0
def test_evaluator2():
    """Hand evaluator test"""
    cards = [['8H', '8D', 'QH', '7H', '9H', 'JH', 'TH'],
             ['KH', '6C', 'QH', '7H', '9H', 'JH', 'TH']]
    expected = 1
    winner, _ = eval_best_hand(cards)
    assert winner == cards[expected]
Beispiel #10
0
def test_evaluator13():
    """Hand evaluator test"""
    cards = [['9S', '7H', 'KS', 'KH', 'AH', 'AS', 'AC'],
             ['8D', '2H', 'KS', 'KH', 'AH', 'AS', 'AC']]
    expected = 0
    winner, _ = eval_best_hand(cards)
    assert winner == cards[expected]
Beispiel #11
0
def test_evaluator12():
    """Hand evaluator test"""
    cards = [['AS', '8H', 'TS', 'JH', '3H', '2H', 'AH'],
             ['QD', 'QH', 'TS', 'JH', '3H', '2H', 'AH']]
    expected = 1
    winner, _ = eval_best_hand(cards)
    assert winner == cards[expected]
Beispiel #12
0
def test_evaluator7():
    """Hand evaluator test"""
    cards = [['AC', 'JS', 'AS', '2D', '5H', '3S', '3H'],
             ['QD', 'JD', 'TS', '9D', '6H', '8S', 'KH'],
             ['2D', '3D', '4S', '5D', '6H', '8S', 'KH']]
    expected = 1
    winner, _ = eval_best_hand(cards)
    assert winner == cards[expected]
    def run_montecarlo(self,
                       original_player_card_list,
                       original_table_card_list,
                       player_amount,
                       ui,
                       maxRuns,
                       timeout,
                       ghost_cards,
                       opponent_range=1):

        if type(opponent_range) == float or type(opponent_range) == int:
            opponent_allowed_cards = self.get_opponent_allowed_cards_list(
                opponent_range)
            log.debug('Preflop reverse tables for ranges for opponent: NO')
        elif type(opponent_range == set):
            log.debug('Preflop reverse tables for ranges for opponent: YES')
            opponent_allowed_cards = opponent_range

        winnerCardTypeList = []
        wins = 0
        runs = 0
        passes = 0
        OriginalDeck = self.create_card_deck()
        if ghost_cards != '':
            OriginalDeck.pop(OriginalDeck.index(ghost_cards[0]))
            OriginalDeck.pop(OriginalDeck.index(ghost_cards[1]))

        for m in range(maxRuns):
            runs += 1
            Deck = copy(OriginalDeck)
            PlayerCardList = copy(original_player_card_list)
            TableCardsList = copy(original_table_card_list)
            Players, Deck, passes = self.distribute_cards_to_players(
                Deck, player_amount, PlayerCardList, TableCardsList,
                opponent_allowed_cards, passes)
            Deck5Cards = self.distribute_cards_to_table(Deck, TableCardsList)
            PlayerFinalCardsWithTableCards = []
            for o in range(0, player_amount):
                PlayerFinalCardsWithTableCards.append(Players[o] + Deck5Cards)

            bestHand, winnerCardType = eval_best_hand(
                PlayerFinalCardsWithTableCards)
            winner = (PlayerFinalCardsWithTableCards.index(bestHand))

            # print (winnerCardType)

            CollusionPlayers = 0
            if winner < CollusionPlayers + 1:
                wins += 1
                winnerCardTypeList.append(
                    winnerCardType
                )  # winnerlist.append(winner)  # self.equity=wins/m  # if self.equity>0.99: self.equity=0.99  # EquityList.append(self.equity)

            self.equity = np.round(wins / runs, 3)

            if passes > 999 and time.time() > timeout:
                log.debug("Cutting short montecarlo due to timeout")
                log.debug("Passes: " + str(passes))
                log.debug("Runs: " + str(runs))
                break

                # if passes >= maxruns: break

        self.equity = wins / runs
        self.winnerCardTypeList = Counter(winnerCardTypeList)
        for key, value in self.winnerCardTypeList.items():
            self.winnerCardTypeList[key] = value / runs

        self.winTypesDict = self.winnerCardTypeList.items()
        self.runs = runs
        self.passes = passes

        return self.equity, self.winTypesDict