python类Grid()的实例源码

layout.py 文件源码 项目:AIclass 作者: mttk 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, layoutText):
        self.width = len(layoutText[0])
        self.height= len(layoutText)
        self.walls = Grid(self.width, self.height, False)
        self.food = Grid(self.width, self.height, False)
        self.capsules = []
        self.agentPositions = []
        self.numGhosts = 0
        self.processLayoutText(layoutText)
        self.layoutText = layoutText
        self.totalFood = len(self.food.asList())
        # self.initializeVisibilityMatrix()
layout.py 文件源码 项目:Pac-Man-Search 作者: xuefengDevelop 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self, layoutText):
        self.width = len(layoutText[0])
        self.height= len(layoutText)
        self.walls = Grid(self.width, self.height, False)
        self.food = Grid(self.width, self.height, False)
        self.capsules = []
        self.agentPositions = []
        self.numGhosts = 0
        self.processLayoutText(layoutText)
        self.layoutText = layoutText
        self.totalFood = len(self.food.asList())
        # self.initializeVisibilityMatrix()
layout.py 文件源码 项目:Pacman-AI 作者: adamtache 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self, layoutText):
    self.width = len(layoutText[0])
    self.height= len(layoutText)
    self.walls = Grid(self.width, self.height, False)
    self.food = Grid(self.width, self.height, False)
    self.capsules = []
    self.agentPositions = []
    self.numGhosts = 0
    self.processLayoutText(layoutText)
    self.layoutText = layoutText
    # self.initializeVisibilityMatrix()
layout.py 文件源码 项目:Pacman-AI 作者: adamtache 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self, layoutText):
    self.width = len(layoutText[0])
    self.height= len(layoutText)
    self.walls = Grid(self.width, self.height, False)
    self.food = Grid(self.width, self.height, False)
    self.capsules = []
    self.agentPositions = []
    self.numGhosts = 0
    self.processLayoutText(layoutText)
    self.layoutText = layoutText
    # self.initializeVisibilityMatrix()
searchAgents.py 文件源码 项目:Pacman-AI 作者: ryanshrott 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def cornersHeuristic(state, problem):
  """
  A heuristic for the CornersProblem that you defined.

    state:   The current search state 
             (a data structure you chose in your search problem)

    problem: The CornersProblem instance for this layout.  

  This function should always return a number that is a lower bound
  on the shortest path from the state to a goal of the problem; i.e.
  it should be admissible (as well as consistent).
  """
  corners = problem.corners # These are the corner coordinates
  walls = problem.walls # These are the walls of the maze, as a Grid (game.py)


  "*** YOUR CODE HERE ***"

  def euclid(x, y):
      return ((x[0]-y[0])**2 + (x[1]-y[1])**2)**0.5
  def manhattan(x, y):
      return (abs(x[0]-y[0]) + abs(x[1]-y[1]))  

  current_position = state[:2]
  corners_state = state[2:]
  corners_not_seen = [corners[i] for i in range(4) if corners_state[i]==0]

  #print('start', state[:2])   
  #print('corners not seen', corners_not_seen)  
  val = 0 # heuristic value to return 
  for i in range(len(corners_not_seen)):
      d_euclid = [[c, manhattan(current_position, c)] for c in corners_not_seen]
      d_euclid.sort(key=lambda x: x[1])
      #print d_euclid[0][1]
      val += d_euclid[0][1] # move to the closest corner 
      current_position = d_euclid[0][0] # update the current position to the new corner position 
      corners_not_seen.remove(d_euclid[0][0]) # we have seen this corner now 

  #print('corners not seen at end', corners_not_seen)  
  #print('dist to goal', val)          
  return val


问题


面经


文章

微信
公众号

扫码关注公众号