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


Python Deck.generate方法代码示例

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


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

示例1: __init__

# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import generate [as 别名]
class Game:
	
	def __init__(self, num_players=1, num_decks=6):
		self.num_decks = num_decks
		self.dealer = Dealer()
		self.bot = Bot('Bot')
		self.players = []
		self.busted = []
		self.stand = []
		self.move = 0
		self.dealer_done = False
		self.bot_moves = []
		for i in xrange(0,num_players):
			self.players.append(Player('Player'+str(i+1)))

		self.players.append(self.bot)
		self.deck = Deck(num_decks)
		self.bot_deck = self.deck.deck * 1
		for player in self.players:
			player.make_bet()
			if player.name == 'Bot':
				player.add(self.bot_deck.pop())
				player.add(self.bot_deck.pop())
				self.bot_deck.pop()
				self.bot_deck.pop()
			else:
				player.add(self.deck.draw())
				player.add(self.deck.draw())
				self.dealer.add(self.deck.draw())
				self.dealer.add(self.deck.draw())

		self.rules = RulesEngine(self.dealer, self.players)

	def ongoing(self):
		return not len(self.players) == 0 or not self.dealer_done

	def winner(self):
		self.stand.sort(key=lambda x: x.val)
		self.stand.reverse()
		winner = self.dealer if self.dealer.val <= 21 else Player("Default")
		for player in self.stand:
			if player.val > winner.val:
				winner = player
		return winner

	def payout(self):
		self.rules.update(self.stand)

	def reset(self):
		self.players = self.rules.players
		self.stand = []
		self.busted = []
		self.dealer_done = False
		self.bot.update(self.players+[self.dealer])
		if len(self.deck.deck) <= self.deck.num_decks*52*0.25: # re-shuffle if < 75% of deck left
			self.deck.deck = self.deck.generate(self.deck.num_decks)
			self.deck.shuffle()
			self.reset_count()

		self.dealer.clear_hand()
		for player in self.players:
			player.clear_hand()
		self.bot_deck = self.deck.deck * 1
		for player in self.players:
			player.make_bet()
			if player.name == 'Bot':
				player.add(self.bot_deck.pop())
				player.add(self.bot_deck.pop())
				self.bot_deck.pop()
				self.bot_deck.pop()
			else:
				player.add(self.deck.draw())
				player.add(self.deck.draw())
				self.dealer.add(self.deck.draw())
				self.dealer.add(self.deck.draw())
		
		self.bot_moves = []

	def move_player(self, player, hand):
		newplayers = []
		
		if self.players[0].name == "Bot":
			move = player.play(self.dealer,hand)
		else:
			move = self.move

		if move == 1:
			player.add(self.deck.draw(),hand)
			if hand == len(player.hands)-1:
				newplayers.append(player)

		elif move == -1:
			if hand == len(player.hands)-1:
				self.busted.append(player)

		elif move == 2:
			player.add(self.deck.draw(),hand)
			player.doubled_down = True
			player.cash -= player.bet
			player.bet *= 2
#.........这里部分代码省略.........
开发者ID:SuperChocomocha,项目名称:Blackjack-Simulator,代码行数:103,代码来源:Game.py


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