from typing import Counter


def compute_state_to_action_distribution(interactions):
    """
    Returns a list (for each player) of counts of each state to action pair
    for a set of interactions. A state to action pair is of the form:

    ((C, D), C)

    Implying that from a state of (C, D) (the first player having played C and
    the second playing D) the player in question then played C.

    The following counter object implies that the player in question was in
    state (C, D) for a total of 12 times, subsequently cooperating 4 times and
    defecting 8 times.

    Counter({((C, D), C): 4, ((C, D), D): 8})

    Parameters
    ----------
    interactions : list of tuples
        A list containing the interactions of the match as shown at the top of
        this file.

    Returns
    ----------
    state_to_C_distributions : List of Counter Object
        List of Counter objects where the keys are the states and actions and
        the values the counts. The
        first/second Counter corresponds to the first/second player.
    """
    if not interactions:
        return None

    distributions = [
        Counter(
            [
                (state, outcome[j])
                for state, outcome in zip(interactions, interactions[1:])
            ]
        )
        for j in range(2)
    ]
    return distributions