Пример #1
0
    def process_round(self, state: GameState):
        pathogens_without_medication = set(state.pathogens).difference(
            state.pathogens_with_medication)
        pathogens_without_medication = list(
            pathogens_without_medication.difference(
                state.pathogens_with_medication_in_development))
        if pathogens_without_medication:
            # develop all medications first
            if state.points >= 20:
                return develop_medication(
                    pathogens_without_medication[0].index)
            else:
                return end_round()
        else:
            pathogens_with_medication = state.pathogens_with_medication
            if pathogens_with_medication:
                if state.points >= 10:
                    # collect all not medicated outbreaks
                    outbreaks_to_medicate = []
                    for city in state.cities:
                        events = city.events
                        medicated_pathogens = list(
                            map(
                                lambda event: event.pathogen,
                                filter(
                                    lambda event: event.event_type ==
                                    "medicationDeployed", events)))
                        outbreaks = list(
                            filter(
                                lambda event: event.event_type == "outbreak",
                                events))
                        outbreaks = list(
                            filter(
                                lambda outbreak_event: outbreak_event.pathogen
                                in pathogens_with_medication, outbreaks))
                        outbreaks = list(
                            filter(
                                lambda outbreak_event: outbreak_event.pathogen
                                not in medicated_pathogens, outbreaks))
                        outbreaks_to_medicate.extend(
                            list(
                                map(
                                    lambda outbreak_event:
                                    (city, outbreak_event), outbreaks)))

                    if outbreaks_to_medicate:
                        outbreaks_to_medicate.sort(key=self.outbreak_priority,
                                                   reverse=True)
                        outbreak_to_vaccinate = outbreaks_to_medicate[0]
                        return deploy_medication(
                            outbreak_to_vaccinate[1].pathogen.index,
                            outbreak_to_vaccinate[0].city_id)
                    else:
                        return end_round()
                else:
                    return end_round()
            else:
                return end_round()
Пример #2
0
 def generate_deployment_action(self, possible_actions: list, state: GameState):
     executable_actions = list(filter(lambda action: self.is_action_executable(action, state), possible_actions))
     if executable_actions:
         action = executable_actions[0]
         if action.is_vaccine:
             return deploy_vaccine(action.pathogen.index, action.city_id)
         else:
             return deploy_medication(action.pathogen.index, action.city_id)
     else:
         return end_round()
 def _generate_city_med_actions(cls, city: City,
                                ordered_available_pathogens: List[Pathogen],
                                pathogens_with_medication: List[Pathogen]):
     city_pathogens_with_medication = list(
         filter(
             lambda city_pathogen: city_pathogen in
             pathogens_with_medication, city.pathogens))
     ordered_city_pathogens_with_medication = [
         actions.deploy_medication(pathogen.index, city.index)
         if pathogen in city_pathogens_with_medication else INVALID_ACTION
         for pathogen in ordered_available_pathogens
     ]
     return ordered_city_pathogens_with_medication
Пример #4
0
    def process_round(self, state: GameState):
        possible_actions = []
        points = state.points

        for city in state.cities:
            if points >= 5:
                not_vaccinated_outbreaks = self.get_not_vaccinated_outbreaks_for_city(city)
                actions = list(map(
                    lambda outbreak: self.generate_possible_action(outbreak, city, True,
                                                                   state.pathogens_with_vaccination),
                    not_vaccinated_outbreaks))
                possible_actions.extend(actions)

            if points >= 10:
                not_medicated_outbreaks = self.get_not_medicated_outbreaks_for_city(city)
                actions = list(map(
                    lambda outbreak: self.generate_possible_action(outbreak, city, False,
                                                                   state.pathogens_with_medication),
                    not_medicated_outbreaks))
                possible_actions.extend(actions)

        if possible_actions:
            possible_actions.sort(key=lambda action: action.priority, reverse=True)

            action = possible_actions[0]
            pathogen = action.pathogen
            if action.is_vaccine:
                if pathogen in state.pathogens_with_vaccination:
                    return deploy_vaccine(pathogen.index, action.city_id)
                elif pathogen not in state.pathogens_with_vaccination_in_development:
                    if points >= 40:
                        return develop_vaccine(pathogen.index)
                    else:
                        return end_round()
                else:
                    return self.generate_deployment_action(possible_actions, state)
            else:
                if pathogen in state.pathogens_with_medication:
                    return deploy_medication(pathogen.index, action.city_id)
                elif pathogen not in state.pathogens_with_medication_in_development:
                    if points >= 20:
                        return develop_medication(pathogen.index)
                    else:
                        return end_round()
                else:
                    return self.generate_deployment_action(possible_actions, state)
        else:
            return end_round()
def test_generate_city_med_actions(
        simple_act_state_processor: SimpleActStateProcessor,
        city_with_pathogens: City, available_pathogens: List[Pathogen],
        pathogens_with_medication: List[Pathogen]):
    deploy_med_actions = [
        actions.deploy_medication(pathogen.index, city_with_pathogens.index) if
        (pathogen in city_with_pathogens.pathogens
         and pathogen in pathogens_with_medication) else INVALID_ACTION
        for pathogen in available_pathogens
    ]

    assert simple_act_state_processor._generate_city_med_actions(
        city_with_pathogens, available_pathogens,
        pathogens_with_medication) == deploy_med_actions

    assert simple_act_state_processor._generate_city_med_actions(
        city_with_pathogens, available_pathogens,
        list(reversed(pathogens_with_medication))) == deploy_med_actions

    assert simple_act_state_processor._generate_city_med_actions(
        city_with_pathogens, list(reversed(available_pathogens)),
        pathogens_with_medication) == list(reversed(deploy_med_actions))