Module pacai.agents.search.staydirection
Expand source code
from pacai.agents.search.base import SearchAgent
from pacai.core.search import search
from pacai.core.search.position import PositionSearchProblem
class StayEastSearchAgent(SearchAgent):
"""
An agent for `pacai.core.search.position.PositionSearchProblem`
with a cost function that penalizes being on the West side of the board.
The cost function for stepping into a position (x, y) is `(1/2)^x`.
"""
def __init__(self, index, **kwargs):
super().__init__(index, **kwargs)
self.searchFunction = search.ucs
costFn = lambda pos: 0.5 ** pos[0]
self.searchType = lambda state: PositionSearchProblem(state, costFn)
class StayWestSearchAgent(SearchAgent):
"""
An agent for `pacai.core.search.position.PositionSearchProblem`
with a cost function that penalizes being on the East side of the board.
The cost function for stepping into a position (x, y) is `2^x`.
"""
def __init__(self, index, **kwargs):
super().__init__(index, **kwargs)
self.searchFunction = search.ucs
costFn = lambda pos: 2 ** pos[0]
self.searchType = lambda state: PositionSearchProblem(state, costFn)
Classes
class StayEastSearchAgent (index, **kwargs)
-
An agent for
PositionSearchProblem
with a cost function that penalizes being on the West side of the board.The cost function for stepping into a position (x, y) is
(1/2)^x
.Expand source code
class StayEastSearchAgent(SearchAgent): """ An agent for `pacai.core.search.position.PositionSearchProblem` with a cost function that penalizes being on the West side of the board. The cost function for stepping into a position (x, y) is `(1/2)^x`. """ def __init__(self, index, **kwargs): super().__init__(index, **kwargs) self.searchFunction = search.ucs costFn = lambda pos: 0.5 ** pos[0] self.searchType = lambda state: PositionSearchProblem(state, costFn)
Ancestors
- SearchAgent
- BaseAgent
- abc.ABC
Static methods
def loadAgent(name, index, args={})
-
Inherited from:
SearchAgent
.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:
SearchAgent
.final
Inform the agent about the result of a game.
def getAction(self, state)
-
Inherited from:
SearchAgent
.getAction
Returns the next action in the path chosen earlier (in registerInitialState). Return Directions.STOP if there is no further action to take.
def observationFunction(self, state)
-
Inherited from:
SearchAgent
.observationFunction
Make an observation on the state of the game. Called once for each round of the game.
def registerInitialState(self, state)
-
Inherited from:
SearchAgent
.registerInitialState
This is the first time that the agent sees the layout of the game board. Here, we choose a path to the goal. In this phase, the agent should compute …
class StayWestSearchAgent (index, **kwargs)
-
An agent for
PositionSearchProblem
with a cost function that penalizes being on the East side of the board.The cost function for stepping into a position (x, y) is
2^x
.Expand source code
class StayWestSearchAgent(SearchAgent): """ An agent for `pacai.core.search.position.PositionSearchProblem` with a cost function that penalizes being on the East side of the board. The cost function for stepping into a position (x, y) is `2^x`. """ def __init__(self, index, **kwargs): super().__init__(index, **kwargs) self.searchFunction = search.ucs costFn = lambda pos: 2 ** pos[0] self.searchType = lambda state: PositionSearchProblem(state, costFn)
Ancestors
- SearchAgent
- BaseAgent
- abc.ABC
Static methods
def loadAgent(name, index, args={})
-
Inherited from:
SearchAgent
.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:
SearchAgent
.final
Inform the agent about the result of a game.
def getAction(self, state)
-
Inherited from:
SearchAgent
.getAction
Returns the next action in the path chosen earlier (in registerInitialState). Return Directions.STOP if there is no further action to take.
def observationFunction(self, state)
-
Inherited from:
SearchAgent
.observationFunction
Make an observation on the state of the game. Called once for each round of the game.
def registerInitialState(self, state)
-
Inherited from:
SearchAgent
.registerInitialState
This is the first time that the agent sees the layout of the game board. Here, we choose a path to the goal. In this phase, the agent should compute …