def a_star_search(start, successors, state_value, is_goal):
if is_goal(start):<EOL><INDENT>return [start]<EOL><DEDENT>explored = []<EOL>g = <NUM_LIT:1><EOL>h = state_value(start)<EOL>f = g + h<EOL>p = [start]<EOL>frontier = [(f, g, h, p)]<EOL>while frontier:<EOL><INDENT>f, g, h, path = frontier.pop(<NUM_LIT:0>)<EOL>s = path[-<NUM_LIT:1>]<EOL>for (action, state) in successors(s, path_actions(path)[-<NUM_LIT:1>] if len(path) != <NUM_LIT:1> else []):<EOL><INDENT>if state not in explored:<EOL><INDENT>explored.append(state)<EOL>path2 = path + [action, state]<EOL>h2 = state_value(state)<EOL>g2 = g + <NUM_LIT:1><EOL>f2 = h2 + g2<EOL>if is_goal(state):<EOL><INDENT>return path2<EOL><DEDENT>else:<EOL><INDENT>frontier.append((f2, g2, h2, path2))<EOL>frontier.sort(key=lambda x:x[:<NUM_LIT:3>])<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return []<EOL>
This is a searching function of A*