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 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 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))
class Sim(): 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 run(self): for x in range(10000): print(f"*** Hand {self.sims+1}***") self.sims += 1 print(self.p1) print(self.p2) self.p1.bet() self.p2.bet() self.deal_cards() while not self.p1.is_done() or not self.p2.is_done(): card = Card(Rank(random.randint(Rank.Ace, Rank.King)), Suit.Spade) action_b = strategy.infinite_basic_action( self.p1.hand, self.dealer) action_c = strategy.infinite_complete_action( self.p2.hand, self.dealer) self.p1.process_action(action_b, card) self.p2.process_action(action_c, card) self.dealer.playout_hand() self.p1.payout(self.dealer.hand) self.p2.payout(self.dealer.hand) self.dealer.reset() self.shoe.reset_shoe( ) # why am I reseting shoe everytime yet still calculating deal probs every hand? print("\n") def deal_cards(self): players_hand = self.random_hand(2) self.p1.add_hand(players_hand) self.p2.add_hand(deepcopy(players_hand)) self.dealer.deal_card( Card(Rank(random.randint(Rank.Ace, Rank.King)), Suit.Spade)) def random_hand(self, size): cards = [] for _ in range(size): card = Card(Rank(random.randint(Rank.Ace, Rank.King)), Suit.Spade) cards.append(card) self.shoe.draw(card) return Hand(cards)