Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import chess
- def simplify_fen_string(fen):
- parts = fen.split(' ')
- simplified_fen = ' '.join(parts[:4])
- return simplified_fen
- def is_mate_in_k_moves(board, k):
- if k == 0:
- return board.is_checkmate()
- if board.is_game_over():
- return False
- for move in board.legal_moves:
- board.push(move)
- if is_mate_in_k_moves(board, k - 1):
- board.pop()
- return True
- board.pop()
- return False
- def update_AR_for_mate_in_k(board, AR, max_k):
- for k in range(1, max_k + 1):
- for fen in list(AR.keys()):
- board.set_fen(fen)
- if AR[fen] is None:
- if is_mate_in_k_moves(board, k):
- # Hráč na tahu může vynutit mat v 'k' tazích
- AR[fen] = 1000 - k
- continue
- board.turn = not board.turn
- if is_mate_in_k_moves(board, k):
- # Hráč na tahu může být matován v 'k' tazích
- AR[fen] = -1000 + k
- board.turn = not board.turn
- def evaluate_initial_positions(board):
- AR = {}
- initial_fen = board.fen()
- simplified_fen = simplify_fen_string(initial_fen)
- AR[simplified_fen] = None
- return AR
- def main():
- initial_fen = "8/8/8/3Q4/8/2k5/7K/8 w - - 0 1" # Standardní šachová pozice
- board = chess.Board(initial_fen)
- AR = evaluate_initial_positions(board)
- # Nastavte max_k na maximální počet tahů, do kterých chcete mat hledat
- max_k = 17
- update_AR_for_mate_in_k(board, AR, max_k)
- for fen, value in AR.items():
- print(f"FEN: {fen}, Hodnota: {value}")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement