當前位置: 首頁>>代碼示例>>Python>>正文


Python Actions.directionToVector方法代碼示例

本文整理匯總了Python中game.Actions.directionToVector方法的典型用法代碼示例。如果您正苦於以下問題:Python Actions.directionToVector方法的具體用法?Python Actions.directionToVector怎麽用?Python Actions.directionToVector使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在game.Actions的用法示例。


在下文中一共展示了Actions.directionToVector方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: applyAction

# 需要導入模塊: from game import Actions [as 別名]
# 或者: from game.Actions import directionToVector [as 別名]
def applyAction( state, action ):
        """
        Edits the state to reflect the results of the action.
        """
        legal = PacmanRules.getLegalActions( state )
        if action not in legal:
            raise Exception("Illegal action " + str(action))

        pacmanState = state.data.agentStates[0]

        # Update Configuration
        vector = Actions.directionToVector( action, PacmanRules.PACMAN_SPEED )
        pacmanState.configuration = pacmanState.configuration.generateSuccessor( vector )

        # Eat
        next = pacmanState.configuration.getPosition()
        nearest = nearestPoint( next )
        if manhattanDistance( nearest, next ) <= 0.5 :
            # Remove food
            PacmanRules.consume( nearest, state ) 
開發者ID:AUTBS,項目名稱:AI-Pacman,代碼行數:22,代碼來源:pacman.py

示例2: applyAction

# 需要導入模塊: from game import Actions [as 別名]
# 或者: from game.Actions import directionToVector [as 別名]
def applyAction( state, action ):
    """
    Edits the state to reflect the results of the action.
    """
    legal = PacmanRules.getLegalActions( state )
    if action not in legal:
      raise Exception("Illegal action " + str(action))

    pacmanState = state.data.agentStates[0]

    # Update Configuration
    vector = Actions.directionToVector( action, PacmanRules.PACMAN_SPEED )
    pacmanState.configuration = pacmanState.configuration.generateSuccessor( vector )

    # Eat
    next = pacmanState.configuration.getPosition()
    nearest = nearestPoint( next )
    if manhattanDistance( nearest, next ) <= 0.5 :
      # Remove food
      PacmanRules.consume( nearest, state ) 
開發者ID:jrios6,項目名稱:Berkeley-AI-PacMan-Lab-1,代碼行數:22,代碼來源:pacman.py

示例3: getSuccessors

# 需要導入模塊: from game import Actions [as 別名]
# 或者: from game.Actions import directionToVector [as 別名]
def getSuccessors(self, state):
        """
        Returns successor states, the actions they require, and a cost of 1.

         As noted in search.py:
            For a given state, this should return a list of triples, (successor,
            action, stepCost), where 'successor' is a successor to the current
            state, 'action' is the action required to get there, and 'stepCost'
            is the incremental cost of expanding to that successor
        """

        successors = []
        for action in [Directions.NORTH, Directions.SOUTH, Directions.EAST, Directions.WEST]:
            # Add a successor state to the successor list if the action is legal
            # Here's a code snippet for figuring out whether a new position hits a wall:
            #   x,y = currentPosition
            #   dx, dy = Actions.directionToVector(action)
            #   nextx, nexty = int(x + dx), int(y + dy)
            #   hitsWall = self.walls[nextx][nexty]

            "*** YOUR CODE HERE ***"

        self._expanded += 1 # DO NOT CHANGE
        return successors 
開發者ID:mttk,項目名稱:AIclass,代碼行數:26,代碼來源:searchAgents.py

示例4: getDistribution

# 需要導入模塊: from game import Actions [as 別名]
# 或者: from game.Actions import directionToVector [as 別名]
def getDistribution( self, state ):
        # Read variables from state
        ghostState = state.getGhostState( self.index )
        legalActions = state.getLegalActions( self.index )
        pos = state.getGhostPosition( self.index )
        isScared = ghostState.scaredTimer > 0

        speed = 1
        if isScared: speed = 0.5

        actionVectors = [Actions.directionToVector( a, speed ) for a in legalActions]
        newPositions = [( pos[0]+a[0], pos[1]+a[1] ) for a in actionVectors]
        pacmanPosition = state.getPacmanPosition()

        # Select best actions given the state
        distancesToPacman = [manhattanDistance( pos, pacmanPosition ) for pos in newPositions]
        if isScared:
            bestScore = max( distancesToPacman )
            bestProb = self.prob_scaredFlee
        else:
            bestScore = min( distancesToPacman )
            bestProb = self.prob_attack
        bestActions = [action for action, distance in zip( legalActions, distancesToPacman ) if distance == bestScore]

        # Construct distribution
        dist = util.Counter()
        for a in bestActions: dist[a] = bestProb / len(bestActions)
        for a in legalActions: dist[a] += ( 1-bestProb ) / len(legalActions)
        dist.normalize()
        return dist 
開發者ID:AUTBS,項目名稱:AI-Pacman,代碼行數:32,代碼來源:ghostAgents.py

示例5: applyAction

