'''simple docstring'''







import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from .tokenization_lxmert import LxmertTokenizer


UpperCamelCase_      	=	{'''vocab_file''': '''vocab.txt''', '''tokenizer_file''': '''tokenizer.json'''}

UpperCamelCase_      	=	{
    '''vocab_file''': {
        '''unc-nlp/lxmert-base-uncased''': '''https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/vocab.txt''',
    },
    '''tokenizer_file''': {
        '''unc-nlp/lxmert-base-uncased''': (
            '''https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/tokenizer.json'''
        ),
    },
}

UpperCamelCase_      	=	{
    '''unc-nlp/lxmert-base-uncased''': 5_12,
}

UpperCamelCase_      	=	{
    '''unc-nlp/lxmert-base-uncased''': {'''do_lower_case''': True},
}




class _SCREAMING_SNAKE_CASE(							_SCREAMING_SNAKE_CASE					):
						A_			:							str     		= VOCAB_FILES_NAMES
						A_			:							Union[str, Any]     		= PRETRAINED_VOCAB_FILES_MAP
						A_			:							int     		= PRETRAINED_INIT_CONFIGURATION
						A_			:							Tuple     		= PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
						A_			:							List[str]     		= LxmertTokenizer




						def __init__(    self :       str							,							UpperCamelCase_ :       str=None							,							UpperCamelCase_ :       int=None							,							UpperCamelCase_ :       Optional[int]=True							,							UpperCamelCase_ :       List[Any]="[UNK]"							,							UpperCamelCase_ :       List[str]="[SEP]"							,							UpperCamelCase_ :       Optional[int]="[PAD]"							,							UpperCamelCase_ :       Dict="[CLS]"							,							UpperCamelCase_ :       Dict="[MASK]"							,							UpperCamelCase_ :       List[str]=True							,							UpperCamelCase_ :       Dict=None							,							**UpperCamelCase_ :       Dict							,							)     ->				Dict:
													super().__init__(
													    UpperCamelCase_							,							tokenizer_file=UpperCamelCase_							,							do_lower_case=UpperCamelCase_							,							unk_token=UpperCamelCase_							,							sep_token=UpperCamelCase_							,							pad_token=UpperCamelCase_							,							cls_token=UpperCamelCase_							,							mask_token=UpperCamelCase_							,							tokenize_chinese_chars=UpperCamelCase_							,							strip_accents=UpperCamelCase_							,							**UpperCamelCase_							,							)

													SCREAMING_SNAKE_CASE__     :str						    = json.loads(self.backend_tokenizer.normalizer.__getstate__()      )
													if (
													    normalizer_state.get('lowercase'							,							UpperCamelCase_      ) != do_lower_case
													    or normalizer_state.get('strip_accents'							,							UpperCamelCase_      ) != strip_accents
													    or normalizer_state.get('handle_chinese_chars'							,							UpperCamelCase_      ) != tokenize_chinese_chars
													):
																				SCREAMING_SNAKE_CASE__     :Optional[Any]						    = getattr(UpperCamelCase_							,							normalizer_state.pop('type'      )      )
																				SCREAMING_SNAKE_CASE__     :Optional[Any]						    = do_lower_case
																				SCREAMING_SNAKE_CASE__     :Optional[Any]						    = strip_accents
																				SCREAMING_SNAKE_CASE__     :Optional[Any]						    = tokenize_chinese_chars
																				SCREAMING_SNAKE_CASE__     :List[Any]						    = normalizer_class(**UpperCamelCase_      )

													SCREAMING_SNAKE_CASE__     :int						    = do_lower_case




						def      __lowerCamelCase       (    self :       str							,							UpperCamelCase_ :       str							,							UpperCamelCase_ :       Tuple=None      )     ->				Optional[int]:
													SCREAMING_SNAKE_CASE__     :str						    = [self.cls_token_id] + token_ids_a + [self.sep_token_id]

													if token_ids_a:
																				output += token_ids_a + [self.sep_token_id]

													return output




						def      __lowerCamelCase       (    self :       str							,							UpperCamelCase_ :       List[int]							,							UpperCamelCase_ :       Optional[List[int]] = None      )     ->				List[int]:
													SCREAMING_SNAKE_CASE__     :int						    = [self.sep_token_id]
													SCREAMING_SNAKE_CASE__     :List[Any]						    = [self.cls_token_id]
													if token_ids_a is None:
																				return len(cls + token_ids_a + sep      ) * [0]
													return len(cls + token_ids_a + sep      ) * [0] + len(token_ids_a + sep      ) * [1]




						def      __lowerCamelCase       (    self :       Any							,							UpperCamelCase_ :       str							,							UpperCamelCase_ :       Optional[str] = None      )     ->				Tuple[str]:
													SCREAMING_SNAKE_CASE__     :Dict						    = self._tokenizer.model.save(UpperCamelCase_							,							name=UpperCamelCase_      )
													return tuple(UpperCamelCase_      )







'''simple docstring'''







from __future__ import annotations

UpperCamelCase_      	=	[
    [-1, 0],  # left
    [0, -1],  # down
    [1, 0],  # right
    [0, 1],  # up
]


