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 elif card2 == "ace": score = card1 + 11 soft = True else: score = card1 + card2 soft = False row_index = score - 4 if dealer_show == "ace": column_index = 0 else: column_index = dealer_show - 1 if soft == True: double_down_check = double_table_soft[row_index][column_index] double_check = hit_table_soft[row_index][column_index] if double_check == False: double_down_check = False else: double_down_check = double_table_reg[row_index][column_index] double_check = hit_table_reg[row_index][column_index] if double_check == False: double_down_check = False if double_down_check == True: if soft == True: hit_card = id.deck(random.randint(1, 13)) if hit_card == "ace": new_score = score + 1 else: new_score = score + hit_card if new_score > 21: new_score = new_score - 10 return [new_score, new_score] else: hit_card = id.deck(random.randint(1, 13)) if score < 11: if hit_card == "ace": new_score = score + 11 else: new_score = score + hit_card else: if hit_card == "ace": new_score = score + 1 else: new_score = score + hit_card if new_score > 21: new_score = 0 return [new_score, new_score] else: return ist.play_a_hand_player(hand, dealer_show)
def play_a_hand_player(hand,dealer_show): if isinstance(hand,list): (score,soft,split) = make_a_score(hand) if 'ace' in hand: ace = True else: ace = False else: score = hand[0] soft = hand[1] split = False ace = False if dealer_show == 'ace': column_index = 0 else: column_index = dealer_show - 1 if split == True: if ace == False: row_index = int(int(score/2) - int(1)) else: row_index = 9 split_check = split_table[row_index][column_index] else: split_check = False row_index = score-4 if split_check == False: if soft == True: return [splitting.play_a_hand_player(int(score),column_index,soft=True)] else: return [splitting.play_a_hand_player(int(score),column_index,soft=False)] else: split_card = score/2 hand1 = [split_card,id.deck(random.randint(1,13))] hand2 = [split_card,id.deck(random.randint(1,13))] if ('ace' in hand1) and (10 in hand1): score1 = 22 else: score1 = play_a_hand_player(hand1,dealer_show) if ('ace' in hand2) and (10 in hand2): score2 = 22 else: score2 = play_a_hand_player(hand2,dealer_show) return [score1,score2]
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)) if new_card == 'ace': player_new_score = player_current_score + 1 else: player_new_score = player_current_score + new_card if player_new_score > 21: return 0 else: return play_a_hand_player(player_new_score,dealer_show_card_index,soft=False) else: if soft_table[row_index][column_index] == False: return player_current_score else: new_card = id.deck(random.randint(1,13)) if new_card == 'ace': player_new_score = player_current_score + 1 else: player_new_score = player_current_score + new_card if player_new_score <= 21: return play_a_hand_player(player_new_score,dealer_show_card_index,soft=True) else: return play_a_hand_player(player_new_score-10,dealer_show_card_index,soft=False) else: new_card = id.deck(random.randint(1,13)) if new_card == 'ace': player_new_score = player_current_score + 11 return play_a_hand_player(player_new_score,dealer_show_card_index,soft=True) else: player_new_score = player_current_score + new_card return play_a_hand_player(player_new_score,dealer_show_card_index,soft=False)
new_score = score + hit_card if new_score > 21: new_score = 0 return [new_score, new_score] else: return ist.play_a_hand_player(hand, dealer_show) # initialize total return as 0.0 total_return = 0.0 number_of_trials = 10000 # Play number_of_trials trials (that many hands) and print expected return for i in range(number_of_trials): dealer_show_card = id.deck(random.randint(1, 13)) dealer_hand = [dealer_show_card, id.deck(random.randint(1, 13))] player_hand = [id.deck(random.randint(1, 13)), id.deck(random.randint(1, 13))] if ("ace" in dealer_hand) and (10 in dealer_hand): dealer_blackjack = True else: dealer_blackjack = False if ("ace" in player_hand) and (10 in player_hand): player_blackjack = True else: player_blackjack = False if (dealer_blackjack == True) and (player_blackjack == True): total_return += 0.0 elif (dealer_blackjack == True) and (player_blackjack == False): total_return += -1.0
score = card1+card2 soft = False return (score,soft) return_away_no_split = np.zeros((10,13)) l = 0 number_of_trials = 10000 #play number_of_trials hands ber [i][j] index and populate array for card_total in (4,6,8,10,12,14,16,18,20,'ace'): for j in range(13): for x in range(number_of_trials): total_return = 0.0 dealer_hand = [id.deck(j+1),id.deck(random.randint(1,13))] dealer_score = id.play_a_hand_dealer(dealer_hand) if dealer_score == 'bust': dealer_score = 0 if card_total == 'ace': score = 12 issoft = True else: score = card_total issoft = False if (10 in dealer_hand) and ('ace' in dealer_hand): dealer_blackjack = True else: