Skip to content
Snippets Groups Projects
Heuristics.py 1.05 KiB
import is_goal
import Sucessors


def queens_opt(path):
    state = path[-1]  # Extracting the current state from the path
    n = len(state)  # Size of the board (N x N)
    current_queens = 0
    # Count the number of outstanding Queens
    for r in state:
        current_queens = current_queens + r.count(True)
    return n - current_queens


def maze_opt(path):
    """maze search heuristic going to have to use the euclidian distance, so it works for any maze"""
    state = path[-1]
    return (is_goal.MAZE_GOAL[0] - state[0]) ** 2 + (is_goal.MAZE_GOAL[1] - state[1]) ** 2


def puzzle_opt(path):
    current_state = path[-1]
    total = 0
    for i in range(len(current_state)):
        for j in range(len(current_state[i])):
            total = total + abs(is_goal.PUZZLE_GOAL[i][j] - current_state[i][j])
    return total


def sudoku_opt(path):
    starting_point = [Sucessors.choose_best_subsquare(path[-1]), Sucessors.choose_best_rows(path[-1]),
                      Sucessors.choose_best_column(path[-1])]
    return max(starting_point, key=lambda w: w[2])[-1]