示例#1
0
    async def on_message(self, message):
        # don't respond to ourselves
        print(str(message.author) + ": " + message.content)
        if message.author == self.user or message.guild == None or message.guild.id != 166679130228785152:
            return

        if message.content == '#init' or message.content == "#play" or message.content == "#start":
            if self.game == None:
                ids = self.seekUsers(
                    ["Satsuwu#4597", message.author, "Knowle#3321"])
                self.game = Poker([Player(x) for x in ids])
                self.game.start()
                for player in self.game.players:
                    image = discord.File(
                        self.drawing.draw(player.cards, player.id.id))
                    await player.id.send("Those are your cards", file=image)
            else:
                await message.channel.send("A game is already in progress")
        elif message.content == '#pass' or message.content == '#next':
            if self.game != None:
                result = self.game.next()
                if result == None:
                    image = discord.File(
                        self.drawing.draw(self.game.tableCards))
                    await message.channel.send("Current table cards",
                                               file=image)
                else:
                    await message.channel.send(
                        "The winners are: " +
                        ", ".join([str(p.id) for p in result]))
                    self.game = None
            else:
                await message.channel.send("There is no game in progress")
示例#2
0
    def test_one_pair(self):
        # First, generate some hands. Some have pairs, some don't.
        H1 = [
            Card(11, 'D'),
            Card(9, 'H'),
            Card(5, 'S'),
            Card(5, 'C'),
            Card(5, 'D')
        ]
        # One pair
        H2 = [
            Card(10, 'S'),
            Card(8, 'D'),
            Card(8, 'S'),
            Card(8, 'H'),
            Card(5, 'S')
        ]
        # Three of a kind
        H3 = [
            Card(14, 'H'),
            Card(13, 'S'),
            Card(12, 'D'),
            Card(12, 'C'),
            Card(6, 'C')
        ]
        # One pair
        H4 = [
            Card(14, 'D'),
            Card(13, 'H'),
            Card(11, 'C'),
            Card(10, 'D'),
            Card(2, 'D')
        ]
        # Nothing
        H5 = [
            Card(14, 'C'),
            Card(12, 'H'),
            Card(11, 'S'),
            Card(7, 'S'),
            Card(3, 'D')
        ]
        # Nothing

        # Now, create a poker game object (so that we can use its methods) and
        # test that it gives the correct results.
        P = Poker(2)

        self.assertTrue(P.is_one_pair(H1))
        self.assertTrue(P.is_one_pair(H2))
        self.assertTrue(P.is_one_pair(H3))
        self.assertFalse(P.is_one_pair(H4))
        self.assertFalse(P.is_one_pair(H5))
示例#3
0
class MyClient(discord.Client):
    game = None
    drawing = Draw()

    def seekUsers(self, ids):
        for i in range(len(ids)):
            if type(ids[i]) is str:
                data = ids[i].split("#")
                ids[i] = discord.utils.get(self.get_all_members(),
                                           name=data[0],
                                           discriminator=data[1])
        return ids

    async def on_ready(self):
        print('Logged on as', self.user)

    async def on_message(self, message):
        # don't respond to ourselves
        print(str(message.author) + ": " + message.content)
        if message.author == self.user or message.guild == None or message.guild.id != 166679130228785152:
            return

        if message.content == '#init' or message.content == "#play" or message.content == "#start":
            if self.game == None:
                ids = self.seekUsers(
                    ["Satsuwu#4597", message.author, "Knowle#3321"])
                self.game = Poker([Player(x) for x in ids])
                self.game.start()
                for player in self.game.players:
                    image = discord.File(
                        self.drawing.draw(player.cards, player.id.id))
                    await player.id.send("Those are your cards", file=image)
            else:
                await message.channel.send("A game is already in progress")
        elif message.content == '#pass' or message.content == '#next':
            if self.game != None:
                result = self.game.next()
                if result == None:
                    image = discord.File(
                        self.drawing.draw(self.game.tableCards))
                    await message.channel.send("Current table cards",
                                               file=image)
                else:
                    await message.channel.send(
                        "The winners are: " +
                        ", ".join([str(p.id) for p in result]))
                    self.game = None
            else:
                await message.channel.send("There is no game in progress")
