Exemplo n.º 1
0
    def parse_choice(choice):
        """
        Parse a choice into a [PlayerState, listOf(Species), listOf(Species]
        :param choice: json list representing [playerstate, listof species, listof species]
        :return: [PlayerState, listOf(Species), listOf(Species)]
        """
        ps = PlayerState.convertPlayerState(choice[0])
        prev_species = [Species.convertSpecies(species) for species in [prev for prev in choice[1]]]
        later_species = [Species.convertSpecies(species) for species in [late for late in choice[2]]]

        return [ps, prev_species, later_species]
Exemplo n.º 2
0
 def parse_cj_dj(json_cj_dj):
     """
     Parse a json cj_dj into a [listOf(listOf(Species)), listOf(listOf(Species))]
     :param json_cj_dj: json list representing [listof species, listof species]
                     - First list of species is each specieslist of all players acting before this player
                     - Second list of species is each specieslist of all players who's turns come after this player
     :return: (listOf(Species), listOf(Species))
     """
     prev_species, later_species = [], []
     for prev in json_cj_dj[0]:
         prev_species.append([Species.convertSpecies(species) for species in prev])
     for later in json_cj_dj[1]:
         later_species.append([Species.convertSpecies(species) for species in later])
     return prev_species, later_species
Exemplo n.º 3
0
 def from_json_state(json_state):
     """
     Takes in a json 'state' of a Player, converting it into a new PlayerState object
     :param json_state: JSON List -  [Natural, [Species+, ..., Species+], Cards]
     :return: PlayerState - the new PlayerState object created from the json representation
     """
     food_bag = json_state[0]
     species_list = [Species.convertSpecies(species) for species in json_state[1]]
     trait_cards = [TraitCard.from_json(trait) for trait in json_state[2]]
     return PlayerState(bag=food_bag, speciesList=species_list, trait_cards=trait_cards)
Exemplo n.º 4
0
 def from_json_gamestate(json_state):
     """
     Takes in a json game state, converting it into a list that contains the PlayerState, WateringHole, and other species
     :param json_state: JSON List - [Natural, [Species+, ..., Species+], Cards, Natural+, LOB]
     :return: [PlayerState, Nat, List of Species]
     """
     ps = PlayerState.from_json_state(json_state[:3])
     watering_hole = json_state[3]
     all_species = []
     for species_list in json_state[4]:
         all_species.append([Species.convertSpecies(species) for species in species_list])
     return [ps, watering_hole, all_species]
Exemplo n.º 5
0
    def convertPlayerState(state):
        """
        Creates a PlayerState from from the given JSON representation
        :param state: JSON list - represents the playerState
        :return: PlayerState - with attributes contained in 'state'
        """
        playerTraitCards = []

        if state[0][0] == ID_LABEL and state[1][0] == SPECIES_LABEL and state[2][0] == BAG_LABEL:
            id = state[0][1]
            speciesList = [Species.convertSpecies(species) for species in state[1][1]]
            bag = state[2][1]
            if len(state) == 4 and state[3][0] == CARDS_LABEL:
                playerTraitCards = [TraitCard.from_json(card) for card in state[3][1]]
            if id < 1 or bag < 0:
                raise Exception("Bad JSON PlayerState Data")

            return PlayerState(id, bag, speciesList, playerTraitCards)

        else:
            raise Exception("Bad JSON PlayerState input")