# 需要導入模塊: from game import Actions [as 別名]
# 或者: from game.Actions import directionToVector [as 別名]
def applyAction(state, action):
        """
        Edits the actions to reflect the results of the actions.
        """
        legal = TargetRules.getLegalActions(state)
        if action not in legal:
            raise Exception("Illegal action" + str(action))
        targetState = state.data.agentStates[0]

        # Update configuration
        # vector = Actions.directionToVector(action, TargetRules.TARGET_SPEED)
        targetState.configuration = targetState.configuration.generateSuccessor(action)
        # 
開發者ID:namidairo777,項目名稱:xiao_multiagent,代碼行數:15,代碼來源:multiAgent.py

示例6: getDistribution

# 需要導入模塊: from game import Actions [as 別名]
# 或者: from game.Actions import directionToVector [as 別名]
def getDistribution( self, state ):
    # Read variables from state
    ghostState = state.getGhostState( self.index )
    legalActions = state.getLegalActions( self.index )
    pos = state.getGhostPosition( self.index )
    isScared = ghostState.scaredTimer > 0
    
    speed = 1
    if isScared: speed = 0.5
    
    actionVectors = [Actions.directionToVector( a, speed ) for a in legalActions]
    newPositions = [( pos[0]+a[0], pos[1]+a[1] ) for a in actionVectors]
    pacmanPosition = state.getPacmanPosition()

    # Select best actions given the state
    distancesToPacman = [manhattanDistance( pos, pacmanPosition ) for pos in newPositions]
    if isScared:
      bestScore = max( distancesToPacman )
      bestProb = self.prob_scaredFlee
    else:
      bestScore = min( distancesToPacman )
      bestProb = self.prob_attack
    bestActions = [action for action, distance in zip( legalActions, distancesToPacman ) if distance == bestScore]
    
    # Construct distribution
    dist = util.Counter()
    for a in bestActions: dist[a] = bestProb / len(bestActions)
    for a in legalActions: dist[a] += ( 1-bestProb ) / len(legalActions)
    dist.normalize()
    return dist 
開發者ID:jrios6,項目名稱:Berkeley-AI-PacMan-Lab-1,代碼行數:32,代碼來源:ghostAgents.py

示例7: getSuccessors

# 需要導入模塊: from game import Actions [as 別名]
# 或者: from game.Actions import directionToVector [as 別名]
def getSuccessors(self, state):
    """
    Returns successor states, the actions they require, and a cost of 1.

     As noted in search.py:
         For a given state, this should return a list of triples,
     (successor, action, stepCost), where 'successor' is a
     successor to the current state, 'action' is the action
     required to get there, and 'stepCost' is the incremental
     cost of expanding to that successor
    """

    successors = []
    for action in [Directions.NORTH, Directions.SOUTH, Directions.EAST, Directions.WEST]:
      x,y = state
      dx, dy = Actions.directionToVector(action)
      nextx, nexty = int(x + dx), int(y + dy)
      if not self.walls[nextx][nexty]:
        nextState = (nextx, nexty)
        cost = self.costFn(nextState)
        successors.append( ( nextState, action, cost) )

    # Bookkeeping for display purposes
    self._expanded += 1
    if state not in self._visited:
      self._visited[state] = True
      self._visitedlist.append(state)

    return successors 
開發者ID:jrios6,項目名稱:Berkeley-AI-PacMan-Lab-1,代碼行數:31,代碼來源:searchAgents.py

示例8: getCostOfActions

# 需要導入模塊: from game import Actions [as 別名]
# 或者: from game.Actions import directionToVector [as 別名]
def getCostOfActions(self, actions):
    """
    Returns the cost of a particular sequence of actions.  If those actions
    include an illegal move, return 999999
    """
    if actions == None: return 999999
    x,y= self.getStartState()
    cost = 0
    for action in actions:
      # Check figure out the next state and see whether its' legal
      dx, dy = Actions.directionToVector(action)
      x, y = int(x + dx), int(y + dy)
      if self.walls[x][y]: return 999999
      cost += self.costFn((x,y))
    return cost 
開發者ID:jrios6,項目名稱:Berkeley-AI-PacMan-Lab-1,代碼行數:17,代碼來源:searchAgents.py

示例9: getStatesFromPath

# 需要導入模塊: from game import Actions [as 別名]
# 或者: from game.Actions import directionToVector [as 別名]
def getStatesFromPath(start, path):
    "Returns the list of states visited along the path"
    vis = [start]
    curr = start
    for a in path:
        x,y = curr
        dx, dy = Actions.directionToVector(a)
        curr = (int(x + dx), int(y + dy))
        vis.append(curr)
    return vis 
開發者ID:ryanshrott,項目名稱:Pacman-AI,代碼行數:12,代碼來源:searchTestClasses.py

示例10: getSuccessors

