コード例 #1
0
ファイル: Player.py プロジェクト: ExTee/Hearts
    def playCard(self, suit, hBroken):
        '''
		suit = ["None", "Hearts","Spades","Diamonds","Clubs"]
		hBroken = If Hearts was broken
		None indicates this player is first to play
		'''

        if Poker.PokerCard('Clubs', 2) in self.hand:
            #Always play the 2 of clubs first
            return Poker.PokerCard('Clubs', 2)

        elif suit == 'None':
            #if the player is the first to play
            card_played = random.sample((self.hand), 1)[0]

            #Loop to make sure we don't get play a heart without it being broken
            if hBroken == False:
                while (card_played.suit == 'Hearts'
                       and len(self.suits["Hearts"]) < len(self.hand)):
                    card_played = random.sample((self.hand), 1)[0]

        else:
            #randomly play a card from the correct suit
            suit_cards = [card for card in self.hand if card.suit == suit]

            if len(suit_cards) > 0:
                card_played = random.sample(suit_cards, 1)[0]

            else:
                #print('No more {} left!'.format(suit))
                card_played = random.sample((self.hand), 1)[0]

        #print(str(card_played))
        return card_played
コード例 #2
0
    def getPlay(self, player, suit='None'):
        #Obtains the play returned by player

        if isinstance(player, HumanPlayer):
            print("Your turn, Human")
            self.showState(player)

        Legal = False
        attemptedPlay = None

        #Check if the play is a valid play
        while (Legal == False):

            Legal = True

            attemptedPlay = player.playCard(suit=suit,
                                            hBroken=self.HeartsBroken)

            #Check if Hearts broken
            if self.HeartsBroken == False:
                if suit == 'None':
                    if attemptedPlay.suit == 'Hearts':
                        #This checks the case where the player ONLY has hearts in hand
                        if len(player.suits["Hearts"]) < len(player.hand):
                            print("Cancelled hearts")
                            Legal = False

            #Check if player did not start with 2 of clubs
            if Poker.PokerCard('Clubs', 2) in player.hand:
                if attemptedPlay != Poker.PokerCard('Clubs', 2):
                    Legal = False

            #Check if player has the card
            if (attemptedPlay not in player.hand):
                Legal = False

            #If card is not in starting suit, check if player has any cards from starting suit
            if attemptedPlay.suit != suit and suit != 'None':
                if len(player.suits[suit]) != 0:
                    Legal = False

            if not Legal:
                print("Play is Illegal, Please choose another play")

        #At this point, the play is legal, and the game is updated.

        #Remove card from player's hand
        player.hand.discard(attemptedPlay)
        player.suits[attemptedPlay.suit].remove(attemptedPlay)

        #Hearts have been broken if someone plays a heart card
        if attemptedPlay.suit == 'Hearts':
            self.HeartsBroken = True

        #returns the card played for point accumulation
        return attemptedPlay
コード例 #3
0
 def __init__(self, players, gameId):
     self._players = players
     self._id = gameId
     self._poker = Poker()
     self._lenPlayer = len(players)
     self._pairs = []
     self._playersState = [True] * self._lenPlayer
     self._flopState = [False] * self._lenPlayer
     self._chipPool = 0
     self._baseChip = 10
     [player.enterGame(self, index) for index, player in enumerate(players)]
コード例 #4
0
    def __init__(self, dir_name=''):
        self.dir_name = dir_name
        self.players = [1, 2]
        self.poker = poker.Poker()
        self.crt = "cumulative_regret_table.obj"
        self.cst = "cumulative_strategy_table.obj"
        self.sp = "strategy_profile.obj"
        self.inofosset = "info_sets.obj"

        if not path.exists(dir_name):
            self.info_sets = infoSets.InfoSets()
            self.cumulative_regret_table = regretTable.RegretTable()
            self.cumulative_strategy_table = strategyTable.StrategyTable()
            self.strategy_profile = stratgeyProfile.StrategyProfile()
        else:
            file = open(dir_name + '/' + self.crt, 'rb')
            self.cumulative_regret_table = pickle.load(file)
            file.close()

            file = open(dir_name + '/' + self.cst, 'rb')
            self.cumulative_strategy_table = pickle.load(file)
            file.close()

            file = open(dir_name + '/' + self.sp, 'rb')
            self.strategy_profile = pickle.load(file)
            file.close()

            file = open(dir_name + '/' + self.inofosset, 'rb')
            self.info_sets = pickle.load(file)
            file.close()

        self.cfr = cfr.CFR(self.poker, self.cumulative_regret_table,
                           self.cumulative_strategy_table,
                           self.strategy_profile, self.info_sets)
コード例 #5
0
    def __init__(self, players: list):

        #List of all players (This is needed because deque will be modified)
        self.playerNames = players

        self.Deck = Poker.Deck()
        self.players = collections.deque(players, 4)

        #Leaderboard
        '''self.Leaderboard = {
								playerNames[0]: 0,
								playerNames[1]: 0,
								playerNames[2]: 0,
								playerNames[3]: 0,
								}'''

        #output file
        self.OUTPUT_FILE = open(FILEPATH, 'w')

        #Variable to determine if hearts have been broken
        self.HeartsBroken = False

        #shuffle the deck before play
        #self.Deck.shuffle()
        print("Hearts game starts with {} players".format(len(self.players)))

        #Show who's playing
        for player in self.players:
            print("Player {} : {}".format(
                players.index(player) + 1, player.name))
コード例 #6
0
    def __init__(self):
        self.MaxCount = 4
        self.state = Type.RoomState.wait
        self.threeModeCount = 0
        self.threeModeUsers = [""] * 4
        self.threeModeIndex = [-1] * 4
        self.users = []
        self.trump_type_who_call_fast = [-1] * 7
        self.bridge = Poker.Bridge()
        self.callFirst = -1
        self.nextuser = -1
        self.callLast = -1

        # for observer
        self.callsRaw = [""] * 4
        self.playsRaw = [""] * 4
        self.boutsWinRecord = ""
        self.attackIndex = [-1] * 2
        self.attackWinNumber = 7
        self.attackTeam = ''
        self.attackScore = 0
        self.defenseTeam = ''
        self.defenseScore = 0
        self.flowerCountRecord = [0] * 4
        self.playsPokerHand = [[] for i in range(4)]
コード例 #7
0
ファイル: poker-app.py プロジェクト: Radhika10128/Projects
def wellcomw():
    card = []
    card = ['AH', 'KH', 'QH', 'JH', '10H','9H', '8H', '7H', '6H', '5H', '4H', '3H', '2H',
            'AD', 'KD', 'QD', 'JD', '10D','9D','8D', '7D', '6D', '5D', '4D', '3D', '2D',
            'AS', 'KS', 'QS', 'JS', '10S','9S','8S', '7S', '6S', '5S', '4S', '3S', '2S',
            'AC', 'KC', 'QC', 'JC', '10C','9C', '8C', '7C', '6C', '5C', '4C', '3C', '2C']
    random.shuffle(card)
    play0 = []
    play2 = []
    for i in range(0, 5):
        play0.append(card[i])
    for i in range(5, 10):
        play2.append(card[i])

    res1=Poker.check(play0)
    res2=Poker.check(play2)
    return render_template('home1.html', name=card, res1=res1, res2=res2)
コード例 #8
0
	def __init__(self):
		self.MaxCount = 4 
		self.state = Type.RoomState.wait
		self.threeModeCount = 0
		self.threeModeUsers = [""] * 4
		self.threeModeIndex = [-1] * 4
		self.callFirst = -1
		self.users = [""] * 4
		self.sockets = []
		self.trump_type_who_play_fast = [-1] * 7
                self.trump_type_who_call_fast = [-1] * 7
		self.bridge = Poker.Bridge()
