Module pacai.agents.ghost.random

Expand source code
from pacai.agents.ghost.base import GhostAgent
from pacai.util import probability

class RandomGhost(GhostAgent):
    """
    A ghost that chooses a legal action uniformly at random.
    """

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

    def getDistribution(self, state):
        dist = {}
        for a in state.getLegalActions(self.index):
            dist[a] = 1.0

        return probability.normalize(dist)

Classes

class RandomGhost (index, **kwargs)

A ghost that chooses a legal action uniformly at random.

Expand source code
class RandomGhost(GhostAgent):
    """
    A ghost that chooses a legal action uniformly at random.
    """

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

    def getDistribution(self, state):
        dist = {}
        for a in state.getLegalActions(self.index):
            dist[a] = 1.0

        return probability.normalize(dist)

Ancestors

Static methods

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

Inherited from: GhostAgent.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: GhostAgent.final

Inform the agent about the result of a game.

def getAction(self, state)

Inherited from: GhostAgent.getAction

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

def getDistribution(self, state)

Inherited from: GhostAgent.getDistribution

Returns a dictionary encoding a distribution over possible actions.

Expand source code
def getDistribution(self, state):
    dist = {}
    for a in state.getLegalActions(self.index):
        dist[a] = 1.0

    return probability.normalize(dist)
def observationFunction(self, state)

Inherited from: GhostAgent.observationFunction

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

def registerInitialState(self, state)

Inherited from: GhostAgent.registerInitialState

Inspect the starting state.