__author__ = "miller" __guy_who_looked_over_Jims_shoulder_and_also_wrote_some_cool_stuff__ = "que" ########## THIS MODULE TESTS THE TOTAL RETURN EXPECTED FROM AN INFINITE DECK WHEN CONSIDERING DOUBLING DOWN ############ import infinite_success_test as ist import infinte_deck as id import random import make_tables # Read data from .txt files to be used in calculations hit_table_reg = make_tables.read_table_file("hit strategy.txt") hit_table_soft = make_tables.read_table_file("Soft Hit Strategy.txt") split_table = make_tables.read_table_file("positive is split.txt") double_table_soft = make_tables.read_table_file("soft double if greater than 0.txt") double_table_reg = make_tables.read_table_file("double down if greater than 0.txt") soft_table = hit_table_soft reg_table = hit_table_reg # Plays a hand for the player, considering opportunities to double # ARGS: hand as list; dealer show card as int # RETURN: two copies of player score as list OR calls ist.play_a_hand_player() def play_a_hand_player(hand, dealer_show): [card1, card2] = hand if (card1 == "ace") and (card2 == "ace"): score = 12 soft = True elif card1 == "ace": score = card2 + 11 soft = True
__author__ = 'miller' __guy_who_looked_over_Jims_shoulder_and_also_wrote_some_cool_stuff__ = 'que' #THIS MODULE BASICALLY DOES THE SAME STUFF AS infinte_deck.py BUT USES A FINITE NUMBER OF DECKS THAT GET RESHUFFLED ## ONCE A CERTAIN NUMBER OF CARDS HAVE BEEN DEALT #COMBINES CONCEPTS FROM infinite_test_double_down.py and infinite_success_test.py ######## EVERY FUNCTION WILL BE PREFACED WITH A BASIC DESCRIPTION AS WELL AS THE ARGUMENTS AND THE RETURN VALUE ######## import random import make_tables import infinite_success_test as ist ################################ READ IN DATA TO MAKE APPROPRIATE TABLES TO DO MATH ON ################################# reg_table = make_tables.read_table_file('hit strategy.txt') soft_table = make_tables.read_table_file('Soft Hit Strategy.txt') split_table = make_tables.read_table_file('positive is split.txt') double_table_soft = make_tables.read_table_file('soft double if greater than 0.txt') double_table_reg = make_tables.read_table_file('double down if greater than 0.txt') #################### DUMMY INSTANCES OF THE HIT AND SOFT HIT STRATEGIES, BECAUSE WE NEED MORE THAN ONE OF EACH ######### ######### TYPING IN ALL CAPS MAKES ME FEEL LIKE I'M YELLING BUT I PROMISE I'M PRETTY LEVEL-HEADED AT THE MOMENT ######## hit_table_reg = reg_table hit_table_soft = soft_table #Creates a whole bunch of cards, depending on the number of decks we want to use #ARGS: number of decks we want #RETURN: a really long list of length (number_of_decks * 52) def generate_decks(number_of_decks): numbers = ['ace',2,3,4,5,6,7,8,9,10,10,10,10]
__author__ = 'miller' __guy_who_looked_over_Jims_shoulder_and_also_wrote_some_cool_stuff__ = 'que' ############## THIS MODULE CACLULATES THE TOTAL AND EXPECTED RETURNS WHEN PLAYING WITH AN INFINITE DECK ################ ################################## CONSIDERS OPPORTUNITIES TO SPLIT AND DOUBLE DOWN #################################### import infinte_deck as id import random import make_tables import splitting #read data in from .txt files, to be used as references for calculation hit_table_reg = make_tables.read_table_file('hit strategy.txt') hit_table_soft = make_tables.read_table_file('Soft Hit Strategy.txt') split_table = make_tables.read_table_file('positive is split.txt') soft_table = hit_table_soft reg_table = hit_table_reg #formats score, unpacking a nested list (e.g., the return value if a player doubles on a split hand #ARGS: score as list within a list (listception?) #RETURN: calls self until it finally returns a single list def make_single_list(nested_list): final_list = [] for element in nested_list: if isinstance(element,list): final_list+=element else: final_list.append(element)
__author__ = 'miller' __guy_who_looked_over_Jims_shoulder_and_also_wrote_some_cool_stuff__ = 'que' ############################# THIS MODULE CONSIDERS THE POSSIBILITY OF SPLITTING A HAND ################################ ############################### PLAYS ON AN INFINITE DECK AND WRITES RESULTS TO .TXT FILE ############################## import numpy as np import infinte_deck as id import random import make_tables #read in data from .txt files, to be used as reference in calculation soft_table = make_tables.read_table_file('Soft Hit Strategy.txt') reg_table = make_tables.read_table_file('hit strategy.txt') #plays a hand for a player, considering opportunities to split #ARGS: player_score as int; dealer show card as int, soft as boolean #RETURN: player score as int OR calls self def play_a_hand_player(player_score,dealer_show_card_index,soft=False): player_current_score = player_score row_index = player_current_score - 4 column_index = dealer_show_card_index if player_current_score >= 11: if soft == False: if reg_table[row_index][column_index] == False: return player_current_score else: new_card = id.deck(random.randint(1,13))