Module pacai.agents.capture.timeout

Classes

class TimeoutAgent (index, **kwargs)
Expand source code
class TimeoutAgent(CaptureAgent):
    """
    An agent that always waits a specified duration before making a random move.
    """

    # The duration to wait.
    # Testers may edit this directly (and reset() when done).
    waitMoveDurationSecs = DEFAULT_WAIT_DURATION_SECS
    waitInitDurationSecs = DEFAULT_WAIT_DURATION_SECS

    def reset():
        TimeoutAgent.waitMoveDurationSecs = DEFAULT_WAIT_DURATION_SECS
        TimeoutAgent.waitInitDurationSecs = DEFAULT_WAIT_DURATION_SECS

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

    def registerInitialState(self, gameState):
        # Wait first.
        time.sleep(TimeoutAgent.waitInitDurationSecs)

        super().registerInitialState(gameState)

    def chooseAction(self, gameState):
        # Wait first.
        time.sleep(TimeoutAgent.waitMoveDurationSecs)

        # Take a random action.
        actions = gameState.getLegalActions(self.index)
        return random.choice(actions)

An agent that always waits a specified duration before making a random move.

Ancestors

Class variables

var waitInitDurationSecs
var waitMoveDurationSecs

Static methods

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

Inherited from: CaptureAgent.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 chooseAction(self, gameState)

Inherited from: CaptureAgent.chooseAction

Expand source code
def chooseAction(self, gameState):
    # Wait first.
    time.sleep(TimeoutAgent.waitMoveDurationSecs)

    # Take a random action.
    actions = gameState.getLegalActions(self.index)
    return random.choice(actions)

Override this method to make a good agent. It should return a legal action within the time limit (otherwise a random legal action will be chosen for …

def final(self, gameState)

Inherited from: CaptureAgent.final

Inform the agent about the result of a game.

def getAction(self, gameState)

Inherited from: CaptureAgent.getAction

Calls CaptureAgent.chooseAction on a grid position, but continues on partial positions. If you subclass CaptureAgent, you shouldn't need to …

def getCurrentObservation(self)

Inherited from: CaptureAgent.getCurrentObservation

Returns the GameState object corresponding this agent's current observation (the observed state of the game - this may not include all of your …

def getFood(self, gameState)

Inherited from: CaptureAgent.getFood

Returns the food you're meant to eat. This is in the form of a Grid where m[x][y] = True if there is food you can eat (based on …

def getFoodYouAreDefending(self, gameState)

Inherited from: CaptureAgent.getFoodYouAreDefending

Returns the food you're meant to protect (i.e., that your opponent is supposed to eat). This is in the form of a Grid where `m[x][y] …

def getMazeDistance(self, pos1, pos2)

Inherited from: CaptureAgent.getMazeDistance

Returns the distance between two points using the builtin distancer.

def getOpponents(self, gameState)

Inherited from: CaptureAgent.getOpponents

Returns agent indices of your opponents. This is the list of the numbers of the agents (e.g., red might be 1, 3, 5)

def getPreviousObservation(self)

Inherited from: CaptureAgent.getPreviousObservation

Returns the AbstractGameState object corresponding to the last state this agent saw. That is the observed state of the game …

def getScore(self, gameState)

Inherited from: CaptureAgent.getScore

Returns how much you are beating the other team by in the form of a number that is the difference between your score and the opponents score. This …

def getTeam(self, gameState)

Inherited from: CaptureAgent.getTeam

Returns agent indices of your team. This is the list of the numbers of the agents (e.g., red might be the list of 1,3,5)

def observationFunction(self, state)

Inherited from: CaptureAgent.observationFunction

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

def registerInitialState(self, gameState)

Inherited from: CaptureAgent.registerInitialState

Expand source code
def registerInitialState(self, gameState):
    # Wait first.
    time.sleep(TimeoutAgent.waitInitDurationSecs)

    super().registerInitialState(gameState)

This method handles the initial setup of the agent and populates useful fields, such as the team the agent is on and the …

def registerTeam(self, agentsOnTeam)

Inherited from: CaptureAgent.registerTeam

Fills the self.agentsOnTeam field with a list of the indices of the agents on your team.

def reset()
Expand source code
def reset():
    TimeoutAgent.waitMoveDurationSecs = DEFAULT_WAIT_DURATION_SECS
    TimeoutAgent.waitInitDurationSecs = DEFAULT_WAIT_DURATION_SECS