

import os
import sys
from contextlib import contextmanager


# Windows only
if os.name == "nt":
     import ctypes
     import msvcrt  # noqa



     class 						_A     (				ctypes.Structure				):





       '''simple docstring'''



       __lowerCamelCase			:      Union[str, Any]					=   [('''size''', ctypes.c_int), ('''visible''', ctypes.c_byte)]







def       lowercase					(	)				->			Optional[Any]:





    '''simple docstring'''




    if os.name == "nt":
        snake_case							:		int        =		CursorInfo()
        snake_case							:		Union[str, Any]        =		ctypes.windll.kernelaa.GetStdHandle(-11		)
        ctypes.windll.kernelaa.GetConsoleCursorInfo(__A ,    ctypes.byref(__A		)		)
        snake_case							:		Union[str, Any]        =		False
        ctypes.windll.kernelaa.SetConsoleCursorInfo(__A ,    ctypes.byref(__A		)		)
    elif os.name == "posix":
        sys.stdout.write("""\033[?25l"""		)
        sys.stdout.flush()







def       lowercase					(	)				->			Tuple:





    '''simple docstring'''




    if os.name == "nt":
        snake_case							:		Optional[Any]        =		CursorInfo()
        snake_case							:		Dict        =		ctypes.windll.kernelaa.GetStdHandle(-11		)
        ctypes.windll.kernelaa.GetConsoleCursorInfo(__A ,    ctypes.byref(__A		)		)
        snake_case							:		Optional[int]        =		True
        ctypes.windll.kernelaa.SetConsoleCursorInfo(__A ,    ctypes.byref(__A		)		)
    elif os.name == "posix":
        sys.stdout.write("""\033[?25h"""		)
        sys.stdout.flush()







@contextmanager
def       lowercase					(	)				->			Union[str, Any]:





    '''simple docstring'''




    try:
        hide_cursor()
        yield
    finally:
        show_cursor()









import heapq
import sys

import numpy as np

_lowerCamelCase      :						Any							=  tuple[int, int]


class 							UpperCamelCase_       :

    '''simple docstring'''






    def __init__(     self :      Any)		->str:





           '''simple docstring'''

           A__ 					=       []
           A__ 					=       set()


    def 			SCREAMING_SNAKE_CASE				(     self :      Optional[int])		->List[str]:





           '''simple docstring'''

           if not self.empty():
                  return self.elements[0][0]
           else:
                  return float('''inf''')


    def 			SCREAMING_SNAKE_CASE				(     self :      Tuple)		->str:





           '''simple docstring'''

           return len(self.elements) == 0


    def 			SCREAMING_SNAKE_CASE				(     self :      Dict   ,					UpperCAmelCase__ :      Tuple   ,					UpperCAmelCase__ :      Optional[Any])		->List[str]:





           '''simple docstring'''

           if item not in self.set:
                  heapq.heappush(self.elements   ,					(priority, item))
                  self.set.add(UpperCAmelCase__)
           else:
                  # update
                  # print("update", item)
                  A__ 					=       []
                  ((A__)					,				(A__)) 					=       heapq.heappop(self.elements)
                  while x != item:
                         temp.append((pri, x))
                         ((A__)					,				(A__)) 					=       heapq.heappop(self.elements)
                  temp.append((priority, item))
                  for pro, xxx in temp:
                         heapq.heappush(self.elements   ,					(pro, xxx))


    def 			SCREAMING_SNAKE_CASE				(     self :      Union[str, Any]   ,					UpperCAmelCase__ :      List[Any])		->Union[str, Any]:





           '''simple docstring'''

           if item in self.set:
                  self.set.remove(UpperCAmelCase__)
                  A__ 					=       []
                  ((A__)					,				(A__)) 					=       heapq.heappop(self.elements)
                  while x != item:
                         temp.append((pro, x))
                         ((A__)					,				(A__)) 					=       heapq.heappop(self.elements)
                  for prito, yyy in temp:
                         heapq.heappush(self.elements   ,					(prito, yyy))


    def 			SCREAMING_SNAKE_CASE				(     self :      List[str])		->List[str]:





           '''simple docstring'''

           return self.elements[0][1]





    def 			SCREAMING_SNAKE_CASE				(     self :      Optional[int])		->int:





           '''simple docstring'''

           ((A__)					,				(A__)) 					=       heapq.heappop(self.elements)
           self.set.remove(UpperCAmelCase__)
           return (priority, item)







