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


Python Directions.WEST属性代码示例

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


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

示例1: initializeVisibilityMatrix

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import WEST [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

示例2: initializeVisibilityMatrix

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import WEST [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

示例3: getSuccessors

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import WEST [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: getMove

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import WEST [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

示例5: tinyMazeSearch

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import WEST [as 别名]
def tinyMazeSearch(problem):
  """
  Returns a sequence of moves that solves tinyMaze.  For any other
  maze, the sequence of moves will be incorrect, so only use this for tinyMaze
  """
  from game import Directions
  s = Directions.SOUTH
  w = Directions.WEST
  return  [s,s,w,s,w,w,s,w] 
开发者ID:jrios6,项目名称:Berkeley-AI-PacMan-Lab-1,代码行数:11,代码来源:search.py

示例6: getMove

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import WEST [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:jrios6,项目名称:Berkeley-AI-PacMan-Lab-1,代码行数:9,代码来源:keyboardAgents.py

示例7: getAction

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import WEST [as 别名]
def getAction(self, state):
    "The agent receives a GameState (defined in pacman.py)."
    if Directions.WEST in state.getLegalPacmanActions():
      return Directions.WEST
    else:
      return Directions.STOP

#######################################################
# This portion is written for you, but will only work #
#       after you fill in parts of search.py          #
####################################################### 
开发者ID:jrios6,项目名称:Berkeley-AI-PacMan-Lab-1,代码行数:13,代码来源:searchAgents.py

示例8: getSuccessors

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import WEST [as 别名]
def getSuccessors(self, currentState):
    """
    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 = currentState[0]
      dx, dy = Actions.directionToVector(action)
      nextx, nexty = int(x + dx), int(y + dy)
      if not self.walls[nextx][nexty]:
        #Copies corner visited by node previously to nextState
        nextState = [(nextx, nexty), currentState[1][:]]
        if nextState[0] in self.corners and nextState[0] not in nextState[1]:
            #Add current corner state visited to nextState node
            nextState[1].append(nextState[0])
        successors.append( ( nextState, action, 1) )

    # Bookkeeping for display purposes
    self._expanded += 1

    return successors 
开发者ID:jrios6,项目名称:Berkeley-AI-PacMan-Lab-1,代码行数:30,代码来源:searchAgents.py

示例9: tinyMazeSearch

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import WEST [as 别名]
def tinyMazeSearch(problem):
    """
    Returns a sequence of moves that solves tinyMaze.  For any other
    maze, the sequence of moves will be incorrect, so only use this for tinyMaze
    """
    from game import Directions
    s = Directions.SOUTH
    w = Directions.WEST
    return  [s,s,w,s,w,w,s,w] 
开发者ID:ryanshrott,项目名称:Pacman-AI,代码行数:11,代码来源:search.py

示例10: getSuccessors

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import WEST [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
    """
    (x,y,c1,c2,c3,c4) = state
    corners_hist_old = [c1,c2,c3,c4] # corners we have already seen
    successors = []
    
    for action in [Directions.NORTH, Directions.SOUTH, Directions.EAST, Directions.WEST]:
      dx, dy = Actions.directionToVector(action)
      nextx, nexty = int(x + dx), int(y + dy)
      if not self.walls[nextx][nexty]:
        nextState = (nextx, nexty)
        if nextState in self.corners: # we found a corner
            #print nextState
            for i in range(4): # determine which corner we hit 
                if nextState == self.corners[i]:
                    corners_hist_new = corners_hist_old[:]
                    corners_hist_new[i] = 1 # mutate the relevant corner 
                    nextValue = nextState + tuple(corners_hist_new)
        else: # we did not hit a corner 
            nextValue = nextState + tuple(corners_hist_old)
    
        cost = self.costFn(nextValue)
        successors.append( ( nextValue, action, cost) )
        
    self._expanded += 1 
    return successors 
开发者ID:ryanshrott,项目名称:Pacman-AI,代码行数:37,代码来源:searchAgents.py

示例11: tinyMazeSearch

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import WEST [as 别名]
def tinyMazeSearch(problem):
    """
    Returns a sequence of moves that solves tinyMaze.  For any other maze, the
    sequence of moves will be incorrect, so only use this for tinyMaze.
    """
    from game import Directions
    s = Directions.SOUTH
    w = Directions.WEST
    return  [s, s, w, s, w, w, s, w] 
开发者ID:deepeshmittal,项目名称:AI-PacMan-Projects,代码行数:11,代码来源:search.py

示例12: getAction

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import WEST [as 别名]
def getAction(self, state):
        "The agent receives a GameState (defined in pacman.py)."
        if Directions.WEST in state.getLegalPacmanActions():
            return Directions.WEST
        else:
            return Directions.STOP

#######################################################
# This portion is written for you, but will only work #
#       after you fill in parts of search.py          #
####################################################### 
开发者ID:deepeshmittal,项目名称:AI-PacMan-Projects,代码行数:13,代码来源:searchAgents.py

示例13: getSuccessors

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import WEST [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: getSuccessors

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import WEST [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 ***"
            cornersNotVisited = state[1]
            x,y = state[0]
            dx, dy = Actions.directionToVector(action)
            nextx, nexty = int(x + dx), int(y + dy)
            hitsWall = self.walls[nextx][nexty]
            if not hitsWall:
            	if (nextx, nexty) in state[1]:
            		cornersNotVisited = filter(lambda a: a != (nextx, nexty), cornersNotVisited) #remove visited corner
            	nextState = ((nextx, nexty), cornersNotVisited)
            	cost = 1
            	successors.append((nextState, action, cost))

        self._expanded += 1 # DO NOT CHANGE
        return successors 
开发者ID:loren-jiang,项目名称:cs188_tbf,代码行数:37,代码来源:searchAgents.py

示例15: getSuccessors

# 需要导入模块: from game import Directions [as 别名]
# 或者: from game.Directions import WEST [as 别名]
def getSuccessors(self, state):
        """
        Returns successor states, the actions they require, and a cost of 1.

            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:mttk,项目名称:AIclass,代码行数:30,代码来源:search.py


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