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


Python Deck.pop_card方法代码示例

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


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

示例1: __init__

# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import pop_card [as 别名]
class Blackjack:
	def __init__(self,h,n=5,b=1):
		self.Stat = Stats()
		self.number_of_decks = n
		self.house = h
		self.players = []
		self.deck = Deck(self.number_of_decks)
		self.minimum_bet = b
		self.deck.shuffle()

	def throw_all_hands(self):
		for a in self.players:
			a.throw_hand()
			a.clear_bet()
		self.house.throw_hand()

	def add_player(self,p):
		self.players.append(p)

	def remove_player(self,p):
		[a for a in self.players if a.name == p]

	def play(self,silent=False):
		#Check if house is bankrupt
		if (self.house.money <= 0):
			print "House is bankrupt"
			return True

		print "*** Game started ***"
		all_players_lost = self.play_round(silent)
		print "cards left %d" %	(self.deck.cards_left())
		print "*** Game End ***\n"

		return all_players_lost

	def pop_card(self):
		#All cards are used create an new deck of cards
		if self.deck.cards_left() == 0:
			self.deck = Deck(self.number_of_decks)
			self.deck.shuffle()

		return self.deck.pop_card()

	def start_deal(self,silent):
		#Has all player money left
		for a in self.players:
			if a.money <= 0:
				print "%s lost all money" % (a.name)
				self.players.remove(a)

		#Check if all players busted
		if (len(self.players) == 0):
			print "House has won!"
			return True

		#Players gets their first cards
		for a in self.players:
			c = self.pop_card()
			a.place_bet(self.minimum_bet)
			a.take_card(c)
			if not silent:
				print "%s hand %d=[%s]" % (a.name,a.sum_hand(),a.get_hand())

		#House gets it's first card
		c = self.pop_card()
		self.house.take_card(c)
		if not silent:
			print "House hand %d" % (c.value)

		#Let players know what card house got
		for a in self.players:
			a.add_house_card(c)

		#House gets it's second card but is not
		#showed to players.
		c = self.pop_card()
		self.house.take_card(c)

		return False

	def play_round(self,silent):

		all_players_lost = self.start_deal(silent)

		#Now players can decide if they should
		#have more cards or stop
		for a in self.players:
			while a.more_cards():
				c = self.pop_card()
				a.take_card(c)
				if not silent:
					print "%s hand %d=[%s]" % (a.name,a.sum_hand(),a.get_hand())

		#House turn to pick cards
		while self.house.more_cards():
			self.house.take_card( self.pop_card())

		#Track all stats
		self.Stat.collect_data(self.house,self.players)

#.........这里部分代码省略.........
开发者ID:lekanovic,项目名称:BlackJack,代码行数:103,代码来源:blackjack.py


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