本文整理汇总了Python中captureAgents.CaptureAgent类的典型用法代码示例。如果您正苦于以下问题:Python CaptureAgent类的具体用法?Python CaptureAgent怎么用?Python CaptureAgent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CaptureAgent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: registerInitialState
def registerInitialState(self, gameState):
"Initializes beliefs and inference modules"
CaptureAgent.registerInitialState(self, gameState)
self.inferenceModules = [ExactInference(RandomGhost(a), self) for a in self.getOpponents(gameState)]
for inference in self.inferenceModules: inference.initialize(gameState)
self.enemyBeliefs = [inf.getBeliefDistribution() for inf in self.inferenceModules]
self.firstMove = True
示例2: registerInitialState
def registerInitialState(self, gameState):
"""
This method handles the initial setup of the
agent to populate useful fields (such as what team
we're on).
A distanceCalculator instance caches the maze distances
between each pair of positions, so your agents can use:
self.distancer.getDistance(p1, p2)
IMPORTANT: This method may run for at most 15 seconds.
"""
'''
Make sure you do not delete the following line. If you would like to
use Manhattan distances instead of maze distances in order to save
on initialization time, please take a look at
CaptureAgent.registerInitialState in captureAgents.py.
'''
CaptureAgent.registerInitialState(self, gameState)
'''
Your initialization code goes here, if you need any.
'''
self.start = gameState.getAgentPosition(self.index)
示例3: registerInitialState
def registerInitialState(self, gameState):
"""
This method handles the initial setup of the
agent to populate useful fields (such as what team
we're on).
A distanceCalculator instance caches the maze distances
between each pair of positions, so your agents can use:
self.distancer.getDistance(p1, p2)
IMPORTANT: This method may run for at most 15 seconds.
"""
'''
Make sure you do not delete the following line. If you would like to
use Manhattan distances instead of maze distances in order to save
on initialization time, please take a look at
CaptureAgent.registerInitialState in captureAgents.py.
'''
CaptureAgent.registerInitialState(self, gameState)
#set up data repository
if self.red:
if not TeamData.RedData:
TeamData.RedData=TeamData(gameState, self.getTeam(gameState), self.getOpponents(gameState), self)
self.data=TeamData.RedData
else:
if not TeamData.BlueData:
TeamData.BlueData=TeamData(gameState, self.getTeam(gameState), self.getOpponents(gameState), self)
self.data=TeamData.BlueData
self.legalPositions=self.data.legalPositions
self.offensive = self.data.getOffensive()
示例4: registerInitialState
def registerInitialState(self, gameState):
"""
This method handles the initial setup of the
agent to populate useful fields (such as what team
we're on).
A distanceCalculator instance caches the maze distances
between each pair of positions, so your agents can use:
self.distancer.getDistance(p1, p2)
IMPORTANT: This method may run for at most 15 seconds.
"""
'''
Make sure you do not delete the following line. If you would like to
use Manhattan distances instead of maze distances in order to save
on initialization time, please take a look at
CaptureAgent.registerInitialState in captureAgents.py.
'''
CaptureAgent.registerInitialState(self, gameState)
'''
Your initialization code goes here, if you need any.
'''
# self.evaluationFunction = util.lookup('evaluate', globals())
self.evaluationFunction = gameState.getScore()
self.myTeam = self.getTeam(gameState)
self.opponents = self.getOpponents(gameState)
print "Opponents for agent ", self.index, "are ", self.opponents
self.agentIndices = sorted(self.myTeam + self.opponents)
self.treeDepth = 2 # int('1') didn't break either
示例5: chooseAction
def chooseAction(self, gameState):
"""
Picks among actions randomly.
"""
actions = gameState.getLegalActions(self.index)
'''
You should change this in your own agent.
'''
optimalAction = "Stop"
danger = False
threshold = 8
for enemy in self.enemyTeam:
if CaptureAgent.getMazeDistance(self, getAgentDistances(enemy), gameState.getAgentPosition(self.index)) < threshold:
danger = True
if danger == True:
optimalAction = random.choice(actions)
else:
optimal = 999
for action in actions:
successor = self.getSuccessor(gameState, action)
foodList = self.getFood(successor).asList()
myPos = successor.getAgentState(self.index).getPosition()
minDistance = min([(self.getMazeDistance(myPos, food), food) for food in foodList])
food = minDistance[1]
distance = CaptureAgent.getMazeDistance(self, successor.getAgentPosition(self.index), food)
if distance < optimal:
optimal = distance
optimalAction = action
return optimalAction
示例6: registerInitialState
def registerInitialState(self, gameState):
CaptureAgent.registerInitialState(self, gameState)
global beliefs
global validPositions
self.distributions = []
self.lastAction = None
self.lastFood = None
self.lastPositions = {}
self.agentFoodEaten = {}
self.positionCount = {}
self.optimalBlocks = None
self.lastBestBlock = None
self.bestDefensePositions = None
self.trappedFood = None
self.lastMoves = []
self.pacmanTime = {}
for enemyIndex in self.getOpponents(gameState):
self.agentFoodEaten[enemyIndex] = 0
self.pacmanTime[enemyIndex] = 0
if len(validPositions) == 0:
# All positions are those that are not walls
validPositions = gameState.getWalls().asList(False)
# We know that each enemy must be at its initial position at registration
for enemyIndex in self.getOpponents(gameState):
self.establishLocation(enemyIndex, gameState.getInitialAgentPosition(enemyIndex))
示例7: registerInitialState
def registerInitialState(self, gameState):
self.start = gameState.getAgentPosition(self.index)
CaptureAgent.registerInitialState(self, gameState)
self.debugging = False
self.stationaryTolerance = random.randint(6,16)
self.depth = 6
"G A M E K E Y L O C A T I O N S D E T E R M I N A T I O N"
if self.red:
leftEdge = gameState.data.layout.width / 2
rightEdge = gameState.data.layout.width - 2
self.safeColumn = leftEdge - 1
self.opSafeColumn = leftEdge
else:
leftEdge = 1
rightEdge = gameState.data.layout.width / 2
self.safeColumn = rightEdge
self.opSafeColumn = rightEdge - 1
self.safeSpaces = []
self.opSafeSpaces = []
for h in xrange(1,gameState.data.layout.height-1):
if not gameState.data.layout.isWall((self.safeColumn, h)):
self.safeSpaces += [(self.safeColumn, h)]
if not gameState.data.layout.isWall((self.opSafeColumn, h)):
self.opSafeSpaces += [(self.opSafeColumn, h)]
if self.debugging:
print "Coloring my safe column white"
self.debugDraw([(self.safeColumn, el) for el in xrange(0, gameState.data.layout.height)], [1,1,1], clear=False)
print "Coloring my safe spaces", self.safeSpaces, "blue"
self.debugDraw(self.safeSpaces, [0,0,1], clear=False)
示例8: registerInitialState
def registerInitialState(self, gameState):
"""
This method handles the initial setup of the
agent to populate useful fields (such as what team
we're on).
A distanceCalculator instance caches the maze distances
between each pair of positions, so your agents can use:
self.distancer.getDistance(p1, p2)
IMPORTANT: This method may run for at most 15 seconds.
"""
# Blue index = 1,3, red = 0,2
start = time.time()
CaptureAgent.registerInitialState(self, gameState)
self.dieCount = 0
if self.index < 2: #one attacker and one defender at the beginning
self.is_attacker = True
else:
self.is_attacker = False
self.opponents = self.getOpponents(gameState)
self.teammate = self.getTeammate()
f = open('data/input_data','r')
self.factors = [int(i) for i in f.read().replace('\n','').split(' ')]
self.is_ghost = True
self.carryingFood = 0 #food you are carrying
if self.red:
self.middle_line = gameState.data.layout.width/2-1
else:
self.middle_line = gameState.data.layout.width/2
self.dangerousness = self.getDangerousness(gameState)
if debug:
print 'eval time for agent %d: %.4f' % (self.index, time.time() - start)
示例9: registerInitialState
def registerInitialState(self, gameState):
CaptureAgent.registerInitialState(self, gameState)
gameStr = str(gameState)
# rows = gameStr.count("\n") + 1
# cols = (len(gameStr) - (rows - 1)) / rows
rows = 30
cols = 14
moveMap = {}
print rows, cols
print gameStr
for x in xrange(rows):
for y in xrange(cols):
print x, y
if not gameState.hasWall(x, y):
moveMap[(x, y)] = self.getPotentialMoves(gameState, x, y)
for (x, y) in moveMap:
length = len(moveMap[(x, y)])
if length != 2:
V.append((x, y))
for (x, y) in moveMap:
if (x, y) not in V:
E.append(self.dfsToVertex(moveMap, (x, y), []))
示例10: __init__
def __init__(self, index):
CaptureAgent.__init__(self, index)
self.firstTurnComplete = False
self.startingFood = 0
self.theirStartingFood = 0
self.legalPositions = None
self.estimate = util.Counter()
示例11: registerInitialState
def registerInitialState(self, gameState):
CaptureAgent.registerInitialState(self, gameState)
#self.particleFilters = [ParticleFilter(gameState.getAgent(opponentIndex), opponentIndex) for opponentIndex in self.getOpponents(gameState)]
self.mostLikelyPositions = {}
self.particleFilters = {}
for i in self.getOpponents(gameState):
self.particleFilters[i] = ParticleFilter(gameState.getAgentState(i), i, self.index)
self.particleFilters[i].initializeUniformly(gameState) #FIXME Should these all initially point toward the corner?
示例12: registerInitialState
def registerInitialState(self, gameState):
"""
This method handles the initial setup of the
agent to populate useful fields (such as what team
we're on).
A distanceCalculator instance caches the maze distances
between each pair of positions, so your agents can use:
self.distancer.getDistance(p1, p2)
IMPORTANT: This method may run for at most 15 seconds.
"""
'''
Make sure you do not delete the following line. If you would like to
use Manhattan distances instead of maze distances in order to save
on initialization time, please take a look at
CaptureAgent.registerInitialState in captureAgents.py.
'''
CaptureAgent.registerInitialState(self, gameState)
'''
Your initialization code goes here, if you need any.
'''
self.initialize(gameState)
self.initializeBeliefs(gameState)
self.isRed = self.red
#Get width and height of maze
self.getMazeDimensions(gameState)
#print self.legalPositions , "Legal"
#print self.walls, "Wall"
'''
HoverZones - Regions where our ghosts will hangout
Basically a vertical band near the transition area
'''
self.hoverZones = []
self.initializeHoverZones(gameState)
#print "hoverZones ", self.hoverZones
quarterHeight = len(self.hoverZones) / 4
threeFourthsHeight = 3 * len(self.hoverZones) / 4
if self.index < 2:
x, y = self.hoverZones[quarterHeight]
else:
x, y = self.hoverZones[threeFourthsHeight]
self.target = (x, y)
#How many moves should our agent attack?
self.moves = 0
#Has the pacman just been killed?
self.pacmanKill = False
示例13: registerInitialState
def registerInitialState(self,gameState):
CaptureAgent.registerInitialState(self, gameState) #Pointless comment
self.inferenceMods = {i:ExactInference(i,self.index,gameState) for i in self.getOpponents(gameState)}
if self.isTimerTracker:
self.isTimerTracker=True
RaptorAgent.isTimerTracker=False
self.foodNum = 0
if (not gameState.isOnRedTeam(self.index)):
RaptorAgent.weights['score']=-abs(RaptorAgent.weights['score'])
示例14: registerInitialState
def registerInitialState(self, gameState):
"""
Initialize the beliefs of the enemies uniformly
and many related operations
"""
start = time.time()
CaptureAgent.registerInitialState(self, gameState)
global beliefs
# legalPositions is a useful variable. it's not provided! let's construct it
width = gameState.data.layout.width
height = gameState.data.layout.height
self.legalPositions = [(x, y) for x in range(width) for y in range(height) if not gameState.hasWall(x, y)]
# set legalPositions for defending and offending respectively
self.defensiveLegalPositions = [p for p in self.legalPositions if self.isOurTerrain(gameState, p)]
self.offensiveLegalPositions = [p for p in self.legalPositions if not (p in self.defensiveLegalPositions)]
# initialize beliefs according to legalPositions
for enemyId in self.getOpponents(gameState):
self.initializeBeliefs(gameState, enemyId, initial = True)
# set availableActions for each grid
self.setNeighbors(gameState)
# set distances on each side
# using global buffer to save time
global buff
if buff == None:
buff = util.Counter()
buff['dd'] = self.getDistances(gameState, self.defensiveLegalPositions)
#buff['dsd'] = self.getSecondDistances(gameState, buff['dd'], self.defensiveLegalPositions)
buff['od'] = self.getDistances(gameState, self.offensiveLegalPositions)
self.defensiveDistance = buff['dd']
#self.defensiveSecondDistance = buff['dsd']
self.offensiveDistance = buff['od']
# set boundaries - entries of the enemy!
self.setBoundary(gameState)
# set trainsition model
self.transition = util.Counter()
self.transition['favor'] = 0.8
self.transition['indifferent'] = 0.05
self.helpDefending = False # initialy, it's not defending
self.alert = 3
# these are for offensive agents.
if self.__class__.__name__ == "OffensiveReflexAgent":
self.role = "offensive"
self.disToDefender = None
else:
self.role = "defensive"
self.crazy = False # it would be crazy if scared
示例15: registerInitialState
def registerInitialState(self, gameState):
CaptureAgent.registerInitialState(self, gameState)
self.ready = False
myTeam = self.getTeam(gameState)
self.team = {}
self.team[myTeam[0]] = 1
self.team[myTeam[1]] = 2
startx = gameState.getWalls().width / 2
starty = gameState.getWalls().height / 2
startPos = []
if self.getTeam(gameState)[0] % 2 != 0:
startx -= 1
self.temStartPoint = (startx, starty)
minDist = 99999
myPos = gameState.getAgentState(self.index).getPosition()
while starty >= 0:
if gameState.hasWall(startx, starty) == False:
dist = self.getMazeDistance(myPos, (startx, starty))
if dist < minDist:
self.Bstart = (startx, starty)
minDist = dist
starty -= 1
startx, starty = self.temStartPoint
minDist = 99999
for i in xrange(gameState.getWalls().height - starty):
if gameState.hasWall(startx, starty) == False:
dist = self.getMazeDistance(myPos, (startx, starty))
if dist < minDist:
self.Astart = (startx, starty)
minDist = dist
starty += 1
self.start = (16, 15)
self.status = None
basePoint = gameState.getAgentState(myTeam[1]).getPosition()
x = basePoint[0]
y = basePoint[1]
self.opponentStatus = {}
if self.getTeam(gameState)[0] % 2 != 0: ## set the origin point,the team is blue
self.teamName = "blue"
if self.index == 1:
self.basePoint = [(x, y - 1), (float(x), float(y - 1))]
elif self.index == 3:
self.basePoint = [(x, y), (float(x), float(y))]
self.opponentStatus[0] = False
self.opponentStatus[2] = False
else:
self.teamName = "red"
if self.index == 0:
self.basePoint = [(x, y + 1), (float(x), float(y + 1))]
elif self.index == 2:
self.basePoint = [(x, y), (float(x), float(y))]
self.opponentStatus[1] = False
self.opponentStatus[3] = False