示例#4
0
    def test_one_pair(self):
        # First, create a poker game object.
        P = Poker(3)

        # Now, let's create a hand with one pair and test that it gives the
        # expected number of points.
        H1 = [
            Card(10, 'C'),
            Card(9, 'C'),
            Card(9, 'D'),
            Card(4, 'H'),
            Card(3, 'S')
        ]
        # One Pair
        expected_points_H1 = 2 * (15**5) + 9 * (15**4) + 9 * (15**3) + 10 * (
            15**2) + 4 * 15 + 3
        self.assertEqual(P._calculate_hand_points(2, H1), expected_points_H1)
示例#5
0
    def test_two_pair(self):
        # First, create a poker game object.
        P = Poker(3)

        # Now, let's create a hand with two pair and test that it gives the
        # expected number of points.
        H1 = [
            Card(13, 'S'),
            Card(10, 'D'),
            Card(10, 'H'),
            Card(2, 'C'),
            Card(2, 'D')
        ]
        # Four of a kind
        expected_points_H1 = 3 * (15**5) + 10 * (15**4) + 10 * (15**3) + 2 * (
            15**2) + 2 * 15 + 13
        self.assertEqual(P._calculate_hand_points(3, H1), expected_points_H1)
示例#6
0
    def test_three_of_a_kind(self):
        # First, create a poker game object.
        P = Poker(3)

        # Now, let's create a full house hand and test that it gives the
        # expected number of points.
        H1 = [
            Card(10, 'S'),
            Card(10, 'D'),
            Card(10, 'H'),
            Card(2, 'C'),
            Card(2, 'D')
        ]
        # Four of a kind
        expected_points_H1 = 4 * (15**5) + 10 * (15**4) + 10 * (15**3) + 10 * (
            15**2) + 2 * 15 + 2
        self.assertEqual(P._calculate_hand_points(4, H1), expected_points_H1)
示例#7
0
    def test_full_house(self):
        # First, create a poker game object.
        P = Poker(3)

        # Now, let's create a full house hand and test that it gives the
        # expected number of points.
        H1 = [
            Card(12, 'S'),
            Card(12, 'D'),
            Card(5, 'H'),
            Card(5, 'C'),
            Card(5, 'D')
        ]
        # Four of a kind
        expected_points_H1 = 7 * (15**5) + 5 * (15**4) + 5 * (15**3) + 5 * (
            15**2) + 12 * 15 + 12
        self.assertEqual(P._calculate_hand_points(7, H1), expected_points_H1)
示例#8
0
    def test_four_of_a_kind(self):
        # First, create a poker game object.
        P = Poker(3)

        # Now, let's create a 4-of-a-kind hand and test that it gives the
        # expected number of points.
        H1 = [
            Card(5, 'S'),
            Card(5, 'D'),
            Card(5, 'H'),
            Card(5, 'C'),
            Card(3, 'D')
        ]
        # Four of a kind
        expected_points_H1 = 8 * (15**5) + 5 * (15**4) + 5 * (15**3) + 5 * (
            15**2) + 5 * 15 + 3
        self.assertEqual(P._calculate_hand_points(8, H1), expected_points_H1)
