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


Python Directions.STOP属性代码示例

本文整理汇总了Python中game.Directions.STOP属性的典型用法代码示例。如果您正苦于以下问题:Python Directions.STOP属性的具体用法?Python Directions.STOP怎么用?Python Directions.STOP使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在game.Directions的用法示例。


在下文中一共展示了Directions.STOP属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getFeatures

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import STOP [as 别名]
def getFeatures(self, gameState, action):
    features = util.Counter()
    successor = self.getSuccessor(gameState, action)

    myState = successor.getAgentState(self.index)
    myPos = myState.getPosition()

    # Computes whether we're on defense (1) or offense (0)
    features['onDefense'] = 1
    if myState.isPacman: features['onDefense'] = 0

    # Computes distance to invaders we can see
    enemies = [successor.getAgentState(i) for i in self.getOpponents(successor)]
    invaders = [a for a in enemies if a.isPacman and a.getPosition() != None]
    features['numInvaders'] = len(invaders)
    if len(invaders) > 0:
      dists = [self.getMazeDistance(myPos, a.getPosition()) for a in invaders]
      features['invaderDistance'] = min(dists)

    if action == Directions.STOP: features['stop'] = 1
    rev = Directions.REVERSE[gameState.getAgentState(self.index).configuration.direction]
    if action == rev: features['reverse'] = 1

    return features 
开发者ID:AUTBS,项目名称:AI-Pacman,代码行数:26,代码来源:DefensiveTeam.py

示例2: getFeatures

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import STOP [as 别名]
def getFeatures(self, gameState, action):
    features = util.Counter()
    successor = self.getSuccessor(gameState, action)

    myState = successor.getAgentState(self.index)
    myPos = myState.getPosition()

    # Computes whether we're on defense (1) or offense (0)
    features['onDefense'] = 1
    if myState.isPacman: features['onDefense'] = 0

    # Computes distance to invaders we can see
    # Computes distance to invaders we can see
    enemies = [successor.getAgentState(i) for i in self.getOpponents(successor)]
    invaders = [a for a in enemies if a.isPacman and a.getPosition() != None]
    features['numInvaders'] = len(invaders)
    if len(invaders) > 0:
      dists = [self.getMazeDistance(myPos, a.getPosition()) for a in invaders]
      features['invaderDistance'] = min(dists)

    if action == Directions.STOP: features['stop'] = 1
    rev = Directions.REVERSE[gameState.getAgentState(self.index).configuration.direction]
    if action == rev: features['reverse'] = 1

    return features 
开发者ID:AUTBS,项目名称:AI-Pacman,代码行数:27,代码来源:baselineTeam.py

示例3: initializeVisibilityMatrix

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import STOP [as 别名]
def initializeVisibilityMatrix(self):
        global VISIBILITY_MATRIX_CACHE
        if reduce(str.__add__, self.layoutText) not in VISIBILITY_MATRIX_CACHE:
            from game import Directions
            vecs = [(-0.5,0), (0.5,0),(0,-0.5),(0,0.5)]
            dirs = [Directions.NORTH, Directions.SOUTH, Directions.WEST, Directions.EAST]
            vis = Grid(self.width, self.height, {Directions.NORTH:set(), Directions.SOUTH:set(), Directions.EAST:set(), Directions.WEST:set(), Directions.STOP:set()})
            for x in range(self.width):
                for y in range(self.height):
                    if self.walls[x][y] == False:
                        for vec, direction in zip(vecs, dirs):
                            dx, dy = vec
                            nextx, nexty = x + dx, y + dy
                            while (nextx + nexty) != int(nextx) + int(nexty) or not self.walls[int(nextx)][int(nexty)] :
                                vis[x][y][direction].add((nextx, nexty))
                                nextx, nexty = x + dx, y + dy
            self.visibility = vis
            VISIBILITY_MATRIX_CACHE[reduce(str.__add__, self.layoutText)] = vis
        else:
            self.visibility = VISIBILITY_MATRIX_CACHE[reduce(str.__add__, self.layoutText)] 
开发者ID:AUTBS,项目名称:AI-Pacman,代码行数:22,代码来源:layout.py

