Пример #1
0
    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 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
Пример #4
0
    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
Пример #5
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))