Ejemplo n.º 1
0
    def _reset(self):
        super(ConditionedGoals, self)._reset()

        x, y = choice(creationutils.empty_locations(self))
        self.sw = mi.Switch(
            location=(x, y),
            nstates=self.n_colors,
            start_state=choice(range(self.n_colors)),
        )
        self._add_item(self.sw)

        self.goals = []
        for i in range(self.n_goals):
            x, y = choice(creationutils.empty_locations(self))
            self.goals.append(mi.Goal(location=(x, y), id=i))
            self._add_item(self.goals[i])
        self.conditions = [randint(0, self.n_goals - 1) for _ in self.goals]

        x, y = choice(
            creationutils.empty_locations(self, bad_blocks=[mi.Block]))
        self.agent = TogglingAgent(location=(x, y))
        self._add_agent(self.agent, "ConditionedGoalsAgent")

        visited, _ = creationutils.dijkstra(self, (x, y),
                                            creationutils.agent_movefunc)

        if (self.sw.location not in visited
                or not any(self.goals[i].location in visited
                           for i in set(self.conditions))):
            raise MazeException("No path to goal")
Ejemplo n.º 2
0
    def _reset(self):
        super(Exclusion, self)._reset()
        if self.visit_min < 1:
            raise MazeException("visit_min is not >= 1")
        if self.visit_max == -1:
            self.visit_max = self.n_goals
        self.visit = list(range(self.n_goals))
        shuffle(self.visit)
        to_visit = randint(self.visit_min, self.visit_max)
        self.exclude = self.visit[to_visit:]
        self.visit = self.visit[:to_visit]
        self.visit = dict((x, False) for x in self.visit)

        self.goals = []
        for i in range(self.n_goals):
            x, y = choice(creationutils.empty_locations(self))
            self.goals.append(mi.Goal(location=(x, y), id=i))
            self._add_item(self.goals[i])

        x, y = choice(
            creationutils.empty_locations(self, bad_blocks=[mi.Block]))
        self.agent = TogglingAgent(location=(x, y))
        self._add_agent(self.agent, "ExclusionAgent")

        visited, _ = creationutils.dijkstra(self, (x, y),
                                            creationutils.agent_movefunc)

        if not all(goal.location in visited for goal in self.goals):
            raise MazeException("No path to goal")
Ejemplo n.º 3
0
    def restore(self, state_info):
        self.current_task = 0
        self.episode_steps = 0

        self.width = state_info['width']
        self.height = state_info['height']
        self._map = [[[] for x in range(self.height)]
                     for y in range(self.width)]
        self._approx_reward_map = [[
            -self.turn_penalty for x in range(self.height)
        ] for y in range(self.width)]

        for loc in state_info['block_locs']:
            self._add_item(maze_items.Block(location=loc))
        for loc in state_info['water_locs']:
            self._add_item(maze_items.Water(location=loc))

        init_state, tasks = state_info['config']
        self.agent = self.agent_cls(location=init_state['loc_a'])
        self._add_agent(self.agent, "TaxiAgent")
        self.target = maze_items.Goal(location=init_state['loc_t'])
        self._add_item(self.target)
        self.passenger = Passenger(location=init_state['loc_p'])
        self._add_item(self.passenger)
        if init_state['is_picked_up']:
            self.agent.actions['pickup']()
        self.current_config = state_info['config']
Ejemplo n.º 4
0
    def _reset(self):
        hole, dim = add_vertical_wall(self)

        # Add the pushblock
        self.pushable = mi.Pushable(location=hole)
        self._add_item(self.pushable)

        # Add additional blocks and waters
        super(BlockedDoor, self)._reset()

        # Add the goal, and agent
        loc = choice(
            creationutils.empty_locations(self, bad_blocks=[mi.Block,
                                                            mi.Door]))
        self.goal = mi.Goal(location=loc)
        self._add_item(self.goal)

        loc = choice(
            creationutils.empty_locations(self, bad_blocks=[mi.Block,
                                                            mi.Door]))
        self.agent = PushBlockAgent(location=loc)
        self._add_agent(self.agent, "BlockedDoorAgent")

        self._remove_item(self.pushable.id)
        visited, _ = creationutils.dijkstra(self, loc,
                                            creationutils.agent_movefunc)
        if self.goal.location not in visited:
            raise MazeException("No path to goal")
        self._add_item(self.pushable)
