Пример #1
0
def one_three_zeros(value):
    squad = Squad()
    for i in ELEMENTS:
        s = Stone()
        s[i] = value
        squad.append(Scient(i, s))
    return squad
Пример #2
0
def one_three_zeros(value):
    squad = Squad()
    for i in ELEMENTS:
        s = Stone()
        s[i] = value
        squad.append(Scient(i, s))
    return squad
Пример #3
0
def max_squad_by_value(value):
    """Takes an integer, ideally even because we round down, and returns a
    squad such that comp[element] == value, comp[orth] == value/2, comp[opp]
    == 0"""
    squad = Squad()
    value = value / 2  #more logical, really.
    half = value / 2
    for i in ELEMENTS:
        s = Stone()
        s[i] = value
        s[OPP[i]] = 0
        for o in ORTH[i]:
            s[o] = half
        squad.append(Scient(i, s))
    return squad
Пример #4
0
def max_squad_by_value(value):
    """Takes an integer, ideally even because we round down, and returns a
    squad such that comp[element] == value, comp[orth] == value/2, comp[opp]
    == 0"""
    squad = Squad()
    value = value / 2  # more logical, really.
    half = value / 2
    for i in ELEMENTS:
        s = Stone()
        s[i] = value
        s[OPP[i]] = 0
        for o in ORTH[i]:
            s[o] = half
        squad.append(Scient(i, s))
    return squad
Пример #5
0
    def create_squad(cls, units_data=None):
        """This method returns Squad class instance

        :arg units_data:
            1.For 'create_from_json_structure' method: List of dicts with units data
            Example: [{'type': 'Soldier'}, ... , {'type': 'Soldier'}]

            2.For 'create_new_structure' method: Default to None

        :return:
            Squad class instance

        """
        units = list()

        if units_data is not None:
            for unit in units_data:
                if unit['type'] == 'Soldier':
                    units.append(cls.create_soldier())
                elif unit['type'] == 'Vehicle':
                    units.append(cls.create_vehicle(len(unit['operators'])))
        else:
            unit_count = randint(u_conf.MIN_UNIT_COUNT, u_conf.MAX_UNIT_COUNT)
            for _ in range(unit_count):
                unit = choice([cls.create_soldier, cls.create_vehicle])()
                units.append(unit)

        squad = Squad(units_lst=units)

        return squad
Пример #6
0
def rand_squad(suit=None, kind='Scient'):
    """Returns a Squad of five random Scients of suit. Random suit used
       if none given."""
    #please clean me up.
    squad = Squad()
    if kind == 'Scient':
        size = 5
        if not suit in ELEMENTS:
            for _ in range(size):
                squad.append(rand_unit(rand_element(), kind))
        else:
            for _ in range(size):
                squad.append(rand_unit(suit, kind))
    else:
        if not suit in ELEMENTS:
            while squad.free_spaces >= 2:
                squad.append(rand_unit(rand_element()))
            if squad.free_spaces == 1:
                squad.append(rand_unit(rand_element(), kind='Scient'))
        else:
            while squad.free_spaces >= 2:
                squad.append(rand_unit(suit))
            if squad.free_spaces == 1:
                squad.append(rand_unit(suit, kind='Scient'))
    squad.name = rand_string()
    return squad
Пример #7
0
def rand_squad(suit=None, kind="Scient"):
    """Returns a Squad of five random Scients of suit. Random suit used
       if none given."""
    # please clean me up.
    squad = Squad()
    if kind == "Scient":
        size = 5
        if not suit in ELEMENTS:
            for _ in range(size):
                squad.append(rand_unit(rand_element(), kind))

        else:
            for _ in range(size):
                squad.append(rand_unit(suit, kind))

    else:
        if not suit in ELEMENTS:
            while squad.free_spaces >= 2:
                squad.append(rand_unit(rand_element()))
            if squad.free_spaces == 1:
                squad.append(rand_unit(rand_element(), kind="Scient"))
        else:
            while squad.free_spaces >= 2:
                squad.append(rand_unit(suit))
            if squad.free_spaces == 1:
                squad.append(rand_unit(suit, kind="Scient"))
    squad.name = rand_string()
    return squad