コード例 #9
0
ファイル: PokerTest.py プロジェクト: VerryPie/Poker
 def test_findTwoPairFalse(self):
     card1 = Poker.Card(figure=10, colour=0)
     card2 = Poker.Card(figure=5, colour=1)
     card3 = Poker.Card(figure=3, colour=3)
     card4 = Poker.Card(figure=10, colour=0)
     card5 = Poker.Card(figure=13, colour=1)
     cardList = [card1, card2, card3, card4, card5]
     pointCounter = Poker.pointCounter()
     self.assertFalse(pointCounter.findTwoPair(cardList))
コード例 #10
0
ファイル: PokerTest.py プロジェクト: VerryPie/Poker
 def test_findFullHouse(self):
     card1 = Poker.Card(figure=10, colour=0)
     card2 = Poker.Card(figure=5, colour=1)
     card3 = Poker.Card(figure=5, colour=3)
     card4 = Poker.Card(figure=10, colour=0)
     card5 = Poker.Card(figure=5, colour=1)
     cardList = [card1, card2, card3, card4, card5]
     pointCounter = Poker.pointCounter()
     self.assertTrue(pointCounter.findFullHouse(cardList))
コード例 #11
0
ファイル: PokerTest.py プロジェクト: VerryPie/Poker
 def test_findSameFiguresFalse(self):
     card1 = Poker.Card(figure=10, colour=0)
     card2 = Poker.Card(figure=5, colour=1)
     card3 = Poker.Card(figure=12, colour=3)
     card4 = Poker.Card(figure=2, colour=0)
     card5 = Poker.Card(figure=1, colour=1)
     cardList = [card1, card2, card3, card4, card5]
     pointCounter = Poker.pointCounter()
     self.assertFalse(pointCounter.findSameFigures(cardList, 3))
コード例 #12
0
ファイル: PokerTest.py プロジェクト: VerryPie/Poker
 def test_checkStraightTrue(self):
     card1 = Poker.Card(figure=2, colour=0)
     card2 = Poker.Card(figure=4, colour=4)
     card3 = Poker.Card(figure=5, colour=0)
     card4 = Poker.Card(figure=6, colour=1)
     card5 = Poker.Card(figure=3, colour=0)
     cardList = [card1, card2, card3, card4, card5]
     pointCounter = Poker.pointCounter()
     self.assertTrue(pointCounter.checkStraight(cardList))
コード例 #13
0
ファイル: PokerTest.py プロジェクト: VerryPie/Poker
 def test_checkSameColourFalse(self):
     card1 = Poker.Card(figure=10, colour=0)
     card2 = Poker.Card(figure=5, colour=1)
     card3 = Poker.Card(figure=12, colour=3)
     card4 = Poker.Card(figure=5, colour=0)
     card5 = Poker.Card(figure=5, colour=1)
     cardList = [card1, card2, card3, card4, card5]
     pointCounter = Poker.pointCounter()
     self.assertFalse(pointCounter.checkSameColour(cardList))
コード例 #14
0
ファイル: PokerTest.py プロジェクト: VerryPie/Poker
 def test_HighCardCombination(self):
     card1 = Poker.Card(figure=14, colour=0)
     card2 = Poker.Card(figure=2, colour=1)
     card3 = Poker.Card(figure=11, colour=3)
     card4 = Poker.Card(figure=9, colour=2)
     card5 = Poker.Card(figure=13, colour=1)
     mock_hand = Mock()
     mock_hand.cards = [card1, card2]
     tableCard = [card3, card4, card5]
     pointCounter = Poker.pointCounter()
     best, bestResultList = pointCounter.countBestResult(
         hand=mock_hand, tableCards=tableCard)
     self.assertEqual(best, Poker.GetResultName('High card'))
