In [ ]:
"""Multiplayer Black Example

This program implements an example of a strategy for playing blackjack.
The player randomly chooses between 'hit' and 'stand' when given the
opportunity.
"""
import random
from blackjack import Player, Dealer


def callback(subject, data):
    """Called by game to allow player decisions and inform player of progress.

    Arguments:
    subject - str specifying why the callback is called
    data    - tuple with varying content, dependent upon subject

    This function is called by the game for different events in the game,
    signified by the subject argument:
    'decision'
        The function is called to allow the player to choose
        between 'hit' (True) and 'stand' (False) during the game.
        Content of data tuple:
        - hand: a list of 2-tuples in which each tuple describes a
          playing card (symbol, color).
        - dealer: the single card shown by the dealer.
    'card_seen'
        When the dealer deals a card visibly to all players,
        this function is called to inform the player of the
        card being shown. All cards dealt are, eventually,
        'seen' in this way. It allows for the player to use
        card counting techniques by memorizing cards seen.
        Content of data tuple:
        - player: name of the player the card was dealt to
        - card: 2-tuple describing card (symbol, color)
    'result'
        This callback informs the player of their individual
        result for the round.
        Content of data tuple:
        - result: string describing round result. String is one of
          "win", "loss" or "draw".
    'message':
        The player is informed of game progress with calls
        to this function. Please note the messages received
        in this fashion are meant to inform the programmer
        of the games progress and are not meant to be used
        by the program.
        Content of data tuple:
        - message: string describing an action of state of the game.
    """

    if subject == "decision":
        hand, dealer = data
        # print(
        #     "Make decision using: hand={}, dealer={}".format(
        #         hand, dealer
        #     )
        # )
        return random.choice([True, False])

    elif subject == "card_seen":
        player, card = data
        # print("Card seen: {} for player {}".format(card, player))

    elif subject == "result":
        result = data
        # print("Round result: {}".format(result))

    elif subject == "message":
        message = data
        print(message)


def silent_callback(subject, data):
    """Silenced version of callback for testing multiple players
    
    This version of the callback function only responds to
    'decision' events. Other events (card_seen, result, message) are
    silently ignored.
    """
    if subject == "decision":
        hand, dealer = data
        return random.choice([True, False])


# n speler experiment:
num_rounds = 10
players = []
n = 4
for i in range(1, n + 1):
    players.append(
        Player(
            name="Player {}".format(chr(i + 64)),
            callback=(callback if i == 1 else silent_callback)
        )
    )
dealer = Dealer(players)
for i in range(num_rounds):
    dealer.play_round()
    print()

In [ ]: