Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if __name__ == "__main__":
- start_fen = "8/4a3/8/4K3/3A4/8/8/1k6 w - - 0 1"
- # AR = calculate_optimal_moves(start_fen)
- find_min_positive_value(AR)
- # print_board_for_value(AR, -996)
- current_fen = start_fen
- simplified_current_fen = simplify_fen(current_fen)
- simplified_current_fen1 = simplified_current_fen
- optimal_moves = [simplified_current_fen]
- max_moves = 50
- move_count = 0
- while move_count < max_moves:
- board = CustomBoard(current_fen)
- print(f"\nAktuální pozice (tah {move_count + 1}):")
- print(board)
- print(f"FEN: {current_fen}")
- if board.is_checkmate():
- print("Mat detekován!")
- break
- if board.is_insufficient_material() or board.halfmove_clock >= 100:
- if board.is_insufficient_material():
- print("Nedostatečný materiál detekován!")
- else:
- print("Remíza pravidlem 50 tahů detekována!")
- AR[simplified_current_fen] = (0, 'drawing')
- break
- if simplified_current_fen not in AR:
- print(f"Pozice {simplified_current_fen} není v AR.")
- break
- current_value = AR[simplified_current_fen][0]
- print(f"Aktuální hodnota: {current_value}")
- if current_value == 0:
- print("Remíza dosažena!")
- break
- best_move = None
- if board.turn == chess.WHITE:
- best_value = float('inf')
- else:
- best_value = float('-inf')
- if board.turn == chess.WHITE:
- best_value = float('inf')
- else:
- best_value = float('inf') # Změněno z float('-inf') na float('inf')
- print("Možné tahy:")
- for move in board.legal_moves:
- board.push(move)
- next_fen = simplify_fen(board.fen())
- if next_fen in AR:
- value = AR[next_fen][0]
- print(f" Tah {move}: hodnota = {value}")
- if board.turn == chess.WHITE:
- print(f"Porovnávání pro bílé: {value} < {best_value}")
- if value < best_value:
- best_value = value
- best_move = move
- print(f" BMW {move}: hodnota = {value}")
- else:
- print(f"Porovnávání pro černé: {value} < {best_value}") # Změněno z '>' na '<'
- if value < best_value: # Změněno z '>' na '<'
- best_value = value
- best_move = move
- print(f" BMBl {move}: hodnota = {value}")
- else:
- print(f" Tah {move}: není v AR")
- board.pop()
- if best_move is None:
- print("Žádný další tah nebyl nalezen.")
- break
- print(f"Nejlepší tah: {best_move}, hodnota: {best_value}")
- board.push(best_move)
- next_fen = board.fen()
- simplified_next_fen = simplify_fen(next_fen)
- optimal_moves.append(simplified_next_fen)
- current_fen = next_fen
- simplified_current_fen = simplified_next_fen
- move_count += 1
- print("\nOptimální tahy:")
- for fen in optimal_moves:
- print_board(fen)
- hodnota, typ_pozice = AR[simplify_fen(fen)]
- print(f"Hodnota: {hodnota}, Typ: {typ_pozice}")
- print(fen)
- print("\n")
- print_board(simplified_current_fen1)
- hodnota, typ_pozice = AR[simplified_current_fen1]
- print(f"Počáteční hodnota: {hodnota}, Typ: {typ_pozice}")
- print(simplified_current_fen1)
- print("\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement