Advertisement
max2201111

validni pozice nenalezena

Jun 21st, 2024
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | Science | 0 0
  1. import chess
  2. from itertools import permutations, combinations
  3.  
  4. def simplify_fen_string(fen):
  5.     parts = fen.split(' ')
  6.     simplified_fen = ' '.join(parts[:4])  # Zachováváme pouze informace o pozici
  7.     return simplified_fen
  8.  
  9. def generate_chess_positions(pieces):
  10.     all_squares = [chess.SQUARES[i] for i in range(64)]
  11.     unique_fens = set()
  12.    
  13.     for squares in combinations(all_squares, len(pieces)):
  14.         for square_perm in permutations(squares):
  15.             board = chess.Board(None)
  16.             board.clear_board()
  17.             for piece, square in zip(pieces, square_perm):
  18.                 board.set_piece_at(square, chess.Piece.from_symbol(piece))
  19.             if board.is_valid():
  20.                 # Přidáme pozici s bílým na tahu
  21.                 board.turn = chess.WHITE
  22.                 unique_fens.add(simplify_fen_string(board.fen()))
  23.                 # Přidáme pozici s černým na tahu
  24.                 board.turn = chess.BLACK
  25.                 unique_fens.add(simplify_fen_string(board.fen()))
  26.     return unique_fens
  27.  
  28. # Testování generování pozic
  29. initial_pieces = ['K', 'k', 'Q']  # Můžete změnit figury podle potřeby
  30. unique_positions = generate_chess_positions(initial_pieces)
  31.  
  32. # Ověření, zda je konkrétní pozice vygenerována
  33. test_position = "8/8/5KQk/8/8/8/8/8 b - - 0 1"
  34. simplified_test_position = simplify_fen_string(test_position)
  35.  
  36. if simplified_test_position in unique_positions:
  37.     print("Pozice nalezena!")
  38. else:
  39.     print("Pozice nenalezena.")
  40.  
  41. # Výpis prvních 10 pozic
  42. print("Ukázka prvních 10 pozic:")
  43. for i, pos in enumerate(unique_positions):
  44.     if i < 10:
  45.         print(pos)
  46.     else:
  47.         break
  48.  
  49. print(f"Celkový počet unikátních pozic: {len(unique_positions)}")
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement