Chapter 4 Exercises — King Safety

Difficulty: ⭐ recall and concepts · ⭐⭐ positions and short analysis · ⭐⭐⭐ data, code and judgement · ⭐⭐⭐⭐ open-ended research.

Every position below comes from a real game in the book's data. Every engine number is from our own Stockfish 19 run, at the stated depth, from White's point of view. Scripts referred to live in this chapter's code/ folder.


Part A — Concepts ⭐

A1. State the "two lives" of the king in one sentence each. What event in the game marks the switch from one to the other?

Answer

Middlegame: a liability to be sheltered, because enough enemy pieces remain to build a mating attack. Endgame: a strong piece to be centralised, because the mating force is gone and the king's reach (up to eight squares) matters. The switch is gradual but usually tied to the queens coming off and the attacking material thinning out.

A2. Compute the shelter points (book definition) for each king: (a) Kg1 with pawns f2, g2, h2; (b) Kg1 with f2, g3, h2; (c) Kg1 with f2, h3 and no g-pawn; (d) Kc1 with a2, b2, c2 after O-O-O; (e) Kh1 with pawns g2 and h3 (careful: which files count for a king on the h-file?).

Answer

(a) 6. (b) 2 + 1 + 2 = 5. (c) f2 = 2, g missing = 0, h3 = 1: 3. (d) For a king on c1 the files are b, c and d: b2 = 2, c2 = 2, and the d-file has no pawn in front of the king here, so 4 (the a2-pawn doesn't count). (e) A king on h1 has only two neighbouring files on the board, g and h: g2 = 2, h3 = 1, total 3 out of a possible 4 — one reason a king in the corner is not automatically safer.

A3. Define king zone and attack weight. Why are pawns not counted in the attack weight?

Answer

King zone: the king's square, its neighbours and the three squares two ranks in front. Attack weight: the sum of N/B 2, R 3, Q 5 over enemy pieces that attack at least one zone square. Pawns are left out because their attacks are short-range and they show up separately as shelter damage or a storm; counting both would double-count the same threat. (It is a book heuristic, not Stockfish's term.)

A4. List the five classical Greek-gift preconditions. Which one was the most informative in our pooled data, and by how much?

Answer

Knight can reach g5; g5 unguarded after Bxh7+ Kxh7 (except by the king); queen can reach h3–h7; no Black knight on f6; White pawn on e5. The e5-pawn: 50.4% of sacrifices winning with it (n = 1,350) vs 29.8% without (n = 5,116).

A5. What is the median castling move in the Lichess data under 1000, and over the board at 2400+? What really differs between the two groups?

Answer

Move 10 and move 9. What differs is whether players castle at all: 53.1% of side-games under 1000 on Lichess, 88.3% of OTB side-games at FIDE 2400+.

A6. Why can a side castled on the opposite wing push its pawns at the enemy king "for free"?

Answer

The storming pawns stand on the other side of the board from their own king, so advancing them weakens no shelter. In same-side castling every storming pawn is also a shelter pawn.

A7. Give two reasons why the h-pawn is the preferred lever in a same-side attack.

Answer

It shields the king least (after h4 the king on g1 still has f2 and g2 in front), and the squares it weakens (g3, g4) are hard for the opponent to reach; meanwhile h4-h5-h6 attacks the g-pawn or fianchetto and opens the h-file or the long diagonal.

A8. What is luft, and when is creating it a good use of a tempo?

Answer

An escape square for the king made by a shelter pawn move (h3/...h6, sometimes g3). It is a good use of a tempo when it solves a concrete problem — a back-rank mate threat, or a piece (knight or bishop) that would land on g5/g4 — not as a general "safety" move.

A9. In the opposite-castling data, the first stormer scored 56.0% over the board (+3.7 above expectation). Name two reasons this number overstates the value of "attacking first".

Answer

(1) First stormers were more often already better when both kings had castled (37.5% were ahead by more than half a pawn, 22.6% behind); among level positions the edge is only +1.7. (2) The effect is concentrated in games where the opponent's storm never arrived — which includes games that ended early for other reasons. When both storms arrived ten or more plies apart, the first stormer scored 49.2%.

A10. True or false: "An intact pawn shelter (6/6) means the king is safe." Use a position from the chapter.

Answer

False. Polugaevsky–Tal before 19.Bxh7+: Black's shelter was 6/6, the attack weight 7 against two defenders, and Stockfish 19 gave White +2.45 at depth 24. Shelter is the wall; the attackers decide.