コード例 #15
0
ファイル: PokerTest.py プロジェクト: VerryPie/Poker
 def test_FlushCombination(self):
     card1 = Poker.Card(figure=7, colour=0)
     card2 = Poker.Card(figure=10, colour=1)
     card3 = Poker.Card(figure=12, colour=1)
     card4 = Poker.Card(figure=5, colour=1)
     card5 = Poker.Card(figure=13, colour=1)
     mock_hand = Mock()
     mock_hand.cards = [card1, card2]
     tableCard = [card3, card4, card5]
     pointCounter = Poker.pointCounter()
     best, bestResultList = pointCounter.countBestResult(
         hand=mock_hand, tableCards=tableCard)
     self.assertEqual(best, Poker.GetResultName('Flush'))
コード例 #16
0
ファイル: Player.py プロジェクト: ExTee/Hearts
    def playCard(self, suit):
        '''
		suit = ["None", "Hearts","Spades","Diamonds","Clubs"]
		None indicates this player is first to play
		'''

        #uses arbitrary nature of set to pop an random element
        #edit this for playing agent

        if Poker.PokerCard('Clubs', 2) in self.hand:
            #Always play the 2 of clubs first
            card_played = Poker.PokerCard('Clubs', 2)
            self.hand.discard(card_played)
            self.suits[card_played.suit].remove(card_played)

        elif suit == 'None':
            #if the player is the first to play
            card_played = self.hand.pop()
            self.suits[card_played.suit].remove(card_played)
        else:
            #randomly play a card from the correct suit
            suit_cards = [card for card in self.hand if card.suit == suit]
            #print("{} : {}".format(self.name, list(map(lambda x : str(x) , suit_cards))))

            if len(suit_cards) > 0:
                card_played = random.choice(suit_cards)
                self.hand.remove(card_played)
                self.suits[card_played.suit].remove(card_played)

            else:
                #print('No more {} left!'.format(suit))
                card_played = self.hand.pop()
                self.suits[card_played.suit].remove(card_played)

        #print(str(card_played))
        return card_played
コード例 #17
0
ファイル: PokerTest.py プロジェクト: VerryPie/Poker
 def test_generateCombinationFromTableLength(self):
     card1 = Poker.Card(figure=2, colour=0)
     card2 = Poker.Card(figure=3, colour=1)
     card3 = Poker.Card(figure=4, colour=3)
     card4 = Poker.Card(figure=5, colour=3)
     card5 = Poker.Card(figure=6, colour=1)
     card6 = Poker.Card(figure=7, colour=2)
     card7 = Poker.Card(figure=12, colour=1)
     mock_hand = Mock()
     mock_hand.cards = [card1, card2]
     tableCards = [card3, card4, card5, card6, card7]
     pointCounter = Poker.pointCounter()
     self.assertEqual(
         10,
         len(
             pointCounter.generateCombinationFromTable(
                 hand=mock_hand, tableCards=tableCards)))
コード例 #18
0
ファイル: Player.py プロジェクト: ExTee/Hearts
    def playCard(self, suit, hBroken):

        mySuit = ''
        myNumber = None

        while (mySuit not in ['Hearts', 'Spades', 'Clubs', 'Diamonds']
               or myNumber not in range(2, 15)):

            mySuit = input("Which card would you like to play? Enter suit. \n")
            myNumber = int(input("Enter number [2 - 14]. \n"))

        #Decide which card to send to the server
        card_played = Poker.PokerCard(mySuit, myNumber)

        #send to server
        print("Card Sent")
        return card_played
コード例 #19
0
ファイル: PokerTest.py プロジェクト: VerryPie/Poker
 def test_sits_full_error(self):
     t = Poker.Table()
     p1 = Poker.Player("A")
     p2 = Poker.Player("B")
     p3 = Poker.Player("C")
     p4 = Poker.Player("D")
     p5 = Poker.Player("ERROR")
     t.take_sit(p1)
     t.take_sit(p2)
     t.take_sit(p3)
     t.take_sit(p4)
     with self.assertRaises(Exception):
         t.take_sit(p5)
