Пример #1
0
    def __init__(self):
        super(BasicVisionCoexsistenceExperiment, self).__init__()

        # Parse world
        self.world = self.parse_world(self.world_representation)

        # Register the previously defined functions.
        enact_logic = Elements.get_enact_logic()

        # Set primitives known/enactable by the agents.
        primitives = []
        primitives.append(Elements.step)
        primitives.append(Elements.step_fail)
        primitives.append(Elements.turn_right)
        primitives.append(Elements.turn_left)
        primitives.append(Elements.wait)
        primitives.append(Elements.cuddle)
        primitives.append(Elements.cuddle_fail)

        # Set intrinsic motivation values.
        motivation = {}
        motivation[Elements.step] = -1
        motivation[Elements.step_fail] = -10
        motivation[Elements.turn_right] = -2
        motivation[Elements.turn_left] = -2
        motivation[Elements.wait] = -1
        motivation[Elements.cuddle] = 50
        motivation[Elements.cuddle_fail] = -1

        for entity in self.world.get_entities():
            if isinstance(entity, model.agent.Agent):
                self.world.add_enact_logic(entity, enact_logic)
                entity.add_primitives(primitives)
                entity.add_motivations(motivation)
Пример #2
0
    def __init__(self):
        super(BasicVisionExperimentLoad, self).__init__()

        # Parse world
        self.world = self.parse_world(self.world_representation)

        # Load the agent. (Note: the file must exist. Create it by running
        # the BasicVisionExperiment for some time, and then saving the agent.)
        a = self.load_agent("20161118T041955 - Agent 3T7U8G.p")
        self.world.add_entity(a)

        # Register the previously defined functions.
        enact_logic = Elements.get_enact_logic()

        for entity in self.world.get_entities():
            if isinstance(entity, model.agent.Agent):
                self.world.add_enact_logic(entity, enact_logic)
Пример #3
0
    def __init__(self):
        super(BasicVisionCoexsistenceDestroyExperiment, self).__init__()

        # Parse world
        self.world = self.parse_world(self.world_representation)

        # Add programmed agent
        a = agentprogram.agentprogram.create_programmable_agent(
            agentprogram.agentprogram.SimpleEatingAndDestroyingAgent,
            self.world)
        a.set_position((1, 2))
        self.world.add_entity(a)

        # Set up primitives
        collaborative_destroy = model.interaction.PrimitiveInteraction(
            "Collaborative Destroy", "Succeed")
        collaborative_destroy_fail = model.interaction.PrimitiveInteraction(
            "Collaborative Destroy", "Fail")

        def _collaborative_destroy(world, agents_interactions):
            enacted = {}

            for agent_1, interaction_1 in agents_interactions.iteritems():
                if agent_1 in enacted:
                    continue
                else:
                    enacted[
                        agent_1] = collaborative_destroy_fail  # Set fail as default, we will now see whether it succeeded

                    entities = world.get_entities_in_front(agent_1)
                    for entity in entities:
                        if isinstance(entity, model.structure.Block):
                            # There is a block at agent 1's position, try to find a second agent attempting to destroy the same block:
                            for agent_2, interaction_2 in agents_interactions.iteritems(
                            ):
                                if agent_1 == agent_2:
                                    continue

                                if agent_2.get_position(
                                ) == agent_1.get_position():
                                    # The agents are at the same position, so the action fails
                                    continue

                                if entity in world.get_entities_in_front(
                                        agent_2):
                                    # Agent 2 is enacting on the same block as agent 1, so the action succeeded
                                    world.remove_entity(entity)
                                    pos = entity.get_position()
                                    pos_2 = (pos.get_x(), pos.get_y() + 1)

                                    food_1 = model.structure.Food()
                                    food_2 = model.structure.Food()
                                    food_1.set_position(pos)
                                    food_2.set_position(pos_2)

                                    self.world.add_entity(food_1)
                                    self.world.add_entity(food_2)

                                    enacted[agent_1] = collaborative_destroy
                                    enacted[agent_2] = collaborative_destroy
            return enacted

        # Register the basic encation logic.
        enact_logic = Elements.get_enact_logic()

        # Register the complex enaction logic just defined.
        self.world.add_complex_enact_logic(_collaborative_destroy,
                                           collaborative_destroy.get_name())

        # Set primitives known/enactable by the agents.
        primitives = []
        primitives.append(Elements.step)
        primitives.append(Elements.step_fail)
        primitives.append(Elements.turn_right)
        primitives.append(Elements.turn_left)
        primitives.append(Elements.wait)
        primitives.append(Elements.eat)
        primitives.append(Elements.eat_fail)
        primitives.append(collaborative_destroy)
        primitives.append(collaborative_destroy_fail)

        # Set intrinsic motivation values.
        motivation = {}
        motivation[Elements.step] = -1
        motivation[Elements.step_fail] = -10
        motivation[Elements.turn_right] = -2
        motivation[Elements.turn_left] = -2
        motivation[Elements.wait] = -1
        motivation[Elements.eat] = 20
        motivation[Elements.eat_fail] = -2
        motivation[collaborative_destroy] = 50
        motivation[collaborative_destroy_fail] = -1

        # Add the logic to all agents present in the world.
        for entity in self.world.get_entities():
            if isinstance(entity, model.agent.Agent):
                self.world.add_enact_logic(entity, enact_logic)
                entity.add_primitives(primitives)
                entity.add_motivations(motivation)