コード例 #1
0
 def test_two_to_one(self):
     deck1 = ["B","C"]
     deck2 = ["A"]
     deal(deck1,deck2)
     deal(deck1,deck2)
     self.assertEquals(deck1,[])
     self.assertEquals(deck2,["A","B","C"])
コード例 #2
0
 def test_two_to_empty(self):
     deck1 = ["A","B"]
     deck2 = list()
     deal(deck1,deck2)
     deal(deck1,deck2)
     self.assertEquals(deck1,[])
     self.assertEquals(deck2,["A","B"])
コード例 #3
0
ファイル: test_deck.py プロジェクト: jbbrokaw/deck-of-cards
def test_deck_deal():
    """Want to be able to get the top card (and 'remove' it)"""
    deck = Deck()
    with pytest.raises(TypeError):
        deck.deal(1)  # No values (for now)
    # Not shuffled, all cards should be in order
    topcard = deck.deal()  # Should be ace of hearts, Card(0, 0)
    assert topcard == Card(0, 0)
    nextcard = deck.deal()  # Should be two of hearts, Card(0, 1)
    assert nextcard == Card(0, 1)
コード例 #4
0
 def test_full_deck_except_one(self):
     freshishDeck = ["AS", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "10S", "JS", "QS", "KS",
     "AH", "2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "10H", "JH", "QH", "KH",
     "AC", "2C", "3C", "4C", "5C", "6C", "7C", "8C", "9C", "10C", "JC", "QC", "KC",
     "AD", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "10D", "JD", "QD"]
     deck = ["AS", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "10S", "JS", "QS", "KS",
     "AH", "2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "10H", "JH", "QH", "KH",
     "AC", "2C", "3C", "4C", "5C", "6C", "7C", "8C", "9C", "10C", "JC", "QC", "KC",
     "AD", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "10D", "JD", "QD", "KD"]
     deck2 = list()
     for i in range(len(deck)-1):
         deal(deck,deck2)
     self.assertEquals(freshishDeck,deck2)
     self.assertEquals(deck,["KD"])
コード例 #5
0
def my_dealer( deck ):
    """

    :param deck: a class imported
    :return:
    """
    cards_deal = []
    for x in range(5):
        cards_deal.append(deck.deal())
    return cards_deal
