当前位置: 首页>>代码示例>>Python>>正文


Python Deck.cardNumber方法代码示例

本文整理汇总了Python中Deck.Deck.cardNumber方法的典型用法代码示例。如果您正苦于以下问题:Python Deck.cardNumber方法的具体用法?Python Deck.cardNumber怎么用?Python Deck.cardNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Deck.Deck的用法示例。


在下文中一共展示了Deck.cardNumber方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import cardNumber [as 别名]
class BlackJack:
	
	# TODO constructors with list of players and deck as parameter
	def __init__(self, players, strategyList=None, deckNumbers=6, lang="French", sleep=0, nRounds=1000
				, logFile="logDF.csv", customCardNumbers=None, negativeCount=[], positiveCount=[]):
		self.deck = Deck(deckNumbers, lang, customCardNumbers=customCardNumbers)
		self.players = players
		self.strategyList = strategyList
		
		if strategyList is None:
			strategyList = []*len(self.players)
			for i in range(len(self.players)):
				strategyList[i] = Strategy("player", negativeCount=negativeCount, positiveCount=negativeCount)
		
		self.sleep = sleep
		self.deckNumbers = deckNumbers
		self.lang = lang
		self.verbose = False
		self.nRounds = nRounds
		self.currentRoundNumber = 0
		self.pbar = ProgressBar(maxval=nRounds+1).start()
		self.cardCountInt = 0
		self.cardCountCorrected = 0.
		self.logFile = logFile
		self.customCardNumbers = customCardNumbers
		self.negativeCount = negativeCount
		self.positiveCount = positiveCount
		
		
		columnsLog = ['dealerCardNumber','dealerCardName']
		
		for i, player in enumerate(self.players):
			playerNumber = str(i+1)
			columnsLog.extend(['money_player'+playerNumber,'bet_player'+playerNumber,'cards_player'+playerNumber,
								'cardsNumber_player'+playerNumber,'actions_player'+playerNumber,'score_player'+playerNumber])
								
		columnsLog.extend(['dealerCards','dealerCardsNames','dealerScore','nCardsInDeck','cardCount','cardCountCorrected'])
		
		self.logDF = pd.DataFrame(columns=columnsLog)
		
		for i in range(len(self.players)):
			if self.strategyList[i].name == "player":
				self.verbose = True
				continue
			
		if not self.verbose:
			print "Starting",nRounds,"Black Jack simulations..."
	
	def setDeck(self, newDeck):
		self.deck = newDeck
	
	def sumCards(self, listCards, ace1=False, ace11=False):
		""" returns sum of the cards, counted following the blackjack rules """
		returnSum = 0
		
		for i in range(len(listCards)):
			cardNumber = self.deck.cardNumber(listCards[i])
			if(cardNumber >= 1 and cardNumber <= 9):
				returnSum += cardNumber+1
			elif(cardNumber >= 10 and cardNumber <= 12):
				returnSum += 10
			elif(cardNumber == 0): # Ace counting
				if(ace1):
					returnSum += 1
				elif(ace11):
					returnSum += 11
				else:
					if(BlackJack.isBetterSum(self, BlackJack.sumCards(self, listCards, True, False), BlackJack.sumCards(self, listCards, False, True))):
						returnSum +=1
					else:
						returnSum += 11
			else:
				print "Unknown card"
				return 0
		
		return returnSum
		
	def isBetterSum(self, s1, s2):
		""" Returns true if s1 beats or ties s2, false if s2 strictly beats s1 """
		if(s2 > 21):
			return True
		else:
			if(s1 > 21):
				return False
			else:
				if(s2 > s1):
					return False
				else:
					return True
		
		return True
		
	def displayPlayerCards(self, playerCards, n=-1):
		returnString = ""
		if(n >= len(self.players) or n < 0):
			for i in range(len(self.players)):
				returnString += self.players[i].getName() + " Cards (Total points {}) :".format(BlackJack.sumCards(self, playerCards[i]))
				returnString += "\n" + self.deck.displayCard(playerCards[i])
		else:
			returnString += self.players[n].getName() + " Cards (Total points {}) :\n".format(BlackJack.sumCards(self, playerCards[n]))
#.........这里部分代码省略.........
开发者ID:haroine,项目名称:BlackJack,代码行数:103,代码来源:BlackJack.py


注:本文中的Deck.Deck.cardNumber方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。