def SCREAMING_SNAKE_CASE							(			lowercase_					,							lowercase_		)  ->			str:



       """simple docstring"""

       A__ 					=       np.array(lowercase_		)
       A__ 					=       np.array(lowercase_		)
       return np.linalg.norm(a - b		)







def SCREAMING_SNAKE_CASE							(			lowercase_					,							lowercase_		)  ->			str:



       """simple docstring"""

       return consistent_heuristic(lowercase_					,							lowercase_		) // t







def SCREAMING_SNAKE_CASE							(			lowercase_					,							lowercase_		)  ->			Union[str, Any]:



       """simple docstring"""

       return abs(p[0] - goal[0]		) + abs(p[1] - goal[1]		)







def SCREAMING_SNAKE_CASE							(			lowercase_					,							lowercase_					,							lowercase_					,							lowercase_		)  ->			Optional[int]:



       """simple docstring"""

       A__ 					=       g_function[start] + Wa * heuristics[i](lowercase_					,							lowercase_		)
       return ans







def SCREAMING_SNAKE_CASE							(			lowercase_					,							lowercase_					,							lowercase_		)  ->			str:



       """simple docstring"""

       A__ 					=       np.chararray((n, n)		)
       for i in range(lowercase_		):
              for j in range(lowercase_		):
                     A__ 					=       '''*'''

       for i in range(lowercase_		):
              for j in range(lowercase_		):
                     if (j, (n - 1) - i) in blocks:
                            A__ 					=       '''#'''

       A__ 					=       '''-'''
       A__ 					=       back_pointer[goal]
       while x != start:
              ((A__)					,				(A__)) 					=       x
              # print(x)
              A__ 					=       '''-'''
              A__ 					=       back_pointer[x]
       A__ 					=       '''-'''

       for i in range(lowercase_		):
              for j in range(lowercase_		):
                     if (i, j) == (0, n - 1):
                            print(grid[i][j]					,							end=''' '''		)
                            print('''<-- End position'''					,							end=''' '''		)
                     else:
                            print(grid[i][j]					,							end=''' '''		)
              print()
       print('''^'''		)
       print('''Start position'''		)
       print()
       print('''# is an obstacle'''		)
       print('''- is the path taken by algorithm'''		)
       print('''PATH TAKEN BY THE ALGORITHM IS:-'''		)
       A__ 					=       back_pointer[goal]
       while x != start:
              print(lowercase_					,							end=''' '''		)
              A__ 					=       back_pointer[x]
       print(lowercase_		)
       sys.exit()







def SCREAMING_SNAKE_CASE							(			lowercase_		)  ->			Dict:



       """simple docstring"""

       if p[0] < 0 or p[0] > n - 1:
              return False
       if p[1] < 0 or p[1] > n - 1:
              return False
       return True







def SCREAMING_SNAKE_CASE							(			lowercase_					,							lowercase_					,							lowercase_					,							lowercase_					,							lowercase_					,							lowercase_					,							lowercase_					,							lowercase_					,							)  ->			Union[str, Any]:



       """simple docstring"""

       for itera in range(lowercase_		):
              open_list[itera].remove_element(lowercase_		)
       # print("s", s)
       # print("j", j)
       ((A__)					,				(A__)) 					=       s
       A__ 					=       (x - 1, y)
       A__ 					=       (x + 1, y)
       A__ 					=       (x, y + 1)
       A__ 					=       (x, y - 1)

       for neighbours in [left, right, up, down]:
              if neighbours not in blocks:
                     if valid(lowercase_		) and neighbours not in visited:
                            # print("neighbour", neighbours)
                            visited.add(lowercase_		)
                            A__ 					=       -1
                            A__ 					=       float('''inf'''		)

                     if valid(lowercase_		) and g_function[neighbours] > g_function[s] + 1:
                            A__ 					=       g_function[s] + 1
                            A__ 					=       s
                            if neighbours not in close_list_anchor:
                                   open_list[0].put(lowercase_					,							key(lowercase_					,							0					,							lowercase_					,							lowercase_		)		)
                                   if neighbours not in close_list_inad:
                                          for var in range(1					,							lowercase_		):
                                                 if key(lowercase_					,							lowercase_					,							lowercase_					,							lowercase_		) <= Wa * key(
                                                     lowercase_					,							0					,							lowercase_					,							lowercase_		):
                                                        open_list[j].put(
                                                            lowercase_					,							key(lowercase_					,							lowercase_					,							lowercase_					,							lowercase_		)		)







