Exemple #1
0
    def _taxi_transition_func(self, state, action):
        '''
        Args:
            state (State)
            action (str)

        Returns
            (State)
        '''
        _error_check(state, action)

        if self.slip_prob > random.random():
            # Flip dir.
            if action == "up":
                action = "down"
            elif action == "down":
                action = "up"
            elif action == "left":
                action = "right"
            elif action == "right":
                action = "left"

        if action == "up" and state.get_agent_y() < self.height:
            next_state = self.move_agent(state, self.slip_prob, dy=1)
        elif action == "down" and state.get_agent_y() > 1:
            next_state = self.move_agent(state, self.slip_prob, dy=-1)
        elif action == "right" and state.get_agent_x() < self.width:
            next_state = self.move_agent(state, self.slip_prob, dx=1)
        elif action == "left" and state.get_agent_x() > 1:
            next_state = self.move_agent(state, self.slip_prob, dx=-1)
        elif action == "dropoff":
            next_state = self.agent_dropoff(state)
        elif action == "pickup":
            next_state = self.agent_pickup(state)
        else:
            next_state = state

        # Make terminal.
        if taxi_helpers.is_taxi_terminal_state(next_state):
            next_state.set_terminal(True)

        # All OOMDP states must be updated.
        next_state.update()

        return next_state
    def _taxi_transition_func(self, state, action):
        '''
        Args:
            state (State)
            action (str)

        Returns
            (State)
        '''
        _error_check(state, action)

        if self.slip_prob > random.random():
            # Flip dir.
            if action == "up":
                action = "down"
            elif action == "down":
                action = "up"
            elif action == "left":
                action = "right"
            elif action == "right":
                action = "left"

        if action == "up" and state.get_agent_y() < self.height:
            next_state = self.move_agent(state, self.slip_prob, dy=1)
        elif action == "down" and state.get_agent_y() > 1:
            next_state = self.move_agent(state, self.slip_prob, dy=-1)
        elif action == "right" and state.get_agent_x() < self.width:
            next_state = self.move_agent(state, self.slip_prob, dx=1)
        elif action == "left" and state.get_agent_x() > 1:
            next_state = self.move_agent(state, self.slip_prob, dx=-1)
        elif action == "dropoff":
            next_state = self.agent_dropoff(state)
        elif action == "pickup":
            next_state = self.agent_pickup(state)
        else:
            next_state = state

        # Make terminal.
        if taxi_helpers.is_taxi_terminal_state(next_state):
            next_state.set_terminal(True)

        # All OOMDP states must be updated.
        next_state.update()

        return next_state