示例#9
0
    def test_three_of_a_kind(self):
        # First, generate some hands. Some have 3 of a kind, some don't.
        H1 = [
            Card(14, 'D'),
            Card(5, 'D'),
            Card(5, 'H'),
            Card(5, 'C'),
            Card(3, 'D')
        ]
        # Three of a kind
        H2 = [
            Card(5, 'S'),
            Card(5, 'D'),
            Card(5, 'H'),
            Card(5, 'C'),
            Card(3, 'D')
        ]
        # Four of a kind
        H3 = [
            Card(13, 'C'),
            Card(10, 'H'),
            Card(5, 'C'),
            Card(4, 'C'),
            Card(4, 'H')
        ]
        # One pair
        H4 = [
            Card(12, 'D'),
            Card(11, 'H'),
            Card(6, 'D'),
            Card(6, 'S'),
            Card(5, 'H')
        ]
        # One pair

        # Now, create a poker game object (so that we can use its methods) and
        # test that it gives the correct results.
        P = Poker(2)

        self.assertTrue(P.is_three_of_a_kind(H1))
        self.assertTrue(P.is_three_of_a_kind(H2))
        self.assertFalse(P.is_three_of_a_kind(H3))
        self.assertFalse(P.is_three_of_a_kind(H4))
示例#10
0
    def test_straight(self):
        # First, generate some hands. Some are straights, some are not.
        H1 = [
            Card(6, 'S'),
            Card(5, 'S'),
            Card(4, 'S'),
            Card(3, 'S'),
            Card(2, 'S')
        ]
        # Straight
        H2 = [
            Card(13, 'S'),
            Card(12, 'D'),
            Card(11, 'H'),
            Card(10, 'H'),
            Card(9, 'C')
        ]
        # Straight
        H3 = [
            Card(12, 'S'),
            Card(11, 'H'),
            Card(7, 'C'),
            Card(5, 'D'),
            Card(3, 'H')
        ]
        # Nothing
        H4 = [
            Card(14, 'D'),
            Card(5, 'D'),
            Card(5, 'H'),
            Card(5, 'C'),
            Card(3, 'D')
        ]
        # Three of a kind

        # Now, create a poker game object (so that we can use its methods) and
        # test that it gives the correct results.
        P = Poker(2)

        self.assertTrue(P.is_straight(H1))
        self.assertTrue(P.is_straight(H2))
        self.assertFalse(P.is_straight(H3))
        self.assertFalse(P.is_straight(H4))
示例#11
0
    def test_straight_flush(self):
        # First, generate some hands. Some are straight flushes, some are not.
        H1 = [
            Card(6, 'S'),
            Card(5, 'S'),
            Card(4, 'S'),
            Card(3, 'S'),
            Card(2, 'S')
        ]
        # straight flush
        H2 = [
            Card(13, 'S'),
            Card(12, 'D'),
            Card(11, 'H'),
            Card(10, 'H'),
            Card(9, 'C')
        ]
        # straight
        H3 = [
            Card(13, 'C'),
            Card(11, 'C'),
            Card(10, 'C'),
            Card(5, 'C'),
            Card(4, 'C')
        ]
        # Flush
        H4 = [
            Card(14, 'D'),
            Card(14, 'C'),
            Card(5, 'H'),
            Card(5, 'C'),
            Card(3, 'D')
        ]
        # two pair

        # Now, create a poker game object (so that we can use its methods) and
        # test that it gives the correct results.
        P = Poker(2)

        self.assertTrue(P.is_straight_flush(H1))
        self.assertFalse(P.is_straight_flush(H2))
        self.assertFalse(P.is_straight_flush(H3))
        self.assertFalse(P.is_straight_flush(H4))
示例#12
0
class Dealer(object):
    '''
    classdocs
    '''
    def __init__(self):
        '''
        Constructor
        '''
        self.poker = Poker()
        self.current_rvier_cards = []

    def sendRandomCard(self):
        total_len = len(self.poker)
        #         print 'total num of cards is', total_len
        id = random.randrange(total_len)
        temp_card = self.poker[id]
        self.poker.removeFromCards(temp_card)
        #         print 'send this card:', temp_card
        return temp_card

    def dropTargetCard(self, card):
        self.poker.removeFromCards(card)
