from random import randrange


def hit_check(attack_roll:int, armor_class:int)->bool:
    return attack_roll >= armor_class


def calculate_initiative(initative_mod: int) -> int:
    dice_roll = randrange(1, 21)
    return dice_roll + initative_mod

# TODO: formula should be codified as a typesomehow, somewhere

def calculate_hp(hit_point_formula: str) -> int:
    """_summary_

    Args:
        hit_point_formula (str): follows this format:
        2d8+2©

    Returns:
        int: _description_
    """
    hp = 0
    formula_parts = hit_point_formula.split("+")
    con_mod_hp_bonus = int(formula_parts[-1])
    
    num_rolls, dice_size = formula_parts[0].split('d')
    num_rolls = int(num_rolls)
    dice_size = int(dice_size)
    
    for i in range(num_rolls):
        dice_roll = randrange(1, dice_size+1)
        hp += dice_roll
    
    dice_roll += con_mod_hp_bonus
    return dice_roll


# TODO: move to tests
if __name__ == "__main__":
    dice_formula = "2d8 + 2"
    calculated_hp = calculate_hp(dice_formula)
    print(f'calculated_hp: {calculated_hp}')