def    lowerCamelCase       (			UpperCAmelCase__				:  list[list[int]]				,						UpperCAmelCase__				:  list[int]				,						UpperCAmelCase__				:  list[int]				,						UpperCAmelCase__				:  int				,						UpperCAmelCase__				:  list[list[int]]				,						)			->	tuple[list[list[int]], list[list[int]]]:


							'''simple docstring'''






							SCREAMING_SNAKE_CASE__     :str						    = [
							    [0 for col in range(len(grid[0]		)		)] for row in range(len(UpperCAmelCase__		)		)
							]  # the reference grid
							SCREAMING_SNAKE_CASE__     :Any						    = 1
							SCREAMING_SNAKE_CASE__     :Dict						    = [
							    [0 for col in range(len(grid[0]		)		)] for row in range(len(UpperCAmelCase__		)		)
							]  # the action grid

							SCREAMING_SNAKE_CASE__     :int						    = init[0]
							SCREAMING_SNAKE_CASE__     :Optional[Any]						    = init[1]
							SCREAMING_SNAKE_CASE__     :List[str]						    = 0
							SCREAMING_SNAKE_CASE__     :List[Any]						    = g + heuristic[x][y]  # cost from starting cell to destination cell
							SCREAMING_SNAKE_CASE__     :List[Any]						    = [[f, g, x, y]]

							SCREAMING_SNAKE_CASE__     :Any						    = False  # flag that is set when search is complete
							SCREAMING_SNAKE_CASE__     :str						    = False  # flag set if we can't find expand

							while not found and not resign:
														if len(UpperCAmelCase__		) == 0:
																					raise ValueError('Algorithm is unable to find solution'		)
														else:  # to choose the least costliest action so as to move closer to the goal
																					cell.sort()
																					cell.reverse()
																					SCREAMING_SNAKE_CASE__     :List[Any]						    = cell.pop()
																					SCREAMING_SNAKE_CASE__     :Optional[int]						    = next_cell[2]
																					SCREAMING_SNAKE_CASE__     :Any						    = next_cell[3]
																					SCREAMING_SNAKE_CASE__     :Dict						    = next_cell[1]

																					if x == goal[0] and y == goal[1]:
																												SCREAMING_SNAKE_CASE__     :Tuple						    = True
																					else:
																												for i in range(len(UpperCAmelCase__		)		):  # to try out different valid actions
																																			SCREAMING_SNAKE_CASE__     :Optional[int]						    = x + DIRECTIONS[i][0]
																																			SCREAMING_SNAKE_CASE__     :int						    = y + DIRECTIONS[i][1]
																																			if xa >= 0 and xa < len(UpperCAmelCase__		) and ya >= 0 and ya < len(grid[0]		):
																																										if closed[xa][ya] == 0 and grid[xa][ya] == 0:
																																																	SCREAMING_SNAKE_CASE__     :str						    = g + cost
																																																	SCREAMING_SNAKE_CASE__     :Union[str, Any]						    = ga + heuristic[xa][ya]
																																																	cell.append([fa, ga, xa, ya]		)
																																																	SCREAMING_SNAKE_CASE__     :Union[str, Any]						    = 1
																																																	SCREAMING_SNAKE_CASE__     :Any						    = i
							SCREAMING_SNAKE_CASE__     :int						    = []
							SCREAMING_SNAKE_CASE__     :Union[str, Any]						    = goal[0]
							SCREAMING_SNAKE_CASE__     :Optional[int]						    = goal[1]
							invpath.append([x, y]		)  # we get the reverse path from here
							while x != init[0] or y != init[1]:
														SCREAMING_SNAKE_CASE__     :Optional[Any]						    = x - DIRECTIONS[action[x][y]][0]
														SCREAMING_SNAKE_CASE__     :Optional[Any]						    = y - DIRECTIONS[action[x][y]][1]
														SCREAMING_SNAKE_CASE__     :Optional[int]						    = xa
														SCREAMING_SNAKE_CASE__     :int						    = ya
														invpath.append([x, y]		)

							SCREAMING_SNAKE_CASE__     :int						    = []
							for i in range(len(UpperCAmelCase__		)		):
														path.append(invpath[len(UpperCAmelCase__		) - 1 - i]		)
							return path, action


if __name__ == "__main__":
		UpperCamelCase_      	=	[
		    [0, 1, 0, 0, 0, 0],
		    [0, 1, 0, 0, 0, 0],  # 0 are free path whereas 1's are obstacles
		    [0, 1, 0, 0, 0, 0],
		    [0, 1, 0, 0, 1, 0],
		    [0, 0, 0, 0, 1, 0],
		]

		UpperCamelCase_      	=	[0, 0]
		# all coordinates are given in format [y,x]
		UpperCamelCase_      	=	[len(grid) - 1, len(grid[0]) - 1]
		UpperCamelCase_      	=	1

		# the cost map which pushes the path closer to the goal
		UpperCamelCase_      	=	[[0 for row in range(len(grid[0]))] for col in range(len(grid))]
		for i in range(len(grid)):
				for j in range(len(grid[0])):
						UpperCamelCase_      	=	abs(i - goal[0]) + abs(j - goal[1])
						if grid[i][j] == 1:
								# added extra penalty in the heuristic map
								UpperCamelCase_      	=	99

		UpperCamelCase_	,			UpperCamelCase_      	=	search(grid, init, goal, cost, heuristic)

		print('''ACTION MAP''')
		for i in range(len(action)):
				print(action[i])

		for i in range(len(path)):
				print(path[i])