# 需要導入模塊: from game import Actions [as 別名]
# 或者: from game.Actions import directionToVector [as 別名]
def getSuccessors(self, state):
    """
    Returns successor states, the actions they require, and a cost of 1.
    
     As noted in search.py:
         For a given state, this should return a list of triples, 
     (successor, action, stepCost), where 'successor' is a 
     successor to the current state, 'action' is the action
     required to get there, and 'stepCost' is the incremental 
     cost of expanding to that successor
    """
    
    successors = []
    for action in [Directions.NORTH, Directions.SOUTH, Directions.EAST, Directions.WEST]:
      x,y = state
      dx, dy = Actions.directionToVector(action)
      nextx, nexty = int(x + dx), int(y + dy)
      if not self.walls[nextx][nexty]:
        nextState = (nextx, nexty)
        cost = self.costFn(nextState)
        successors.append( ( nextState, action, cost) )
        
    # Bookkeeping for display purposes
    self._expanded += 1 
    if state not in self._visited:
      self._visited[state] = True
      self._visitedlist.append(state)
      
    return successors 
開發者ID:ryanshrott,項目名稱:Pacman-AI,代碼行數:31,代碼來源:searchAgents.py

示例11: getCostOfActions

# 需要導入模塊: from game import Actions [as 別名]
# 或者: from game.Actions import directionToVector [as 別名]
def getCostOfActions(self, actions):
    """
    Returns the cost of a particular sequence of actions.  If those actions
    include an illegal move, return 999999.  This is implemented for you.
    """
    #print(actions)
    if actions == None: return 999999
    x,y= self.startingPosition
    for action in actions:
      dx, dy = Actions.directionToVector(action)
      x, y = int(x + dx), int(y + dy)
      if self.walls[x][y]: return 999999
    return len(actions) 
開發者ID:ryanshrott,項目名稱:Pacman-AI,代碼行數:15,代碼來源:searchAgents.py

示例12: getFeatures

# 需要導入模塊: from game import Actions [as 別名]
# 或者: from game.Actions import directionToVector [as 別名]
def getFeatures(self, state, action):
    # extract the grid of food and wall locations and get the ghost locations
    food = state.getFood()
    walls = state.getWalls()
    ghosts = state.getGhostPositions()

    features = util.Counter()
    
    features["bias"] = 1.0
    
    # compute the location of pacman after he takes the action
    x, y = state.getPacmanPosition()
    dx, dy = Actions.directionToVector(action)
    next_x, next_y = int(x + dx), int(y + dy)
    
    # count the number of ghosts 1-step away
    features["#-of-ghosts-1-step-away"] = sum((next_x, next_y) in Actions.getLegalNeighbors(g, walls) for g in ghosts)

    # if there is no danger of ghosts then add the food feature
    if not features["#-of-ghosts-1-step-away"] and food[next_x][next_y]:
      features["eats-food"] = 1.0
    
    dist = closestFood((next_x, next_y), food, walls)
    if dist is not None:
      # make the distance a number less than one otherwise the update
      # will diverge wildly
      features["closest-food"] = float(dist) / (walls.width * walls.height) 
    features.divideAll(10.0)
    return features 
開發者ID:victorgrego,項目名稱:Reinforcement-Learning,代碼行數:31,代碼來源:featureExtractors.py

示例13: getSuccessors

# 需要導入模塊: from game import Actions [as 別名]
# 或者: from game.Actions import directionToVector [as 別名]
def getSuccessors(self, state):
        """
        Returns successor states, the actions they require, and a cost of 1.

         As noted in search.py:
             For a given state, this should return a list of triples,
         (successor, action, stepCost), where 'successor' is a
         successor to the current state, 'action' is the action
         required to get there, and 'stepCost' is the incremental
         cost of expanding to that successor
        """

        successors = []
        for action in [Directions.NORTH, Directions.SOUTH, Directions.EAST, Directions.WEST]:
            x,y = state
            dx, dy = Actions.directionToVector(action)
            nextx, nexty = int(x + dx), int(y + dy)
            if not self.walls[nextx][nexty]:
                nextState = (nextx, nexty)
                cost = self.costFn(nextState)
                successors.append( ( nextState, action, cost) )

        # Bookkeeping for display purposes
        self._expanded += 1 # DO NOT CHANGE
        if state not in self._visited:
            self._visited[state] = True
            self._visitedlist.append(state)

        return successors 
開發者ID:deepeshmittal,項目名稱:AI-PacMan-Projects,代碼行數:31,代碼來源:searchAgents.py

示例14: getCostOfActions

# 需要導入模塊: from game import Actions [as 別名]
# 或者: from game.Actions import directionToVector [as 別名]
def getCostOfActions(self, actions):
        """
        Returns the cost of a particular sequence of actions. If those actions
        include an illegal move, return 999999.
        """
        if actions == None: return 999999
        x,y= self.getStartState()
        cost = 0
        for action in actions:
            # Check figure out the next state and see whether its' legal
            dx, dy = Actions.directionToVector(action)
            x, y = int(x + dx), int(y + dy)
            if self.walls[x][y]: return 999999
            cost += self.costFn((x,y))
        return cost 
開發者ID:deepeshmittal,項目名稱:AI-PacMan-Projects,代碼行數:17,代碼來源:searchAgents.py


注:本文中的game.Actions.directionToVector方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。