Module pacai.agents.random

Expand source code
import random

from pacai.agents.base import BaseAgent

class RandomAgent(BaseAgent):
    """
    An agent that moves randomly while still obeying the rules.
    """

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

    def getAction(self, state):
        return random.choice(state.getLegalActions(self.index))

Classes

class RandomAgent (index, **kwargs)

An agent that moves randomly while still obeying the rules.

Expand source code
class RandomAgent(BaseAgent):
    """
    An agent that moves randomly while still obeying the rules.
    """

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

    def getAction(self, state):
        return random.choice(state.getLegalActions(self.index))

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):
    return random.choice(state.getLegalActions(self.index))
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.