def SCREAMING_SNAKE_CASE							(			)  ->			Optional[int]:



       """simple docstring"""

       A__ 					=       []
       for x in range(1					,							5		):
              for y in range(1					,							6		):
                     some_list.append((x, y)		)

       for x in range(15					,							20		):
              some_list.append((x, 17)		)

       for x in range(10					,							19		):
              for y in range(1					,							15		):
                     some_list.append((x, y)		)

    # L block
       for x in range(1					,							4		):
              for y in range(12					,							19		):
                     some_list.append((x, y)		)
       for x in range(3					,							13		):
              for y in range(16					,							19		):
                     some_list.append((x, y)		)
       return some_list


_lowerCamelCase      :						Dict							=  {0: consistent_heuristic, 1: heuristic_a, 2: heuristic_a}

_lowerCamelCase      :						Optional[Any]							=  [
    (0, 1),
    (1, 1),
    (2, 1),
    (3, 1),
    (4, 1),
    (5, 1),
    (6, 1),
    (7, 1),
    (8, 1),
    (9, 1),
    (10, 1),
    (11, 1),
    (12, 1),
    (13, 1),
    (14, 1),
    (15, 1),
    (16, 1),
    (17, 1),
    (18, 1),
    (19, 1),
]
_lowerCamelCase      :						Optional[int]							=  make_common_ground()


_lowerCamelCase      :						Optional[Any]							=  blocks_blk
# hyper parameters
_lowerCamelCase      :						Optional[int]							=  1
_lowerCamelCase      :						Optional[int]							=  1
_lowerCamelCase      :						List[Any]							=  20
_lowerCamelCase      :						Any							=  3  # one consistent and two other inconsistent

# start and end destination
_lowerCamelCase      :						str							=  (0, 0)
_lowerCamelCase      :						Tuple							=  (n - 1, n - 1)

_lowerCamelCase      :						int							=  1







def SCREAMING_SNAKE_CASE							(			lowercase_					,							lowercase_					,							lowercase_		)  ->			str:



       """simple docstring"""

       A__ 					=       {start: 0, goal: float('''inf'''		)}
       A__ 					=       {start: -1, goal: -1}
       A__ 					=       []
       A__ 					=       set()

       for i in range(lowercase_		):
              open_list.append(PriorityQueue()		)
              open_list[i].put(lowercase_					,							key(lowercase_					,							lowercase_					,							lowercase_					,							lowercase_		)		)

       A__ 					=       []
       A__ 					=       []
       while open_list[0].minkey() < float('''inf'''		):
              for i in range(1					,							lowercase_		):
                     # print(open_list[0].minkey(), open_list[i].minkey())
                     if open_list[i].minkey() <= Wa * open_list[0].minkey():
                            global t
                            t += 1
                            if g_function[goal] <= open_list[i].minkey():
                                   if g_function[goal] < float('''inf'''		):
                                          do_something(lowercase_					,							lowercase_					,							lowercase_		)
                            else:
                                   A__					,				A__ 					=       open_list[i].top_show()
                                   visited.add(lowercase_		)
                                   expand_state(
                                       lowercase_					,							lowercase_					,							lowercase_					,							lowercase_					,							lowercase_					,							lowercase_					,							lowercase_					,							lowercase_					,							)
                                   close_list_inad.append(lowercase_		)
                     else:
                            if g_function[goal] <= open_list[0].minkey():
                                   if g_function[goal] < float('''inf'''		):
                                          do_something(lowercase_					,							lowercase_					,							lowercase_		)
                            else:
                                   A__ 					=       open_list[0].top_show()
                                   visited.add(lowercase_		)
                                   expand_state(
                                       lowercase_					,							0					,							lowercase_					,							lowercase_					,							lowercase_					,							lowercase_					,							lowercase_					,							lowercase_					,							)
                                   close_list_anchor.append(lowercase_		)
       print('''No path found to goal'''		)
       print()
       for i in range(n - 1					,							-1					,							-1		):
              for j in range(lowercase_		):
                     if (j, i) in blocks:
                            print('''#'''					,							end=''' '''		)
                     elif (j, i) in back_pointer:
                            if (j, i) == (n - 1, n - 1):
                                   print('''*'''					,							end=''' '''		)
                            else:
                                   print('''-'''					,							end=''' '''		)
                     else:
                            print('''*'''					,							end=''' '''		)
                     if (j, i) == (n - 1, n - 1):
                            print('''<-- End position'''					,							end=''' '''		)
              print()
       print('''^'''		)
       print('''Start position'''		)
       print()
       print('''# is an obstacle'''		)
       print('''- is the path taken by algorithm'''		)


if __name__ == "__main__":
  multi_a_star(start, goal, n_heuristic)