Part B — Positions ⭐⭐

B1. Find the tactic. Kasparov–Short, London rapid match 1993. White to move.

Kasparov–Short after 19...Bb4

♟️ Position: White Kg1, Qb3, Rc3, Rf1, Bd2, Bd3, Nf3, a4, b2, d4, e5, f2, g2, h2; Black Kg8, Qd8, Rc8, Rf8, Bb4, Bb7, Nc7, a5, b6, d5, e6, f7, g7, h7 — White to move. FEN: 2rq1rk1/1bn2ppp/1p2p3/p2pP3/Pb1P4/1QRB1N2/1P1B1PPP/5RK1 w - - 10 20

Solution

20.Bxh7+! Stockfish 19 gives +7.22 at depth 20 (the next-best move, 20.Bg5, only +1.71). The module counts three preconditions (knight to g5, pawn on e5, no f6-knight); the queen on d8 guards g5 and White's queen is not yet on the h-file. Why it works anyway: the rook on c3 can swing to h3. The game went 20...Kxh7 21.Ng5+ Kg8 22.Rh3 Re8 23.Qf3 Qd7 24.Qh5 Kf8 25.Nh7+ Ke7 26.Bg5+ f6 27.Nxf6, and White won. Black's 19...Bb4 had attacked the rook but taken the bishop away from the kingside — the "missing precondition" (the queen's route) was supplied by a rook lift.

B2. Find the mate. Alekhine–Tenner, Cologne 1911. White has sacrificed his queen (11.Nxe5 Bxd1 12.Bxf7+ Ke7 13.Bxc5+ Kf6). White to move.

Alekhine–Tenner after 13...Kf6

♟️ Position: White Ke1, Ra1, Rh1, Bc5, Bf7, Ne5, a2, b2, c2, d3, e4, g2, h2; Black Kf6, Qd8, Ra8, Rh8, Bd1, Nh5, a7, b7, c7, g7, h7 — White to move. FEN: r2q3r/ppp2Bpp/5k2/2B1N2n/4P3/3P4/PPP3PP/R2bK2R w KQ - 1 14

Solution

14.O-O+! — castling with check: the rook arrives on f1 facing the king on f6. Stockfish 19 (depth 20) reports a forced mate, #6, starting with 14.O-O+. In the game Black played 14...Kxe5 and was mated at once by 15.Rf5#. The lesson for this chapter: castling is not only a defensive move — it brings a rook to the centre or to an open f-file in one tempo, and here the king the castling "protects" is never in danger because Black has no attackers left near it.

B3. Analyze this position. Judit Polgar–Karpov, Essent (Hoogeveen) 2003. White to move. How many Greek-gift preconditions hold, and what decides the position?

Polgar–Karpov after 24...Qc5

♟️ Position: White Kg1, Qd1, Re1, Re3, Bd3, Be5, c3, d5, f2, g2, h2; Black Kg8, Qc5, Re8, Rf8, Bd7, Na5, a7, b6, c7, f7, g7, h7 — White to move. FEN: 4rrk1/p1pb1ppp/1p6/n1qPB3/8/2PBR3/5PPP/3QR1K1 w - - 2 25

Solution

Three of five by the module: g5 unguarded after the capture, queen to the h-file (Qd1–h5), no f6-knight. There is no knight to go to g5 and no e5-pawn — but the bishop on e5 does the pawn's job (it covers g7 and f6) and a rook on e3 can lift to g3 or h3. Stockfish 19: +11.15 at depth 20 with 25.Bxh7+. The engine line declines (25...Kh8 26.Qh5 Bg4 27.Bxg7+ ...); the game went 25.Bxh7+ Kxh7 26.Qh5+ and Black resigned. The preconditions are a checklist of jobs (cover f6, reach h5, deny defenders); a different piece can do a missing job.

B4. Should you sacrifice? Lopez Gonzalez–Macieja, 2025 (FIDE 2394 vs 2503 in the record). Black has just played 15...Nxe5, capturing a White knight. White to move. 16.Bxh7+?

Lopez Gonzalez–Macieja after 15...Nxe5

♟️ Position: White Kc1, Qe2, Rf1, Rh1, Bd2, Bd3, Nf3, a2, b2, c2, g2, h4; Black Kg8, Qc7, Ra8, Rf8, Bc5, Bc8, Nd5, Ne5, a7, b5, e6, f7, g7, h7 — White to move. FEN: r1b2rk1/p1q2ppp/4p3/1pbnn3/7P/3B1N2/PPPBQ1P1/2K2R1R w - - 0 16

Solution

No. First count the material: White is a knight down and must recapture with 16.Nxe5 (Stockfish 19: −1.28 at depth 20, −1.30 at depth 24 — Black is better but White is fighting). The game's 16.Bxh7+ is rated −5.48 (depth 20) / −6.36 (depth 24): White sacrifices a second piece while the first is still hanging. The module still counts three preconditions (knight to g5, g5 unguarded, no f6-knight), which is exactly why the checklist is not enough on its own — the knight that would go to g5 is the same knight that must recapture on e5. Black won.

B5. Build the plan. Fischer–Sherwin, East Orange 1957, after 17.h4 Nf6 18.Nxh7 Nxh7. White to move.

Fischer–Sherwin after 18...Nxh7

♟️ Position: White Kg1, Qc2, Ra1, Re1, Bc1, Bg2, a2, b2, c3, d4, f2, g3, h4; Black Kg8, Qd6, Rb8, Rf8, Bc8, Ng6, Nh7, a7, b6, c4, e6, f7, g7 — White to move. FEN: 1rb2rk1/p4ppn/1p1qp1n1/8/2pP3P/2P3P1/PPQ2PB1/R1B1R1K1 w - - 0 19

Solution

19.h5! (Stockfish 19: +2.49 at depth 20), driving the g6-knight away so the queen on c2 sees h7 and the h-pawn can continue to h6. The tempting 19.Qe2, aiming at c4 and h5, is rated −2.97: it lets Black consolidate a piece up. Fischer played 19.h5 Nh4 20.Bf4 Qd8 21.gxh4 Rb7 22.h6 and won. Plan in words: evict the defender (h5), develop with tempo (Bf4), open the g- and h-files (gxh4, h6), then lift a rook (Re4-e3-h3).

B6. Engine analysis. Karpov–Korchnoi, Candidates final 1974, game 2, after 17.Bh6. Black to move. Compare Stockfish's verdict at two depths and explain the difference.

Karpov–Korchnoi after 17.Bh6

♟️ Position: White Kc1, Qd2, Rd1, Rh1, Bh6, Nc3, Ne2, a2, b2, c2, e4, f3, g4; Black Kg8, Qa5, Rc4, Rf8, Bd7, Bg7, Nf6, a7, b7, d6, e7, f7, g6, h7 — Black to move. FEN: 5rk1/pp1bppbp/3p1npB/q7/2r1P1P1/2N2P2/PPPQN3/2KR3R b - - 4 17

Solution

Depth 20: +0.83 with 17...Rfc8; depth 24: +1.20 with 17...Bxh6. The deeper search finds more for White — after ...Bxh6 Qxh6 the plan Nd5 (or g5) against the f6-knight is faster than Black's c-file play. Both depths agree that White is better and that the race favours White; they disagree on how much and on Black's best try. Sharp king-attack positions are where depth matters most: always state it. (Korchnoi played 17...Bxh6.)

B7. Find the defence. Abdusattorov–Gukesh, Tata Steel Masters 2026, after 36.Qf5. Black to move. Black's shelter is gone and White's queen eyes f6. One move holds the balance; the game move lost at once.

Abdusattorov–Gukesh after 36.Qf5

♟️ Position: White Kg2, Qf5, Re1, Rf1, a4, c2, c4, d3, e5, f3; Black Kg7, Qd4, Rd8, Rg6, a5, b6, c5, c7, f6, g3, h7 — Black to move. FEN: 3r4/2p3kp/1p3pr1/p1p1PQ2/P1Pq4/3P1Pp1/2P3K1/4RR2 b - - 4 36

Solution

36...Rf8! (Stockfish 19: +0.02 at depth 20) defends f6 a second time; after 37.Re4 Qc3 the position is level. The game's 36...Rg5?? moved the rook off the sixth rank, so f6 lost a defender: 37.Qxf6+ (+11.08, depth 20) and Black resigned. Count the defenders of the square the attacker hits — here f6 was attacked by the queen and the e5-pawn and defended by the g6-rook (along the sixth rank) and the g7-king; after ...Rg5 only the king remained. Case Study 1 tells the whole story.


Part C — Data & Code ⭐⭐–⭐⭐⭐

C1. Database research — Greek gifts by speed. Extend 02_greek_gift.py: split the OTB broadcast Greek gifts by speed (classical / rapid / blitz). For each, report n, acceptance rate, the sacrificer's score vs Elo expectation, and the refuted share. Expected output: a 3-row table; expect fewer than 2,554 rows in total because some games have unknown speed. Does the practical edge grow at faster time controls?

C2. Database research — Bxh7+ vs ...Bxh2+. Using code/greek_gift_events.csv, compare White's Greek gifts with Black's (side column). Report counts, winning/refuted shares and sacrificer scores per source. Expected output: a 6-row table (3 sources × 2 sides). Is Black's version rarer, and is it any less sound?

C3. Change the definition. In 03_opposite_castling_race.py, a storm "arrives" on the attacker's 5th rank. Change it to the 4th rank (rr >= 4) and rerun (delete race_replay_cache.csv first). How do the first stormer's OTB score and the "only one storm arrived" row change? Expected output: the same table as in Section 4.5 with new numbers, and two or three sentences on why an earlier definition dilutes (or sharpens) the effect.

C4. Castling side by opening. Join game_features (castling sides) with the opening column of the broadcast data and list the ten opening families (text before ':') with the highest share of opposite-side castling (minimum 500 games). Expected output: a 10-row table with family, games, opposite share, draw rate. You should find Sicilian families near the top — check whether the Dragon lines appear.

C5. Shelter with fianchetto. Our shelter points give a pawn on g3 only 1 point. Write a variant shelter_score_fianchetto that gives full credit to g3 (g6) when a friendly bishop stands on g2 (g7). Rerun the shelter-vs-eval table of 04_shelter_and_eval.py with both definitions. Expected output: two 7-row tables (shelter 0–6) per source; does the fianchetto-aware version correlate better with the evaluation?

C6. King centralisation by band. Extend the endgame block of 04_shelter_and_eval.py to report the Spearman correlation between king-centralisation lead and evaluation separately for each rating band (rating_band column of positions_sample; n ≥ 300 per band). Expected output: one row per band and source. Does king activity matter more at higher levels, or is it the same everywhere?

C7. Castling timing and the clock. Using game_features for Lichess (weighted by sample_weight, BOTs excluded), compare the share of side-games that castle by move 10 in bullet, blitz and rapid, within the 1400–1599 band only. Expected output: a 3-row table. Our speed-level table shows bullet players castling by move 10 slightly more often than rapid players (49.2% vs 41.7% across all bands); does that survive within a single band, and why might fast games encourage earlier castling?

Hints for C1–C7

C1: out[out.source == "broadcast"].groupby("speed"). C2: the side column is "white" for Bxh7+. C3: the storm test is in storm(); the replay is cached, so remember to delete the cache. C4: use opening.str.split(":").str[0]. C5: check board.piece_at(chess.G2) for a friendly bishop. C6: positions_sample already has rating_band; add it to the columns= list. C7: filter rating_band or compute chessdata.rating_bands(avg_elo), then weight with np.average(..., weights=sample_weight).


Part D — Judgment & Transfer ⭐⭐⭐

D1. On Lichess under 1000 the Greek-gift sacrificer scored 37.9% against an expectation of 48.2%; over the board at FIDE 1400–1599 it scored 68.0% against 54.5%. Write advice for a 900-rated online player and for a 1500-rated tournament player about when to play Bxh7+. Why might the advice differ even though the chess is the same?

D2. An uncastled king cost only −0.8 to −2.2 points on average in our data, yet coaches insist on early castling. Using the open-centre split (47.9% vs 36.5%), write a paragraph explaining to a sceptical student why both facts can be true.

D3. In Fischer–Sherwin the engine preferred a quiet move (18.Qe2, +2.79) to Fischer's sacrifice (+1.97). In Batsiashvili–Kosteniuk the engine called the sacrifice a blunder (−4.41) and it won. Write a short "sacrifice policy" for a 1700 player in a rapid game that respects both lessons.

D4. At FIDE 2400+ the opposite-castling draw rate was 29.6% against 41.8% for same-side castling. If you are Grace, needing a win in the last round against a stronger player, how would you use that number — and what would make you avoid opposite castling anyway?

D5. In Abdusattorov–Gukesh the engine never rated White better until move 36, yet White's attack "worked". Is it fair to call 19.h4 a good move? Discuss what "good" means for a human in a classical game against a world-class defender, using the engine numbers (+0.01 before 19.h4, −0.21 after 24.h5 at depth 24, +11.08 after 36...Rg5).

Guidance for Part D

D1: the soundness rate rises with the preconditions everywhere, but the practical value depends on how often defenders find the refutation; under 1000 the sacrifice is usually played without preconditions (2.6% had four or more) and loses. D2: averages mix closed and open centres; the penalty concentrates in open positions. D3: e.g. "play it when you have four or more preconditions or can calculate every king reply; with fewer, play it only if the defence requires a single non-obvious move and the clock is short — and never a piece down". D4: opposite castling raises decisiveness for both sides; avoid it if the opponent's storm would arrive first or if your opening knowledge of the race is thin. D5: the move kept the objective balance (it cost nothing) while creating a long series of problems for the defender; "good" for a human combines soundness with the difficulty it creates. A move that is objectively equal and practically hard to meet is a fine choice.


Part M — Mixed / Interleaved ⭐⭐–⭐⭐⭐

M1 (with Chapter 1). Convert the three evaluations of the hook position after 15.Ng5+ (−4.27, 0.00, +3.86 at depth 24) into White's winning percentage using Chapter 1's win% model. What does the spread tell you about the importance of the defender's choice?

Answer

About 17.2%, 50.0% and 80.6% for White (the model gives 17.2 for −427 cp and 80.6 for +386 cp). A single king move swings White's practical chances by over 60 percentage points.

M2 (with Chapter 2). The Karpov–Korchnoi game is a Dragon Sicilian with White's pawns on e4/f3 and Black's fianchetto. Which structural feature from Chapter 2 makes White's h4-h5 lever effective, and which Black pawn move would remove it?

Answer

Black's g6-pawn is a "hook": a pawn that an advancing h-pawn can attack and exchange to open the h-file. ...h5 (the engine's 12...h5) stops h4-h5 directly and makes the hook harder to catch.