Ejemplo n.º 5
0
    def _reset(self):
        intersection, holes = add_4_walls(self)

        # No doors for now 
        # self.door = mi.Door(location=hole,
        #                     state=choice(range(1, self.switch_states)))
        # self._add_item(self.door)

        # ad blocks on the holes temporarily
        blocked_holes = []
        for i in range(len(holes)):
            blocked_holes.append(mi.Block(location= holes[i]))
            self._add_item(blocked_holes[i])

        # Add additional blocks and waters 
        # only blocks and water have reset methods, and that sprinkles blocs and waters around
        super(TrapKey, self)._reset()


        # empty the wall opening if they have been blocked
        for i in range(len(holes)):
            self._remove_item(blocked_holes[i].id)

        
        # Add the goal
        loc = choice(creationutils.empty_locations(
            self, bad_blocks=[mi.Block, mi.Trap, mi.Water])) # bad blocks where the goal can't be placed
        self.goal = mi.Goal(location=loc)
        self._add_item(self.goal)
        

        # # no switches for now
        # side = choice([-1, 1])
        # # for adding switch to the opposite side of the goal
        # def mask_func(x, y):
        #     return side * ((x, y)[1 - dim] - hole[1 - dim]) > 0

        # loc = choice(creationutils.empty_locations(
        #     self, bad_blocks=[mi.Block, mi.Door, mi.Goal], mask=mask_func))
        # self.sw = mi.Switch(location=loc, nstates=self.switch_states)
        # self._add_item(self.sw)

        # add agent 
        loc = choice(creationutils.empty_locations(
            self, bad_blocks=[mi.Block, mi.Trap]))
        self.agent = TriggerAgent(location=loc)
        self._add_agent(self.agent, "TrapKeyAgent")

        # check if goal can be visited or not 
        visited, _ = creationutils.dijkstra(self, loc,
                                            creationutils.agent_movefunc)
        
        if self.goal.location not in visited :
            raise MazeException("No path to goal")
Ejemplo n.º 6
0
    def _reset(self):
        super(SingleGoal, self)._reset()

        loc = choice(creationutils.empty_locations(self))
        self.goal = mi.Goal(location=loc)
        self._add_item(self.goal)

        loc = choice(creationutils.empty_locations(self,
                                                   bad_blocks=[mi.Block]))
        self.agent = MovingAgent(location=loc)
        self._add_agent(self.agent, "SingleGoalAgent")

        visited, _ = creationutils.dijkstra(self, loc,
                                            creationutils.agent_movefunc)
        if self.goal.location not in visited:
            raise MazeException("No path to goal")
Ejemplo n.º 7
0
    def _reset(self):
        super(TaxiGame, self)._reset()

        agent_loc = choice(
            creationutils.empty_locations(self, bad_blocks=[maze_items.Block]))
        self.agent = self.agent_cls(location=agent_loc)
        self._add_agent(self.agent, "TaxiAgent")
        n_items = 2
        placement_locs = self._get_placement_locs(agent_loc, n_items)
        target_loc, psg_loc = rnd.sample(placement_locs, n_items)

        self.target = maze_items.Goal(location=target_loc)
        self._add_item(self.target)

        self.passenger = Passenger(location=psg_loc)
        self._add_item(self.passenger)
        self.episode_steps = 0
Ejemplo n.º 8
0
    def _reset(self):
        super(MultiGoals, self)._reset()

        self.goals = []
        for i in range(self.n_goals):
            x, y = choice(creationutils.empty_locations(self))
            self.goals.append(mi.Goal(location=(x, y), id=i))
            self._add_item(self.goals[i])
        shuffle(self.goals)
        self.v = 0

        x, y = choice(
            creationutils.empty_locations(self, bad_blocks=[mi.Block]))
        self.agent = MovingAgent(location=(x, y))
        self._add_agent(self.agent, "MultiGoalsAgent")

        visited, _ = creationutils.dijkstra(self, (x, y),
                                            creationutils.agent_movefunc)
        if not all(goal.location in visited for goal in self.goals):
            raise MazeException("No path to goal")
