Exemple #1
0
    def __init__(self, bot, message, bj):
        player = Player(message.author)
        self.bj = bj
        self.bot = bot
        self.players = [{'status': 'playing', 'player': player}]
        # Our buffer for players who want to join
        # People cannot join in the middle of a game, so we'll add them at the end
        self._added_players = []
        # Our list of players who lost/left
        self._removed_players = []

        # The channel we'll send messages to
        self.channel = message.channel

        # People can join in on this game, but lets make sure we don't go over the limit however
        self._max_players = 10

        # Lets create our main deck, and shuffle it
        self.deck = utils.Deck()
        # So apparently, it is possible, with 10 players and nearly everyone/everyone busting
        # To actually deplete the deck, and cause it to return None, and mess up later
        # Due to this, lets make put 2 decks in here
        _deck2 = utils.Deck()
        self.deck.insert(list(_deck2.draw(52)))
        del _deck2
        self.deck.shuffle()
        # The dealer
        self.dealer = Player('Dealer')

        self.min_bet = 5
        self.max_bet = 500
        self.bet = 0

        self.task = self.bot.loop.create_task(self.game_task())
Exemple #2
0
def full_enumeration(hands, board=[]):
    """
    Return ev of each player.

    hands -> list of two card hands
    board -> any # of cards 0-5.
    """
    nplayers = len(hands)
    if nplayers == 2:
        return enum2p(hands[0], hands[1], board)
    if nplayers == 1:
        return [1.0]
    wins = [0 for __ in range(nplayers)]
    trials = 0
    dead = sum(hands, board)
    deck = utils.Deck(dead)
    needed_cards = 5 - len(board)
    for cards in itertools.combinations(deck, needed_cards):

        winners = multi_holdem(hands, board + list(cards))
        nwinners = len(winners)
        trials += 1
        for w in winners:
            wins[w] += 1.0 / nwinners

    return [w / trials for w in wins]
Exemple #3
0
def enum2p(h1, h2, board=[]):
    """
    Return ev of each player.

    hands -> list of two card hands
    board -> any # of cards 0-5.
    """
    wins = [0, 0, 0]
    dead = h1 + h2 + board
    deck = utils.Deck(dead)
    needed_cards = 5 - len(board)
    for cards in itertools.combinations(deck, needed_cards):

        winners = holdem2p(h1, h2, board + list(cards))
        wins[winners] += 1

    ev1 = (wins[0] + .5 * wins[2]) / sum(wins)
    return [ev1, 1.0 - ev1]
Exemple #4
0
def monte_carlo(hands, trials=100000):
    """
    Return ev of each player.

    hands -> list of 2 - 22 hands
    trials -> the approximate number of simulations to run
    """
    nplayers = len(hands)
    wins = [0 for __ in range(nplayers)]

    nboards = int((52 - nplayers * 2) / 5)
    scheme = [5] * nboards
    deck = utils.Deck(sum(hands, []))

    for t in range(int(trials / nboards)):
        for b in deck.deal(scheme):
            winners = multi_holdem(hands, b)
            nwinners = len(winners)
            for w in winners:
                wins[w] += 1.0 / nwinners
    trials = trials / nboards * nboards
    return [w / trials for w in wins]
    def __init__(self, ctx, bot):
        self.ctx = ctx
        self.bot = bot
        # Higher or Lower
        self.moves = [
            utils.HighLow.HIGH.value,
            utils.HighLow.LOW.value,
            utils.Controls.CANCEL.value,
        ]
        self.deck = utils.Deck()
        self.deck.shuffle()
        # use half a deck since it can be a long game otherwise
        self.deck = self.deck.split(2)[0]
        self.dealer_score = 0
        self.player_score = 0

        self.embed = discord.Embed(
            title=None,
            type='rich',
            color=np.random.randint(0xFFFFFF),  # Random color
        ).set_author(
            name=self.ctx.author.display_name,
            icon_url=self.ctx.author.avatar_url_as(static_format='png'),
        ).add_field(
            name='Higher or Lower?',
            value=None,  # will be filled later
            inline=False,
        ).add_field(
            name='Previous Card',
            value=None,  # will be filled later
            inline=True,
        ).add_field(
            name='Next Card',
            value=None,  # will be filled later
            inline=True,
        )
Exemple #6
0
    def __init__(self, member):
        self.member = member
        self.hand = utils.Deck(prefill=False)

        # The chips a player starts with
        self.chips = 1000