diff --git a/positions.py b/positions.py new file mode 100644 index 0000000..c6b609a --- /dev/null +++ b/positions.py @@ -0,0 +1,28 @@ +import chess +import chess.engine + +# Initialize Stockfish engine +stockfish = chess.engine.SimpleEngine.popen_uci("./stockfish") + +# Sample FEN for board position; you can replace this with reading from a file +# This FEN represents the starting position of a chess game +fen_string = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1" +board = chess.Board(fen_string) + +# Placeholder: Uncomment the lines below if you'd like to read the FEN from a file +# with open("path_to_fen_file.txt", "r") as f: +# fen_string = f.readline().strip() +# board = chess.Board(fen_string) + +# Iterate over all squares and find legal moves for each piece +for square in chess.SQUARES: + piece = board.piece_at(square) + if piece: + # Get legal moves for the current piece + legal_moves = [move for move in board.legal_moves if move.from_square == square] + target_squares = [move.to_square for move in legal_moves] + + print(f"{piece.symbol()} at {chess.square_name(square)} can move to: {[chess.square_name(ts) for ts in target_squares]}") + +# Don't forget to quit the engine when done +stockfish.quit()