Exemplo n.º 1
0
def simulate_deuce_to_seven(t1, p2, cards, trials, runs):
    scores = []
    cards_to_pull = 1

    t1_unique_count = unique_value_count(t1)
    _, is_t1_flush, is_t1_straight, t1_values_sorted = CARDS_FROM_HAND[t1]

    deck = list(card_index_from_hand(cards))
    for _ in range(trials):
        score = (0, 0, 0)
        for _ in range(runs):
            t2 = p2
            cards_added = set()
            cards_added_count = 0
            #for i in range(cards_to_pull):
            while cards_added_count < cards_to_pull:
                c = choice(deck)
                #c = Deck.cardPeek(cards, 52 - 9 - cards_added_count)
                if c not in cards_added:
                    t2 = Card.add(t2, c)
                    cards_added.add(c)
                    cards_added_count += 1

            _, is_t2_flush, is_t2_straight, t2_values_sorted = CARDS_FROM_HAND[
                t2]
            result = rank_hands(t2, t2_values_sorted, is_t2_flush,
                                is_t2_straight, t1_unique_count, is_t1_flush,
                                is_t1_straight, t1_values_sorted)
            score = tuple(map(add, score, result))

        scores.append(score)

    return zip(*scores)
Exemplo n.º 2
0
def cards_from_deck(deck, cards):
    hand = 0
    for c, s in cards:
        card = Card.to_index((s.value, c.value))
        hand = Card.add(hand, card)
        deck = Card.remove(deck, card)

    return deck, hand
Exemplo n.º 3
0
    f'Simulating {len(DRAWING_HANDS)} hands drawing {TRIALS * RUNS} times against the top {TOP_HANDS_COUNT} hands.'
)
for drawing_cards in DRAWING_HANDS:

    HAND_WALLCLOCK = default_timer()
    cards = Deck.create(52)
    cards, p2 = cards_from_deck(cards, drawing_cards)
    hand_name = '-'.join(reversed(list(cards_value_minimal(p2))))

    hand_results = []
    for hand in HAND_RANKINGS:
        p1 = 0
        sim_deck = cards
        for s, v in zip(p1_suits, hand):
            c = Card.to_index((s.value, v.value))
            p1 = Card.add(p1, c)
            sim_deck = Card.remove(sim_deck, c)

        wins, loses, ties = simulate_deuce_to_seven(p1, p2, sim_deck, TRIALS,
                                                    RUNS)
        hand_results.append(round((RUNS - np.mean(loses)) / RUNS * 100, 2))
        #print(
        #    '-'.join(reversed(list(cards_value_minimal(p1)))),
        #    f'{round((RUNS-np.mean(loses))/RUNS*100, 2):.2f}% +/- {round((np.std(loses))/RUNS*100, 2):.2f}%',
        #    list(map(np.sum, (wins, loses, ties))),
        #    f'{round(time() - wallclock, 3)}s')

    results[hand_name] = hand_results
    LOGGER.info(f'{hand_name}, {round(default_timer() - HAND_WALLCLOCK, 2)}')

LOGGER.info(f'Simulation completed, {round(default_timer() - WALLCLOCK, 2)}')