示例#13
0
    def test_non_special(self):
        # First, create a poker game object.
        P = Poker(3)

        # Now, let's create some non-special hands and check that they give
        # the number of points that we expect.
        H1 = [
            Card(14, 'D'),
            Card(13, 'H'),
            Card(11, 'C'),
            Card(10, 'D'),
            Card(2, 'D')
        ]
        # Nothing
        expected_points_H1 = 1 * (15**5) + 14 * (15**4) + 13 * (15**3) + 11 * (
            15**2) + 10 * 15 + 2
        self.assertEqual(P._calculate_hand_points(1, H1), expected_points_H1)

        H2 = [
            Card(13, 'S'),
            Card(12, 'D'),
            Card(11, 'H'),
            Card(10, 'H'),
            Card(9, 'C')
        ]
        # Straight
        expected_points_H2 = 5 * (15**5) + 13 * (15**4) + 12 * (15**3) + 11 * (
            15**2) + 10 * 15 + 9
        self.assertEqual(P._calculate_hand_points(5, H2), expected_points_H2)

        H3 = [
            Card(13, 'C'),
            Card(7, 'C'),
            Card(6, 'C'),
            Card(5, 'C'),
            Card(2, 'C')
        ]
        # Flush
        expected_points_H3 = 6 * (15**5) + 13 * (15**4) + 7 * (15**3) + 6 * (
            15**2) + 5 * 15 + 2
        self.assertEqual(P._calculate_hand_points(6, H3), expected_points_H3)

        H4 = [
            Card(6, 'S'),
            Card(5, 'S'),
            Card(4, 'S'),
            Card(3, 'S'),
            Card(2, 'S')
        ]
        # straight flush
        expected_points_H4 = 9 * (15**5) + 6 * (15**4) + 5 * (15**3) + 4 * (
            15**2) + 3 * 15 + 2
        self.assertEqual(P._calculate_hand_points(9, H4), expected_points_H4)
def main():

    # create a poker game "controller"
    poker = Poker()

    # add a 'view' to the "controller"
    poker_game_interface = PokerGameInterface(poker)

    # connect the poker object and PokerGameInterface for messaging
    poker.add_view(poker_game_interface)

    # Start the poker game simulation
    poker.play()
示例#15
0
 def test_high_card(self):
     assert Poker("Black:2H 3D 5S 9C KD;White:2C 3H 4S 8C AH") == "White wins"
示例#16
0
def main():
    # BFSAgent = BFSPlayer(300)
    # RandomAgent = RandomPlayer(300)
    # GreedyAgent = GreedyPlayer(300)

    # BFS = Poker(BFSAgent,4)
    # Random = Poker(RandomAgent,4)
    # Greedy = Poker(GreedyAgent, 4)

    BFS_Data = []
    Random_Data = []
    Greedy_Data = []

    for i in range(100):
        print(i)
        BFSAgent = BFSPlayer(300)
        RandomAgent = RandomPlayer(300)
        GreedyAgent = GreedyPlayer(300)
        BFS = Poker(BFSAgent, 4)
        Random = Poker(RandomAgent, 4)
        Greedy = Poker(GreedyAgent, 4)

        BFS.play_poker()
        BFS_Data.append(BFS.get_game_info())

        Random.play_poker()
        Random_Data.append(Random.get_game_info())

        Greedy.play_poker()
        Greedy_Data.append(Greedy.get_game_info())

    BFS_DF = pd.DataFrame(BFS_Data)
    BFS_Mean = BFS_DF.mean(axis=0)
    Random_DF = pd.DataFrame(Random_Data)
    Random_Mean = Random_DF.mean(axis=0)
    Greedy_DF = pd.DataFrame(Greedy_Data)
    Greedy_Mean = Greedy_DF.mean(axis=0)

    print("\n       BFS Mean")
    print(BFS_Mean)
    print("\n       Random Mean")
    print(Random_Mean)
    print("\n       Greedy Mean")
    print(Greedy_Mean)

    print("")
    print(BFS_Mean.to_latex())
    print("")
    print(Random_Mean.to_latex())
    print("")
    print(Greedy_Mean.to_latex())
