def __init__(self):
     self.deck = treys.Deck()
     self.evaluator = treys.Evaluator()
     self.reward_range = (
         -1, 1)  # we will process the reward to fit in [-1,1] from [-10,10]
     self.metadata = {'render_modes': ['ansi']}
     self.observation_space = OFCSObservationSpace(356)
     self.action_space = gym.spaces.Discrete(2)
     self.done = False
     self.obs = self.reset()
Beispiel #2
0
    def _card_combinations(excluded_cards: List[int], tuple_size: int) -> List[Tuple[int]]:
        deck = treys.Deck()
        cards = deck.draw(MAX_CARDS)
        deck_as_set = set(cards)

        for card in excluded_cards:
            deck_as_set.remove(card)

        combos = list(itertools.combinations(deck_as_set, tuple_size))
        sample_size = min(len(combos), 75)

        return random.sample(combos, sample_size)
 def reset(self):
     """Returns a new observation and resets the env"""
     self.deck = treys.Deck()
     # create a new starting observation
     obs = np.concatenate([
         np.zeros(320, dtype='int'),
         np.array(convert_card_to_bitlist(self.deck.draw(1)), dtype='int')
     ])
     obs = np.concatenate([obs, [0, 0, 0,
                                 0]])  # add 4 bits of 0 for the game state
     self.obs = obs
     self.done = False
     return obs
    def __init__(self):
        self.action_space = spaces.Discrete(26) # 5 choose 3,  plus 5 choose 2,  plus 5, plus 1
        self.observation_space = spaces.Discrete(2598960) # number of five card hand combos
        self.deck = treys.Deck()
        self.hand = self.deal_hand()
        # self.done = False
        self.evaluator = treys.Evaluator()
        
        # SET THE REWARDS
        self.RANK_CLASS_STRING_TO_REWARD = {
            'Straight Flush': 100,
            'Four of a Kind': 25,
            'Full House': 9,
            'Flush': 6,
            'Straight': 4,
            'Three of a Kind': 3,
            'Two Pair': 2,
            'Pair': 1, 
            'High Card': -1}
        
        self.RANK_CLASS_TO_STRING = {
        1: "Straight Flush",
        2: "Four of a Kind",
        3: "Full House",
        4: "Flush",
        5: "Straight",
        6: "Three of a Kind",
        7: "Two Pair",
        8: "Pair",
        9: "High Card"
    }

        # get the hand rank for jacks 
        # so we can later check if the player hand is better than jacks 
        self._jacks_hand_score = self.evaluator.evaluate( [
                                                        treys.Card.new('Jh'), 
                                                        treys.Card.new('Js'), 
                                                        treys.Card.new('2s')
                                                        ],
                                                        [
                                                        treys.Card.new('3h'), 
                                                        treys.Card.new('4d')
                                                        ]
                                                    )
Beispiel #5
0
    def train(self, num_games: int) -> None:
        print("Training poker bot with \033[0;32m{}\033[0m games...".format(
            num_games))

        prev_checkpoint = -CHECKPOINT_DIST - 1

        for i in range(num_games):
            if i > prev_checkpoint + CHECKPOINT_DIST:
                prev_checkpoint = i
                percent_complete = (i / num_games) * 100
                _print_progress(percent_complete)

            deck = treys.Deck()
            bundle = hulth.FakeCardBundle(deck, self._evaluator)

            root_info_set = hulth.create_game_root(bundle)

            for trainee in [hulth.SMALL_BLIND, hulth.BIG_BLIND]:
                self._chance_sampling_cfr(root_info_set, trainee,
                                          INITIAL_REACH_PROB,
                                          INITIAL_REACH_PROB)

        _print_progress(percent_complete=100.0)
        print()