示例4: getAction

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import STOP [as 别名]
def getAction( self, state):
        from graphicsUtils import keys_waiting
        from graphicsUtils import keys_pressed
        keys = keys_waiting() + keys_pressed()
        if keys != []:
            self.keys = keys

        legal = state.getLegalActions(self.index)
        move = self.getMove(legal)

        if move == Directions.STOP:
            # Try to move in the same direction as before
            if self.lastMove in legal:
                move = self.lastMove

        if (self.STOP_KEY in self.keys) and Directions.STOP in legal: move = Directions.STOP

        if move not in legal:
            move = random.choice(legal)

        self.lastMove = move
        return move 
开发者ID:AUTBS,项目名称:AI-Pacman,代码行数:24,代码来源:keyboardAgents.py

示例5: initializeVisibilityMatrix

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import STOP [as 别名]
def initializeVisibilityMatrix(self):
    global VISIBILITY_MATRIX_CACHE
    if reduce(str.__add__, self.layoutText) not in VISIBILITY_MATRIX_CACHE:
      from game import Directions
      vecs = [(-0.5,0), (0.5,0),(0,-0.5),(0,0.5)]
      dirs = [Directions.NORTH, Directions.SOUTH, Directions.WEST, Directions.EAST]
      vis = Grid(self.width, self.height, {Directions.NORTH:set(), Directions.SOUTH:set(), Directions.EAST:set(), Directions.WEST:set(), Directions.STOP:set()})
      for x in range(self.width):
        for y in range(self.height):
          if self.walls[x][y] == False:
            for vec, direction in zip(vecs, dirs):
              dx, dy = vec
              nextx, nexty = x + dx, y + dy
              while (nextx + nexty) != int(nextx) + int(nexty) or not self.walls[int(nextx)][int(nexty)] :
                vis[x][y][direction].add((nextx, nexty))
                nextx, nexty = x + dx, y + dy
      self.visibility = vis      
      VISIBILITY_MATRIX_CACHE[reduce(str.__add__, self.layoutText)] = vis
    else:
      self.visibility = VISIBILITY_MATRIX_CACHE[reduce(str.__add__, self.layoutText)] 
开发者ID:HarvardURC,项目名称:Pacbot,代码行数:22,代码来源:layout.py

示例6: getAction

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import STOP [as 别名]
def getAction( self, state):
    from graphicsUtils import keys_waiting
    from graphicsUtils import keys_pressed
    keys = keys_waiting() + keys_pressed()
    if keys != []:
      self.keys = keys
    
    legal = state.getLegalActions(self.index)
    move = self.getMove(legal)
    
    if move == Directions.STOP:
      # Try to move in the same direction as before
      if self.lastMove in legal:
        move = self.lastMove
    
    if (self.STOP_KEY in self.keys) and Directions.STOP in legal: move = Directions.STOP

    if move not in legal:
      move = random.choice(legal)
      
    self.lastMove = move
    return move 
开发者ID:adamtache,项目名称:Pacman-AI,代码行数:24,代码来源:keyboardAgents.py

示例7: getDirection

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import STOP [as 别名]
def getDirection(self, agentState):
        if agentState.configuration == None: return Directions.STOP
        return agentState.configuration.getDirection() 
开发者ID:AUTBS,项目名称:AI-Pacman,代码行数:5,代码来源:graphicsDisplay.py

示例8: getLegalActions

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import STOP [as 别名]
def getLegalActions( state, ghostIndex ):
        """
        Ghosts cannot stop, and cannot turn around unless they
        reach a dead end, but can turn 90 degrees at intersections.
        """
        conf = state.getGhostState( ghostIndex ).configuration
        possibleActions = Actions.getPossibleActions( conf, state.data.layout.walls )
        reverse = Actions.reverseDirection( conf.direction )
        if Directions.STOP in possibleActions:
            possibleActions.remove( Directions.STOP )
        if reverse in possibleActions and len( possibleActions ) > 1:
            possibleActions.remove( reverse )
        return possibleActions 
开发者ID:AUTBS,项目名称:AI-Pacman,代码行数:15,代码来源:pacman.py

