import numpy as np
from itertools import product
from typing import List

from src.config import ConfigChess
from src.chess.board import Board
from src.chess.move import Move


def get_all_possible_moves() -> List[Move]:
    all_possible_moves = set()
    array = np.zeros((ConfigChess.board_size, ConfigChess.board_size)).astype("int8")
    for i, j, piece in product(
        range(ConfigChess.board_size), range(ConfigChess.board_size), ["Q", "N"]
    ):
        array[i][j] = Board.piece_symbol_to_int(piece)
        all_possible_moves.update(
            set(map(lambda move: Move(uci=move.uci()), Board(array=array).legal_moves))
        )
        array[i][j] = 0
    # underpromotion moves
    array[1, :] = Board.piece_symbol_to_int("P")
    all_possible_moves.update(
        set(map(lambda move: Move(uci=move.uci()), Board(array=array).legal_moves))
    )
    array[0, :] = Board.piece_symbol_to_int("p")
    all_possible_moves.update(
        set(map(lambda move: Move(uci=move.uci()), Board(array=array).legal_moves))
    )
    # no need to add castling moves: they have already be added with queen moves under UCI notation
    return sorted(list(all_possible_moves))

[((22, 18, 22, 48), 'src.chess.board.Board.piece_symbol_to_int', 'Board.piece_symbol_to_int', ({(22, 44, 22, 47): '"""P"""'}, {}), "('P')", False, 'from src.chess.board import Board\n'), ((26, 18, 26, 48), 'src.chess.board.Board.piece_symbol_to_int', 'Board.piece_symbol_to_int', ({(26, 44, 26, 47): '"""p"""'}, {}), "('p')", False, 'from src.chess.board import Board\n'), ((16, 22, 16, 54), 'src.chess.board.Board.piece_symbol_to_int', 'Board.piece_symbol_to_int', ({(16, 48, 16, 53): 'piece'}, {}), '(piece)', False, 'from src.chess.board import Board\n'), ((12, 12, 12, 70), 'numpy.zeros', 'np.zeros', ({(12, 21, 12, 69): '(ConfigChess.board_size, ConfigChess.board_size)'}, {}), '((ConfigChess.board_size, ConfigChess.board_size))', True, 'import numpy as np\n'), ((24, 51, 24, 69), 'src.chess.board.Board', 'Board', (), '', False, 'from src.chess.board import Board\n'), ((28, 51, 28, 69), 'src.chess.board.Board', 'Board', (), '', False, 'from src.chess.board import Board\n'), ((18, 55, 18, 73), 'src.chess.board.Board', 'Board', (), '', False, 'from src.chess.board import Board\n')]