fix: Correctly generate FEN positions before/after moves in move exchange
The previous implementation tried to use undo() on a Chess object created from a FEN string, which has no move history. This resulted in all three FEN positions being identical. Now we use the game object's PGN (which contains full move history) and load it into temporary Chess objects before undoing moves. This correctly generates: - FEN before user's move (undo both computer and user moves) - FEN after user's move (undo only computer move) - FEN after computer's reply (current position) This ensures the LLM receives accurate position context for each stage of the move exchange.
This commit is contained in:
@@ -239,11 +239,22 @@ IMPORTANT CONTEXT:
|
||||
}
|
||||
|
||||
// Get FEN before user's move (need to undo both moves)
|
||||
const tempGame = new Chess(currentFen);
|
||||
tempGame.undo(); // Undo computer move
|
||||
const fenAfterUserMove = tempGame.fen();
|
||||
tempGame.undo(); // Undo user move
|
||||
const fenBeforeUserMove = tempGame.fen();
|
||||
// We need to use the game object which has the full move history
|
||||
const history = game.history({ verbose: true });
|
||||
|
||||
// Current position is after both user and computer moves
|
||||
// To get FEN after user move, we need to undo the computer move
|
||||
const tempGame1 = new Chess();
|
||||
tempGame1.loadPgn(game.pgn());
|
||||
tempGame1.undo(); // Undo computer move
|
||||
const fenAfterUserMove = tempGame1.fen();
|
||||
|
||||
// To get FEN before user move, we need to undo both moves
|
||||
const tempGame2 = new Chess();
|
||||
tempGame2.loadPgn(game.pgn());
|
||||
tempGame2.undo(); // Undo computer move
|
||||
tempGame2.undo(); // Undo user move
|
||||
const fenBeforeUserMove = tempGame2.fen();
|
||||
|
||||
const prompt = `
|
||||
[SYSTEM TRIGGER: move_exchange]
|
||||
|
||||
Reference in New Issue
Block a user