コード例 #1
0
class HandSimulator:
    def __init__(self):
        self.deck = Deck()
        self.hand_strength = HandStrength()

    def simulate(self,
                 hero_cards,
                 n_simulations,
                 n_villains=3,
                 villain_cards=None):
        self.deck.shuffle()
        hero_card_names = [hero_cards[0].name, hero_cards[1].name]

        win_counter = Counter()
        for _ in range(n_simulations):
            self.deck = Deck()
            self.deck.shuffle()
            self.deck.get_list(hero_card_names)
            all_hands = {i + 1: self.deck.deal(2) for i in range(n_villains)}
            all_hands[0] = Stack(cards=[hero_cards[0], hero_cards[1]])
            community_cards = self.deck.deal(5)
            for h in all_hands:
                all_hands[h].add(community_cards)
            winners = self.hand_strength.compare_hands(all_hands)
            for w in winners:
                win_counter[w] += 1
        print(win_counter)
コード例 #2
0
class Game28Deck:
    deck: Deck

    def __init__(self):
        self.deck = Deck()
        self.deck.empty()
        self.deck.add(Game28Deck.get_stack_for_deck())
        self.deck.shuffle()

    def reset_deck(self):
        self.deck = Deck(cards=self.get_stack_for_deck())

    def get_all_cards(self):
        return self.deck.cards

    def deal_cards(self, count):
        # TODO: might have to group this by suite
        return self.deck.deal(count)

    @staticmethod
    def get_stack_for_deck():
        stack: Stack = Stack();
        cards: List[Card] = []
        for suit in SUITS:
            for value in VALUES:
                if value not in ["2", "3", "4", "5", "6"]:
                    cards.append(Card(value, suit))
        stack.add(cards)
        return stack
コード例 #3
0
 def reshuffle(self):
     """Reset the decks so that there is one deck of 104 shuffled cards"""
     new_deck = Deck()
     new_deck.build()
     new_deck.shuffle()
     self.deck = new_deck
     self.cut_num = random.randint(12, 42)
コード例 #4
0
class Dealer(object):
    def __init__(self):
        self.deck = Deck()
        self.hand = Stack()
        self.deck.build()
        self.deck.shuffle()
        self.cut_num = random.randint(12, 42)

    def get_deck(self):
        return self.deck

    def get_hand(self):
        return self.hand

    def initial_deal(self, player):
        """Deal two cards to the player and the dealer."""
        cards = self.deck.deal(2)
        player.add_cards(cards)
        self.hand += self.deck.deal(2)

    def deal(self):
        """Get one card from the deck"""
        return self.deck.deal(1)

    def deal_dealer(self):
        """Deal one card to the dealer's hand"""
        self.hand += self.deck.deal(1)

    def empty_hand(self):
        """Remove all cards from the dealer's hand"""
        self.hand.empty()

    def reshuffle(self):
        """Reset the decks so that there is one deck of 104 shuffled cards"""
        new_deck = Deck()
        new_deck.build()
        new_deck.shuffle()
        self.deck = new_deck
        self.cut_num = random.randint(12, 42)
コード例 #5
0
 def __init__(self):
     self.deck = Deck()
     self.deck.empty()
     self.deck.add(Game28Deck.get_stack_for_deck())
     self.deck.shuffle()
コード例 #6
0
 def reset_deck(self):
     self.deck = Deck(cards=self.get_stack_for_deck())
コード例 #7
0
 def __init__(self):
     self.deck = Deck()
     self.hand = Stack()
     self.deck.build()
     self.deck.shuffle()
     self.cut_num = random.randint(12, 42)