M3 (with Chapter 3). In Polugaevsky–Tal the module counted two defenders of Black's king zone. Using Chapter 3's ideas about piece activity, which Black piece would have been the most valuable defender, and where should it have stood?

Answer

The knight: on f6 (blocked by e5 — so on f8 or g6 via e7) it would have covered h7 and g5. Its trip to b2 made it an active-looking but useless piece; activity is relative to where the fight is.

M4 (with Chapters 2 and 3). Explain why a White pawn on e5 shows up both as a structure feature (Chapter 2's French chain) and as a piece-activity feature (an outpost on d6/f6 for knights) and as a king-safety feature (Greek-gift precondition). Give one move from this chapter's games where all three roles mattered at once.

Answer

Polugaevsky's 17.e5: it fixed the structure (d5 isolated after exd5), took f6 from Black's knight and prepared the Greek gift; the knight was then driven to the rim.

M5 (with Chapter 1). Chapter 1 describes plans as directions. Write the plan of White in Abdusattorov–Gukesh (19.h4 … 24.h5 … Qh5) as a direction, and say what the engine's +0.00 before 19.h4 means for that plan.

Answer

Direction: "open lines against the h8-king with the h-pawn, then bring the queen and knights to h5/h6". +0.00 means the plan does not change the objective balance — it is a choice of battlefield, not a winning method. Its value was practical: it forced Black to find accurate moves for twenty moves.


Part E — Research & Extension ⭐⭐⭐⭐

E1. The h-pawn and the engine era. The master files show h-pawn storms rising from 16.0% (1970s) to 27.4% (2020s) of O-O vs O-O games. Design a study that could separate an "engine influence" explanation from (a) changes in openings and (b) the over-representation of modern elite players in the files. Consider restricting to a fixed set of openings, to players active across decades, or to events before and after 2018. Run the simplest version with 05_rook_pawn_storms.py and report what you find, with sample sizes.

E2. A better king-danger score. Combine shelter points, attack weight, defenders, open files and castling status into a single logistic-regression model that predicts the king owner's result from a middlegame position in positions_sample. Use a train/test split by game, report accuracy against a rating-only baseline, and inspect the coefficients. Does any single term dominate? Is the model better on OTB or Lichess positions?

E3. Defence statistics. For every accepted Greek gift followed by Ng5+ in greek_gift_events.csv, replay the game and record the king's reply (…Kg8, …Kg6, …Kh6, …Kh8, or a capture on g5). Using the engine at depth 18 on a sample of at most 300 positions, find the best reply in each and measure how often defenders at each rating band chose it. Which defence is most often missed?