當前位置: 首頁>>代碼示例>>Python>>正文


Python Deck.dealHand方法代碼示例

本文整理匯總了Python中Deck.dealHand方法的典型用法代碼示例。如果您正苦於以下問題:Python Deck.dealHand方法的具體用法?Python Deck.dealHand怎麽用?Python Deck.dealHand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Deck的用法示例。


在下文中一共展示了Deck.dealHand方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Engine

# 需要導入模塊: import Deck [as 別名]
# 或者: from Deck import dealHand [as 別名]
class Engine(object):
    
    #Creates a dictionary to map each type of hand to a corresponding score
	hand_values = {
	    'Pair' : 1, 'Two Pair' : 2, 'Three of a Kind' : 3,
            'Straight' : 4, 'Flush' : 5, 'Full House' : 6,
            'Four of a Kind' : 7, 'Straight Flush' : 8,
            'Royal Flush' : 9, 'High Card' : 0 }
	
    #Builds the deck and adds each player's hand to a list
	def __init__(self, comp_players):
		

		self.comp_players = comp_players

        #Create a list of Hand objects, one for each player
		self.hands = []

		print "Computer Players: ", self.comp_players
		
        #Build and shuffle the deck
		self.poker_deck = Deck()
		self.poker_deck.shuffle()
		
        #Add the player's Hand to self.hands
		self.hands.append(Hand(self.poker_deck.dealHand()))
		
        #Add one Hand to self.hands for each computer player
		for i in range(comp_players):
			self.hands.append(Hand(self.poker_deck.dealHand()))
	
    #Plays the game by comparing the scores of each player's type of hand
	def play(self):
		    
        #Remove the player's hand from self.hands and determines its score
		player_hand = self.hands.pop(0)
		player_score = Engine.hand_values[player_hand.determineScore()]
		
        #Print out the user's hand and its type
		print "*" * 20
		print "     YOUR HAND     "
		print "*" * 20
		player_hand.__str__()		
		print "*" * 20
		print "HAND: ", player_hand.determineScore()
		print "*" * 20
		
		comp_scores = []
		
        #Add each computer player's score to a list
		for i in range(self.comp_players):
			comp_scores.append(Engine.hand_values[self.hands.pop().determineScore()])
		
        #If any computer player has a better hand, the user loses
        #If the player ties for the best hand, the player ties
        #If the player has the highest scoring hand, the user wins
		canWin = True
		for score in comp_scores:
			if player_score < score:
				return 'You lose!'
			elif player_score == score:
				canWin = False
		
		if canWin:
			return 'You win!'
		else:
			return 'You tied!'
開發者ID:briangillespie,項目名稱:poker,代碼行數:69,代碼來源:Engine.py


注:本文中的Deck.dealHand方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。