Код работал, но результаты были не те, что я хочу получить.
В игре «Блэкджек» должно быть «A» как 1 или 11, но она не работала
By по некоторым причинам, если я 'h' (ударил) по карте, она не позволит мне go вернуться к 's' (стоять)
Если я получил блэкджек, дилер снова открыл карту, даже если дилер сделал это не получить блэкджек.
Могут быть и другие проблемы .... Я понятия не имею: (
Я не знаком с def, поэтому я мог бы попытаться снова изучить def в следующий раз. .
Я очень хочу решить эту проблему ..
import random
card_dict = {'A': 11, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, 'T':10, 'J':10, 'Q':10, 'K':10}
cardcolor = ['S', 'H', 'C', 'D']
def player_draw():
return random.choice(list(card_dict))
def dealer_draw():
return random.choice(list(card_dict))
player_color = random.choice(cardcolor)
dealer_color = random.choice(cardcolor)
player_score = 0
dealer_score = 0
player_cards = []
while True:
player_card = []
player_card.append(player_draw())
player_card.append(player_draw())
print('your cards:',player_card[0]+player_color,player_card[1]+player_color)
player_total = card_dict[player_card[0]]+card_dict[player_card[1]]
dealer_card = []
dealer_card.append(dealer_draw())
dealer_card.append(dealer_draw())
dealer_cards = []
for i in dealer_card:
dealer_cards.append(card_dict[i])
dealer_total = sum(dealer_cards)
stand_hit = input('(S)tand or (H)it?...: ')
if player_total == 21:
if dealer_total != 21:
print('Blackjack!')
player_score += 1
print('Dealer:', dealer_score, 'Player:', player_score)
play_again = input('Play again (Y/N)?...: ')
if play_again == 'y':
print()
elif play_again == 'n':
print('\n')
break
elif dealer_total == 21:
print('It is too bad')
if stand_hit == 's':
print('Dealer cards:', dealer_card[0]+dealer_color, dealer_card[1]+dealer_color)
if dealer_total >= 17:
if dealer_total > player_total:
print('Dealer wins')
dealer_score += 1
print('Dealer:', dealer_score, 'Player:', player_score)
play_again = input('Play again (Y/N)?...: ')
if play_again == 'y':
print()
continue
elif play_again == 'n':
print('\n')
break
elif dealer_total == player_total:
print('Draw')
print('Dealer:', dealer_score, 'Player:', player_score)
play_again = input('Play again (Y/N)?...: ')
if play_again == 'y':
print()
continue
elif play_again == 'n':
print('\n')
break
elif dealer_total < player_total:
print('You win!')
player_score += 1
print('Dealer:', dealer_score, 'Player:', player_score)
play_again = input('Play again (Y/N)?...: ')
if play_again == 'y':
print()
continue
elif play_again == 'n':
print('\n')
break
elif dealer_total < 17:
while dealer_total < 17:
if player_total or dealer_total < 11:
card_dict['A'] = 11
elif player_total or dealer_total > 10:
card_dict['A'] = 1
a = random.choice(list(card_dict))
print('Dealer drew:', a + dealer_color)
dealer_total += card_dict[a]
if dealer_total > 21:
print('You win!')
player_score += 1
print('Dealer:', dealer_score, 'Player:', player_score)
play_again = input('Play again (Y/N)?...: ')
if play_again == 'y':
print()
continue
elif play_again == 'n':
print('\n')
break
elif dealer_total <= 21:
if dealer_total > player_total:
print('Dealer wins')
dealer_score += 1
print('Dealer:', dealer_score, 'Player:', player_score)
play_again = input('Play again (Y/N)?...: ')
if play_again == 'y':
print()
continue
elif play_again == 'n':
print('\n')
break
elif dealer_total == player_total:
print('Draw')
print('Dealer:', dealer_score, 'Player:', player_score)
play_again = input('Play again (Y/N)?...: ')
if play_again == 'y':
print()
continue
elif play_again == 'n':
print('\n')
break
elif dealer_total < player_total:
print('You win!')
player_score += 1
print('Dealer:', dealer_score, 'Player:', player_score)
play_again = input('Play again (Y/N)?...: ')
if play_again == 'y':
print()
continue
elif play_again == 'n':
print('\n')
break
elif stand_hit == 'h':
if player_total or dealer_total < 11:
card_dict['A'] = 11
elif player_total or dealer_total > 10:
card_dict['A'] = 1
a_cards = random.choice(list(card_dict))
print('You drew:', a_cards + player_color)
player_total += card_dict[a_cards]
if player_total > 21:
print('Dealer wins')
dealer_score += 1
print('Dealer:', dealer_score, 'Player:', player_score)
play_again = input('Play again (Y/N)?...: ')
if play_again == 'y':
print()
continue
elif play_again == 'n':
print('\n')
break
elif player_total <= 21:
stand_hit = input('(S)tand or (H)it?...: ')