def make_capital_duchy(origin=Cube(0, 0, 0),
                       size_list=KINGDOM_SIZE_LIST[0],
                       rgb_tuple=None,
                       coastal=True):
    '''Makes a duchy whose capital county is clumped.
    If coastal=True and size_list[0]<7, one water hex bordering the capital will be included.
    rgb_tuple should be ((r,g,b),[(r,g,b)*])'''
    rgb_tuple = rgb_tuple or random_rgb_tuple(size_list)
    capital_county = make_capital_county(c_size=size_list[0],
                                         coastal=coastal,
                                         rgb=rgb_tuple[1][0])
    duchy = Tile(origin=origin,
                 tile_list=[capital_county],
                 hex_list=[],
                 rgb=rgb_tuple[0])
    for idx, el in enumerate(size_list[1:]):
        try:
            duchy.add_new_tile(el, rgb=rgb_tuple[1][idx + 1])
        except:
            print(idx, rgb_tuple)
            raise ValueError
    if coastal:
        drhl = duchy.real_hex_list()
        if check_water_access(drhl, duchy.real_water_list(),
                              max([el.mag() for el in drhl])):
            return duchy
        else:
            return make_capital_duchy(origin, size_list, rgb_tuple, coastal)
    else:
        return duchy
def make_original_center_duchy(
        origin=Cube(0, 0, 0), size_list=CENTER_SIZE_LIST, rgb_tuple=None):
    rgb_tuple = rgb_tuple or random_rgb_tuple(size_list)
    capital_county = make_capital_county(c_size=size_list[0],
                                         coastal=False,
                                         rgb=rgb_tuple[1][0])
    duchy = Tile(origin=origin,
                 tile_list=[capital_county],
                 hex_list=[],
                 rgb=rgb_tuple[0])
    for idx, c_size in enumerate(size_list[1:]):
        duchy.add_new_tile(c_size,
                           rgb=rgb_tuple[1][idx + 1],
                           capital=Cube(0, -2, 2).rotate_right(idx * 2))
    return duchy
def make_kingdom(
    origin=Cube(0, 0, 0),
    size_list=KINGDOM_SIZE_LIST,
    rgb_tuple=None,
    coastal=True,
):
    """rgb_tuple is complicated. For each level, the left element is the rgb of the title for that tile,
    and the right element is a list of rgb_tuples for the tiles the next element below 
    (or a list of rgb tuples for baronies)."""
    rgb_tuple = rgb_tuple or random_rgb_tuple(size_list)
    kingdom = Tile(origin=origin,
                   tile_list=[
                       make_capital_duchy(size_list=size_list[0],
                                          coastal=coastal,
                                          rgb_tuple=rgb_tuple[1][0])
                   ],
                   hex_list=[],
                   rgb=rgb_tuple[0])
    d_idx = 1
    while d_idx < len(size_list):
        duchy_size_list = size_list[d_idx]
        krhl = kingdom.relative_hex_list()
        krwl = kingdom.relative_water_list()
        new_county = Tile.new_tile(duchy_size_list[0],
                                   rgb=rgb_tuple[1][d_idx][1][0])
        if new_county.move_into_place([kingdom.relative_neighbors()], krhl,
                                      krwl):
            new_duchy = Tile(origin=Cube(0, 0, 0),
                             tile_list=[new_county],
                             hex_list=[],
                             rgb=rgb_tuple[1][d_idx][0])
            for c_idx, county_size_list in enumerate(duchy_size_list[1:]):
                new_duchy.add_new_tile(county_size_list,
                                       cant=krhl + krwl,
                                       rgb=rgb_tuple[1][d_idx][1][c_idx])
            if check_water_access(krhl + new_duchy.relative_hex_list(), krwl):
                kingdom.add_tile(new_duchy)
                d_idx += 1
    return kingdom