Advertisement
MateusNoremberg

Untitled

May 24th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. def breadthFirstSearch(problem, heuristic):
  2.     """Search the shallowest nodes in the search tree first."""
  3.     "*** YOUR CODE HERE ***"
  4.     """print "Start:", problem.getStartState()
  5.    print "Is the start a goal?", problem.isGoalState(problem.getStartState())
  6.    print "Start's successors:", problem.getSuccessors(problem.getStartState())    """
  7.     current = (problem.getStartState(), "Stop" , 0xFFF)
  8.     actions = []
  9.     while True:
  10.         cost=0xFFF
  11.         for n in problem.getSuccessors(current[0]):
  12.             if(heuristic(n[0], problem)<cost):
  13.                 neighbor = n
  14.                 cost=heuristic(n[0], problem)
  15.  
  16.         if heuristic(neighbor[0], problem) >= heuristic(current[0], problem):
  17.             return actions
  18.         current = neighbor
  19.         actions.append(current[1])
  20.  
  21.     return []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement