
"""simple docstring"""

from __future__ import annotations

UpperCamelCase			:       str									=				list[tuple[int, int]]

UpperCamelCase			:       str									=				[
    [0, 0, 0, 0, 0, 0, 0],
    [0, 1, 0, 0, 0, 0, 0],  # 0 are free path whereas 1's are obstacles
    [0, 0, 0, 0, 0, 0, 0],
    [0, 0, 1, 0, 0, 0, 0],
    [1, 0, 1, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 1, 0, 0],
]

UpperCamelCase			:       Dict									=				([-1, 0], [0, -1], [1, 0], [0, 1])  # up, left, down, right

class __lowerCAmelCase	:





     def __init__(			self			,  __UpperCAmelCase			,  __UpperCAmelCase			,  __UpperCAmelCase			,  __UpperCAmelCase			,  __UpperCAmelCase			,  __UpperCAmelCase			,  ):

      '''simple docstring'''




      __UpperCamelCase       						= pos_x
      __UpperCamelCase       						= pos_y
      __UpperCamelCase       						= (pos_y, pos_x)
      __UpperCamelCase       						= goal_x
      __UpperCamelCase       						= goal_y
      __UpperCamelCase       						= g_cost
      __UpperCamelCase       						= parent
      __UpperCamelCase       						= self.calculate_heuristic()





     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      __UpperCamelCase       						= abs(self.pos_x - self.goal_x   )
      __UpperCamelCase       						= abs(self.pos_y - self.goal_y   )
      return dx + dy







     def __lt__(			self			,  __UpperCAmelCase   ):

      '''simple docstring'''




      return self.f_cost < other.f_cost


class __lowerCAmelCase	:





     def __init__(			self			,  __UpperCAmelCase			,  __UpperCAmelCase   ):

      '''simple docstring'''




      __UpperCamelCase       						= Node(start[1]			,  start[0]			,  goal[1]			,  goal[0]			,  0			,  __UpperCAmelCase   )
      __UpperCamelCase       						= Node(goal[1]			,  goal[0]			,  goal[1]			,  goal[0]			,  9_9999			,  __UpperCAmelCase   )

      __UpperCamelCase       						= [self.start]
      __UpperCamelCase       						= []

      __UpperCamelCase       						= False





     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      while self.open_nodes:
       # Open Nodes are sorted using __lt__
       self.open_nodes.sort()
       __UpperCamelCase       						= self.open_nodes.pop(0   )

       if current_node.pos == self.target.pos:
        __UpperCamelCase       						= True
        return self.retrace_path(__UpperCAmelCase   )

       self.closed_nodes.append(__UpperCAmelCase   )
       __UpperCamelCase       						= self.get_successors(__UpperCAmelCase   )

       for child_node in successors:
        if child_node in self.closed_nodes:
         continue

        if child_node not in self.open_nodes:
         self.open_nodes.append(__UpperCAmelCase   )
        else:
         # retrieve the best current path
         __UpperCamelCase       						= self.open_nodes.pop(self.open_nodes.index(__UpperCAmelCase   )   )

         if child_node.g_cost < better_node.g_cost:
          self.open_nodes.append(__UpperCAmelCase   )
         else:
          self.open_nodes.append(__UpperCAmelCase   )

      if not self.reached:
       return [self.start.pos]
      return None





     def 		UpperCAmelCase      (			self			,  __UpperCAmelCase   ):

      '''simple docstring'''




      __UpperCamelCase       						= []
      for action in delta:
       __UpperCamelCase       						= parent.pos_x + action[1]
       __UpperCamelCase       						= parent.pos_y + action[0]

       if not (0 <= pos_x <= len(grid[0]   ) - 1 and 0 <= pos_y <= len(__UpperCAmelCase   ) - 1):
        continue

       if grid[pos_y][pos_x] != 0:
        continue

       successors.append(
           Node(
               __UpperCAmelCase			,  __UpperCAmelCase			,  self.target.pos_y			,  self.target.pos_x			,  parent.g_cost + 1			,  __UpperCAmelCase			,  )   )
      return successors







     def 		UpperCAmelCase      (			self			,  __UpperCAmelCase   ):

      '''simple docstring'''




      __UpperCamelCase       						= node
      __UpperCamelCase       						= []
      while current_node is not None:
       path.append((current_node.pos_y, current_node.pos_x)   )
       __UpperCamelCase       						= current_node.parent
      path.reverse()
      return path


if __name__ == "__main__":
      UpperCamelCase			:       List[str]									=				(0, 0)
      UpperCamelCase			:       int									=				(len(grid) - 1, len(grid[0]) - 1)
      for elem in grid:
            print(elem)

      print("------")

      UpperCamelCase			:       Tuple									=				GreedyBestFirst(init, goal)
      UpperCamelCase			:       Any									=				greedy_bf.search()
      if path:
            for pos_x, pos_y in path:
                  UpperCamelCase			:       str									=				2

            for elem in grid:
                  print(elem)





"""simple docstring"""

def 							A		(       snake_case   :int       ,      snake_case   :int	)   ->			int:
 return int(input_a == input_a == 0	)






def 							A		(       )   ->			None:
 print('Truth Table of NOR Gate:'	)
 print('|   Input 1   |  Input 2  | Output |'	)
 print(f'|      0      |    0      |  {nor_gate(0       ,      0	)}     |'	)
 print(f'|      0      |    1      |  {nor_gate(0       ,      1	)}     |'	)
 print(f'|      1      |    0      |  {nor_gate(1       ,      0	)}     |'	)
 print(f'|      1      |    1      |  {nor_gate(1       ,      1	)}     |'	)


if __name__ == "__main__":
      import doctest

      doctest.testmod()
      main()



