#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""HTML checkboxes for monster hit points."""

import argparse
import json
import numpy as np
import random
import sys

def roll(n, d):
    """Roll n d-sided dice."""

    r = 0
    for i in range(n):
        r += random.randint(1, d)
    return r

def parse(hitdice):
    """Parse hit dice string, e.g., 5d8+10."""

    if "+" in hitdice:
        a, m = [x.strip() for x in hitdice.split("+")]
        n, d = [int(x.strip()) for x in a.split("d")]
        modifier = int(m)
    elif "-" in hitdice:
        a, m = [x.strip() for x in hitdice.split("-")]
        n, d = [int(x.strip()) for x in a.split("d")]
        modifier = -int(m)
    else:
        n, d = [int(x.strip()) for x in hitdice.split("d")]
        modifier = 0

    return n, d, modifier

if __name__ == "__main__":
    p = argparse.ArgumentParser(prog="hitpoints.py", description=__doc__)

    p.add_argument("-n", "--number", dest="n", type=int, default=1,
                   help="number of creatures")
    p.add_argument(dest="hitdice", nargs="?", type=str,
                   help="hitdice (3d8+9)")
    args = p.parse_args()

    n, d, modifier = parse(args.hitdice)

    stats = []
    for i in range(args.n):
        hp = str(roll(n, d) + modifier)
        stats.append(hp)

    print(", ".join(stats))
