Selection of the best response correspondence of `g` that selects
    the best response action with the smallest index when there are
    ties, where the input and output are flattened action profiles.

    Parameters
    ----------
    x : array_like(float, ndim=1)
        Array of flattened mixed action profile of length equal to n_0 +
        ... + n_N-1, where `out[indptr[i]:indptr[i+1]]` contains player
        i's mixed action.

    g : NormalFormGame

    indptr : array_like(int, ndim=1), optional(default=None)
        Array of index pointers of length N+1, where `indptr[0] = 0` and
        `indptr[i+1] = indptr[i] + n_i`. Created internally if None.

    Returns
    -------
    out : ndarray(float, ndim=1)
        Array of flattened mixed action profile of length equal to n_0 +
        ... + n_N-1, where `out[indptr[i]:indptr[i+1]]` contains player
        i's mixed action representation of his pure best response.

def _best_response_selection(x, g, indptr=None):
    """
    Selection of the best response correspondence of `g` that selects
    the best response action with the smallest index when there are
    ties, where the input and output are flattened action profiles.

    Parameters
    ----------
    x : array_like(float, ndim=1)
        Array of flattened mixed action profile of length equal to n_0 +
        ... + n_N-1, where `out[indptr[i]:indptr[i+1]]` contains player
        i's mixed action.

    g : NormalFormGame

    indptr : array_like(int, ndim=1), optional(default=None)
        Array of index pointers of length N+1, where `indptr[0] = 0` and
        `indptr[i+1] = indptr[i] + n_i`. Created internally if None.

    Returns
    -------
    out : ndarray(float, ndim=1)
        Array of flattened mixed action profile of length equal to n_0 +
        ... + n_N-1, where `out[indptr[i]:indptr[i+1]]` contains player
        i's mixed action representation of his pure best response.

    """
    N = g.N

    if indptr is None:
        indptr = np.empty(N+1, dtype=int)
        indptr[0] = 0
        indptr[1:] = np.cumsum(g.nums_actions)

    out = np.zeros(indptr[-1])

    if N == 2:
        for i in range(N):
            opponent_action = x[indptr[1-i]:indptr[1-i+1]]
            pure_br = g.players[i].best_response(opponent_action)
            out[indptr[i]+pure_br] = 1
    else:
        for i in range(N):
            opponent_actions = tuple(
                x[indptr[(i+j)%N]:indptr[(i+j)%N+1]] for j in range(1, N)
            )
            pure_br = g.players[i].best_response(opponent_actions)
            out[indptr[i]+pure_br] = 1

    return out