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 create_dealer_from_configuration(json_configuration):
        """
        Takes in a configuration from stdin as a JSON object
        :param json_configuration: the JSON configuration
        :return: Dealer - the dealer created from the configuration
        """
        try:
            list_of_player_states = []
            for player_state in json_configuration[0]:
                ps = PlayerState.convertPlayerState(player_state)
                ps.player_reference = Player(ps.id)
                list_of_player_states.append(ps)

            wh = json_configuration[1]

            if isinstance(wh, int) and not isinstance(wh, bool) and wh >= 0:
                watering_hole = json_configuration[1]
                hand = Dealer.get_hand(json_configuration[2])

                return Dealer(list_of_player_states, watering_hole, hand)
            else:
                raise Exception("Invalid JSON Watering Hole")
        except:
            raise Exception("Ill formed json configuration")