1

Programa para calcular las probabilidad de una mano de pocker (extensible)

A continuación dejo un script the python que calcula la probabilidad de una mano de que salga escalera o corrida.

El diseño del programa permite agregar otros tipos de manos

import random

SUITS = ['Spades', 'Diamonds', 'Hearts', 'Clubs']
CARDS = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King']

defcreate_maze():
    result = []
    for p in SUITS:
        for c in range(0, len(CARDS)):
            result.append((p, c))
    return result

defstr_maze(maze):return [(suite, CARDS[card_ix]) for suite, card_ix in maze]

#escaleradefstraight_hand(hand):
    indexes = [card_ix for suite, card_ix in hand]
    indexes.sort()
    start = 1
    last = indexes[0]
    is_as = last == 0if is_as:
        last = indexes[1]    
        start = 2for x in range(start, 5):
        if indexes[x] - last != 1:
            returnFalse
        last = indexes[x]
    if is_as andnot (indexes[4] == 12or indexes[1] == 1):
        returnFalsereturnTrue#corridadefflush_hand(hand):
    suits = [suite for suite, card_ix in hand]
    first = suits[0]
    for x in range(1, 5):
        if first != suits[x]:
            returnFalsereturnTruedefmain(num_attemps, hand_type):
    maze = create_maze()
    counter = 0for attemp in range(0, num_attemps):
        hand = random.sample(maze, 5)
        if hand_type(hand):
            counter += 1
    
    print(f"The probability of {hand_type.__name__} is {(counter/num_attemps*100):.4f}%")

if __name__ == '__main__':
    main(10000, flush_hand)
    main(10000, straight_hand)
Escribe tu comentario
+ 2