def getCaptureSequences(cap_moves:list[chess.Move], board:chess.Board, targetedSquare:chess.Square) -> int: targetedCaptures:list[chess.Move] = [] #allCaptures = generateLegalCaptures(board) allCaptures = board.generate_legal_captures() for capture_move in allCaptures: if capture_move.to_square == targetedSquare: targetedCaptures.append(capture_move) for i in range(len(targetedCaptures)): swapped = False piece_value = PIECE_VALUES[board.piece_type_at(targetedCaptures[i].from_square)] for j in range(i): sorted_piece_value = PIECE_VALUES[board.piece_type_at(cap_moves[j].from_square)] if piece_value < sorted_piece_value: swapped = True cap_moves.insert(j, targetedCaptures[i]) break if not swapped: cap_moves.insert(i, targetedCaptures[i]) return len(targetedCaptures)
def quiescenceEvaluation(board:chess.Board) -> int: staticScore = staticEvaluation(board) if board.is_game_over(): return staticScore #captureMoves = generateLegalCaptures(board) captureMoves = board.generate_legal_captures() if len(list(captureMoves)) == 0: return staticScore else: bestScore = staticScore for move in captureMoves: if StaticExchangeEvaluation(board, move.to_square) <= 0: continue makeMove(board, move) score = quiescenceEvaluation(board) unMakeMove(board) if board.turn == chess.WHITE and score > bestScore or\ board.turn == chess.BLACK and score < bestScore: bestScore = score return bestScore
def generateLegalCaptures(board:chess.Board) -> list[chess.Move]:#Slow function!!! return [move for move in board.generate_legal_captures()]