Module pacai.core.environment

Classes

class Environment
Expand source code
class Environment(abc.ABC):
    @abc.abstractmethod
    def getCurrentState(self):
        """
        Returns the current state of enviornment.
        """

        pass

    @abc.abstractmethod
    def getPossibleActions(self, state):
        """
        Returns possible actions the agent can take in the given state.
        Can return the empty list if we are in a terminal state.
        """

        pass

    @abc.abstractmethod
    def doAction(self, action):
        """
        Performs the given action in the current
        environment state and updates the enviornment.

        Returns a (reward, nextState) pair.
        """

        pass

    @abc.abstractmethod
    def reset(self):
        """
        Resets the current state to the start state.
        """

        pass

    def isTerminal(self):
        """
        Has the enviornment entered a terminal state?
        This means there are no successors.
        """

        state = self.getCurrentState()
        actions = self.getPossibleActions(state)

        return len(actions) == 0

Helper class that provides a standard way to create an ABC using inheritance.

Ancestors

  • abc.ABC

Subclasses

Methods

def doAction(self, action)
Expand source code
@abc.abstractmethod
def doAction(self, action):
    """
    Performs the given action in the current
    environment state and updates the enviornment.

    Returns a (reward, nextState) pair.
    """

    pass

Performs the given action in the current environment state and updates the enviornment.

Returns a (reward, nextState) pair.

def getCurrentState(self)
Expand source code
@abc.abstractmethod
def getCurrentState(self):
    """
    Returns the current state of enviornment.
    """

    pass

Returns the current state of enviornment.

def getPossibleActions(self, state)
Expand source code
@abc.abstractmethod
def getPossibleActions(self, state):
    """
    Returns possible actions the agent can take in the given state.
    Can return the empty list if we are in a terminal state.
    """

    pass

Returns possible actions the agent can take in the given state. Can return the empty list if we are in a terminal state.

def isTerminal(self)
Expand source code
def isTerminal(self):
    """
    Has the enviornment entered a terminal state?
    This means there are no successors.
    """

    state = self.getCurrentState()
    actions = self.getPossibleActions(state)

    return len(actions) == 0

Has the enviornment entered a terminal state? This means there are no successors.

def reset(self)
Expand source code
@abc.abstractmethod
def reset(self):
    """
    Resets the current state to the start state.
    """

    pass

Resets the current state to the start state.