# Review a game Go through a finished game move by move. Engine judges every move, then Knight explains only the mistakes and blunders. A move-by-move review of a finished game, with the worst moves explained in words. It is a [Recipe](/docs/recipes): copy it, then change the prompt to suit your app. **Calls:** one Engine call for the whole game, and one Generate call on Knight per mistake or blunder, about $0.02 a game. ## The review A game review goes through a finished game move by move, finds where each side went wrong, and explains the worst moves in words. It takes two APIs: [Engine](/docs/engine) judges every move in numbers, then Generate explains only the mistakes and blunders, so you pay for words where they matter. 1. **Engine once on the whole game.** Send the PGN with no `ply`, and Engine [reviews every move](/docs/engine#review-a-whole-game) in one call, each position to `depth` 14 unless you set a limit. Each move comes back with its evaluation before and after, its Move `verdict` and Engine's best Line from before it. 2. **The verdict is Lichess's.** Each evaluation becomes a win chance from −1, Black wins, to +1, White wins: `2 / (1 + exp(−0.00368208 × cp)) − 1`, and ±1 for a mate. A move that lost 0.1 of it for the side that played it is an `inaccuracy`, 0.2 a `mistake` and 0.3 a `blunder`; `best` is Engine's own move, and the rest are `good`. `win_chance_lost` has the number. 3. **Generate on Knight for the mistakes and blunders only**, at the move's `ply`, the position it was played from, with Engine's best Line and its evaluation in the message, so the explanation starts from the right answer. **What one game costs:** a 40-move game is one Engine call of about 80 positions at depth 14, about 10 s of Engine time or $0.008 on Stockfish, plus about 5 Knight turns, about $0.01: **about $0.02 a game.** The [Estimator](/pricing) has it as Engine's "Review a game". A higher `depth` can find deeper mistakes but costs more Engine time, and the whole game must fit a call's 60 seconds; past that, review it in parts with `{pgn, ply}`. If you also [grade the game's accuracy](/docs/recipes/game-accuracy), reuse these same evaluations rather than calling Engine again. The game below falls into Légal's trap: Black's 5...Bxd1 grabs the queen and gets mated. The curl tab shows the Engine call for the game and the Knight call for that one move; the Python and JavaScript tabs review the whole game: one Engine call for its 12 moves, and 2 Knight calls for its mistake and its blunder. **Reading `lines`:** Knight's reply links the moves it names, starting from the position before the mistake. Show Engine's best Line beside it as the move to learn. ```text System prompt You review a student's chess game. The move they ask about was a mistake or a blunder. In at most three sentences, in plain words, say what the move allowed and why the engine's best move is better. Use the engine's Line and evaluation you are given, and show the moves you name. Judge positions in words, such as "Black is losing", never in numbers. ``` ```bash curl # Engine on the whole game: every move with its verdict and Engine's best Line. curl https://api.chessdrive.io/v1/engine \ -H "Authorization: Bearer $CHESSDRIVE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "engine": "stockfish", "position": { "pgn": "1. e4 e5 2. Nf3 d6 3. Bc4 Bg4 4. Nc3 g6 5. Nxe5 Bxd1 6. Bxf7+ Ke7" } }' # 5...Bxd1, played from ply 9, is a blunder, so Knight explains it. curl https://api.chessdrive.io/v1/generate \ -H "Authorization: Bearer $CHESSDRIVE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "knight-1", "system": "You review a student'\''s chess game. The move they ask about was a mistake or a blunder.\nIn at most three sentences, in plain words, say what the move allowed and why the engine'\''s best move is better.\nUse the engine'\''s Line and evaluation you are given, and show the moves you name.\nJudge positions in words, such as \"Black is losing\", never in numbers.", "position": { "pgn": "1. e4 e5 2. Nf3 d6 3. Bc4 Bg4 4. Nc3 g6 5. Nxe5 Bxd1 6. Bxf7+ Ke7", "ply": 9 }, "messages": [{ "role": "user", "content": "I played 5...Bxd1, a blunder. The engine'\''s best Line was dxe5 Qxg4 Nc6 d3 Nf6 Qf3 Bg7 a4, evaluated +2.51. What went wrong?" }] }' ``` ```python Python import os import requests API = "https://api.chessdrive.io/v1" HEADERS = {"Authorization": f"Bearer {os.environ['CHESSDRIVE_API_KEY']}"} PGN = "1. e4 e5 2. Nf3 d6 3. Bc4 Bg4 4. Nc3 g6 5. Nxe5 Bxd1 6. Bxf7+ Ke7" REVIEW = """You review a student's chess game. The move they ask about was a mistake or a blunder. In at most three sentences, in plain words, say what the move allowed and why the engine's best move is better. Use the engine's Line and evaluation you are given, and show the moves you name. Judge positions in words, such as "Black is losing", never in numbers.""" def post(path, body): r = requests.post(f"{API}/{path}", headers=HEADERS, json=body) r.raise_for_status() return r.json() def score(e): if e["mate"] is not None: return f"{'' if e['mate'] > 0 else '-'}M{abs(e['mate'])}" return f"{e['cp'] / 100:+.2f}" review = post("engine", {"engine": "stockfish", "position": {"pgn": PGN}}) for m in review["moves"]: move = f"{m['move_number']}{'.' if m['color'] == 'white' else '...'}{m['move']['san']}" verdict = m["verdict"] if m["verdict"] in ("inaccuracy", "mistake", "blunder") else "" print(move, verdict) if verdict in ("mistake", "blunder"): line = " ".join(b["san"] for b in m["best_line"]) reply = post("generate", { "model": "knight-1", "system": REVIEW, "position": {"pgn": PGN, "ply": m["ply"]}, "messages": [{"role": "user", "content": f"I played {move}, a {verdict}. The engine's best Line was {line}, evaluated {score(m['eval_before'])}. What went wrong?"}], }) print(reply["content"]) ``` ```js JavaScript const API = "https://api.chessdrive.io/v1"; const PGN = "1. e4 e5 2. Nf3 d6 3. Bc4 Bg4 4. Nc3 g6 5. Nxe5 Bxd1 6. Bxf7+ Ke7"; const REVIEW = `You review a student's chess game. The move they ask about was a mistake or a blunder. In at most three sentences, in plain words, say what the move allowed and why the engine's best move is better. Use the engine's Line and evaluation you are given, and show the moves you name. Judge positions in words, such as "Black is losing", never in numbers.`; async function post(path, body) { const res = await fetch(`${API}/${path}`, { method: "POST", headers: { Authorization: `Bearer ${process.env.CHESSDRIVE_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify(body), }); if (!res.ok) throw new Error(await res.text()); return res.json(); } const score = (e) => e.mate !== null ? `${e.mate > 0 ? "" : "-"}M${Math.abs(e.mate)}` : `${e.cp >= 0 ? "+" : ""}${(e.cp / 100).toFixed(2)}`; const review = await post("engine", { engine: "stockfish", position: { pgn: PGN } }); for (const m of review.moves) { const move = `${m.move_number}${m.color === "white" ? "." : "..."}${m.move.san}`; const verdict = ["inaccuracy", "mistake", "blunder"].includes(m.verdict) ? m.verdict : ""; console.log(move, verdict); if (verdict === "mistake" || verdict === "blunder") { const line = m.best_line.map((b) => b.san).join(" "); const reply = await post("generate", { model: "knight-1", system: REVIEW, position: { pgn: PGN, ply: m.ply }, messages: [{ role: "user", content: `I played ${move}, a ${verdict}. The engine's best Line was ${line}, evaluated ${score(m.eval_before)}. What went wrong?` }], }); console.log(reply.content); } } ``` ```text Output 1.e4 1...e5 2.Nf3 2...d6 3.Bc4 3...Bg4 4.Nc3 4...g6 mistake 4...g6 lets White give up the queen with [Nxe5](line:L1), hitting your bishop's defender and f7 at once. The engine's [Nf6](line:L2) develops and keeps the game level. 5.Nxe5 5...Bxd1 blunder Taking the queen walks into Légal's mate: after [Bxf7+ Ke7 Nd5#](line:L1) your king has no square. The engine's [dxe5 Qxg4](line:L2) gives the bishop back and keeps you in the game, only a pawn down. 6.Bxf7+ 6...Ke7 ```