def __init__(self, players): self.deck = deck() self.board = [] if len(players) < 2 or len(players) > 10: raise Exception('Invalid number of players. It must be between 2 and 10.') self.players = players
def createDeck( self, file ) : cards = [] newdeck = deck(cards) # Read the lines from the file and create the cards for line in file : card_text = line.split(' ') newcard = self.makeCard(card_text) newdeck.addCard(newcard) return newdeck
def __init__(self, deck): '''creates the hand; takes argument: deck''' self._hand = [] if len(deck)<5: deck=deck() else: for card in range(5): c = deck.deal() self._hand.append(c)
def deal(player, d, c, v=VERBOSE): while True: try: c.append(d.draw()) player.append(c[-1]) break except IndexError: # the deck is empty.... # deal from a new deck or something... d = deck() if v>1: sys.stderr.write("\n[WARNING] - NEW DECK CREATED\n") continue return d, c
def initDeck( self ) : create = raw_input('Create new deck? (y or n): ') if create == 'n' : sys.exit(0) deck_name = raw_input('Enter Name of Deck: ') list = [] gamedeck = deck(deck_name, list) # Loop to create cards to add to the deck while True: newcard = raw_input('Create a card? (y or n): ') if newcard == 'n' : break if newcard == 'y' : gamedeck = self.createCard( gamedeck ) # Check to see the user wants to save the deck while True: save = raw_input('Would you like to save this deck (y or n): ') if save == 'n' : break if save == 'y' : self.saveDeck(gamedeck) print 'Save successful!' break
def __init__(self): self.background = pygame.image.load("background.jpg").convert() self.clicker_detector = self.cap_clickDetector() self.deck = deck("card/cards.xml")
return f"{number} of {suit}" def cardname_fromTuple(list, name): """Function to print a card name when only the values are known. Asks for list name and card object name.""" result = cardname_fromIndex(list, list.index(name)) return result def print_deck(self, deck_name): """Function to print a whole deck card by card. Mostly used during development.""" for i in range(len(deck_name)): cardname_fromIndex(deck_name, i) deck = Deck() print(deck(type)) class Suit: """Class used to describe a single suit of a standard 52-card deck""" def __init__(self, suit, suit_cards=13): self.suit = suit self.suit_cards = suit_cards card_suits = {0: "Hearts", 1: "Diamonds", 2: "Clubs", 3: "Spades"} def total_suit(self): return self.suit_cards class Card:
if card.num < 22: break if card.num > 21: return 1 # returns player won if aiTotal == playerTotal: return 2 # returns draw elif aiTotal > playerTotal: return 1 else: return 0 if __name__ == "__main__": command = '' print("Welcome to Blackjack!") deck = deck() deck.shuffle() deck.split(int(input("Enter in a number 0-51 to split the deck: "))) while 1: # infinite game loop print("Your cards:") ownCards = [] dealerCards = [] ownCards.append(deck.take()) ownCards.append(deck.take()) while 1: print(ownCards) print("Enter H for hit, S for stand, of Q for quit:") command = input() print() if command.lower().strip() == 'q':
print(Fore.CYAN + '{} cards: '.format(blackjack_player.get_name())) print_cards(Player1.get_dealt_cards(), True) print(Fore.CYAN + '{} combined card value: {} '.format(blackjack_player.get_name(), Player1.get_cards_total_value(True))) print_separation_line() def print_dealer_cards_info(blackjack_dealer, inc_last_card = True): print(Fore.MAGENTA + "{}'s cards: ".format(blackjack_dealer.get_name())) print_cards(Dealer.get_dealt_cards(), inc_last_card) print(Fore.MAGENTA + '{} combined card value: {}'.format(blackjack_dealer.get_name(), Dealer.get_cards_total_value(inc_last_card))) print_separation_line() if __name__ == '__main__': colorama.__init__(autoreset= True) a_deck_of_cards = deck() a_deck_of_cards.shuffle() Player1 = player('Your') Dealer = dealer(a_deck_of_cards, 'Dealer') intro_prompt() while a_deck_of_cards.is_deck_near_empty() == False: picked_cards = Dealer.deal_cards(4) # Pulls cards from the dealt cards above and # assigns them to the appropriate player/dealer variables Player1.give_dealt_card(picked_cards[0]) Dealer.give_dealt_card(picked_cards[1]) Player1.give_dealt_card(picked_cards[2]) Dealer.give_dealt_card(picked_cards[3])
def __init__(self): self.clicker_detector = self.cap_clickDetector() self.deck = deck("card/cards.xml")
from card import card import deck def deal(dealerHand, playerHand): for i in range(1,5): if i%2=1: playerHand.append(deck[i-1]) else: dealerHand.append(deck[i-1]) for i in range(0,4): del deck(4-i) def checkScore(dealerHand,playerHand) playerScore=0 dealerScore=0 for i in range(1,3): if i%2==1: for card in dealerHand: dealerScore+=card.val else: for card in playerHand: playerScore+=card.val if __name__ == "__main__": playerHand= [] dealerHand= [] deal(playerHand,dealerHand) checkScore(playerHand,dealerHand)
from computerplayer import * from pokerdecisions import * plName = raw_input("Please enter your name:") numAI = input("Please enter the number of computer players:") while True: #Creating each round because this is proof of concept #would do something else for final project. gamepl = player(plName) aiPlayers = [] for i in range(int(numAI)): aiPlayers.append(computerPlayer()) ourDeck = deck() ourDeck.shuffle() for i in range(5): gamepl.addCard(ourDeck.deal()) for i in aiPlayers: i.addCard(ourDeck.deal()) gamepl.sortHand() for i in aiPlayers: i.sortHand() check = True while check: if len(gamepl.hand) == 0:
def runTable(players, hands = NUM_HANDS, dealer=DEALER, v=VERBOSE): __players__ = players d = deck() c = [] # Outermost game loop for j in range(hands): players=list(__players__) d,c = deal(dealer, d, c) d,c = deal(dealer, d, c) c[-1].hidden = True for jj in [0,1]: # do this twice.. for i in players: # for each player: if i.hasDough and (jj == 0): # if this is the first pass i.dChips(-10) # charge 'em money i.stake = 10 if i.hasDough: # if he's got the money d, c = deal(i, d, c) # deal him in else: i.stand = True # gtfo broke isFirstMove = True # now let them play.... while (False in map(lambda x: x.stand, players)): # while SOMEONE is still up, for player in players: if not player.stand: d,c = doShit(player, d, c, isFirstMove) isFirstMove = False while not dealer.stand: d,c = doShit(dealer, d, c, False) if v>0: print "\n\n[+/-] Bot's Name Score Chips Hand" try: print "[DEALER] "+20*"-"+"> ",dealer.__score__() except Exception: print 0 for p in __players__: p.hands += 1 if p.__score__() > dealer.__score__(): if v>0: print "[+]"+" "*4, p.chips += (2*p.stake) else: if v>0: print "[-]"+" "*4, if v>0: l=len(p.nicename()) print p.nicename()," "*2, p.__score__(), " "*(8-len(str(p.__score__()))), p.chips, print " "*(12-len(str(p.__score__())+str(p.chips))), for a in range(len(p.hand)): print p.hand[a].letter(), if v>0: print "" p.hand = [] p.stake = 0 p.stand = False dealer.hand = [] dealer.stand = False for l in c: l.hidden = False # unhide the dealer's old cards if v>0: print "\n\n Scores:" for player in __players__: if player != dealer: if v>0: print player.nicename(), player.chips player.rounds += 1 player.__reset__() if v>0: print "\n"