Beispiel #6
0
def evaluate_table(n_cards):
    stats = np.zeros(N_SCORES)

    deck = treys.Deck()
    evaluator = treys.Evaluator()
    for k in range(N_LOOPS):
        for l in range(PRINT_FREQUENCY):
            deck.shuffle()
            hand = deck.draw(n_cards)
            score = evaluator.evaluate([], hand)
            stats[score] += 1
        summation = np.cumsum(stats)
        summation /= summation[-1]
        print("-" * 80)
        print("Table {0} of {1} cards known:".format(k, n_cards))
        for i in range(1, N_BINS):
            idx = int(i * N_SCORES / N_BINS)
            print("\tHand value {0} loses to {1}% of possible hands".format(
                idx, int(100 * summation[idx])))

    sns.lineplot(x=np.arange(N_SCORES), y=stats / np.sum(stats))
    plt.savefig("dist_{}.png".format(n_cards))
    plt.clf()
    np.save("dist_{}.npy".format(n_cards), summation)
 def __init__(self, n):
     self.n = n
     self.shape = (n, )
     self.deck = treys.Deck()
     super(MultiBinary, self).__init__((self.n, ), np.int8)
 def reset(self):
     self.deck = treys.Deck()
     self.hand = self.deal_hand()
Beispiel #9
0
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('!poker'):
        user = bot.user
        user2 = bot.user
        author: discord.Member = message.author
        channel = message.channel
        deck = treys.Deck()
        evaluator = treys.Evaluator()
        board = deck.draw(5)
        p1_hand = deck.draw(0)
        await channel.send(treys.Card.print_pretty_cards(board + p1_hand))

        change = await channel.send(
            str(author.mention) +
            ', quantas cartas você quer trocar? (Espere todos os emotes aparecerem, você tem 20 segundos)'
        )

        await change.add_reaction('0️⃣')
        await change.add_reaction('1️⃣')
        await change.add_reaction('2️⃣')
        await change.add_reaction('3️⃣')
        await change.add_reaction('4️⃣')
        await change.add_reaction('5️⃣')

        def check(reaction, user):
            if str(reaction.emoji) == '0️⃣':
                return user == message.author and str(reaction.emoji) == '0️⃣'
            if str(reaction.emoji) == '1️⃣':
                return user == message.author and str(reaction.emoji) == '1️⃣'
            elif str(reaction.emoji) == '2️⃣':
                return user == message.author and str(reaction.emoji) == '2️⃣'
            elif str(reaction.emoji) == '3️⃣':
                return user == message.author and str(reaction.emoji) == '3️⃣'
            elif str(reaction.emoji) == '4️⃣':
                return user == message.author and str(reaction.emoji) == '4️⃣'
            elif str(reaction.emoji) == '5️⃣':
                return user == message.author and str(reaction.emoji) == '5️⃣'

        def check2(reaction):
            if str(reaction.emoji) == '0️⃣':
                return -1
            if str(reaction.emoji) == '1️⃣':
                return 0
            elif str(reaction.emoji) == '2️⃣':
                return 1
            elif str(reaction.emoji) == '3️⃣':
                return 2
            elif str(reaction.emoji) == '4️⃣':
                return 3
            elif str(reaction.emoji) == '5️⃣':
                return 4

        try:
            while (user != message.author):
                reaction, user = await bot.wait_for('reaction_add',
                                                    timeout=20.0,
                                                    check=check)
            a = check2(reaction) + 1
            x = np.zeros(a)

            if (a != 0):
                change = await channel.send(
                    str(author.mention) +
                    ', quais cartas você quer trocar? (Espere todos os emotes aparecerem, você tem 20 segundos)'
                )
                await change.add_reaction('1️⃣')
                await change.add_reaction('2️⃣')
                await change.add_reaction('3️⃣')
                await change.add_reaction('4️⃣')
                await change.add_reaction('5️⃣')

            for i in range(a):
                while (user2 != message.author):
                    reaction, user2 = await bot.wait_for('reaction_add',
                                                         timeout=20.0,
                                                         check=check)
                user2 = bot.user
                x[i] = check2(reaction)
            x.sort()
            x = x[::-1]
            for i in range(a):
                board[int(x[i])] = deck.draw(1)

        except asyncio.TimeoutError:
            await channel.send(str(author.mention) + ', demorou demais')
        else:
            await channel.send(treys.Card.print_pretty_cards(board + p1_hand))
            p1_score = evaluator.evaluate(board, p1_hand)
            p1_class = evaluator.get_rank_class(p1_score)
            await channel.send(
                str(author.mention) + ', você tirou um ' +
                evaluator.class_to_string(p1_class))

    await bot.process_commands(message)
Beispiel #10
0
def generate_card_bundle() -> hulth.CardBundle:
    hand_evaluator = evaluator.Evaluator()
    deck = treys.Deck()

    return hulth.CardBundle(deck, hand_evaluator)