コード例 #20
0
    def playMatch(self, matchNumber):
        '''
		Shuffle the deck before each match
		Deal the cards to players
		Show players' cards
		'''
        self.Deck.shuffle()
        self.dealDeck()
        self.printPlayerCards()
        self.HeartsBroken = False

        #Passing Phase
        t = matchNumber % 4
        '''
		if t == 0:
			#Pass left
		elif t == 1:
			#pass right
		elif t == 2:
			#pass across
		else:
			#no pass
		'''

        #First Trick is played by the 2 of clubs
        #print(self.Deck.cards.index(Poker.PokerCard('Clubs',2)))
        starting_player = self.players[int(
            self.Deck.cards.index(Poker.PokerCard('Clubs', 2)) / 13)]

        winner = starting_player

        for trick in range(1, 14):

            print(bcolors.HEADER + '\nTrick number {}'.format(trick) +
                  bcolors.ENDC)
            self.OUTPUT_FILE.write('Trick number {}'.format(trick))

            winner = self.playTrick(winner)

        print("\nScores : \n\tA: {}\n\tB: {}\n\tC: {}\n\tD: {}".format(
            self.playerNames[0].points, self.playerNames[1].points,
            self.playerNames[2].points, self.playerNames[3].points))
コード例 #21
0
ファイル: poker-app.py プロジェクト: Prince-Mittal/Poker_Game
def welcome():
    cards = [
        'AH', 'KH', 'QH', 'JH', '10H', '9H', '8H', '7H', '6H', '5H', '4H',
        '3H', '2H', 'AD', 'KD', 'QD', 'JD', '10D', '9D', '8D', '7D', '6D',
        '5D', '4D', '3D', '2D', 'AS', 'KS', 'QS', 'JS', '10S', '9S', '8S',
        '7S', '6S', '5S', '4S', '3S', '2S', 'AC', 'KC', 'QC', 'JC', '10C',
        '9C', '8C', '7C', '6C', '5C', '4C', '3C', '2C'
    ]
    user1_card = []
    user2_card = []
    random.shuffle(cards)
    for i in range(0, 5):
        user1_card.append(cards[i])
    for i in range(5, 10):
        user2_card.append(cards[i])
    output = Poker.check(user1_card, user2_card)
    return render_template("index.html",
                           cards1=user1_card,
                           cards2=user2_card,
                           winner=output)
コード例 #22
0
ファイル: PokerTest.py プロジェクト: VerryPie/Poker
 def test_card_printer2(self):
     card = Poker.Card(0, 3)
     self.assertEqual('Card colour is SPADES and figure is 3', str(card))
コード例 #23
0
ファイル: PokerTest.py プロジェクト: VerryPie/Poker
 def test_get_colour_name(self):
     card = Poker.Card(2, 11)
     self.assertEqual(
         'DIMONDS',
         card.geColourName(),
     )
コード例 #24
0
        else:
            self.highlight = False


# Run until the user asks to quit
if __name__ == '__main__':
    running = True
    radius = 270
    cards = []
    origin_x = 350
    origin_y = 350

    PLAYERS = 7
    BUY_IN = 1000

    game = Poker(PLAYERS, BUY_IN)
    game.deal()
    game.print_hands()
    game.print_flop()
    game.score_hands()

    flop_paths = []
    for card in game.flop:
        flop_paths.append(card.image_path())

    player_card_paths = []
    for player in game.players:
        hand_paths = []
        for card in player.hand:
            hand_paths.append(card.image_path())
        player_card_paths.append(hand_paths)
コード例 #25
0
ファイル: PokerTest.py プロジェクト: VerryPie/Poker
 def test_get_figure_name(self):
     card = Poker.Card(0, 11)
     self.assertEqual('JACK', card.getFigureName())
コード例 #26
0
from werkzeug.utils import secure_filename
# 画像のダウンロード
from flask import send_from_directory, render_template, jsonify
# 別ファイルのimport
from app.name import module_api
from app.play import module_play
# from app.play import module_play
import Change
import Poker
import json
import Type_Adjust
import Compare
import pandas
# インスタンス
change_class = Change.ChangeHand()
hand_class = Poker.TrumpGame()
module_change = Blueprint('change', __name__)
module_battle = Blueprint('battle', __name__)


