Module pacai.agents.ghost.base

Expand source code
import abc

from pacai.agents.base import BaseAgent
from pacai.core.directions import Directions
from pacai.util import probability

class GhostAgent(BaseAgent):
    """
    The base class for ghost agents.
    Ghosts provide a distribution of possible actions,
    which is then sampled from to get the next action.
    """

    def __init__(self, index, **kwargs):
        super().__init__(index, **kwargs)

    def getAction(self, state):
        dist = self.getDistribution(state)

        if (len(dist) == 0):
            return Directions.STOP
        else:
            return probability.sample(dist)

    @abc.abstractmethod
    def getDistribution(self, state):
        """
        Returns a dictionary encoding a distribution over possible actions.
        """

        pass

Classes

class GhostAgent (index, **kwargs)

The base class for ghost agents. Ghosts provide a distribution of possible actions, which is then sampled from to get the next action.

Expand source code
class GhostAgent(BaseAgent):
    """
    The base class for ghost agents.
    Ghosts provide a distribution of possible actions,
    which is then sampled from to get the next action.
    """

    def __init__(self, index, **kwargs):
        super().__init__(index, **kwargs)

    def getAction(self, state):
        dist = self.getDistribution(state)

        if (len(dist) == 0):
            return Directions.STOP
        else:
            return probability.sample(dist)

    @abc.abstractmethod
    def getDistribution(self, state):
        """
        Returns a dictionary encoding a distribution over possible actions.
        """

        pass

Ancestors

Subclasses

Static methods

def loadAgent(name, index, args={})

Inherited from: BaseAgent.loadAgent

Load an agent with the given class name. The name can be fully qualified or just the bare class name. If the bare name is given, the class should …

Methods

def final(self, state)

Inherited from: BaseAgent.final

Inform the agent about the result of a game.

def getAction(self, state)

Inherited from: BaseAgent.getAction

The BaseAgent will receive an AbstractGameState, and must return an action from Directions.

Expand source code
def getAction(self, state):
    dist = self.getDistribution(state)

    if (len(dist) == 0):
        return Directions.STOP
    else:
        return probability.sample(dist)
def getDistribution(self, state)

Returns a dictionary encoding a distribution over possible actions.

Expand source code
@abc.abstractmethod
def getDistribution(self, state):
    """
    Returns a dictionary encoding a distribution over possible actions.
    """

    pass
def observationFunction(self, state)

Inherited from: BaseAgent.observationFunction

Make an observation on the state of the game. Called once for each round of the game.

def registerInitialState(self, state)

Inherited from: BaseAgent.registerInitialState

Inspect the starting state.