コード例 #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")
コード例 #2
0
    def _reset(self):
        super(PushBlock, self)._reset()

        self.sw_loc = choice(creationutils.empty_locations(self))
        self.sw = mi.Switch(location=self.sw_loc)
        self._add_item(self.sw)

        x, y = choice(creationutils.empty_locations(self))
        self.pushable = mi.Pushable(location=(x, y))
        self._add_item(self.pushable)

        visited, p = creationutils.dijkstra(self, (x, y),
                                            creationutils.pushblock_movefunc)
        if self.sw_loc not in visited:
            raise MazeException("No path to sw")
        self.waypoints = pbwps(p, self.pushable.location, self.sw.location)

        x, y = choice(
            creationutils.empty_locations(self, bad_blocks=[mi.Block]))
        self.agent = PushBlockAgent(location=(x, y))
        self._add_agent(self.agent, "PushBlockAgent")
        visited, _ = creationutils.dijkstra(self, (x, y),
                                            creationutils.agent_movefunc)
        if self.waypoints[0] not in visited:
            raise MazeException("No path to pushblock")
コード例 #3
0
 def _side_information(self):
     # Featurize the goals, and add it to the features of some dummy
     # switches in the right state
     return super(ConditionedGoals, self)._side_information() + \
         [
             [self.FEATURE.IF] +
             mi.Switch(nstates=self.n_goals, start_state=i).featurize() +
             [self.FEATURE.GOTO] +
             self.goals[st].featurize()
         for i, st in enumerate(self.conditions)]
コード例 #4
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")
コード例 #5
0
    def _reset(self):
        super(Switches, self)._reset()

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

        visited, _ = creationutils.dijkstra(self, loc,
                                            creationutils.agent_movefunc)

        self._switches = []
        for _ in range(self.n_switches):
            loc = choice(creationutils.empty_locations(self))
            self._switches.append(
                mi.Switch(
                    location=loc,
                    nstates=self.switch_states,
                    start_state=choice(range(self.switch_states)),
                ))
            self._add_item(self._switches[-1])
            if loc not in visited:
                raise MazeException("No path to goal")