@module_change.route("/change", methods=['GET'])
def change():
    # 自分の手札のリスト
    hand_list = []
    hand_list.append(request.args.get('hand0', None))
    hand_list.append(request.args.get('hand1', None))
    hand_list.append(request.args.get('hand2', None))
    hand_list.append(request.args.get('hand3', None))
    hand_list.append(request.args.get('hand4', None))
    # 関数を呼び出せる形にするためのリスト
    hand_dictionary = []
コード例 #27
0
ファイル: Test.py プロジェクト: xiliu/DDZ_1
    if k > 0 and k <= n:
        for i in range(n + 1, n + 1 - k, -1):
            value *= i

        for i in range(k):
            value_d *= (i + 1)
    else:
        print('参数不合法...')

    return int(value / value_d)


if __name__ == '__main__':

    print("------------------初始化牌-------------")
    poker = Poker(54)
    poker.detail()
    print("")
    print("------------------洗牌-------------")
    poker.shuffle()
    poker.detail()
    print("")
    print("------------------发牌-------------")

    players = []
    for i in range(3):
        cards = []
        for j in range(17):
            cards.append(poker.deal())

        player = Player(i + 1, cards)
コード例 #28
0
ファイル: PokerTest.py プロジェクト: VerryPie/Poker
 def test_deck_size(self):
     deck = Poker.Deck()
     hand = Poker.Hand(deck, 2)
     self.assertEqual(len(deck.cardList), 50)
コード例 #29
0
ファイル: CardGames.py プロジェクト: tnohren/Card-Games
def play():
    # Initialize Chips
    # TODO

    # Start New Window
    window = Window()

    # Initialize Database
    database = MainDatabase("app_db.sqlite")

    # Retrieve List of Profiles
    profiles = database.ExecuteSelectQuery(
        database.dynamicTables.SelectProfile())

    # Create User Prompt
    promptChoices = []
    if profiles != []:
        promptChoices = [profile[0] for profile in profiles]
    promptChoices.append('New Profile')

    # Display User Prompt
    profileChoice = window.AddPrompt(["Which profile would you like to use?"],
                                     promptChoices)

    # Create a New Profile
    if profileChoice == 'New Profile':
        profileChoice = window.AddTextInput([
            "Please Input Your New Profile Name",
            "Press the Enter Key When Finished"
        ])

        # Verify Profile Name's Uniqueness
        profiles = database.ExecuteSelectQuery(
            database.dynamicTables.SelectProfile(profileChoice),
            [profileChoice])

        while profiles != []:
            # Continue prompting the user until a unique profile name is chosen
            profileChoice = window.AddTextInput([
                "The Profile Name Chosen Has Already Been Used. Please Input a Different Profile Name.",
                "Press the Enter Key when Finished"
            ])
            profiles = database.ExecuteSelectQuery(
                database.dynamicTables.SelectProfile(profileChoice),
                [profileChoice])

        # Insert New Profile Into Database
        database.ExecuteUpdateDeleteOrInsertQuery(
            database.dynamicTables.saveProfile, [profileChoice])

    # Retrieve List of Available Game Types
    gameTypes = [
        gameType[0] for gameType in database.ExecuteSelectQuery(
            database.constantTables.SelectGameType())
    ]

    # Ask User Which Game They Would Like to Play
    gameType = window.AddPrompt(["Which card game would you like to play?"],
                                gameTypes)
    if gameType == 'Blackjack':
        game = Blackjack(window, database, profileChoice)
    elif gameType == 'Poker':
        game = Poker(window, database, profileChoice)
    else:
        print("Invalid input")

    window.Quit()
    quit()
コード例 #30
0
ファイル: PokerTest.py プロジェクト: VerryPie/Poker
 def test_card_printer(self):
     card = Poker.Card(1, 12)
     self.assertEqual('Card colour is HEARTS and figure is QUEEN',
                      str(card))