def rank_to_util(rank, num_players):
    """
    Helper method to convert a rank into a utility value
    (copied from AIUtils in the Ludii Java code)

    :param rank:
    :param num_players:
    :return:
    """
    if num_players == 1:
        return 2.0 * rank - 1.0
    else:
        return 1.0 - ((rank - 1.0) * (2.0 / (num_players - 1)))