当前位置: 首页>>代码示例>>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;未经允许,请勿转载。