示例#17
0
# -*- coding: utf-8 -*-
# Pokerを動かす為のメインプログラム

from Poker import Poker
from Tactics import tactics

# 初期化
Poker = Poker()

# 初回の手札表示
print(Poker.printhand())

# 繰り返し処理(5回)
c_card = []
for count in range(5):
    print('\n\n{}回目の手札交換を行います.\n"c"を入力してください:'.format(count + 1), end="")
    x = input()

    # 手札交換
    c_card = tactics(Poker.gethand(), count)
    Poker.change_card(c_card)
    print(Poker.printhand())
示例#18
0
from Poker import Poker

game = Poker()
game.NewGame()
示例#19
0
 def test_straight_flush(self):
     assert Poker("Black:5H 6H 7H 8H 9H;White:3D 4D 5D 6D 7D") == "Black wins"
示例#20
0
 def test_four_of_a_kind(self):
     assert Poker("Black:6H 6D 3S 6S 6C;White:8D 8H 8C 8S 3H") == "White wins"
示例#21
0
 def test_full_hose(self):
     assert Poker("Black:2H KD KS 2S KH;White:3D 8H 8C 8S 3H") == "Black wins"
示例#22
0
 def test_flush(self):
     assert Poker("Black:2H 5H 7H 9H QH;White:3H 8H QH KH AH") == "White wins"
示例#23
0
 def test_straight(self):
     assert Poker("Black:2H 3D 4S 5C 6D;White:TD JH QC KS AH") == "White wins"
示例#24
0
 def test_three_of_a_kind(self):
     assert Poker("Black:2H 2D 3S 2C KD;White:2S 4H 4C 4S KH") == "White wins"
示例#25
0
 def test_two_pairs(self):
     assert Poker("Black:2H 2D 4S 4C KD;White:4H 4D 2C 2S KH") == "Tie"
示例#26
0
 def test_pair(self):
     assert Poker("Black:2H 2D 5S 9C KD;White:2C 2S 4S KC 8H") == "Black wins"
示例#27
0
 def __init__(self):
     '''
     Constructor
     '''
     self.poker = Poker()
     self.current_rvier_cards = []
示例#28
0
    def is_two_pair(self, hand):
        single_at_front = hand[1].rank == hand[2].rank and hand[
            3].rank == hand[4].rank and hand[2].rank != hand[3].rank
        single_in_middle = hand[0].rank == hand[1].rank and hand[
            3].rank == hand[4].rank
        single_at_end = hand[0].rank == hand[1].rank and hand[2].rank == hand[
            3].rank and hand[1].rank != hand[2].rank
        return single_at_front or single_in_middle or single_at_end

    def is_one_pair(self, hand):
        for i in range(len(hand) - 1):
            if (hand[i].rank == hand[i + 1].rank):
                return True
        return False

    def is_high_card(self, hand):
        return True


from Poker import Poker
if __name__ == '__main__':

    num_players = int(input("Enter number of players: "))
    while num_players < 2 or num_players > 6:
        num_players = int(input("Enter number of players: "))
    # create the Poker object
    game = Poker(num_players)
    # play the game (poker)
    game.play()
