# pip install chessimport chess def build_prompt(fen: str) -> str: board = chess.Board(fen) names = {1: "Pawn", 2: "Knight", 3: "Bishop", 4: "Rook", 5: "Queen", 6: "King"} pieces = {} for sq in chess.SQUARES: p = board.piece_at(sq) if p: key = f"{'White' if p.color else 'Black'} {names[p.piece_type]}" pieces.setdefault(key, []).append(chess.square_name(sq)) order = [f"{c} {t}" for c in ("White", "Black") for t in ("King", "Queen", "Rook", "Bishop", "Knight", "Pawn")] arrangement = ", ".join(f"{k}: {sorted(pieces[k])}" for k in order if k in pieces) legal = ", ".join(m.uci() for m in board.legal_moves) return ( f"You are given a chess position in FEN: {fen}.\n" f"Piece positions: {arrangement}\n" f"Legal moves: {legal}\n" "Find the best move for the side to play.\n" "Analyze step by step and explain your reasoning.\n" "Finish with a single line formatted EXACTLY as:\n" "FINAL_ANSWER: <answer>\n" "Use UCI notation (e.g., e2e4, c2b1q) for the final answer." ) MODEL_ID = "UofTCSSLab/C1-4B"FEN = "2kr3r/ppp2Npp/2nbp3/6N1/2PP2n1/4B2q/PP2BP2/R2Q1RK1 b - - 2 15"messages = [{"role": "user", "content": build_prompt(FEN)}]