Ejemplo n.º 9
0
    def _reset(self):
        super(GotoHidden, self)._reset()

        self.goals = []
        for i in range(self.n_goals):
            x, y = choice(creationutils.empty_locations(self))
            self.goals.append(mi.Goal(location=(x, y), id=i, visible=False))
            self._add_item(self.goals[i])

        self.goal = choice(self.goals)

        x, y = choice(
            creationutils.empty_locations(self, bad_blocks=[mi.Block]))
        self.agent = MovingAgent(location=(x, y))
        self._add_agent(self.agent, "GotoHiddenAgent")

        visited, _ = creationutils.dijkstra(self, (x, y),
                                            creationutils.agent_movefunc)
        if self.goal.location not in visited:
            raise MazeException("No path to goal")
Ejemplo n.º 10
0
    def _reset(self):
        hole, dim = add_vertical_wall(self)

        # Add the door
        self.door = mi.Door(location=hole,
                            state=choice(range(1, self.switch_states)))
        self._add_item(self.door)

        # Add additional blocks and waters
        super(LightKey, self)._reset()

        # Add the goal, agent, and switch
        loc = choice(
            creationutils.empty_locations(self, bad_blocks=[mi.Block,
                                                            mi.Door]))
        self.goal = mi.Goal(location=loc)
        self._add_item(self.goal)
        side = choice([-1, 1])

        def mask_func(x, y):
            return side * ((x, y)[1 - dim] - hole[1 - dim]) > 0

        loc = choice(
            creationutils.empty_locations(
                self, bad_blocks=[mi.Block, mi.Door, mi.Goal], mask=mask_func))
        self.sw = mi.Switch(location=loc, nstates=self.switch_states)
        self._add_item(self.sw)

        loc = choice(
            creationutils.empty_locations(self,
                                          bad_blocks=[mi.Block, mi.Door],
                                          mask=mask_func))
        self.agent = SwitchesAgent(location=loc)
        self._add_agent(self.agent, "LightKeyAgent")

        visited, _ = creationutils.dijkstra(self, loc,
                                            creationutils.agent_movefunc)
        if self.goal.location not in visited or self.sw.location not in visited:
            raise MazeException("No path to goal")
Ejemplo n.º 11
0
    def _reset(self):
        super(TaxiMultiTask, self)._reset()
        #print('=============RESET====================')
        self.current_task = None
        n_items = 2  #passenger, target
        loc_agent = choice(
            creationutils.empty_locations(self, bad_blocks=[maze_items.Block]))
        self.agent = self.agent_cls(location=loc_agent)
        self._add_agent(self.agent, "TaxiAgent")

        placement_locs = self._get_placement_locs(loc_agent, n_items)
        loc_target, loc_pass = rnd.sample(placement_locs, n_items)
        init_state, tasks = self._get_new_config()

        # check relationship between locations of the passenger and the taxi locations
        if init_state.pRt == Relation.FAR:
            self.passenger = Passenger(location=loc_pass)
            self._add_item(self.passenger)
        else:
            self.passenger = Passenger(location=loc_agent)
            self._add_item(self.passenger)
            if init_state.pRt == Relation.INSIDE:
                self.agent.actions['pickup']()
                assert self.passenger.is_pickedup, "Can't put a passenger into a taxi for init_state={}".format(
                    init_state)

        self.target = maze_items.Goal(location=loc_target)
        self._add_item(self.target)
        self.current_task = 0
        self.episode_steps = 0
        detailed_state = dict(loc_a=self.agent.location,
                              loc_p=self.passenger.location,
                              loc_t=self.target.location,
                              is_picked_up=self.passenger.is_pickedup)
        self.current_config = MultiTaskEpisodeConfig(init_state=detailed_state,
                                                     tasks=tasks)