<file_sep>import re

from deck import Deck, deck_36_cards
from player import Player

# 36 карт
# ходят по очереди
# не вскрываемся 

class BlackJack:
    _deck = deck_36_cards()
    _players: [Player]
    _value_to_points = {
        6: 6,  
        7: 7,  
        8: 8,  
        9: 9,  
        10: 10, 
        'J': 2,
        'Q': 3,
        'K': 4,
        'A': 1,
    }

    def __init__(self):
        self._deck = deck_36_cards()
        self._deck.shuffle()
        self._players = []

    def add_player(self, player):
        self._players.append(player)

    def _count_players_score(self, player: Player):
        points_total = 0
        for card in player.cards:
            value = card.value # 6 - 10, "J" ...
            points = self._value_to_points[value]
            points_total += points
        return points_total

    def _get_yes_or_no(self):
        no_regexp = " *[нН][еЕ]?[тТ]?"
        yes_regexp = " *[дД][аА]?"

        take_card = None
        while take_card is None: 
            answer = input("Берешь карту? <Да/Нет>")
            if re.match(no_regexp, answer):
                take_card = False
            elif re.match(yes_regexp, answer):
                take_card = True
            else:
                print("Неправильный ответ, повторите")
        return take_card

    def play(self):
        # раздаем по 2 карты в начале игры
        for player in self._players:
            player.cards.append(self._deck.pop())
            player.cards.append(self._deck.pop())

        # игроки берут карты
        for player in self._players:
            self._player_turn(player)

        # определяем победителя
        best = 0, []
        for player in self._players:
            player_score = self._count_players_score(player)
            if player_score > 21: 
                player_score = 0
            if player_score == best[0]:
                best[1].append(player)
            elif player_score > best[0]:
                best = player_score, [player]

        print(f"Победители (набрали {best[0]} очков)")
        for winner in best[1]:
            print(player.name)

    def _player_turn(self, player: Player):
        print(f"Привет, {player.name}. Ходи.")
        
        while self._count_players_score(player) < 21:
            print(f"Очков: {self._count_players_score(player)}")
            take_card = self._get_yes_or_no()
            if take_card:
                card_from_deck = self._deck.pop()
                player.cards.append(card_from_deck)
                print(card_from_deck)
            else:
                break

        print(f"Хорошая игра, {player.name}. Ваш счет {self._count_players_score(player)}")

                
                
                


<file_sep>import random

from card import Card, Suits


class Deck:

    def __init__(self):
        self._cards = []

    def add(self, card: Card):
        self._cards.append(card)

    def pop(self): #take card from top
        if len(self._cards) == 0:
            return None
        return self._cards.pop()

    @property
    def size(self):
        return len(self._cards)

    @property
    def empty(self):
        return len(self._cards) == 0

    def shuffle(self): #перетасовать колоду
        for i in range(4):
            random.shuffle(self._cards)

    def __str__(self):
        return f"Колода в которой {self.size} карт"


def deck_36_cards():
    deck = Deck()
    for value in [6,7,8,9,10,'J','Q','K','A']:
        for suit in list(Suits):
            deck.add(Card(value, suit))
    return deck<file_sep>from enum import Enum

Suits = Enum("Suits", "Diamonds Hearts Spades Clubs")

_suit_to_picture = {
    Suits.Diamonds: "♦",
    Suits.Hearts  : "♥",
    Suits.Spades  : "♠",
    Suits.Clubs   : "♣"
}

class Card:

    def __init__(self, value, suit):
        value_ok = (isinstance(value, int) and (6 <= value <= 10) 
                 or isinstance(value, str) and (value in "JQKA"))
        suit_ok = suit in list(Suits)
        if not (value_ok and suit_ok):
            raise TypeError("Карта создана с неправильным значением либо мастью")
        self._value = value
        self._suit = suit

    @property
    def value(self):
        return self._value

    @property
    def suit(self):
        return self._suit

    def __str__(self):
        suit_symbol = _suit_to_picture[self._suit]
        return f"{self._value}{suit_symbol}"
<file_sep>from player import Player
from blackjack import BlackJack

game = BlackJack()
game.add_player(Player("Petya"))
game.add_player(Player("Vova"))

game.play()<file_sep>class Player:
    def __init__(self, nickname):
        self.name = nickname
        self.cards = []
    