Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

complete the code for the following: def A_Star_H2(puzzle): A-Star with Heauristic 2 Arguments: - puzzle: Node object representing initial state of the puzzle Return:

complete the code for the following:

def A_Star_H2(puzzle):

"""

A-Star with Heauristic 2

Arguments:

- puzzle: Node object representing initial state of the puzzle

Return:

final_solution: An ordered list of moves representing the final solution.

"""

final_solution = []

# TODO: WRITE CODE

return final_solution

test the code by using the main.py

from search import BFS, DFS, A_Star_H1, A_Star_H2, UP, DOWN, LEFT, RIGHT

def get_move_string(moves):

"""

Helper function to print moves.

"""

move_string = ""

if len(moves) == 0:

return "NONE"

for move in moves:

if move == UP:

move_string = move_string + "U "

elif move == LEFT:

move_string = move_string + "L "

elif move == DOWN:

move_string = move_string + "D "

elif move == RIGHT:

move_string = move_string + "R "

else:

move_string = move_string + "INVALID "

return move_string

def read_puzzle(filename):

"""

Helper to read a puzzle from a file.

Arguments:

filename: Name of file to read from.

"""

puzzle = []

with open(filename, "r") as f:

for line in f.readlines():

puzzle.append(line.split(' '))

return puzzle

def run_test(size, filename):

"""

Takes a filename,

then creates a puzzle,

reads it in from file,

and runs each of the search algorithms

"""

print(f"{filename}:")

puzzle = read_puzzle(filename)

moves = BFS(puzzle)

print(" BFS | " + get_move_string(moves))

puzzle = read_puzzle(filename)

moves = DFS(puzzle)

print(" DFS | " + get_move_string(moves))

puzzle = read_puzzle(filename)

moves = A_Star_H1(puzzle)

print(" A* H1 | " + get_move_string(moves))

puzzle = read_puzzle(filename)

moves = A_Star_H2(puzzle)

print(" A* H2 | " + get_move_string(moves))

print("-" * 20)

run_test(3, 'test_data/ex1.txt')

run_test(3, 'test_data/ex2.txt')

run_test(3, 'test_data/ex3.txt')

please provide a complete solution

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions

Question

LO1 Identify why performance management is necessary.

Answered: 1 week ago