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


Python Deck.create_deck方法代码示例

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


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

示例1: run

# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import create_deck [as 别名]
def run():
	playing = True
	won_round = True
	round = 1
	# Creating bot opponents 
	cpu_players = []
	for i in range(num_players):
		cpu = ComputerPlayer("CPU" + str(i+1), PLAYING_STYLES[0]) #Playing style
		hand = Hand()
		cpu.set_hand(hand)
		cpu_players.append(cpu)
	player = Player("User", is_big_blind = True)
	deck = Deck()
	deck.create_deck()
	hand = Hand()
	table = Table()
	
	#start game loop 
	while (player.can_play() and playing):
		print "Round: %d" % round
		deck.shuffle()
		player.set_hand(hand)
		if PLAY_WITH_BLINDS:
			table.set_player_blinds(player, cpu_players)
			for p in ([player] + cpu_players):
				if p.is_big_blind():
					blind = p.pay_blind(table.get_big_blind_size())
					table.add_bet(blind)
					print "*%s is big blind*" % str(p)
				elif p.is_small_blind():
					blind = p.pay_blind(table.get_small_blind_size())
					table.add_bet(blind)
					print "*%s is small blind*" % str(p)
			print ""
			
		deck.deal(2, player.get_hand())
		for cpu in cpu_players:
			deck.deal(2, cpu.get_hand())
			if (DEBUG_MODE):
				print "%s\'s HAND: %s" % (str(cpu), str(cpu.get_hand()))##### FOR DEBUGGING
		non_folded_cpu = cpu_players[:]
		# Hold'em rules: discard, "burn" 2 cards before the display of the flop
		for i in range(5):
			if i < 2:
				table.burn(deck.draw())
			else:
				table.push(deck.draw())
		turn = 1
		
		#condition to allow bets to continue 
		betting = True
		while turn < 4 and non_folded_cpu != []:
			print "%s:\n%s \n" % ("Flop" if turn ==1 else ("Turn" if turn ==2 else "River"), str(table))
			print "Current Hand: %s" % str(player.get_hand())
			print "Chip amount: %d" % player.get_value()
			current_bet = 0
			
			###START BETTING LOOP#####
			while(betting or not [cpu.is_checked() for cpu in non_folded_cpu]):
				ready_to_exit = True #boolean to control wheter we leave bet loop
				user_input = parse_input("Bet, Check, or Fold? (Enter B/C/F):")
				if user_input == "B":
					current_bet = player.bet()
					table.add_bet(current_bet)
				#ADD SO I CAN CHECK IF THE BET IS HIGHER THAN MY LAST
				elif user_input == "C":
					pass
				elif user_input == "F":
					betting = False
					won_round = False
				#for loop to decide cpu action
				for cpu in non_folded_cpu:
					print "%s is deciding..." % str(cpu)
					sleep(1)
					cpu_bet = cpu.bet(current_bet)
					if cpu_bet == -1:
						print "%s folds." % str(cpu)
						non_folded_cpu.remove(cpu)
					elif cpu.is_checked() and current_bet == 0:
						print "%s checks." % str(cpu)
					#there was a raise
					elif cpu_bet > current_bet:
						print "%s raises to %d." % (str(cpu), cpu_bet) 
						table.add_bet(cpu_bet)
						current_bet = cpu_bet
					elif cpu_bet == current_bet:
						print "%s matches the bet." % str(cpu)
						table.add_bet(cpu_bet)
					else:
						raise RuntimeError("Problem Occured, exiting")
						exit(0)
					print "\nCurrent Pot: %d" % table.get_value()
					#end for
					
					if non_folded_cpu == []:
						break
					#####ADD CONDITION TO EXIT OUT OF BETTING LOOP

					for cpu in non_folded_cpu:
						if cpu.get_last_bet() < current_bet:
#.........这里部分代码省略.........
开发者ID:montycheese,项目名称:PythonPoker,代码行数:103,代码来源:Main.py


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