Exemplo n.º 1
0
def get_board_defence_total_value(board: chess.Board) -> float:
    total_value = 0

    for square_defend in chess.SQUARES:
        piece_defend = board.piece_at(square_defend)
        if piece_defend is not None and piece_defend.color == board.turn:
            if board.is_attacked_by(not board.turn, square_defend):

                for square_defendant in chess.SQUARES:
                    piece_defendant = board.piece_at(square_defendant)
                    if piece_defendant is not None and piece_defendant.color == board.turn:

                        if square_defend in board.attacks(square_defendant):
                            total_value += Macros.PIECE_VALUES[
                                piece_defend.
                                piece_type] / Macros.BOARD_INTERVAL_FIX

    return total_value