Exemplo n.º 1
0
    def add_stored_fat_food(self, stored_fat_food, owner_body_size):
        """ Set the stored fat food which is always GEN_TRAIT_CARD_STORED_FOOD for Non-FatTissueCards
        :param stored_fat_food: The amount of food you wish to store
        :type stored_fat_food: Nat
        :param owner_body_size: The owner's body size
        :type owner_body_size: Nat
        :return: The new self.food
        :rtype: Nat
        """
        if not (is_natural(stored_fat_food) and is_natural(owner_body_size) and stored_fat_food <= owner_body_size):
            raise ValueError("TraitCard - add_stored_fat_food: 0 <= stored_fat_food <= owner_body_size")

        return 0
Exemplo n.º 2
0
    def __init__(self, id, species_list=None,
                 food_bag=PLAYER_STARTING_FOOD_TOKENS, hand=None):
        """ Create a new player-state made for clients, with the given
        number of food tokens and the given list of Species
        :param id: The id number of the player
        :type id: Nat+
        :param species_list: the list of Species owned by the Player
        :type species_list: [Species, ...]
        :param food_bag: the number of tokens in the food bag
        :type food_bag: Nat+
        :param hand: This Player's initial hand
        :type hand: [TraitCard, ...]
        :return: None
        """
        if not is_natural_plus(id):
            raise ValueError(
                "__init__: Player Id must be a positive Natural, got: " + str(
                    id))
        if not (is_list_of(species_list, Species) or species_list is None):
            raise ValueError(
                "__init__: Species List is not a valid list of Species: " + repr(
                    species_list))
        if not is_natural(food_bag):
            raise ValueError(
                "__init__: The food bag must be a Natural, got: " + str(
                    food_bag))
        if not (is_list_of(hand, TraitCard) or hand is None):
            raise ValueError(
                "__init__: Invalid Hand, must be a List of TraitCards")

        self.id = id
        self.food_bag = food_bag
        self.species_list = [] if species_list is None else species_list
        self.hand = [] if hand is None else hand
def is_pj_pop(value):
    """ Is the given value a PyJSON Population?
    :param value: The value being checked
    :type value: Any
    :return: True the given value a PyJSON Population, False otherwise
    :rtype: Boolean
    """
    return is_list_with_len(
        value, PJ_FIELD_LEN) and (value[0] == POP_STR) and is_natural(value[1])
Exemplo n.º 4
0
def new_convert_g(g, class_name):
    """
    Converts a gb or gp to a CardPlay
    :param g:gb or gp
    :type gp: PYJSON
    :param g_key: string representing key
    in PYJSON
    :type g_key: String
    :param class_name: constructor of cardplay
    :type class_name: Nat Nat -> CardPlay
    :return: the corresponding CardPlay
    :rtype: CardPlay
    """
    [species_index, card_index] = g
    if not (is_natural(species_index) and is_natural(card_index)):
        raise ConvertPyJSONError("expected a natural number")

    return class_name(card_index, species_index)
def is_pj_body(value):
    """ Is the given value a PyJSON Body?
    :param value: The value being checked
    :type value: Any
    :return: True the given value a PyJSON Body, False otherwise
    :rtype: Boolean
    """
    return is_list_with_len(
        value, PJ_FIELD_LEN) and (value[0] == BODY_STR) and is_natural(
            value[1])
def is_pj_fat_food(value):
    """ Is the given value a PyJSON Fat-Food?
    :param value: The value being checked
    :type value: Any
    :return: True the given value a PyJSON Fat-Food, False otherwise
    :rtype: Boolean
    """
    return is_list_with_len(
        value, PJ_FIELD_LEN) and (value[0] == FAT_FOOD_STR) and is_natural(
            value[1])
def convert_to_pj_body(body_nat):
    """ Convert the given Natural into a PyJSON Body
    :param body_nat: The body size to be converted
    :type body_nat: Nat
    :return: PyJSON Body
    :rtype: PJ_Body
    """
    if not (is_natural(body_nat)):
        raise ValueError("convert_to_pj_body: Invalid Natural")

    return [BODY_STR, body_nat]
def convert_to_pj_pop(pop_nat):
    """ Convert the given population count into a PyJSON Population
    :param pop_nat: The natural number being converted
    :type pop_nat: Nat
    :return: The PyJSON Population
    :rtype: PJ_Pop
    """
    if not is_natural(pop_nat):
        raise ValueError("convert_to_pj_population: Invalid Natural")

    return [POP_STR, pop_nat]
def convert_to_pj_fat_food(fat_food_nat):
    """ Convert the given Natural to a PyJSON PJ_Fat_Food
    :param fat_food_nat: The Natural being converted
    :type fat_food_nat: Nat
    :return: The resulting PyJSON PJ_Fat_Food
    :rtype: PJ_Fat_Food

    fat-food = [\"fat-food\", Natural]
    """
    if not is_natural(fat_food_nat):
        raise ValueError("convert_fat_food: Invalid Natural]")
    return [FAT_FOOD_STR, fat_food_nat]
def convert_to_pj_food(food_nat):
    """
     Convert the given Natural into a PyJSON food
    :param food_nat: The Natural
    :type food_nat: Nat
    :return: The PyJSON Food
    :rtype: PJ_Food

    food = [\"food\", Natural]
    """
    if not (is_natural(food_nat)):
        raise ValueError("convert_to_pj_food: Invalid Natural")

    return [FOOD_STR, food_nat]
Exemplo n.º 11
0
    def add_stored_fat_food(self, stored_fat_food):
        """
         Store the given Amount of fat food on your Fat Token
        :param stored_fat_food: The fat you wish to store
        :type stored_fat_food: Nat+
        :return: None
        """
        if not (is_natural(stored_fat_food)
                and stored_fat_food <= self.get_body_size()):
            raise ValueError(
                "Species - add_stored_fat_food: Invalid stored_fat_food : {}. Must be between {} and {}."
                .format(stored_fat_food, 0, self.get_body_size()))

        [
            trait.add_stored_fat_food(stored_fat_food, self.body_size)
            for trait in self.get_active_cards()
        ]
Exemplo n.º 12
0
    def __init__(self,
                 id,
                 species_list=None,
                 food_bag=PLAYER_STARTING_FOOD_TOKENS,
                 hand=None):
        """ Create a new player-state made for clients, with the given
        number of food tokens and the given list of Species
        :param id: The id number of the player
        :type id: Nat+
        :param species_list: the list of Species owned by the Player
        :type species_list: [Species, ...]
        :param food_bag: the number of tokens in the food bag
        :type food_bag: Nat+
        :param hand: This Player's initial hand
        :type hand: [TraitCard, ...]
        :return: None
        """
        if not is_natural_plus(id):
            raise ValueError(
                "__init__: Player Id must be a positive Natural, got: " +
                str(id))
        if not (is_list_of(species_list, Species) or species_list is None):
            raise ValueError(
                "__init__: Species List is not a valid list of Species: " +
                repr(species_list))
        if not is_natural(food_bag):
            raise ValueError(
                "__init__: The food bag must be a Natural, got: " +
                str(food_bag))
        if not (is_list_of(hand, TraitCard) or hand is None):
            raise ValueError(
                "__init__: Invalid Hand, must be a List of TraitCards")

        self.id = id
        self.food_bag = food_bag
        self.species_list = [] if species_list is None else species_list
        self.hand = [] if hand is None else hand