当前位置: 首页>>代码示例>>Python>>正文


Python captureAgents.CaptureAgent类代码示例

本文整理汇总了Python中captureAgents.CaptureAgent的典型用法代码示例。如果您正苦于以下问题:Python CaptureAgent类的具体用法?Python CaptureAgent怎么用?Python CaptureAgent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了CaptureAgent类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:stephenchiang,项目名称:pacman,代码行数:7,代码来源:baselineAgents.py


示例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)
开发者ID:cjzcpsyx,项目名称:UCBerkeley,代码行数:25,代码来源:backup3.py


示例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()
开发者ID:adrsamanta,项目名称:CS-4260,代码行数:33,代码来源:myTeam.py


示例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
开发者ID:bradcardello,项目名称:cmps140project,代码行数:31,代码来源:test.py


示例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
开发者ID:IanDrynan,项目名称:PacMan-Ai-Project,代码行数:33,代码来源:myTeam.py


示例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))
开发者ID:keerthanakumar,项目名称:contest,代码行数:30,代码来源:workingHumbleAgents.py


示例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)
开发者ID:zzeleznick,项目名称:contest1,代码行数:33,代码来源:yimpTeam.py


示例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)
开发者ID:noname8135,项目名称:metaheu_final_prj,代码行数:32,代码来源:ShuaiTeam.py


示例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), []))
开发者ID:keerthanakumar,项目名称:contest,代码行数:26,代码来源:notAnAgent.py


示例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()
开发者ID:rioleo,项目名称:Team-Radr,代码行数:8,代码来源:ninjaAgents.py


示例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?
开发者ID:ramsay-shuck,项目名称:contest,代码行数:8,代码来源:Bayesians.py


示例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
开发者ID:aditvenk,项目名称:pacman-ctf,代码行数:58,代码来源:myTeam.py


示例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'])
开发者ID:Arctangent1759,项目名称:Amphibious-Caveman-of-the-Drunken-Blood-God,代码行数:9,代码来源:myTeam.py


示例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
开发者ID:raowang87,项目名称:homework_2012,代码行数:56,代码来源:agents.py


示例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
开发者ID:AlanLyu1992,项目名称:Pacman-contest,代码行数:56,代码来源:Flamingo.py


示例16: __init__

 def __init__(self, index, timeForComputing=.1):
     CaptureAgent.__init__(self, index, timeForComputing)
     team.append(self)
     
     if self.index % 2 == 0:
         self.isRed = True
         self.middle = (ReflexCaptureAgent.MAP_WIDTH / 4, ReflexCaptureAgent.MAP_HEIGHT / 2)
     else:
         self.isRed = False
         self.middle = (ReflexCaptureAgent.MAP_WIDTH * 3 / 4), (ReflexCaptureAgent.MAP_HEIGHT / 2)
开发者ID:dacphuc1993,项目名称:COMP90054_Pacman_contest,代码行数:10,代码来源:myTeam.py


示例17: registerInitialState

  def registerInitialState(self, gameState):
    CaptureAgent.registerInitialState(self, gameState)

    # Get all non-wall positions on the board
    self.legalPositions = gameState.data.layout.walls.asList(False)

    # Initialize position belief distributions for opponents
    self.positionBeliefs = {}
    for opponent in self.getOpponents(gameState):
      self.initializeBeliefs(opponent)
开发者ID:danxmoran,项目名称:pacmanCTF,代码行数:10,代码来源:agents.py


示例18: __init__

 def __init__(self, index):
   CaptureAgent.__init__(self, index)
   
   self.legalPositions = []
   
   "tuple with (boolean, belief distribution, actual/most probable position)"
   "TODO: Assumes 6 agents, will not always work"
   self.positions = [None, None, None, None, None, None] 
   
   self.firstMove = True
开发者ID:pabloc11,项目名称:awp-pacman,代码行数:10,代码来源:baselineAgents.py


示例19: __init__

  def __init__(self, index, timeForComputing = .1):
    CaptureAgent.__init__(self, index, timeForComputing)

    self.depth = 4
    self.numParticles = 10
    self.steps = [(0, 0), (0, 1), (1, 0), (-1, 0), (0, -1)]

    self.teammateLocations = {}
    self.enemyParticles = {}
    self.lastAction = None
开发者ID:keerthanakumar,项目名称:contest,代码行数:10,代码来源:theNameOfOurAgent.py


示例20: __init__

 def __init__( self, index, timeForComputing = .1 ):
     CaptureAgent.__init__( self, index, timeForComputing)
     print self.red, index, timeForComputing
     self.visibleAgents = []
     self.foodLeft = 0
     self.foodEaten = 0
     self.isPacman = False
     self.a = []
     self.first = True
     self.size = 0
开发者ID:Musket33rs,项目名称:Project2,代码行数:10,代码来源:cookieMonsters.py



注:本文中的captureAgents.CaptureAgent类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。