示例9: getFeatures

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import STOP [as 别名]
def getFeatures(self, gameState, action):
    features = util.Counter()
    successor = self.getSuccessor(gameState, action)

    myState = successor.getAgentState(self.index)
    myPos = myState.getPosition()

    # Computes whether we're on defense (1) or offense (0)
    features['onDefense'] = 1
    # the line below prevent ghost become pacman, can lose the tie.
    if myState.isPacman: features['onDefense'] = 0

    # Computes distance to invaders we can see
    enemies = [successor.getAgentState(i) for i in self.getOpponents(successor)]
    invaders = [a for a in enemies if a.isPacman and a.getPosition() != None]
    features['numInvaders'] = len(invaders)
    if len(invaders) > 0:
      dists = [self.getMazeDistance(myPos, a.getPosition()) for a in invaders]
      # for a in invaders:
      #     print "Ghost position", a.getPosition(), "MyPosition: ", myPos
      # features['invaderDistance'] = min(dists)

    if action == Directions.STOP: features['stop'] = 1
    rev = Directions.REVERSE[gameState.getAgentState(self.index).configuration.direction]
    if action == rev: features['reverse'] = 1

    return features 
开发者ID:AUTBS,项目名称:AI-Pacman,代码行数:29,代码来源:mamadteam2.py

示例10: __init__

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import STOP [as 别名]
def __init__( self, index = 0 ):

        self.lastMove = Directions.STOP
        self.index = index
        self.keys = [] 
开发者ID:AUTBS,项目名称:AI-Pacman,代码行数:7,代码来源:keyboardAgents.py

示例11: getMove

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import STOP [as 别名]
def getMove(self, legal):
        move = Directions.STOP
        if   (self.WEST_KEY in self.keys or 'Left' in self.keys) and Directions.WEST in legal:  move = Directions.WEST
        if   (self.EAST_KEY in self.keys or 'Right' in self.keys) and Directions.EAST in legal: move = Directions.EAST
        if   (self.NORTH_KEY in self.keys or 'Up' in self.keys) and Directions.NORTH in legal:   move = Directions.NORTH
        if   (self.SOUTH_KEY in self.keys or 'Down' in self.keys) and Directions.SOUTH in legal: move = Directions.SOUTH
        return move 
开发者ID:AUTBS,项目名称:AI-Pacman,代码行数:9,代码来源:keyboardAgents.py

示例12: getAction

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import STOP [as 别名]
def getAction( self, state ):
        dist = self.getDistribution(state)
        if len(dist) == 0:
            return Directions.STOP
        else:
            return util.chooseFromDistribution( dist ) 
开发者ID:namidairo777,项目名称:xiao_multiagent,代码行数:8,代码来源:pursuerAgents.py

示例13: getDirection

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import STOP [as 别名]
def getDirection(self, agentState):
    if agentState.configuration == None: return Directions.STOP
    return agentState.configuration.getDirection() 
开发者ID:jrios6,项目名称:Berkeley-AI-PacMan-Lab-1,代码行数:5,代码来源:graphicsDisplay.py

示例14: getLegalActions

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import STOP [as 别名]
def getLegalActions( state, ghostIndex ):
    """
    Ghosts cannot stop, and cannot turn around unless they
    reach a dead end, but can turn 90 degrees at intersections.
    """
    conf = state.getGhostState( ghostIndex ).configuration
    possibleActions = Actions.getPossibleActions( conf, state.data.layout.walls )
    reverse = Actions.reverseDirection( conf.direction )
    if Directions.STOP in possibleActions:
      possibleActions.remove( Directions.STOP )
    if reverse in possibleActions and len( possibleActions ) > 1:
      possibleActions.remove( reverse )
    return possibleActions 
开发者ID:jrios6,项目名称:Berkeley-AI-PacMan-Lab-1,代码行数:15,代码来源:pacman.py

示例15: getAction

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import STOP [as 别名]
def getAction( self, state ):
    dist = self.getDistribution(state)
    if len(dist) == 0: 
      return Directions.STOP
    else:
      return util.chooseFromDistribution( dist ) 
开发者ID:jrios6,项目名称:Berkeley-AI-PacMan-Lab-1,代码行数:8,代码来源:ghostAgents.py


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