示例#29
0
def main():

    print "\nUnit Testing of the PokerGameInterface Class.....\n"

    print "\n.... This is where most of the Poker Game Interface logic will be located for the Poker Game presentation...\n"

    from PokerGameInterface import PokerGameInterface
    from Player import Player
    from Deck import Deck
    '''
    Scenario 1:
    Test PokerGameInterface class with Player without any HAND object
    
    Execute all of the methods in the PokerGameInterface class to insure 
    that we have no errors.
    '''
    # create a poker game "controller"
    game = Poker()

    # add a 'view' to the "controller"
    game_view = PokerGameInterface(game)

    print "\nNow Going Thru Scenario 1\n"
    '''
    Add  player Joe without a HAND to the PokerGame
    '''
    player_joe = Player("joe")
    print "\n...Adding Player Joe hand to the poker game via 'game.add_player() method .....\n"
    game.add_player(player_joe)

    print "The number of cards in the deck of cards:\t{}".format(
        game.get_deck().get_deck_size())

    game.add_view(game_view)

    game_view.display_welcome()

    game_view.display_new_game()

    game_view.display_players_five_card_stud_hand_table_summary()

    game_view.display_winnings(450)

    game_view.display_bank_roll()

    result = 1000
    game_view.display_action_result(result)

    deposit_amount = game_view.get_deposit()

    print "Players Deposit Amount:\t{}\n".format(deposit_amount)

    bet_amount = game_view.get_bet()

    print "Players Bet Amount:\t{}\n".format(bet_amount)

    index = 0
    action = game_view.get_action(index)

    print "Players Action 'Keep' or 'Discard':\t{}\n".format(action)

    action = game_view.get_end_of_game_action()

    print "Players Action 'continue', 'deposit', or 'quit':\t{}\n".format(
        action)

    #sys.exit(2)
    '''
    Scenario 2:
    Test PokerGameInterface class with Player with HAND object or a valid
    set of 5 cards.
    
    Re-execute all of the methods in the PokerGameInterface class to insure 
    that we have no errors.
    
    This scenario will mimic a one poker hand being played.  This is done to 
    flush out the bugs and make sure the application is properly working as 
    intended.
    '''
    print "\nNow Going Thru Scenario 2\n"
    bob = Player("bob")
    print "Players name:\t{}\n".format(bob.get_name())

    #deck = Deck()
    #deck.shuffle()

    print "The number of cards in the deck of cards:\t{}".format(
        game.get_deck().get_deck_size())

    #sys.exit(2)
    '''
    Add a player to the PokerGame
    '''
    print "\n...Adding Bob hand to the poker game via 'game.add_player() method .....\n"
    game.add_player(bob)

    game_view.display_welcome()

    # Ask the player to add funds
    deposit_amount = game_view.get_deposit()
    game.get_player().add_funds(deposit_amount)

    game_view.display_new_game()
    game_view.display_bank_roll()

    bet_amount = game_view.get_bet()

    for i in range(0, 5):
        game.get_player().add_card(game.get_deck().draw_card())
    '''
    List Comprehension
    The above command is coded up in the Pythonic way listed below.
    '''
    #[game.get_player().add_card(game.get_deck().draw_card()) for i in range(0, 5)]

    game_view.display_players_five_card_stud_hand_table_summary()

    print "The number of cards in the deck of cards:\t{}".format(
        game.get_deck().get_deck_size())

    # Card Position Keep/Delete Card Management
    game.player_card_keep_delete_position_management()

    game_view.display_players_five_card_stud_hand_table_summary()

    print "The number of cards in the deck of cards:\t{}".format(
        game.get_deck().get_deck_size())

    print "\nCONVERTED HAND LIST IS {}".format(
        game.get_poker_hand_utility().get_converted_current_hand_list())
    print "CONVERTED HAND STRING IS {}\n".format(
        game.get_poker_hand_utility().get_converted_current_hand_string())

    cards = game.get_poker_hand_utility().get_converted_current_hand_string()

    cmd = game.evaluate_hand(bet_amount)

    print("%-18r %-15s %r" %
          (cards, cmd.getCommandName(), cmd.getTieBreaker()))

    print "\nPAYOUT is {}".format(cmd.calculate_payout())
示例#30
0
 def test_two_kind(self):
     assert Poker("Black:2H 4S 4C 2D 4H;White:2S 8S AS QS 3S") == "Black wins"