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


Python Deck.draw方法代码示例

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


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

示例1: test

# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import draw [as 别名]
def test():
    """ Simple test program for card dragging. """

    from Deck import Deck

    pygame.init()
    screen = pygame.display.set_mode((640, 480))

    deck = Deck()
    handler = CardDraggingEventHandler(deck)

    while True:
        pygame.time.wait(30)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    sys.exit()
            else:
                handler.handle_card_dragging(event)

        screen.fill((0x00, 0xb0, 0x00))

        deck.draw(screen)

        pygame.display.flip()
开发者ID:enoki,项目名称:pitta-pitta-patta,代码行数:30,代码来源:CardDraggingEventHandler.py

示例2: __init__

# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import draw [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

示例3: test_draw

# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import draw [as 别名]
 def test_draw(self):
     for x in xrange(1, 10):
         d = Deck(x)
         for y in xrange(1, 10):
             d.draw()
             self.assertEqual(d.getSize(), (54 * x) - y)
开发者ID:esmonges,项目名称:FindingFriends,代码行数:8,代码来源:Deck_Test.py

示例4: run

# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import draw [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

示例5: __init__

# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import draw [as 别名]
class Solitaire:

    # __init__ : void
    # Initializes all member variables and sets the game board
    def __init__(self):
        self.deck = Deck() # grab a shuffled deck of cards
        self.columns = [["ZZ"], ["ZZ"], ["ZZ"], ["ZZ"], 
                ["ZZ"], ["ZZ"], ["ZZ"]] # empty sentinel
        self.faceup = [1, 1, 1, 1, 1, 1, 1] # beginning configuration
        self.draw = [] # To begin, no cards are face up
        self.stacks = [["ZZ"], ["ZZ"], ["ZZ"], ["ZZ"]] # empty stacks
        self.hint = [] # No hint to start
        self.moves = [] # list of bools telling if the draw holds valid moves
        self.lateral_list = {}
        self.prev = copy.deepcopy(self)
        self.can_undo = False
        self.winnable_is_known = False

        # Deal a new game
        for i in range(7):
            for j in range (i + 1):
                self.columns[i].append(self.deck.draw())

    # printboard : void
    # Prints board layout in traditional Klondike style
    def printboard(self):
        # Top row: Draw cards and accumulation piles
        sys.stdout.write("\n")
        print "          DC   A1 A2 A3 A4"
        print "          \/"
        if len(self.deck.cards) > 0:
            sys.stdout.write('\033[44m' + "[.]" + '\033[0m') # cards remain
        else:
            sys.stdout.write('\033[44m' + "[ ]" + '\033[0m') # deck is empty
        sys.stdout.write(" ")

        # Print up to three drawn cards
        for i in range(-3, 0):
            if len(self.draw) >= (i * -1): # To print *last three* of the array
                self.print_card(self.draw[i])
            else: 
                sys.stdout.write("  ")
            sys.stdout.write(" ")
        sys.stdout.write("  ")

        # Print accumulation piles
        for stack in self.stacks:
            if len(stack) > 1:
                self.print_card(stack[-1]) # show only the top card
            else:
                sys.stdout.write("__")
            sys.stdout.write(" ")
        sys.stdout.write("\n\n")

        # Number the columns for ease of reference
        sys.stdout.write(" ")
        for num in range(1, 8):
            sys.stdout.write(str(num))
            sys.stdout.write("   ")
        sys.stdout.write("\n\n")

        # Find the largest column of working cards for array bounds
        max_length = max(len(x) for x in self.columns)

        # Print each column of cards one row at a time
        for row in range(1, (max_length + 1)):
            for col in range(7):
                if len(self.columns[col]) > row:
                    # If the card is uncovered, print its identity
                    if (len(self.columns[col]) - (row)) <= self.faceup[col]:
                        self.print_card(self.columns[col][row])
                    else:
                        sys.stdout.write('\033[44m' + "[]" + '\033[0m')

                    sys.stdout.write("  ")
                else:
                    sys.stdout.write("    ")
            sys.stdout.write("     " + str(row)) # number each row
            sys.stdout.write("\n")
        sys.stdout.write("\n")

    # print_card : card -> void
    # Prints card with color depending on suit
    def print_card(self, c):
        if c[1] == "D":
            sys.stdout.write('\033[37;41m' + c + '\033[0m')
        elif c[1] == "H":
            sys.stdout.write('\033[32;41m' + c + '\033[0m')
        elif c[1] == "S":
            sys.stdout.write('\033[36;40m' + c + '\033[0m')
        elif c[1] == "C":
            sys.stdout.write('\033[33;40m' + c + '\033[0m')

    # can_stack_up : card card -> bool
    # Returns whether c1 can be placed on top of c2 in an accumulation pile
    def can_stack_up(self, c1, c2):
        ranks = "A23456789TJQK"
        order = c2[0] + c1[0] # e.g. "28", "JQ", "43"

        if c2[0] == "Z" and c1[0] == "A": 
#.........这里部分代码省略.........
开发者ID:alexvking,项目名称:Pyklon,代码行数:103,代码来源:Solitaire.py

示例6: __init__

# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import draw [as 别名]

#.........这里部分代码省略.........
				player.socket.send(message)
			except:
				self.removePlayer(player)
			
		for key in self.table:
			if ( self.table[key] == None ):
				continue
			try:
				self.table[key].socket.send(message)
			except:
				self.removePlayer(self.table[key])
	#--------------------------------------------------------------------------
	def close(self):
		for socket in self.connections:
			socket.close()
			
		self.server.close()
		
	#--------------------------------------------------------------------------		
	def clearInsurance(self):
		for key in self.table:
			if ( self.table[key] == None ):
				continue
				
			self.table[key].insurance = 0
			
		
	#--------------------------------------------------------------------------
	def deal(self):
		#Clear the table and player's insurance
		self.clearTable()
		self.clearInsurance()
		self.deck.shuffle()
		card = self.deck.draw()
		self.dealerHand.append(card)
		card = self.deck.draw()
		self.dealerHand.append(card)
		
		#Deal out the cards
		for key in self.table:
			if ( self.table[key] == None ):
				continue
			
			#Give player two cards from the deck
			card = self.deck.draw()
			self.table[key].hand1.append(card)
			card = self.deck.draw()
			self.table[key].hand1.append(card)
		
		#Broadcast hand to everyone
		tableHand = self.getTableHands()
		dealMessage = "[deal|" + self.dealerHand[0] + '|shufy|' + \
					   tableHand[0] + '|' + tableHand[1] + '|' + tableHand[2] \
					   +  '|' + tableHand[3] + '|' + tableHand[4] + '|' + \
					   tableHand[5] + ']' 
					   
		dealMessage.rstrip('\r\n')
		self.broadcastMessage(dealMessage)
	
	
	#--------------------------------------------------------------------------
	def getTableHands(self):
		tableHand = []
		
		seat = self.getHandFromSeat('1')
		tableHand.append(seat)
开发者ID:nnguyen939,项目名称:BlackJackGame,代码行数:70,代码来源:server.py


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