コード例 #6
0
ファイル: test_deck.py プロジェクト: jbbrokaw/deck-of-cards
def test_deck_shuffle():
    """Want to be able to shuffle it"""
    deck = Deck()
    with pytest.raises(TypeError):
        deck.shuffle(1)  # No values (for now)
    unmoved_cards = 0
    deck.shuffle()
    for i in xrange(52):
        card = deck.deal()
        if card == Card(i // 13, i % 13):
            unmoved_cards += 1
    print unmoved_cards
    assert unmoved_cards < 5  # It would be weird if this was higher
コード例 #7
0
 def test_three_decks(self):
     deck1 = ["A","C"]
     deck2 = ["B"]
     deck3 = list()
     deal(deck1,deck3)
     deal(deck2,deck3)
     deal(deck1,deck3)
     self.assertEquals(deck1,[])
     self.assertEquals(deck2,[])
     self.assertEquals(deck3,["A","B","C"])
コード例 #8
0
ファイル: card.py プロジェクト: axQzore/Jackbot
    async def poker(self, ctx, arg: str = None):
        """["join/leave/deal"] Play poker against other users"""
        db = sqlite3.connect('main.sqlite')
        cursor = db.cursor()
        embed = discord.Embed(color=0x228b22, title="Poker Table")
        if arg == None:
            cursor.execute(
                f'SELECT user_id, jacks, poker FROM main WHERE poker > 0')
            results = cursor.fetchall()
            if len(results) != 0:
                players = []
                for result in results:
                    players.append(
                        f'{self.client.get_user(int(result[0]))} \u2022 {result[1]} chips'
                    )
                output = ""
                for player in range(len(players)):
                    output += players[player] + "\n"
                embed.add_field(name="Poker players",
                                value=output,
                                inline=False)
            else:
                embed.add_field(name="Empty",
                                value="There is no one at the table now")
            await ctx.send(content=None, embed=embed)
        elif arg.lower() == "join":
            cursor.execute(
                f'SELECT user_id, jacks, poker FROM main WHERE user_id = {ctx.author.id}'
            )
            result = cursor.fetchone()
            if result is None:
                embed.add_field(
                    name="Error!",
                    value="You must register before you can play this game",
                    inline=False)
            else:
                if result[2] is None or int(result[2]) != 1:
                    sql = ("UPDATE main SET poker = ? WHERE user_id = ?")
                    val = (1, ctx.author.id)
                    cursor.execute(sql, val)
                    db.commit()
                    embed.add_field(
                        name="Success!",
                        value="You have successfully joined the poker table",
                        inline=False)
                    embed.set_footer(
                        text=f"You have {result[1]} chips to play with")
                else:
                    embed.add_field(
                        name="Error:",
                        value="You are already sitting at the poker table",
                        inline=False)
            await ctx.send(content=None, embed=embed)
        elif arg.lower() == "leave":
            cursor.execute(
                f'SELECT user_id, jacks, poker FROM main WHERE user_id = {ctx.author.id}'
            )
            result = cursor.fetchone()
            if result is None:
                embed.add_field(
                    name="Error!",
                    value="You must register before you can play this game",
                    inline=False)
            else:
                if result[2] > 0:
                    sql = ("UPDATE main SET poker = ? WHERE user_id = ?")
                    val = (0, ctx.author.id)
                    cursor.execute(sql, val)
                    db.commit()
                    embed.add_field(name="Success!",
                                    value="You have left the table",
                                    inline=False)
                else:
                    embed.add_field(name="Error:",
                                    value="You are not at the poker table",
                                    inline=False)
            await ctx.send(content=None, embed=embed)
        elif arg.lower() == "deal":
            cursor.execute(
                f'SELECT user_id, jacks, poker FROM main WHERE user_id = {ctx.author.id}'
            )
            result = cursor.fetchone()
            if result[2] is None or int(result[2]) == 0:
                embed.add_field(
                    name="Error:",
                    value="Only someone at the poker table can start the game")
                await ctx.send(content=None, embed=embed)
            elif result[2] == 2:
                embed.add_field(name="Error:",
                                value="You are already in a game!")
                await ctx.send(content=None, embed=embed)
            else:
                deck = pydealer.Deck(rebuild=True,
                                     re_shuffle=True,
                                     ranks=POKER_RANKS)
                deck.shuffle()
                cursor.execute(
                    f'SELECT user_id, jacks, poker FROM main WHERE poker = 1')
                results = cursor.fetchall()
                if len(results) == 1:
                    embed.add_field(
                        name="Error:",
                        value=
                        "You cannot start a poker game without any other players",
                        inline=False)
                    await ctx.send(content=None, embed=embed)
                else:
                    hands = []
                    for result in results:
                        sql = (
                            f"UPDATE main SET poker = {2} WHERE user_id = {result[0]}"
                        )
                        cursor.execute(sql)
                        db.commit()
                        player = self.client.get_user(int(result[0]))
                        hand = pydealer.Stack()
                        hand.add(deck.deal(2))
                        hands.append(hand)
                        embed.add_field(name="Your hand:",
                                        value=f"{hand}",
                                        inline=False)
                        await player.send(content=None, embed=embed)
                        embed.remove_field(0)
                    river = pydealer.Stack()
                    river.add(deck.deal(3))
                    # Loop through users prompt to raise/call/fold
                    calls = 0
                    checks = 0
                    pot = 0
                    player_hand = 0
                    bid = 0
                    while len(results) > 1 and len(river) < 5:
                        for result in results:
                            player = self.client.get_user(int(result[0]))
                            embed.add_field(name="River:",
                                            value=f"{river}")  #field(0)
                            embed.add_field(name="Pot:",
                                            value=f'{pot}')  #field(1)
                            embed.add_field(
                                name=f"{player}'s turn:",
                                value=
                                f"{player.mention}! Would you like to `raise (+ bid)`, `fold`, `check`, or `call`?",
                                inline=False)  #field(2)
                            await ctx.send(content=None, embed=embed)
                            msg = await self.client.wait_for(
                                'message',
                                check=lambda message: message.author == player)
                            if msg.content.startswith("raise"):
                                bid = int(''.join(x for x in msg.content
                                                  if x.isdigit()))
                                if bid is None or bid < 0:
                                    bid = 20
                                elif bid > int(result[1]):
                                    bid = int(result[1])
                                sql = (
                                    f"UPDATE main SET jacks = {int(result[1]) - bid} WHERE user_id = {result[0]}"
                                )
                                cursor.execute(sql)
                                db.commit()
                                checks = 0
                                calls = 0
                                embed.remove_field(2)
                                embed.add_field(
                                    name=f"{player}'s turn:",
                                    value=
                                    f"{player} has raised <:chip:657253017262751767> **{bid}** chips",
                                    inline=False)
                                await ctx.send(content=None, embed=embed)
                                pot += bid
                            elif msg.content == "fold":
                                sql = (
                                    f"UPDATE main SET poker = {1} WHERE user_id = {result[0]}"
                                )
                                cursor.execute(sql)
                                db.commit()
                                # Remove player from results
                                results.remove(result)
                                del hands[player_hand]
                                embed.remove_field(2)
                                embed.add_field(name=f"{player}'s turn:",
                                                value=f"{player} has folded",
                                                inline=False)
                                await ctx.send(content=None, embed=embed)
                            else:
                                if bid == 0 or bid is None:
                                    checks += 1
                                    embed.remove_field(2)
                                    embed.add_field(
                                        name=f"{player}'s turn:",
                                        value=f"{player} has checked",
                                        inline=False)
                                    await ctx.send(content=None, embed=embed)
                                    if checks == len(results):
                                        river.add(deck.deal(1))
                                        checks = 0
                                else:
                                    if bid > int(result[1]):
                                        bid = result[1]
                                    sql = (
                                        f"UPDATE main SET jacks = {int(result[1]) - bid} WHERE user_id = {result[0]}"
                                    )
                                    cursor.execute(sql)
                                    db.commit()
                                    embed.remove_field(2)
                                    embed.add_field(
                                        name=f"{player}'s turn:",
                                        value=
                                        f"{player} has called the <:chip:657253017262751767> **{bid}** chip bid",
                                        inline=False)
                                    await ctx.send(content=None, embed=embed)
                                    pot += bid
                                    calls += 1
                                    if calls == len(results) - 1:
                                        calls = 0
                                        bid = 0
                            embed.remove_field(2)
                            embed.remove_field(1)
                            embed.remove_field(0)
                            player_hand = 0
                    # Announce winner of the round
                    if len(results) == 1:
                        await ctx.send(
                            'Only 1 player remains, all others have folded')
                    j = 0
                    for result in results:
                        sql = (
                            f"UPDATE main SET poker = {1} WHERE user_id = {result[0]}"
                        )
                        cursor.execute(sql)
                        db.commit()
                        # prints hands, I want to change that
                        player = self.client.get_user(int(result[0]))
                        embed.add_field(name=f"{player}'s hand:",
                                        value=f'{hands[j]}',
                                        inline=False)
                        j += 1
                    await ctx.send(content=None, embed=embed)

        cursor.close()
        db.close()
コード例 #9
0
    bet = input("What would you like to bet? ")
    bet = int(bet)
    r = go.Round(bet)
    if not player_balance.bet_accepted(r.bet):
        print('Bet too much! Please choose a smaller amount')
        while not player_balance.bet_accepted(r.bet):
            bet = input("What would you like to bet? ")
            bet = int(bet)
            r = go.Round(bet)

    # Define player and dealer hand
    player_hand = hand.Hand()
    dealer_hand = hand.Hand()

    # Deal cards
    player_hand.deal_card_to_hand(deck.deal())
    dealer_hand.deal_card_to_hand(deck.deal())
    player_hand.deal_card_to_hand(deck.deal())
    dealer_hand.deal_card_to_hand(deck.deal())

    # Hide one dealer card
    dealer_hand.cards[0].is_hidden = True

    print('Your hand: (' + str(player_hand.total()) + ')')
    print(player_hand.display())
    print('Dealer\'s hand: (' + str(dealer_hand.total()) + ')')
    print(dealer_hand.display())

    if player_hand.is_blackjack():
        print('BLACKJACK!')
        player_hand.stick()
コード例 #10
0
ファイル: card.py プロジェクト: axQzore/Jackbot
 async def blackjack(self, ctx, arg: int):
     """Play blackjack against the bot"""
     db = sqlite3.connect('main.sqlite')
     cursor = db.cursor()
     cursor.execute(
         f'SELECT user_id, jacks FROM main WHERE user_id = {ctx.author.id}')
     result = cursor.fetchone()
     embed = discord.Embed(color=0x228b22, title="Blackjack")
     if result is not None:
         if arg > result[1]:
             embed.add_field(
                 name="Error",
                 value=f"You can't bid more chips than you have!",
                 inline=False)
             embed.set_footer(
                 text=
                 "You can check your balance using the *profile* command")
         else:
             player, house = [], []
             deck.deal(player, 2)
             deck.deal(house, 2)
             embed.add_field(
                 name="Your Hand:",
                 value=
                 f"```{deck.display_hand(player)}``` \n Value: {deck.hand_value(player)}"
             )
             embed.add_field(
                 name="Dealer's Hand:",
                 value=
                 f"```['{deck.display_hand(house)[1]}', '?'] ``` \n Value: ?"
             )
             embed.set_footer(
                 text="Type `hit` or `stay` to take your turn!")
             await ctx.send(content=None, embed=embed)
             if deck.hand_value(house) != 21 and deck.hand_value(
                     player) != 21:
                 msg = await self.client.wait_for(
                     'message',
                     check=lambda message: message.author == ctx.author)
                 while msg.content.startswith(
                         "hit") or msg.content.startswith("Hit"):
                     embed.remove_field(0)
                     deck.deal(player)
                     embed.insert_field_at(
                         0,
                         name="Your Hand:",
                         value=
                         f"```{deck.display_hand(player)}``` \n Value: {deck.hand_value(player)}"
                     )
                     await ctx.send(content=None, embed=embed)
                     if deck.hand_value(player) > 21:
                         break
                     msg = await self.client.wait_for(
                         'message',
                         check=lambda message: message.author == ctx.author)
             embed.remove_field(1)
             embed.set_footer(text="")
             deck.house_turn(house)
             embed.add_field(
                 name="Dealer's Hand:",
                 value=
                 f"```{deck.display_hand(house)}``` \n Value: {deck.hand_value(house)}"
             )
             if deck.hand_value(player) == 21:
                 outcome = "Blackjack!"
                 bal = "won"
                 chips = int(result[1] + arg * 1.5)
             elif deck.hand_value(player) > 21:
                 outcome = "Player bust, you lose"
                 bal = "lost"
                 chips = int(result[1] - arg)
             elif deck.hand_value(house) > 21:
                 outcome = "Dealer bust, you win!"
                 bal = "won"
                 chips = int(result[1] + arg)
             elif deck.hand_value(player) > deck.hand_value(house):
                 outcome = "Win!"
                 bal = "won"
                 chips = int(result[1] + arg)
             elif deck.hand_value(player) == deck.hand_value(house):
                 outcome = "Push, chips back"
                 bal = "gotten back your"
                 chips = int(result[1])
             else:
                 outcome = "Loss"
                 bal = "lost"
                 chips = int(result[1] - arg)
             sql = ("UPDATE main SET jacks = ? WHERE user_id = ?")
             val = (chips, ctx.author.id)
             cursor.execute(sql, val)
             db.commit()
             cursor.close()
             db.close()
             if chips == int(result[1]):
                 chips += arg
             embed.add_field(
                 name=outcome,
                 value=
                 f"You have {bal} <:chip:657253017262751767> **{abs(int(result[1] - chips))}** chips",
                 inline=False)
         await ctx.send(content=None, embed=embed)
     else:
         await ctx.send("You must register before you can play blackjack!")
コード例 #11
0
def hit(deck, hand):
    next_card = deck.deal()
    hand.add_card(next_card)
    hand.adjust_for_ace()
    print(f"card after hit : {next_card}")
コード例 #12
0
 def __init__(self, deck):
     self._cards = []
     new_cards = deck.deal(num_of_cards=2)
     for card in new_cards:
         self._cards.append(card)
     self.owner = None
コード例 #13
0
 def hit(self, deck, num_of_cards):
     new_cards = deck.deal(num_of_cards=num_of_cards)
     for card in new_cards:
         self._cards.append(card)
コード例 #14
0
    
    # If else block based on user input
    if user_input.lower() == "q":
        print("GAME = **OVER**")
        game_on = False
    
    # ----- Add Player -----
    elif user_input.lower() == "a":
        new_player = input("Player name?: ")
        players.append(person.Person(new_player, 100))
        print(new_player + " added, starting with 100 chips.")
        print(divider)
    
    # ----- Playing Hand -----
    elif user_input.lower() == "p":
        deck.deal(players)
        # ---------- Loop to bet or fold ----------
        for player in players:
            chosen = False
            while not chosen:
                user_choice = input(player.name + " would you like to play this hand? play(p) fold(f): ")
                
                # Type Check
                if type(user_choice) != str:
                    print("Must enter an string ex. 'p'")

                # Player folding hand
                elif user_choice.lower() == "f":
                    player.fold()
                    chosen = True
                    print(divider)