import random


def one_run(wr: float, fr: float, ranks: dict, start_rank: int, end_rank: int,
            max_battles: int) -> int:
    """
    Simulate battles required to complete ranked season.

    :param wr: win rate
    :param fr: first place rate
    :param ranks: information on stars in each rank
    :param start_rank: initial rank for the simulation
    :param end_rank: final rank (simulation ends when reaching this rank)
    :param max_battles: maximum battles before simulation ends (prevents infinite loops).
    :return: number of battles
    """
    battles = 0
    stars = 0
    simulated_rank = start_rank

    while simulated_rank != end_rank:
        battles += 1
        if battles > max_battles:
            break

        # Determine battle outcome
        if random.random() < wr:
            stars += 1  # win
        elif random.random() >= fr:  # best player doesn't lose star
            stars -= 1  # loss and no star saved

        # Check if player moved up a rank
        if stars == ranks[simulated_rank]['stars']:
            simulated_rank -= 1  # move "up" a rank
            if ranks[simulated_rank]['free-star']:
                stars = 1  # get a free star for next rank
            else:
                stars = 0  # no free star

        # Check if a player moved down a rank
        if stars < 0:
            if ranks[simulated_rank]['irrevocable']:
                stars = 0
            else:
                simulated_rank += 1  # move "down" a rank
                stars = ranks[simulated_rank]['stars'] - 1  # 1 star away from next rank
    return battles