def calc_hard_strategy(decks): shoe = Shoe(decks) rows = 10 cols = 10 bs_hard = [ [0] * cols for _ in range(rows)] #Hard table for row in range(0, rows): for col in range(0, cols): d_rank = Rank(col+1) if d_rank == 10: d_rank = Rank.Ace # player values 8 - 11 if row < 4: p1 = Card(Rank.Six, Suit.Spade) p2 = Card(Rank(row+1), Suit.Spade) # Player values 12 - 18 elif row >= 4: p1 = Card(Rank.Ten, Suit.Spade) p2 = Card(Rank(row-3), Suit.Spade) upcard = Card(d_rank, Suit.Spade) p_hand = Hand([p1,p2]) game = Game(p_hand, upcard, shoe) optimal = optimal_action(game) bs_hard[row][col] = optimal shoe.reset_shoe() print(DataFrame(bs_hard))
def informal_hand_test(): from shoe import Shoe s = Shoe() h = Hand(10) h.isVerbose = True print(h) c = s.draw() c.flip() print(c) if h.can_hit(): h.hit(c) print(h) c = s.draw() c.flip() print(c) if h.can_hit(): h.hit(c) print(h) print('Can double:', h.can_double()) print('Can hit:', h.can_hit()) print('Can split:', h.can_split()) c = s.draw() c.flip() h.double_down(c, h.bet) print(h) #should be busted now try: c = s.draw() c.flip() h.hit(c) except RuleError as error: print(error) print("tried and failed to hit a busted hand.")
def calc_split_strategy(decks): # Split Table shoe = Shoe(8) rows = 9 cols = 10 bs_split = [ [0] * cols for _ in range(rows)] for row in range(0, rows): for col in range(0, cols): assert(shoe.cards_in_shoe == 52*shoe.DECKS) d_rank = Rank(col+1) p_rank = Rank(row+1) if d_rank == 10: d_rank = Rank.Ace if p_rank == 10: p_rank = Rank.Ace p1 = Card(p_rank, Suit.Spade) p2 = Card(p_rank, Suit.Spade) p_hand = Hand([p1,p2]) upcard = Card(d_rank, Suit.Spade) game = Game(p_hand, upcard, shoe) optimal = optimal_action(game) shoe.reset_shoe() bs_split[row][col] = optimal print(DataFrame(bs_split))
def run_sims(num_hands, params, num_decks=1, print_results=True, file=None): dealer_hits_on_soft_17 = params['Dealer Hits on Soft 17'] double_after_split = params['Double Allowed After Split'] surrender_allowed = params['Surrender Allowed'] double_allowed = params['Double Allowed'] blackjack_return = params['Blackjack Payout'] total_return = 0 total_wagers = 0 total_squared = 0 shoe = Shoe(num_decks) for i in range(num_hands): player_hand = Hand(shoe.get_random_card(), shoe.get_random_card()) dealer_hand = Hand(shoe.get_random_card()) dealer_hand.dealer_hit(shoe, replace=True, hit_on_soft_17=False) new_wagers, new_winnings = analyze_hand(player_hand, dealer_hand, 1, shoe, blackjack_return, dealer_hits_on_soft_17, double_after_split, surrender_allowed, double_allowed) total_wagers += new_wagers total_return += new_winnings total_squared += new_winnings * new_winnings if print_results: print_values(total_wagers, total_return, num_hands, total_squared, params, file) return get_values(total_wagers, total_return, num_hands, total_squared)
def __init__(self, name = 'Bob the dealer', money = 1000000, delay = 1, verbose = True): super().__init__(name, money) self._playingPlayers = [] self._playersWithInsurance = [] self._shoe = Shoe() self.delay = delay self.isVerbose = verbose
def __init__(self): self.chairs = [] self.shoe = Shoe(6) self.dealer = Dealer() self.insurance = True self.blackjack_payout = 1.5 self.shoe_size = 6
def __init__(self): self.DECKS = 8 self.shoe = Shoe(8) self.p1 = Player("Complete_Strategy", 10000) self.p2 = Player("Basic_Strategy", 10000) self.dealer = Dealer(self.shoe) self.sims = 0
def test_probability_class(): shoe = Shoe(8) prob = Probability(shoe) hand = Hand([c9, c4]) dealer = Hand([c6]) prob1 = prob.probability_of_hand(hand, 0) exp1 = 0.0059314179796107515 prob2 = prob.probability_of_card(c0) exp2 = 0.07692307692307693 if prob1 == exp1: print("SUCCESS: probability class return correct probability") else: print( f"FAIL: probability return '{prob1}' probability expected '{exp1}'" ) if prob2 == exp2: print("SUCCESS: probability class return correct probability") else: print( f"FAIL: probability return '{prob2}' probability expected '{exp2}'" )
def calc_soft_strategy(decks): shoe = Shoe(decks) rows = 7 # S13 - S19 cols = 10 bs_soft = [ [0] * cols for _ in range(rows)] #Soft Table for row in range(0, rows): for col in range(0, cols): assert(shoe.cards_in_shoe == 52*shoe.DECKS) d_rank = Rank(col+1) # dealer's up card rank if d_rank == 10: d_rank = Rank.Ace upcard = Card(d_rank, Suit.Spade) p1 = Card(Rank.Ace, Suit.Spade) p2 = Card(Rank(row+1), Suit.Spade) p_hand = Hand([p1,p2]) game = Game(p_hand, upcard, shoe) optimal = optimal_action(game) bs_soft[row][col] = optimal shoe.reset_shoe() print(DataFrame(bs_soft))
def __init__(self, name, money): super().__init__(name, money) self.shoe = Shoe() self.players = [] # Holds bets before hands have been dealt # We could make this a dictionary with the player's name as the key, # but that assumes the player names are unique. Better solution would # probably be to set bets on the Player object self.playerBets = []
def main(path): shoe_file = open(path, 'r').readlines() matchers = ['heel', 'toe', 'padded'] matching = [s for s in shoe_file if any(xs in s for xs in matchers)] materials = shoe_file[shoe_file.index('Materials\n') + 1] #Length is static just for the challenge #Can change it to apply to many cases if (len(matching) == 3): shoe = Shoe(matching[0].strip('-'), matching[1].strip('-'), materials.strip('\n')) print(shoe) if (len(matching) == 4): shoe = Shoe(matching[0].strip('-'), matching[2].strip('-'), materials, matching[1].strip('-').strip('\n')) print(shoe)
def __init__(self, agents, print_desc=False): # A typical shoe has 6 decks and reshuffles when roughly 5/6 decks are used. self.shoe = Shoe(6, 0.8) self.dealer = DealerActor() self.agents = [] self.player_count = len(agents) + 1 self.print_desc = print_desc # Add the agents. self.agents = agents
def switch_all_shoes(self): """ When any table calls this method, give a new, identical shoe to each table in the simulation. :return: """ shoe = Shoe() for table in self.tables: if table.has_active_players(): table._dealer.switch_shoe(deepcopy(shoe))
def test_deal(self): shoe = Shoe(1) self.assertEqual(len(shoe._cards), 52) card1 = shoe.draw() card2 = shoe.draw() self.assertEqual(len(shoe._cards), 50) self.assertNotIn(card1, shoe._cards) self.assertNotIn(card2, shoe._cards) shoe.receive([card1, card2]) self.assertEqual(len(shoe._cards), 52)
def main(): shoes = [] shoes.append( Shoe("Yeezreel RF Size 12", "https://stockx.com/adidas-yeezy-boost-350-v2-yeezreel-reflective?size=12", 350)) shoes.append( Shoe("Yeezreel RF Size 13", "https://stockx.com/adidas-yeezy-boost-350-v2-yeezreel-reflective?size=13", 350)) shoes.append(Shoe("Yechiel NRF Size 12.5", "https://stockx.com/adidas-yeezy-boost-350-v2-yecheil?size=12.5", 350)) headers = { 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36', } message = "" for shoe in shoes: res = requests.get(shoe.url, headers=headers) parser = BeautifulSoup(res.text, features="html.parser") shoe.price = parser.find('div', attrs={'class': 'sale-value'}).text # print("Name: {}\tPrice: {}\n".format(shoe.name, shoe.price)) message = message + "Name: {}\tPrice: {}\n".format(shoe.name, shoe.price) # message = message + "SENT ON AWS" return send_sms(message)
def main(): decks_of_cards = 6 shoe = Shoe(decks_of_cards) stats = Stats() running = True while running: try: game = Game(shoe) game.play() stats.games.append(game) except OutOfCardsException: running = False stats.print_game_stats()
def main(DECKS): shoe = Shoe(DECKS) while True: choice = input("n - new hand, q - quit: ").upper() if choice == "Q": break elif choice == "N": p1 = input("Your first card: ").upper() du = input("Dealer up card: ").upper() p2 = input("Your second card: ").upper() h = Hand(p1, p2, du) shoe.remove(p1) shoe.remove(p2) shoe.remove(du) print(h) while True: choice2 = input("h - hit, p - split, s - stand: ").upper() if choice2[0] == "S": break elif choice2[0] == "H": choicesplit = choice2.split(" ") try: handindex = int(choicesplit[2]) except: handindex = 1 h.hit(choicesplit[1], handindex=handindex) shoe.remove(choicesplit[1]) print(h) elif choice2[0] == "P": choicesplit = choice2.split(" ") try: handindex = int(choicesplit[1]) except: handindex = 1 h.split(handindex=handindex) print(h) print(shoe.count)
def dealer_class_test(card, exp): shoe = Shoe(8) prob = Probability(shoe) dealer = Dealer(shoe, prob) dealer.deal_card(card) probs = dealer.dealer_outcome_probs() # make sure probability isn't greated than one if round(sum(probs), 2) != 1.0: print(f"FAIL: dealer outcome probabilites < or > 1 : '{sum(probs)}'") return if exp == probs: print("\tSUCCESS: dealer outcome probabilites as expected") else: print("\tFAIL: dealer outcome probabilites NOT as expected")
def play_round(self): if len(self.shoe.cards) < (self.shoe_size * 13): self.shoe = Shoe(self.shoe_size) for chair in self.chairs: chair.player.count = 0 decks_left = len(self.shoe.cards) / 52 self.dealer.hand = Hand() for chair in self.chairs: chair.hands = [] chair.active = True chair.splits = False hand = Hand() chair.add_hand({ 'hand': hand, 'bet': chair.player.make_bet(decks_left), 'active': True }) self.dealer.deal_round(self) if len(self.dealer.hand.cards) > 0: if self.dealer.hand.is_dealer_blackjack(): for chair in self.chairs: if chair.hands[0]['hand'].is_blackjack(): chair.player.blackjacks += 1 self.dealer.refund_player(chair.hands[0], chair) chair.active = False elif self.dealer.showing() is 11: if self.insurance: for chair in self.chairs: if chair.player.insurance and chair.active: chair.player.pay_insurance() if self.dealer.hand.is_blackjack(): for chair in self.chairs: if chair.player.insurance: if self.insurance: self.dealer.refund_player( chair.hands[0], chair) elif chair.hands[0]['hand'].is_blackjack(): chair.player.blackjacks += 1 self.dealer.refund_player(chair.hands[0], chair) chair.active = False else: self.resolve_chairs() self.dealer.resolve_round(self) else: self.resolve_chairs() self.dealer.resolve_round(self)
def __init__(self, log, bankroll, rules_section="Blackjack"): # Logger self.log = log # Required objects self.rules = BlackjackRules(log, rules_section) self.shoe = Shoe(log, self.rules.get_decks()) self.event_listener = EventListener(log) # Variables self.bankroll = bankroll self.original_bet = 0 self.need_to_shuffle = False self.split_hand_number = 1 self.insurance = 0 # Dealer hand related variables self.dealer_hand = [] self.dealer_bust = False # Player hand related variables self.player_hand = self.new_player_hand() self.split_hands = []
def __init__(self, players, shoe_size=4, debug=False, verbose=False, min_bet=1, max_bet=10, shoe=None): if verbose: # print(chr(27) + "[2J") print("-" * 80) self.verbose = verbose self.debug = debug self.rules = self.Rules(shoe_size=shoe_size, min_bet=min_bet, max_bet=max_bet) self.shoe = Shoe(shoe_size) if shoe != None: self.shoe = shoe self.shoe.shuffle() self.state = [self.PlayerState(Dealer()) ] + [self.PlayerState(p) for p in players] self.done = False
def setUp(self): self.shoe = Shoe(1)
def __init__(self): super().__init__() self._shoe = Shoe(1)
def test_four_of_each_face(self): shoe = Shoe(1) for face in Face: self.assertEqual(len([x for x in shoe._cards if x.face == face]), 4)
# %load main.py from player import Player from shoe import Shoe from utilities import hit, newHand, deal, getReward, getAction, getUpdatedQsa from collections import defaultdict from IPython.display import clear_output #import logging #logging.basicConfig(filename='LearningPolicy.log', filemode='w', level=logging.DEBUG, format='%(asctime)s %(levelname)s:%(message)s', datefmt='%m/%d/%Y %I:%M:%S %p') # Initialize shoe = Shoe(1) dealer = Player() player = Player() Q = defaultdict(float) N = defaultdict(float) RTG = [] # Reward to Go function CR = [] # Cumulative reward function LOSS = [] # Loss function ACTIONS = ( 'HIT', 'STAND', ) epsilon = 10 lr = 0.08 discount = 0.99
from shoe import Shoe shoe_one = Shoe('brown', '7.5', 'sneaker', 110) shoe_two = Shoe('white', '4.5', 'flip-flop', 80) print(shoe_one.color) print(shoe_one.price) shoe_two.change_price(90) print(shoe_two.price) shoe_one.color = 'blue' shoe_one.size = 5.0 shoe_one.price = 78
def set_table_style(self, insurance, blackjack_payout, shoe_size): self.insurance = insurance self.blackjack_payout = blackjack_payout self.shoe_size = shoe_size self.shoe = Shoe(shoe_size)
def __init__(self, num_decks): self.shoe = Shoe(num_decks) self.balance = 0 self.lower_balance = 0 self.playing = True
from shoe import Shoe from card import Card, Rank, Suit decks = 8 shoe = Shoe(decks) c = Card(Rank.Ten, Suit.Spade) print(shoe.draw_probability(c))