Question
3.2.4 a star f function factory(heuristic, goal board) Given a heuristic function and a goal board, returns an f-value FUNCTION that takes a board and
3.2.4 a star f function factory(heuristic, goal board)
Given a heuristic function and a goal board, returns an f-value FUNCTION
that takes a board and a depth and returns an f-value, as in the A* algorithm.
(Using the lambda keyword here may be helpful.)
###########################################
# Problem 4 - A* f-value Function Factory
###########################################
# Objectives:
# (1) Given a heuristic function and a goal board, returns a f-value FUNCTION
# (like ucs_f_function) that evaluates boards and depths as in the A* algorithm.
#
# Notes:
# (1) It may be helpful to consult your solution for a1.compose here.
def a_star_f_function_factory(heuristic, goal_board):
raise NotImplementedError
# Here is an example heuristic function.
def manhattan_distance(current_board, goal_board):
total = 0
goal_matrix = goal_board.matrix
for goal_r in range(len(goal_board.matrix)):
for goal_c in range(len(goal_board.matrix[0])):
val = goal_matrix[goal_r][goal_c]
if val == 0:
continue
current_r, current_c = current_board.find_element(val)
total += abs(goal_r - current_r) + abs(goal_c - current_c)
return total
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started