old_contents: from random import randint, shuffle
  
  
  class Player:
      def __init__(self, notify):
          self.can_exchange_cards = True
          self.tokens_left = 29
          self.deck = [randint(1, 4) for _ in range(36)]
          self.hand = []
          self.cartouches = []
          self.discard = []
          self.points = 0
          self.notify = notify
  
      def draw_cards(self):
          self.discard.extend(self.hand)
          self.hand = []
  
          while len(self.hand) != 4:
              if self.deck:
                  self.hand.append(self.deck[0])
                  self.deck = self.deck[1:]
              else:
                  self.deck = self.discard
                  self.discard = []
                  shuffle(self.deck)
  
          assert len(self.hand) == 4
          self.notify('hand ' + ' '.join(str(card) for card in self.hand))
  
  
  class AtonCore:
      def __init__(self, notifiers):
          self.finished = False
          self.players = {
              'red': Player(notifiers[0]),
              'blue': Player(notifiers[1]),
          }
  
          for player in self.players.values():
              player.draw_cards()
  
new_contents: from random import randint, shuffle
  
  
  class Player:
      def __init__(self, notifier=None):
          self.can_exchange_cards = True
          self.tokens_left = 29
          self.deck = [randint(1, 4) for _ in range(36)]
          self.hand = []
          self.cartouches = []
          self.discard = []
          self.points = 0
          self.notifier = notifier
  
      def notify(self, message):
          if self.notifier:
              self.notifier(message)
  
      def draw_cards(self):
          self.discard.extend(self.hand)
          self.hand = []
  
          while len(self.hand) != 4:
              if self.deck:
                  self.hand.append(self.deck[0])
                  self.deck = self.deck[1:]
              else:
                  self.deck = self.discard
                  self.discard = []
                  shuffle(self.deck)
  
          assert len(self.hand) == 4
          self.notify('hand ' + ' '.join(str(card) for card in self.hand))
  
  
  class AtonCore:
      def __init__(self, notifiers):
          self.finished = False
          self.players = {
              'red': Player(notifiers[0]),
              'blue': Player(notifiers[1]),
          }
  
          for player in self.players.values():
              player.draw_cards()
  
subject: Refactor player notifier