def main(): cardset = build_default_cardset() deck = card.Deck(cardset) user_cards = deck.draw(5) user_hand = Hand(user_cards) bot_cards = deck.draw(5) bot_hand = Hand(bot_cards) def colorize_card(card): s = str(card) if card.suit in [Suit.JOKER]: s = Color.blue(s) elif card.suit in [Suit.HEART, Suit.DIAMOND]: s = Color.red(s) return s def format_colored_hand(cards, hand, prefix): return prefix + " " + ", ".join(map(colorize_card, cards)) + \ " ({})".format(hand) print(format_colored_hand(user_cards, user_hand, "Your hand:")) print(format_colored_hand(bot_cards, bot_hand, "Dealer hand:")) if user_hand == bot_hand: print("Draw") elif user_hand > bot_hand: print("You win!") else: print("You lose")
def gamePlay(self): self.deck = card.Deck() self.deck.shuffle() self.hands = self.deck.distribute(self.no_of_players, self.no_of_cards) for hand in self.hands: hand.checkForJokers() self.name = input('Enter your name ? ') self.hands[0].playerName = self.name while True: player = self.hands[self.turn] if self.turn != 0: # For Computer Player player.draw_card() if player.check_for_win(): self.gameOver(player) break player.choose_and_drop_card() self.displayInfo() else: # For Human Player print(self.name) print('Your cards:') self.displayHand(player) print('On Floor:') floorCard = self.deck.get_top_card_on_floor() print(decorate(floorCard)) print('Joker:', colored(card.rankName[self.deck.joker], 'red')) print(message1) inp = input('>>> ') if inp == '1': player.pick_from_floor() else: player.draw_from_deck() if player.check_for_win(): self.gameOver(player) break self.displayHand(player) print(message2) index = self.getIndex() player.drop(player.cards[index - 1]) self.nextTurn()
def __init__(self, player_name='Player'): self.values = dict({str(i): i for i in range(2, 11)}, Ace=1, Jack=10, Queen=10, King=10) self.deck = card.Deck() self.dealer = card.player('Dealer') self.player = card.player(player_name) self.player_wall = 28 self.dealer_wall = 28 self.table_string = '\n|{:>49}|'
def main(): myDeck = card.Deck() myDeck.shuffle() playerNo = int(input('Enter no of player? ')) hands = myDeck.distribute(playerNo, 3) for hand in hands: print(colored(f'\n{hand.playerName}', 'cyan')) line = decorate(hand.getCardList()) print(f'{line} \n') winner = findWinner(hands) showWinner(winner)
def __init__(self, size): self.deck = card.Deck() self.deck.create(size) self.deck.shuffle() self.deck.blackjack() self.playerDeck = [] self.playerDeckBust = False self.playerSplitBust = False self.playerSplit = [] self.playerSplitBool = False self.playerDouble = False self.playerSplitDouble = False self.dealerDeck = [] self.playerTotal = 0 self.playerSplitTotal = 0 self.dealerTotal = 0
def Monte_Carlo(bot, table): """ A implimentation of the Monte Carlo algorithm, this algorithm works by taking a sample size of the different possibilities of what the remaining cards on the table will be and what cards the player has in their hand. It takes 10,000 different samples and calculates if it will win in each scenario and returns how many times it won out of 10,000 Inputs: bot - an object of the bot class, essentially our bot we will be playing against table - an object of the Table class Output: How many times the bot won in 10,000 scenarios Runtime: O(p*xlog(x) + plog(p)) where x=n+m where n is the the number of cards that the player has and m is the number of cards on the table and p is the number of players """ count = 0 for i in range(MONTE_CARLO_ITERATIONS): #O(10,000)=O(1) my_deck = cardsets.Deck() my_deck.remove_card(bot.get_cards()[0]) #O(n) my_deck.remove_card(bot.get_cards()[1]) #O(n) for card in table.get_cards(): my_deck.remove_card(card) listed_deck = my_deck.get_cards() x = sample(listed_deck, 7 - len(table.get_cards())) person = cardsets.Player(0, x[0:2]) players = [person, bot] new_table = cardsets.Table(table.get_cards() + x[2:]) if type(winner( new_table, players, printing=False)) is cardsets.Bot: #O(p*xlog(x) + plog(p)) count += 1 return count
description='BlackJack Neural Network Tester') parser.add_argument('num_runs', type=int, help="number of runs to test the model") args = parser.parse_args() # run parameters num_runs = args.num_runs max_steps = 10 # actions in world: hit, stay; split comes later actionCount = 2 wins = 0 push = 0 deck = card.Deck() for i in range(num_runs): # reset environment deck.reset() deck.shuffle() dealer = [] # Deal cards to dealer and player hand = [] hand.append(deck.draw()) dealer.append(deck.draw()) hand.append(deck.draw()) dealer.append(deck.draw()) #print("Starting hand %s %s" %(hand[0],hand[1]))
def __init__(self): Player.__init__(self, "Dealer") self.chips = 10000 self.deck = card.Deck()
def __init__(self): # initilize the gui gui.Desktop.__init__(self) self.connect(gui.QUIT, self.quit, None) # crate a container in APP self.c = gui.Container(width=800, height=750) # create a Deck deck = card.Deck() # reshuffle 2*3*playerAmount cards playerAmount = 4 playerName_0 = 'Andy' playerName_1 = 'July' playerName_2 = 'Salary' playerName_3 = 'Alan' # ----------------------------------------------- # step1. create a human player # ----------------------------------------------- self.humanPlayer_0 = humanPlayer(playerName_0, self.c) self.EsUsed = 0 self.stacks = stacks = deck.createCardField(playerAmount) # ----------------------------------------------- # create a button to open the drating dialog # ----------------------------------------------- b = gui.Button('Open Drafting Dialog') def ddo(self): self.humanPlayer_0.DecisionMaking_Drafting(self.stacks) # the game manager should monitor the confirm event from drafting dialog b.connect(gui.CLICK, ddo, self) def ddq(self): self.stacks = general.delcard( self.stacks, self.humanPlayer_0.getSelectedStackIndex()) print('draft dialog closed, the latest amount of stacks is ', len(self.stacks)) self.hp0_ddcb = self.humanPlayer_0.getDraftDialogConfirmButton() self.hp0_ddcb.connect(gui.CLICK, ddq, self) self.c.add(b, 300, 500) # ----------------------------------------------- # test the function of open/close playing dialog # ----------------------------------------------- self.openPlayingDialog = True buttonOCPD = gui.Button('Open/Close Playing Window') def ocpd(self): self.openPlayingDialog = not self.openPlayingDialog self.humanPlayer_0.showHidePlayDialog(self.openPlayingDialog) buttonOCPD.connect(gui.CLICK, ocpd, self) self.c.add(buttonOCPD, 50, 500) # ----------------------------------------------- # test to capture the confirmation of playing from human player # ----------------------------------------------- def pdq(self): print('get the confirmation from playing dialog') print(playerName_0, ' played ', self.humanPlayer_0.getSelectedCard().getName(), ' in this turn!') self.hp0_pdcb = self.humanPlayer_0.getPlayDialogConfirmButton() self.hp0_pdcb.connect(gui.CLICK, pdq, self) # ----------------------------------------------- # create a button to test emergency stop card function # ----------------------------------------------- bes = gui.Button('Open Emergency Stop Dialog') def eso(self): self.humanPlayer_0.startEsDialog() bes.connect(gui.CLICK, eso, self) self.c.add(bes, 500, 500) def cesd(self): self.EsUsed = self.humanPlayer_0.getEsUsed() self.humanPlayer_0.getEsDialogConfirmButton().connect( gui.CLICK, cesd, self) self.widget = self.c