コード例 #8
0
ファイル: gamble.py プロジェクト: Firescoutt/BattleBanana
async def blackjack(ctx, price, **details):
    """gamble:blackjack:Help"""
    user = details["author"]
    BattleBanana = players.find_player(ctx.guild.me.id)

    if user.money < price or price > 1000000000:
        raise util.BattleBananaException(
            ctx.channel, translations.translate(ctx,
                                                "gamble:blackjack:HighBet"))
    if price < 1:
        raise util.BattleBananaException(
            ctx.channel, translations.translate(ctx,
                                                "gamble:blackjack:LowBet"))
    if (user.gamble_play and int(time.time() - user.last_played) < 120
        ) or int(time.time() - user.last_played) < 120:
        raise util.BattleBananaException(
            ctx.channel,
            translations.translate(ctx, "gamble:blackjack:AlreadyPlay"))

    # Create new deck, make player playing
    deck = Deck() + Deck() + Deck() + Deck()
    deck.shuffle()
    user.gamble_play = True
    user.last_played = time.time()

    # Hands out 2 cards to each & calculate the count
    dealer_hand = deck.deal(2)
    user_hand = deck.deal(2)
    user_value, dealer_value = blackjackGame.compare_decks(
        user_hand, dealer_hand)

    blackjack_embed = discord.Embed(
        title=translations.translate(ctx, "gamble:blackjack:StartTitle"),
        description=translations.translate(ctx, "gamble:blackjack:StartDesc",
                                           user.get_name_possession(), price),
        type="rich",
        colour=gconf.DUE_COLOUR)
    blackjack_embed.add_field(name=translations.translate(
        ctx, "gamble:blackjack:UserHand", user_value),
                              value=user_hand)
    blackjack_embed.add_field(name=translations.translate(
        ctx, "gamble:blackjack:DealerHand", dealer_value),
                              value=dealer_hand)
    blackjack_embed.set_footer(
        text=translations.translate(ctx, "gamble:blackjack:StartFooter"))

    msg = await util.reply(ctx, embed=blackjack_embed)
    # Player's play
    while True:
        user.last_played = time.time()
        user_value, dealer_value = blackjackGame.compare_decks(
            user_hand, dealer_hand)
        if user_value >= 21 or dealer_value >= 21:
            break
        user_msg = await util.wait_for_message(ctx, ctx.author)

        if user_msg != None and user_msg.content.lower() == "hit":
            user_hand += deck.deal(1)
            user_value, dealer_value = blackjackGame.compare_decks(
                user_hand, dealer_hand)

            blackjack_embed.clear_fields()
            blackjack_embed.add_field(name=translations.translate(
                ctx, "gamble:blackjack:UserHand", user_value),
                                      value=user_hand)
            blackjack_embed.add_field(name=translations.translate(
                ctx, "gamble:blackjack:DealerHand", dealer_value),
                                      value=dealer_hand)

            await util.edit_message(msg, embed=blackjack_embed)

            await util.delete_message(user_msg)
        else:
            if user_msg:
                await util.delete_message(user_msg)
            break

    # Dealer's turn
    while True:
        user_value, dealer_value = blackjackGame.compare_decks(
            user_hand, dealer_hand)
        if dealer_value >= 21 or user_value > 21 or dealer_value > user_value:
            break
        if dealer_value < 17:  # Make him pick a card
            dealer_hand += deck.deal(1)
        else:
            break

    # Manage who wins/loses
    user_value, dealer_value = blackjackGame.compare_decks(
        user_hand, dealer_hand)
    gain = 0
    if user_value > dealer_value:
        if user_value > 21:
            gain -= price
            result = translations.translate(ctx, "gamble:blackjack:UserBust")
        elif user_value == 21:
            gain += price * 1.5
            result = translations.translate(ctx, "gamble:blackjack:UserBJ")
        else:
            gain += price
            result = translations.translate(ctx, "gamble:blackjack:UserWin",
                                            user_value, dealer_value)
    elif user_value < dealer_value:
        if dealer_value > 21:
            if user_value == 21:  # If you have 21 and dealer busted
                gain += price * 1.5
            else:
                gain += price
            result = translations.translate(ctx, "gamble:blackjack:DealBust")
        elif dealer_value == 21:
            gain -= price
            result = translations.translate(ctx, "gamble:blackjack:DealBJ")
        else:
            gain -= price
            result = translations.translate(ctx, "gamble:blackjack:DealWin",
                                            dealer_value, user_value)
    else:
        result = translations.translate(ctx, "gamble:blackjack:Tie",
                                        user_value, dealer_value)

    # Manage the message
    gain = math.floor(gain)
    user.money += gain
    if gain > 0:
        result += translations.translate(ctx, "gamble:blackjack:RewardWin",
                                         price + gain)
    elif gain < 0:
        result += translations.translate(ctx, "gamble:blackjack:RewardLose",
                                         price)
        BattleBanana.money += price
    else:
        result += translations.translate(ctx, "gamble:blackjack:RewardTie")

    blackjack_embed.clear_fields()
    blackjack_embed.add_field(name=translations.translate(
        ctx, "gamble:blackjack:UserHand", user_value),
                              value=user_hand)
    blackjack_embed.add_field(name=translations.translate(
        ctx, "gamble:blackjack:DealerHand", dealer_value),
                              value=dealer_hand)
    blackjack_embed.add_field(name=translations.translate(
        ctx, "gamble:blackjack:Result"),
                              value=result,
                              inline=False)
    blackjack_embed.set_footer()

    user.command_rate_limits['blackjack_saved_cooldown'] = int(time.time())
    user.gamble_play = False
    user.last_played = 0
    user.save()
    BattleBanana.save()

    await util.edit_message(msg, embed=blackjack_embed)
コード例 #9
0
 def __init__(self):
     self.deck = Deck()
     self.hand_strength = HandStrength()