59 min read

December 2025, the Global Chess League, a rapid game relayed on Lichess. Nino Batsiashvili has White

Chapter 4 — King Safety: When to Attack, When to Castle, and the Art of the Kingside Assault

December 2025, the Global Chess League, a rapid game relayed on Lichess. Nino Batsiashvili has White against Alexandra Kosteniuk, a former Women's World Champion; the broadcast record lists them at 2346 and 2450. It is a quiet London-type position, and after thirteen moves it looks like this:

Batsiashvili–Kosteniuk after 13...fxe5: White to move. The bishop on d3 stares at h7.

♟️ Position: White Ke1, Qd1, Ra1, Rh1, Bd3, Bf4, Nf3, a2, b2, c3, f2, g2, h4; Black Kg8, Qd8, Ra8, Rf8, Bd7, Be7, Nc6, a7, b7, d5, e5, g7, h7 — White to move. FEN: r2q1rk1/pp1bb1pp/2n5/3pp3/5B1P/2PB1N2/PP3PP1/R2QK2R w KQ - 0 14

Everything a club player has been told about the Greek gift — the bishop sacrifice on h7 — seems to be here. The bishop on d3 aims at h7. The knight on f3 can jump to g5 with check. The h-pawn has already reached h4, so a rook on h1 is ready to join along the h-file. Black's king has just lost its f-pawn neighbour. Batsiashvili played 14.Bxh7+, Kosteniuk took, 14...Kxh7, and after 15.Ng5+ the position became a test of one decision.

After 15.Ng5+: Black has three ways out of check. One wins, one draws, one loses.

♟️ Position: White Ke1, Qd1, Ra1, Rh1, Bf4, Ng5, a2, b2, c3, f2, g2, h4; Black Kh7, Qd8, Ra8, Rf8, Bd7, Be7, Nc6, a7, b7, d5, e5, g7 — Black to move. FEN: r2q1r2/pp1bb1pk/2n5/3pp1N1/5B1P/2P5/PP3PP1/R2QK2R b KQ - 1 15

We asked Stockfish 19 for its three best replies:

SF19 d24:   -4.27  Kg8 Qxd5+ Kh8 O-O-O Rxf4 Qxd7 Qxd7 Rxd7
SF19 d24:   +0.00  Bxg5 hxg5+ Kg6 Qh5+ Kf5 Be3 Qe8 Qh3+
SF19 d24:   +3.86  Kg6 h5+ Kf6 Be3 g6 hxg6 Bf5 Nh7+

Retreating the king to g8 leaves Black more than four pawns ahead in the engine's eyes (−4.27, Stockfish 19, depth 24). Taking the knight with the bishop is a draw (+0.00). Stepping forward with 15...Kg6 — the "active" defence that keeps the king near its pieces — is losing (+3.86). The sacrifice itself was objectively bad: right after 14.Bxh7+ the engine gives −4.41 (depth 24), where the quiet 14.Bxe5 kept +0.12. Kosteniuk chose 15...Kg6, the king was driven to f6, e6, d5 and finally e4, and White won on move 32.

Three lessons from one position, and they organise this chapter:

  1. King safety is concrete. The bishop on d3, the knight on f3, the pawn on h4 are not decoration; they are the preconditions that decide whether a sacrifice works. Section 4.4 counts them across 9,899 real Greek gifts and shows how strongly they predict the outcome.
  2. Defence is a skill with right and wrong answers. In the most famous attacking pattern in chess the defender's first choice — g8, g6 or the capture — swung the evaluation by eight pawns.
  3. The engine and the result can disagree. The sacrifice was unsound and won anyway, in a rapid game, because the defender had to find one narrow path with a clock running. Practical chances are real; they are not the same thing as soundness.

The rest of the chapter builds the tools to read such positions before you are in them: when to castle, how to measure a pawn shelter, how to count the attackers, when the Greek gift works, how opposite-side castling races are won, and why the h-pawn has become the modern grandmaster's favourite battering ram.

♟️ Improver Track: Read 4.1–4.4 closely and do every 📋 position on a board in your head first. The Greek-gift checklist in 4.4 is worth points the next time your opponent's bishop points at h7.

📊 Analyst Track: The data sections are 4.2 (castling timing by band), 4.3 (do shelter and attacker counts track the engine?), 4.4 (9,899 Greek gifts), 4.5 (the opposite-castling race) and 4.6 (the h-pawn by era). Each states its population, filter and sample size.

🏆 Competitor Track: 4.5 and 4.6 are about choosing a castling side and timing a storm in a real tournament game; 4.7 is about defending when you are on the receiving end.

💻 Developer Track: This chapter's Outpost module is king_safety.py — shelter points, a king zone, attack weight, castling timelines and a Greek-gift precondition checker. See the Project Checkpoint.


4.1 The King's Two Lives

The principle. In the middlegame the king is the one piece you cannot afford to lose, so it is a liability: every enemy piece aimed at it is a threat, every pawn moved in front of it is a door left open. In the endgame, once the queens (and most of the attacking force) are gone, the king becomes a strong piece: it attacks pawns, escorts its own and controls key squares. Good players switch between these two attitudes at the right moment; weaker players either expose the king too early or leave it huddled in the corner too long.

The reasoning. Why should the same piece change character? Look at what can hurt it. A king can be checked from up to eight directions along lines and diagonals, plus the knight's jumps. In the middlegame the opponent usually has a queen, two rooks and minor pieces — enough force to deliver mate if two or three of them can reach the squares around the king at once. The king zone (the king's square and its neighbours) is small, and the king cannot defend it alone because it cannot move into check. Shelter pawns and defending pieces have to do that job.

When the queens come off, two things happen. First, mating nets need far more coordination: a rook and a minor piece rarely trap a king in the open board. Second, the king's own reach — it touches up to eight squares, as many as a knight in the centre — becomes a real asset in a position where every pawn matters. The king walks toward the centre because that is where it touches the most squares that matter.

🔍 Why this works: Count the squares. A king on g1 behind f2-g2-h2 can be checked only on a few lines that pawns already block; the same king on e4 in a middlegame can be checked along the e-file, the fourth rank and two long diagonals. In a queenless ending the danger lines are covered by far fewer enemy pieces, while the king on e4 now controls d3, d4, d5, e3, e5, f3, f4 and f5 — the squares through which passed pawns advance. The geometry hasn't changed; the number of enemy long-range pieces has.

The data. We can test the endgame half directly. Our script 04_shelter_and_eval.py takes the queenless endgame positions in positions_sample (one random position per game, from both the broadcast and Lichess games) that carry an evaluation and have equal material by the 1/3/3/5/9 count, and measures how much closer White's king is to the centre than Black's (distance to the nearest of d4, d5, e4, e5). A lead of +2 means White's king is two king-moves nearer the centre.

=== Queenless endgames, equal material: White's king centralisation lead vs eval and score ===
                   n  mean_eval  score
source    diff
broadcast -3      52     -234.0   30.8
          -2     414      -98.0   36.6
          -1    1320      -28.8   45.3
           0    2705       11.6   50.9
           1    1317       45.1   56.1
           2     391      128.3   59.7
           3      46      221.3   64.1
broadcast: Spearman rho(lead, eval) = +0.192 (n = 6,245)
lichess: Spearman rho(lead, eval) = +0.169 (n = 2,572)

In over-the-board games, the side whose king is two steps more central scores 59.7% (n = 391), the side two steps behind 36.6% (n = 414), with material level. That is an association, not proof that walking the king forward causes the win — a centralised king is also a sign of a position that was already comfortable — but the direction is clear and the effect is larger than anything we will find for pawn shelters in the middlegame (Section 4.3). Chapter 15 turns the king into a fighting piece; for this chapter, remember the switch: queens on, hide the king; queens off, use it.

⚠️ Common pitfall: "Queens are off, so my king is safe." Not with two rooks and minor pieces still on and the king's pawns scattered. The switch is gradual: as attacking material drops, the king can step forward. Watch for back-rank mates and rook-plus-knight nets until material is genuinely thin.

🔄 Check your understanding 1. Why does the king become a strong piece once the queens are off? 2. In our queenless-endgame sample (OTB, equal material), what did the side whose king was two steps more central score — and why can't we call that a causal effect?

Answer

  1. Mating attacks need several long-range pieces to reach the king zone together; without queens there are rarely enough. Meanwhile the king controls up to eight squares, which in an ending are the squares pawns must pass.
  2. 59.7% (n = 391), against 36.6% for the side two steps behind (n = 414). A centralised king is also a sign of an already comfortable position, so the data shows association, not cause.

4.2 Castling: When, Which Side, and What It Costs

The principle. Castling does two jobs in one move: it tucks the king behind pawns, away from the central files that open first, and it brings a rook toward the centre so the rooks connect. Most of the time you should castle early — but the right question is not "have I castled?" but "can the centre open before my king is safe?"

The reasoning. The centre is where pawns get exchanged first, because both sides fight for d4, d5, e4 and e5 (see Chapter 2). Once the e-file or d-file opens, a king on e1 or e8 stands on a highway for rooks and queens. On g1 it stands behind three pawns that nobody has any reason to exchange early. Castling queenside puts the king on c1 or c8, one file closer to the centre and with the a-pawn further away, which is why long castling usually comes with a plan: a pawn storm on the other wing or an immediate rook on d1.

How real players castle

Let's look before we preach. Our first script, 01_castling_timing.py, reads the castling move of every side-game in the book's data (game_features): Lichess human games (bots excluded, bullet to classical, weighted to the 4-million-game sample) and the over-the-board broadcast games with both FIDE ratings. A few lines do the work — this is the pandas idiom we will reuse all book long: build a table, group it by rating band, aggregate:

def side_games(df, weighted):
    """Stack White and Black into one row per side-game."""
    rows = []
    for c in ("white", "black"):
        rows.append(pd.DataFrame({"castle": df[f"{c}_castle"], "ply": df[f"{c}_castle_ply"],
                                  "avg_elo": df.avg_elo, "n_plies": df.n_plies,
                                  "w": df.sample_weight if weighted else 1.0}))
    s = pd.concat(rows, ignore_index=True)
    s["move"] = np.ceil(s.ply / 2)                       # ply 15 -> move 8
    s["band"] = chessdata.rating_bands(s.avg_elo)       # '1400-1599', ...
    return s

pd.concat stacks the White rows on top of the Black rows; groupby("band") then lets us compute, for each rating band, the share who castled at all, the share who castled by move 10, and the quartiles of the castling move. The output:

=== Lichess (weighted): castling by band (side-games) ===
     band  side_games  castled  by_move10  long_share  p25  median  p75
    <1000      111226     53.1       29.5        19.3  7.0    10.0 13.0
1000-1199      163176     67.5       37.5        19.2  7.0    10.0 13.0
1200-1399      232104     73.6       41.8        18.6  7.0    10.0 13.0
1400-1599      298882     77.7       45.2        17.5  7.0    10.0 13.0
1600-1799      317426     81.2       49.2        16.3  7.0     9.0 12.0
1800-1999      277064     83.4       52.6        15.0  7.0     9.0 12.0
2000-2199      177580     84.4       54.5        14.3  7.0     9.0 12.0
2200-2399       85868     85.9       56.1        14.3  7.0     9.0 12.0
    2400+       43280     86.6       57.7        13.9  7.0     9.0 12.0

=== OTB broadcast (FIDE bands): castling by band (side-games) ===
     band  side_games  castled  by_move10  long_share  p25  median  p75
    <1000        3300     71.5       47.8        14.1  6.0     9.0 12.0
1400-1599       36354     88.2       59.3        10.0  7.0     9.0 11.0
1800-1999      137796     88.8       59.4        10.2  7.0     9.0 12.0
2200-2399      123294     88.4       59.0        10.1  6.0     9.0 12.0
    2400+       74598     88.3       59.1         9.4  6.0     9.0 12.0

(The OTB table is abridged here; the full one is in the script output.)

Distribution of the castling move: Lichess under 1200, Lichess 1800–1999, OTB FIDE 2400+.

📊 Figure (described): The share of side-games that castle on each move number, for three groups. All three peak between moves 7 and 10 and tail off by move 13; the curves have almost the same shape. What differs is the height: among Lichess players under 1200, a large share never castle at all, while OTB players rated 2400+ castle in the same window far more consistently.

Castled at all and castled by move 10, by rating band, Lichess vs OTB.

📊 Figure (described): Online, castling climbs steadily with rating — from 53.1% of side-games under 1000 to 86.6% at 2400+ (Lichess), and castling by move 10 from 29.5% to 57.7%. Over the board, the line is flat: from FIDE 1400 to 2400+ about 88% of side-games castle and about 59% by move 10. (Lichess and FIDE bands are different scales; compare shapes, not heights band by band.)

Three things stand out:

  • When people castle, they castle at the same time. The median castling move is 9 or 10 in every band, online and over the board. Grandmasters do not castle "earlier" than club players in any useful sense; they castle more reliably.
  • Online, the lowest bands often never castle. Under 1000 on Lichess, 46.9% of side-games end with the king uncastled. Some of those games are short (a quick mate or a resignation), so not castling is partly a symptom of a game that ended early — but it is also a habit, and it is the cheapest habit in chess to fix.
  • Over the board the habit is near-universal from 1400 up. The OTB rate is flat at about 88% across every band from 1400 to 2400+. The skill that separates a 1600 from a 2400 is not whether to castle but which side, when exactly, and what to do with the time.

Long castling (O-O-O) is rarer at the top: 19.3% of Lichess castlers under 1000 go long versus 13.9% at 2400+, and about 10% of OTB castlers at every level. That fits the reasoning above — queenside castling is a commitment that needs a plan.

What not castling costs — less than you think, on average

Now the uncomfortable statistic. The book's data snapshot already contains a table for kings that are still on their home square at move 15 (ply 30) in games that lasted longer than that. Over the board, a side whose king is still on e1/e8 at ply 30 while the opponent has castled scores 47.8% (n = 52,830), −2.2 points below its rating expectation. On Lichess, in balanced games with queens still on, the same situation scores 49.1% (n = 133,440), only −0.8 points from expectation. By Lichess band the penalty ranges from −0.2 to −2.3 points — never large.

The "castle early" principle, measured as "castled by move 10 vs not", is worth about +0.7 score points on Lichess and +0.6 over the board after adjusting for ratings. Real, but small.

Is the principle wrong, then? No — the average hides the cases where it matters. In script 04 we split the uncastled kings (still on the home square, enemy queen on the board, equal material, middlegame) by whether the king's own d- and e-pawns are still there:

=== King still on its home square with the enemy queen on: open vs closed centre (own d/e pawns) ===
                          n  median_eval  mean_eval  score
source    centre_open
broadcast False        2484        -13.5      -27.4   47.9
          True          155         -4.0      -81.0   36.5
lichess   False        1746        -18.5      -41.4   47.3
          True          125        -17.0      -24.6   50.8
castled kings (reference):
broadcast  21819         -0.0        6.2   50.6
lichess     9467          1.0       12.5   50.9

Over the board, an uncastled king behind its own centre pawns scores 47.9% (n = 2,484); with both of its d- and e-pawns gone it scores 36.5% (n = 155) and the mean evaluation drops to −0.81. The Lichess sample shows no such gap (50.8%, n = 125) — the sample is small and online games are decided by more blunders in both directions, so treat the OTB result as suggestive, not settled. The direction matches the reasoning: a king in the centre is only as safe as the pawns in front of it. If the centre is closed, you may have time; if it opens, you have none.

The classic punishment: Carlsen–Groenn, Norwegian Championship 2005

Our example of the open centre comes from the early pages of Magnus Carlsen's file in the PGN Mentor collection — Carlsen (rated 2528 in the record) against Groenn at the 2005 Norwegian Championship. Black grabbed the c3-pawn with his bishop (11...Bxc3) and spent the next moves retreating it, so at move 17 his king was still on e8:

Carlsen–Groenn after 16...b6. Black's king is still on e8; White's pieces all point at f7 and e6.

♟️ Position: White Kg1, Qe4, Rb1, Rf1, Bc4, Bh4, Ne5, a2, d4, e3, f4, g2, h2; Black Ke8, Qc7, Ra8, Rh8, Bc8, Bd6, Nb8, a7, b6, c6, e6, f7, g7, h6 — White to move. FEN: rnb1k2r/p1q2pp1/1ppbp2p/4N3/2BPQP1B/4P3/P5PP/1R3RK1 w kq - 0 17

Our king-safety report for Black's king reads "king still in the centre; file next to the king: d". Its attack weight is only 6 — the danger isn't yet on the king zone, it is one move away. White has the knight on e5 hitting f7, the bishop on c4 hitting e6 (and f7 behind it), the f-pawn ready to open the f-file, and the queen on e4 aiming at the long diagonal and at c6. Black has a rook on h8 and a knight on b8 that have never moved. Carlsen played 17.Nxf7! Qxf7 18.f5:

17.Nxf7 Qxf7 18.f5 Qh5 19.Bxe6 Nd7 20.f6 Nxf6 21.Rxf6 Qxh4 22.Qxc6+ Ke7 23.Rf7+ Kxe6 24.Qc4#

🤖 Engine check: Before 17.Nxf7, Stockfish 19 gives +7.03 at depth 20 and +7.49 at depth 24 with exactly 17.Nxf7 Qxf7 18.f5. Its second choice, 18.f5 at once, is also winning (+5.08, depth 20). Why so large? Count the pieces: White has five pieces developed and a rook on f1 behind an f-pawn that is about to open the f-file; Black has two pieces that have never moved and a king with no rook connection. The sacrifice "costs" a knight but opens two lines (the f-file and the a2–g8 diagonal) to a king that has nowhere to go. The engine isn't seeing a trick; it is counting attackers against defenders on the lines that matter.

Final position: 24.Qc4#. The king that never castled is mated on e6.

♟️ Position: White Kg1, Qc4, Rb1, Rf7, a2, d4, e3, g2, h2; Black Ke6, Qh4, Ra8, Rh8, Bc8, Bd6, a7, b6, g7, h6 — Black to move. FEN: r1b4r/p4Rp1/1p1bk2p/8/2QP3q/4P3/P5PP/1R4K1 b - - 1 24

At different levels. Under 1200 online, the lesson is simply "castle" — nearly half of side-games in the lowest band never do, and the open-centre catastrophe is common. Around 1600–2000, players castle but sometimes spend the critical tempo on a pawn grab (like 11...Bxc3 here) with the king still in the centre; the habit to build is asking, before every material grab, "if the centre opens next move, where does my king go?" At 2200+, keeping the king in the centre is a deliberate choice in specific openings (some Sicilians, some French lines) where the centre is locked — and the data above says that choice is only cheap while the d- and e-pawns stay.

⚠️ Common pitfall: Castling into an attack. If the opponent has already pushed g4-g5 or h4-h5 and has a rook ready on the g- or h-file, castling kingside walks the king toward the storm. Castling is a decision, not a reflex: look at where the enemy pawns and pieces are pointing first.

🔄 Check your understanding 1. In our Lichess data, what is the median castling move under 1000, and at 2400+? 2. Over the board, how much does an uncastled king (opponent castled) cost on average at move 15, and why does that average understate the danger in some positions?

Answer

  1. Move 10 under 1000 and move 9 at 2400+ — almost the same. The difference between bands is whether players castle at all (53.1% vs 86.6% of side-games), not when.
  2. About −2.2 points against rating expectation (47.8%, n = 52,830). The average mixes closed centres (where the king is fairly safe) with open ones; in our equal-material middlegame sample, an uncastled king whose own d- and e-pawns are gone scored 36.5% (n = 155) against 47.9% with the centre closed.

4.3 The Pawn Shelter and the Pieces Aimed at It

The principle. A castled king's safety has two halves: the shelter (the pawns in front of it) and the pressure (the enemy pieces that can reach the squares around it). Most club players look only at the first — "my pawns are unmoved, I'm safe." Strong players count both, and they know which one matters more.

The reasoning. Pawns cannot move backward. Every advance in front of your king — h3, g3, f4 — gives up control of squares forever: after g2-g3, the f3 and h3 squares can never again be covered by the g-pawn; after h2-h3, g3 is gone. Those weakened squares become landing spots for enemy pieces. But a weakened square only matters if an enemy piece can get there. An intact shelter facing a queen, a rook and two minor pieces is in more danger than a battered shelter facing a lone knight.

To talk about this precisely, we need three definitions. They are the heart of this chapter's Outpost module.

📐 Definition — shelter points: For a king, look at its own file and the two files beside it. On each file, a friendly pawn directly in front of the king (on the next rank) scores 2; a pawn one rank further (e.g. h3 for a king on g1) scores 1; a pawn further up, or no pawn, scores 0. The total is 0–6. A king on g1 behind f2-g2-h2 has 6; after h2-h3 it has 5; after g2-g4 and h2-h3, 3. (This is the book's definition, built on structures.king_shelter from the toolkit, which counts the sheltered files 0–3.)

📐 Definition — king zone: The king's square, its up-to-eight neighbours, and the three squares two ranks in front of it (for a king on g8: f6, g6, h6). The zone is where an attack must arrive.

📐 Definition — attack weight: For every enemy knight, bishop, rook or queen that attacks at least one square of the king zone, add its weight: knight 2, bishop 2, rook 3, queen 5. Pawns and the king are not counted. Defenders = the number of your own N/B/R/Q that cover at least one zone square. The weights are a book heuristic in the spirit of engine king-danger terms, not Stockfish's own numbers.

Here is the code for shelter points — short enough to read in one go. (python-chess numbers ranks 0–7; board.pieces(chess.PAWN, color) is the set of squares holding that side's pawns.)

def shelter_score(board, color):
    k = board.king(color)
    out = {"points": 0, "files": {}}
    kr = chess.square_rank(k)
    for f in _files_around(k):                       # king file -1, 0, +1 (on the board)
        best = None
        for sq in board.pieces(chess.PAWN, color):   # nearest own pawn IN FRONT on this file
            if chess.square_file(sq) != f:
                continue
            d = (chess.square_rank(sq) - kr) * _FWD[color]   # ranks ahead of the king
            if d >= 1 and (best is None or d < best):
                best = d
        pts = 2 if best == 1 else (1 if best == 2 else 0)
        out["points"] += pts
        out["files"][chess.FILE_NAMES[f]] = {2: "home", 1: "advanced"}.get(pts, "far/missing")
    return out

The full module is in project/outpost/king_safety.py; zone_pressure() computes the attack weight with board.attacks(square), which returns every square a piece on that square attacks.

An intact shelter in mortal danger

Here is the position from Polugaevsky–Tal (USSR Championship 1969) that we will study in the next section. Black's shelter is perfect: f7, g7 and h7 all on their home squares.

Polugaevsky–Tal after 18...Nb2: shelter 6/6, yet the king is in danger. Arrows: Bd3 at h7, Nf3 to g5, Qf4 to h4.

♟️ Position: White Kg1, Qf4, Rd1, Re1, Bd3, Nf3, a2, e5, f2, g2, h2; Black Kg8, Qd8, Rc8, Rf8, Bb7, Nb2, a7, b6, d5, f7, g7, h7 — White to move. FEN: 2rq1rk1/pb3ppp/1p6/3pP3/5Q2/3B1N2/Pn3PPP/3RR1K1 w - - 3 19

The module's report (from project_checkpoint.py):

Black king g8 (castled-short): shelter 6/6 [f:home,g:home,h:home], attack weight 7 from 2 piece(s), 2 defender(s)
  verdict: danger - check concrete lines - heavy pressure (attack weight 7 vs 2 defenders)
White king g1 (castled-short): shelter 6/6 [f:home,g:home,h:home], attack weight 0 from 0 piece(s), 4 defender(s)
  verdict: solid

Same shelter on both sides, opposite verdicts. White's bishop and queen already bear on Black's king zone; Black's knight has wandered to b2, his bishop on b7 bites on the d5-pawn, and only the rook on f8 and the queen on d8 cover the zone. The numbers say what a strong player sees at a glance: shelter is the wall, attackers are the army; walls fall when the army outnumbers the defenders.

A broken shelter that holds

The opposite case comes from the Tata Steel Masters, January 2026: Nodirbek Abdusattorov against Gukesh D, two players rated 2751 and 2754 in the broadcast record. White pushed his h-pawn to h5 and Black took it, leaving his king on h8 with no g-pawn and doubled h-pawns:

Abdusattorov–Gukesh after 24...gxh5: Black's shelter has 2 points out of 6.

♟️ Position: White Kh1, Qg3, Ra1, Rf1, Be3, Nc4, Ng4, a4, b3, c2, d3, e4, f3, g2; Black Kh8, Qd7, Rd8, Re8, Ba6, Bg7, Ne6, a5, b6, c5, c7, e5, f6, h5, h7 — White to move. FEN: 3rr2k/2pq2bp/bp2np2/p1p1p2p/P1N1P1N1/1P1PBPQ1/2P3P1/R4R1K w - - 0 25

Shelter 2/6, an open g-file — and Stockfish 19 at depth 20 says Black is slightly better: −0.41 after the best move 25.Nh6. Black's pieces cover the dark squares around his king (bishop on g7, knight on e6, queen on d7), and the open g-file belongs to whoever puts a rook there first. We will follow the rest of this game in Case Study 1; it is a lesson in how a "broken" shelter can be perfectly defensible — and how the attacker still won, eleven moves later, when the defender slipped.

What the data says: walls versus armies

If shelter and attackers both matter, which matters more? Script 04 measures both for every castled king in an equal-material middlegame from positions_sample (20,066 positions with an evaluation, two kings each) and compares them with the position's evaluation from the king owner's point of view.

=== Castled kings, enemy queen on: by attack weight on the king zone ===
                      n  median_eval  mean_eval  score
source    att_bin
broadcast 0        6743         13.0       41.0   54.9
          1-3      6894          0.0        4.9   49.7
          4-6      4926          0.0        2.2   50.0
          7-9      2936         -8.0      -43.2   45.3
          10-12     306        -90.5     -175.4   36.3
lichess   0        3012         22.0       63.1   55.3
          7-9      1427        -12.0      -52.3   45.0
          10-12     149       -149.0     -249.4   34.2

=== Correlations (castled kings, enemy queen on): Spearman rho with owner eval ===
broadcast: shelter +0.047; attack weight -0.144; attack - defenders -0.143  (n = 21,819)
lichess: shelter +0.088; attack weight -0.141; attack - defenders -0.145  (n = 9,467)

Mean evaluation by shelter points, OTB and Lichess.

📊 Figure (described): Mean evaluation (king owner's view, equal material, queens on) by shelter points 0–6. Both lines rise from damaged shelters (1–3 points: about −0.5 to −0.1 pawns) to intact ones (4–6 points: about +0.1 to +0.5), with one exception — OTB kings with no shelter at all average +0.19 (n = 293). The whole range is under one pawn: shelter matters, but it is a weaker and noisier signal than the attackers in the next figure.

Mean evaluation by attack weight on the king zone.

📊 Figure (described): The same positions grouped by attack weight. Both lines fall steadily: kings with no attackers in their zone average about +0.4 to +0.6 for their owner; kings facing an attack weight of 10–12 average −1.75 (OTB) and −2.49 (Lichess), and their owners score about 35%. Attackers predict the evaluation far better than pawn shelter does.

Two findings to carry to the board:

  1. Attackers matter more than pawn cover. The rank correlation of attack weight with the evaluation (about −0.14 in both databases) is several times that of shelter points (+0.05 OTB, +0.09 Lichess). A king facing attack weight 10–12 scored 36.3% over the board (n = 306) — with material equal.
  2. A broken shelter is not, by itself, a lost position. Over the board, castled kings with 0 shelter points (n = 293) averaged +0.19 for their owners. Many of those are positions where the pawns went forward on purpose — to attack, or after a trade that also removed attackers. Pawn moves in front of the king are a cost you pay; whether the bill comes due depends on who can reach the weakened squares.

Both are associations in a sample (and evaluations here are the Lichess server and cloud evals stored in the games), so read them as "what tends to go together", not "what causes what". But they agree with the classic teaching of attacking chess: count the attackers and defenders.

🤖 Engine check: For the Polugaevsky–Tal position above, Stockfish 19 gives +2.11 at depth 20 and +2.45 at depth 24, both with 19.Bxh7+. For Abdusattorov–Gukesh after 24...gxh5 it gives −0.41 (depth 20). The engine has no "shelter points" term — modern Stockfish evaluates with a neural network — but its numbers line up with the human count: in the first position three White pieces can reach Black's king zone in one move and two Black pieces defend it; in the second, Black's pieces outnumber White's around h8.

🔄 Check your understanding 1. Compute the shelter points of a king on g1 with pawns on f2, g3 and h4. 2. Which predicted the evaluation better in our sample, shelter points or attack weight?

Answer

  1. f2 is on the next rank (2), g3 one rank further (1), h4 further still (0): 3 points.
  2. Attack weight: rank correlation about −0.14 in both databases, against +0.05 (OTB) and +0.09 (Lichess) for shelter points. Kings facing attack weight 10–12 scored 36.3% OTB with material level.

4.4 The Greek Gift: Bxh7+ and Its Preconditions

🧩 Productive struggle: Before reading on, look again at the Polugaevsky–Tal position (diagram above, White to move). Would you play 19.Bxh7+ Kxh7 20.Ng5+? Write down Black's three possible replies to 20.Ng5+ and, for each, White's next move. Only then continue.

The principle. The Greek gift is the sacrifice Bxh7+ (for Black, ...Bxh2+) against a king on g8, followed by Ng5+ and the queen coming to the h-file. It works when — and mostly only when — a small set of preconditions holds. Learn the preconditions, not the move.

The reasoning. After Bxh7+ Kxh7 Ng5+, Black's king has three choices, and each must be answered:

  • ...Kg8 (back home): White needs the queen to reach h5 or h7 quickly — Qh5 threatening Qh7 mate, or Qh5 and Qxf7+. If the queen can't get there, or a Black knight on f6 covers h5 and h7, Black is simply a piece up.
  • ...Kg6 (forward): the king steps toward the White pieces. White needs more attackers — h4-h5+, Qd3+, Qg4 — and Black's own pieces to be far away.
  • ...Kh6 or ...Kh8: usually met by a discovered check or Qh5 depending on the details.
  • And sometimes Black can simply take the knight on g5 — with a bishop on e7 or the queen on d8 — so a guard of g5 is a defensive resource.

From those lines come five classical preconditions, which the module's greek_gift_check() tests for the side to move:

  1. knight to g5 — a knight can reach g5 now (usually from f3);
  2. g5 unguarded — after Bxh7+ Kxh7, no Black piece except the king guards g5 (no ...Bxg5, no ...Qxg5);
  3. queen to the h-file — after Bxh7+ Kxh7 the queen stands on, or attacks, a square from h3 to h7;
  4. no knight on f6 — the classic defender of h7 and h5 is absent;
  5. pawn on e5 — it covers f6 (so no ...Nf6) and d6, and it often drove the f6-knight away.
def _greek_gift_white(b):                     # White to move; Black is handled by mirroring the board
    res = {"knight_to_g5": any(b.attacks(sq) & chess.BB_SQUARES[chess.G5]
                               for sq in b.pieces(chess.KNIGHT, chess.WHITE)),
           "no_f6_knight": b.piece_at(chess.F6) != chess.Piece(chess.KNIGHT, chess.BLACK),
           "e5_pawn": b.piece_at(chess.E5) == chess.Piece(chess.PAWN, chess.WHITE)}
    t = b.copy(stack=False)
    t.push(chess.Move(bishop_square, chess.H7))       # Bxh7+
    t.push(chess.Move(chess.G8, chess.H7))            # ...Kxh7
    guards = [s for s in t.attackers(chess.BLACK, chess.G5) if t.piece_type_at(s) != chess.KING]
    res["g5_unguarded"] = not guards
    res["queen_to_h_file"] = any(chess.square_file(q) == 7 or
                                 any(t.attacks(q) & chess.BB_SQUARES[s] for s in H3_TO_H7)
                                 for q in t.pieces(chess.QUEEN, chess.WHITE))
    return res

(Abridged from the module: the real function also checks that the bishop can take on h7, that the king is on g8 and that ...Kxh7 is legal.)

The classic: Polugaevsky–Tal, USSR Championship 1969

Mikhail Tal, world champion in 1960–61 and the most famous attacker of his era, is on the receiving end here. The game, from the data:

1.c4 Nf6 2.Nc3 e6 3.Nf3 d5 4.d4 c5 5.cxd5 Nxd5 6.e4 Nxc3 7.bxc3 cxd4 8.cxd4 Bb4+ 9.Bd2 Bxd2+
10.Qxd2 O-O 11.Bc4 Nc6 12.O-O b6 13.Rad1 Bb7 14.Rfe1 Na5 15.Bd3 Rc8 16.d5 exd5 17.e5 Nc4 18.Qf4 Nb2
19.Bxh7+ Kxh7 20.Ng5+ Kg6 21.h4 Rc4 22.h5+ Kh6 23.Nxf7+ Kh7 24.Qf5+ Kg8 25.e6 Qf6 26.Qxf6 gxf6
27.Rd2 Rc6 28.Rxb2 Re8 29.Nh6+ Kh7 30.Nf5 Rexe6 31.Rxe6 Rxe6 32.Rc2 Rc6 33.Re2 Bc8 34.Re7+ Kh8
35.Nh4 f5 36.Ng6+ Kg8 37.Rxa7 1-0

Look at how the preconditions were built. 16.d5 exd5 17.e5 planted the pawn on e5 (precondition 5) and made sure no Black knight would ever reach f6 (4). 18.Qf4 put the queen one move from h4 (3). The knight has sat on f3 since move 3 (1). Black's knight went to the rim, a5–c4–b2, chasing material — a defender of the kingside sent to the other wing. Only precondition 2 fails: after Bxh7+ Kxh7 Ng5+, the queen on d8 guards g5. The module's verdict: four of five.

The engine shows why the one missing precondition doesn't save Black:

After 20.Ng5+: Black to move. The queen on d8 can take on g5 — but at a price.

♟️ Position: White Kg1, Qf4, Rd1, Re1, Ng5, a2, e5, f2, g2, h2; Black Kh7, Qd8, Rc8, Rf8, Bb7, Nb2, a7, b6, d5, f7, g7 — Black to move. FEN: 2rq1r2/pb3ppk/1p6/3pP1N1/5Q2/8/Pn3PPP/3RR1K1 b - - 1 20

  SF19 d24:   +2.39  Kg6 h4 Rc4 Rd4 Rxd4 Qxd4 Bc8 Qxb2
  SF19 d24:   +4.88  Kg8 Qh4 Qxg5 Qxg5 Nxd1 Rxd1 Rfe8 h4
  SF19 d24:   +5.49  Qxg5 Qxg5 Nxd1 Rxd1 Kg8 h4 Rc6 Rd3

🤖 Engine check: Tal found the best defence, 20...Kg6 (+2.39, Stockfish 19, depth 24). Retreating with 20...Kg8 runs into 21.Qh4 and mate threats on h7, so Black must give the queen for the knight (+4.88); taking at once, 20...Qxg5 21.Qxg5, also loses the queen for a knight (+5.49). The "guard" on g5 is the queen — a piece too valuable to trade for a knight — so precondition 2 is satisfied in spirit even though it fails on paper. That's the lesson of the checklist: it tells you what to calculate, not what to play. After 20...Kg6 21.h4, White brings a fourth attacker (the h-pawn) with threats of h5+; Stockfish still gives +2.71 (depth 20).

After 21.h4: the h-pawn joins the attack. Black's king stands on g6, in front of its own pawns.

♟️ Position: White Kg1, Qf4, Rd1, Re1, Ng5, a2, e5, f2, g2, h4; Black Kg6, Qd8, Rc8, Rf8, Bb7, Nb2, a7, b6, d5, f7, g7 — Black to move. FEN: 2rq1r2/pb3pp1/1p4k1/3pP1N1/5Q1P/8/Pn3PP1/3RR1K1 b - - 0 21

Polugaevsky didn't mate Tal. He did something more instructive: he converted. After 22.h5+ Kh6 23.Nxf7+ Kh7 24.Qf5+ Kg8 25.e6, Black had to trade queens to survive, and White won the endgame with a dominant knight and an active rook. The attack's job was not to deliver mate; it was to force concessions — and a 2-pawn engine edge in a middlegame converted to a full point in an ending.

The same idea, decades later

The Greek gift appears in the PGN Mentor files of almost every great player in this book. A few, from the script output (Stockfish 19 at depth 18, White's view, before → after the sacrifice): Kasparov–Short, London rapid match 1993, 20.Bxh7+ (+7.23 → +7.34); Judit Polgar–Karpov, Essent 2003, 25.Bxh7+ (+9.54 → +10.00, the clipping ceiling); Polugaevsky–Tal above (+1.62 → +2.43 at depth 18). Notice that in the first two, the position was already winning — the sacrifice is the finishing blow after an earlier error. That is typical. The Greek gift is often less a bolt from the blue than the moment a better position gets cashed in.

What 9,899 Greek gifts say

Script 02_greek_gift.py finds every classical Greek gift in the book's three databases — a bishop takes a pawn on h7 (h2) with check, the king is on g8 (g1), and the king is allowed to take the bishop — and records the preconditions and the evaluation right after the sacrifice (our own Stockfish 19 run at depth 18 for the master games; the stored cloud evals for broadcast games; the Lichess server evals for analysed Lichess games). It scans the move text for the strings Bxh7+/Bxh2+ first, so only a small fraction of the 1.3 million games with moves needs to be replayed.

master games containing Bxh7+/Bxh2+: 1,209; classical Greek gifts found: 576
broadcast human OTB classical Greek gifts: 2,554
Lichess human classical Greek gifts: 6,769 (analysed games with evals: 3,589)

=== Greek gifts by source ===
masters   n=   576  accepted  74.3%  sacrificer score  57.2% (Elo-expected  51.9%)
broadcast n= 2,554  accepted  71.3%  sacrificer score  59.2% (Elo-expected  53.2%)
lichess   n= 6,769  accepted  77.8%  sacrificer score  54.1% (Elo-expected  50.0%)

The sacrifice is accepted about three times in four, and in every database the sacrificer outscores the rating expectation — by 5.3 points in the master files, 6.0 over the board, 4.1 on Lichess. But that average hides the essential fact. We classify each sacrifice by the evaluation right after it, from the sacrificer's view: winning (≥ +2.00), refuted (≤ −1.00) or playable (in between). Then we group by how many of the five preconditions held:

=== Pooled (all three sources), preconditions 0-1 / 2 / 3 / 4-5 ===
grp    n  winning  refuted  playable  score  med_eval_after
0-1  816     25.2     50.1      24.6   43.6          -100.5
  2 2956     28.3     39.7      32.0   55.2             0.0
  3 2106     38.0     33.3      28.7   60.4            26.0
4-5  588     61.6     17.2      21.3   71.1           338.5

Outcome of the Greek gift by preconditions met, three databases.

📊 Figure (described): Stacked bars for each database: the share of Greek gifts that were winning (blue), playable (grey) and refuted (orange) by the evaluation right after Bxh7+, grouped by how many preconditions held (groups with n ≥ 30). In the OTB and Lichess panels the blue segment grows and the orange shrinks steadily from 1 to 4 preconditions; the master panel shows the same tendency more weakly, with smaller samples.

With zero or one precondition, half of all Greek gifts are refuted and only a quarter are winning (n = 816). With four or five, 61.6% are winning and only 17.2% refuted (n = 588), and the sacrificer scores 71.1%. The single most informative precondition is the pawn on e5: with it, 50.4% of sacrifices were winning (n = 1,350); without it, 29.8% (n = 5,116). The absence of a Black knight on f6 matters too — when one was on f6, 48.7% of sacrifices were refuted (n = 725).

⚠️ Common pitfall: Treating "the bishop sees h7 and the knight can go to g5" as enough. Those two are the visible preconditions, and in our data they barely move the needle on their own (knight can reach g5: 36.9% winning when present vs 32.5% when absent). The invisible ones — the e5-pawn, the missing f6-knight, the queen's route to the h-file, the guards of g5 — decide the outcome.

At different levels. The Lichess data splits by band (Glicko-2 ratings, average of both players):

=== Lichess by band (avg rating; score weighted; outcome on analysed games) ===
     band    n  n_eval  score  expected  accepted  winning  refuted  pre4
    <1000  277     183   37.9      48.2      83.7     33.3     58.5   2.6
1000-1199  576     333   44.6      49.5      78.9     29.1     58.9   4.2
1200-1399  927     519   51.8      49.9      79.8     32.4     50.5   5.7
1400-1599 1180     614   54.0      49.7      77.5     36.6     45.3   6.3
1600-1799 1364     689   56.3      50.1      76.3     36.7     43.8  10.7
1800-1999 1270     625   58.3      50.4      76.6     34.9     40.5  11.4
2000-2199  722     361   53.4      50.1      78.6     38.2     37.7  13.5
2200-2399  307     169   60.8      51.9      78.7     38.5     39.1  10.1
    2400+  146      96   57.0      49.3      73.4     34.4     31.2   8.5

Greek gifts by rating band, Lichess and OTB.

📊 Figure (described): Left, Lichess: below 1200 the sacrificer scores under the rating expectation (37.9% vs 48.2% under 1000) and the evaluation refutes nearly 6 in 10 sacrifices; from 1200 up the sacrificer scores above expectation and the refuted share falls to about 31% at 2400+. Right, OTB (FIDE bands): the sacrificer is well above expectation at 1400–1599 (68.0% vs 54.5%, n = 164) and the edge shrinks band by band to nothing at 2400+ (48.9% vs 49.9%, n = 179).

The story by level is coherent. Under 1200 online, Greek gifts are mostly played without the preconditions (only 2.6% have four or more under 1000) and are mostly unsound — and the sacrificer loses more than expected. From 1200 up, the sacrifice pays in practice even when the engine disapproves, because defending is hard. Over the board, the practical edge is biggest at club level and vanishes at 2400+, where defenders find 15...Kg8-type answers. Your own rule should depend on your opponents: the weaker the defence you expect, the more a speculative Bxh7+ pays — but at every level, the preconditions are what make it sound.

Back to the hook: Batsiashvili's 14.Bxh7+ met only two preconditions (knight to g5 and no f6-knight; g5 was guarded by the e7-bishop, the queen could not reach the h-file at once, and there was no e5-pawn — in fact the e5-pawn was Black's). Stockfish put it at −4.41. It worked because 15...Kg6 is the natural-looking move and 15...Kg8 requires seeing that 16.Qxd5+ Kh8 leaves White short of attackers.

📋 Try it — Analyze this position. Idani–Marcelin, French club championship 2026 (FIDE 2614 vs 2421 in the record). White to move. Count the preconditions. Is 12.Bxh7+ sound, winning, or refuted?

Idani–Marcelin after 11...Nh4: White to move.

♟️ Position: White Kg1, Qd1, Ra1, Rf1, Bc1, Bd3, Nb5, Nf3, a2, b2, c3, e5, f2, g2, h2; Black Kg8, Qd8, Ra8, Rf8, Bc5, Bd7, Nc6, Nh4, a5, b7, d5, e6, f7, g7, h7 — White to move. FEN: r2q1rk1/1p1b1ppp/2n1p3/pNbpP3/7n/2PB1N2/PP3PPP/R1BQ1RK1 w - - 4 12

Answer

Three of five: the knight on f3 reaches g5, the e5-pawn is in place, and there is no Black knight on f6. Missing: after Bxh7+ Kxh7 the queen on d8 guards g5, and White's queen cannot reach the h-file in one move, because the knight on f3 blocks the d1–h5 diagonal. Stockfish 19 rates 12.Bxh7+ as 0.00 at depths 20 and 24 — exactly as good as the quiet 12.Bf4 (0.00). After 12.Bxh7+ Kxh7 13.Ng5+ the only move is 13...Kg6 (0.00); 13...Kg8 loses to 14.Qh5 (+4.86) and 13...Qxg5 to 14.Bxg5 (+5.48). So: sound, not winning — a practical choice that sets Black one precise problem. The game continued 13...Kg6 14.Qg4 Nxe5 15.Qxh4, and White won after a later blunder.

🔄 Check your understanding 1. Name the five classical Greek-gift preconditions the module checks. 2. In our pooled data, what share of Greek gifts with 0–1 preconditions were refuted, and with 4–5? 3. Why did the guard of g5 not save Tal?

Answer

  1. A knight can reach g5; after Bxh7+ Kxh7 no Black piece but the king guards g5; the queen can reach the h-file (h3–h7); no Black knight on f6; a White pawn on e5.
  2. 50.1% refuted with 0–1 (n = 816); 17.2% with 4–5 (n = 588).
  3. The guard was the queen. 20...Qxg5 21.Qxg5 gives up the queen for a knight (+5.49 at depth 24), so the "guard" is not a real defensive resource. The checklist tells you what to calculate.

4.5 Opposite-Side Castling: The Race

The principle. When the kings castle on opposite wings, each side can throw its pawns at the enemy king without weakening its own. Both attacks start at once, and the game becomes a race: tempo is everything, material is secondary, and the side whose attack arrives first usually — but not always — wins.

The reasoning. In same-side castling, pushing g4-g5 or h4-h5 strips your own king. With the kings on opposite wings, your storming pawns are on the other side of the board from your king; they cost you nothing defensively. So both players attack, and the question becomes arithmetic: how many moves until my pawn opens a file next to his king, versus his next to mine? A pawn that arrives on the fifth rank, touching the enemy shelter, forces either a capture (opening a file) or a further advance (opening a diagonal). Pieces matter as much as pawns: an exchange sacrifice on c3 against a king on c1 or b1 can open lines faster than any pawn.

The classic: Karpov–Korchnoi, Candidates final 1974, game 2

The Yugoslav Attack against the Dragon Sicilian is the textbook race: White castles long, pushes h4-h5 and opens the h-file against the king on g8; Black castles short and attacks down the c-file. Here is the second game of the 1974 Candidates final from the data:

1.e4 c5 2.Nf3 d6 3.d4 cxd4 4.Nxd4 Nf6 5.Nc3 g6 6.Be3 Bg7 7.f3 Nc6 8.Qd2 O-O 9.Bc4 Bd7 10.h4 Rc8
11.Bb3 Ne5 12.O-O-O Nc4 13.Bxc4 Rxc4 14.h5 Nxh5 15.g4 Nf6 16.Nde2 Qa5 17.Bh6 Bxh6 18.Qxh6 Rfc8
19.Rd3 R4c5 20.g5 Rxg5 21.Rd5 Rxd5 22.Nxd5 Re8 23.Nef4 Bc6 24.e5 Bxd5 25.exf6 exf6 26.Qxh7+ Kf8
27.Qh8+ 1-0

Karpov–Korchnoi after 12.O-O-O: opposite-side castling. White's h-pawn and Black's c-file rook are the two engines of the race.

♟️ Position: White Kc1, Qd2, Rd1, Rh1, Bb3, Be3, Nc3, Nd4, a2, b2, c2, e4, f3, g2, h4; Black Kg8, Qd8, Rc8, Rf8, Bd7, Bg7, Ne5, Nf6, a7, b7, d6, e7, f7, g6, h7 — Black to move. FEN: 2rq1rk1/pp1bppbp/3p1np1/4n3/3NP2P/1BN1BP2/PPPQ2P1/2KR3R b - - 4 12

Stockfish 19 gives +0.40 at depth 20 here: a race with chances for both. Our castling_timeline() says White's storm "arrived" (a pawn on the fifth rank next to Black's king) at ply 27, 14.h5; Black's pawn storm never arrived at all. Black's counterplay was piece play: ...Nc4, ...Rxc4, ...Qa5, the rook lift ...R4c5. 14.h5 offered a pawn to open the h-file (+1.25 at depth 20 after 14.h5; Black took it, 14...Nxh5, and White chased the knight with 15.g4).

The critical moment is 17.Bh6 — the trade of Black's best defender, the Dragon bishop on g7:

After 17.Bh6: White offers to exchange the g7-bishop, the guardian of Black's dark squares.

♟️ 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

The module's report for Black's king shows the attack weight jumping to 10 with only three defenders, while the shelter still has 5 points out of 6 (only g6 has moved). The pawns look intact; the pieces say otherwise.

🤖 Engine check: Stockfish 19 rates the position after 17.Bh6 at +0.83 (depth 20) and +1.20 (depth 24) — the deeper search sees more of White's attack, a reminder to state depth when the position is sharp. Why is White better? After ...Bxh6 Qxh6, White's queen sits on h6, a knight can come to d5 to remove the f6-knight (the only piece guarding h7), and g4-g5 drives it away. Black's counterattack on the c-file needs two or three more moves to hurt White's king. Karpov's 20.g5 and 21.Rd5 executed exactly that plan; at the end, Stockfish gives +6.62 (depth 20).

Final position after 27.Qh8+: Black resigned.

♟️ Position: White Kc1, Qh8, Rh1, Nf4, a2, b2, c2, f3; Black Kf8, Qa5, Re8, Bd5, a7, b7, d6, f6, f7, g6 — Black to move. FEN: 4rk1Q/pp3p2/3p1pp1/q2b4/5N2/5P2/PPP5/2K4R b - - 2 27

Watching the attack build: an engine swing

Section 4.3 claimed that pressure on the king zone shows up in the engine's numbers. Here is a single game, move by move. 06_annotated_games.py runs engine.analyse_game (depth 16) on the whole game and, for every ply, the module's attack weight and shelter points for Black's king:

Eval graph of Karpov–Korchnoi (left) and Abdusattorov–Gukesh (right), with Black's attack weight and shelter points underneath.

📊 Figure (described): Top, White's win percentage after each ply (Stockfish 19, depth 16); bottom, the attack weight on Black's king zone (orange) and Black's shelter points (blue). In Karpov–Korchnoi the attack weight jumps from 5 to 10 at 17.Bh6 (ply 33) while the shelter stays at 5 — and the eval follows a few moves later, climbing past 85% after 20...Rxg5. In Abdusattorov–Gukesh the shelter drops step by step to 2 and the attack weight spikes to 9, yet the evaluation stays at or slightly below 50% for White — until one move, 36...Rg5, sends it to 100%.

The two games show the two faces of king safety. In the first, rising pressure preceded a rising evaluation: the attackers arrived, then the engine (and the result) followed. In the second, the shelter was wrecked and the pressure was high for twenty moves, and the engine never thought White was better — until the defender made one mistake. Pressure creates chances; it is not the same as an advantage.

The modern example: Esipenko–Caruana, FIDE Candidates 2026

The race is not always won by the side whose pawns arrive first. In the 2026 Candidates (round 14 in the broadcast record), Fabiano Caruana met White's long castling in a Najdorf-turned-Dragon with a classic piece sacrifice against the queenside king:

Esipenko–Caruana after 13.h3: Black to move. 13...Rxc3! smashes White's queenside shelter.

♟️ Position: White Kb1, Qe3, Rd1, Rh1, Be2, Bg5, Nb3, Nc3, a2, b2, c2, e4, f2, g2, h3; Black Kg8, Qd8, Rc8, Rf8, Be6, Bg7, Ne5, Nf6, a6, b7, d6, e7, f7, g6, h7 — Black to move. FEN: 2rq1rk1/1p2ppbp/p2pbnp1/4n1B1/4P3/1NN1Q2P/PPP1BPP1/1K1R3R b - - 0 13

The module rates White's king as "solid": shelter 6/6, attack weight 5. 13...Rxc3! changes that in one move. After 14.bxc3, White's king on b1 has an open b-file, doubled c-pawns and a Black queen on its way to c7.

🤖 Engine check: Stockfish 19 picks 13...Rxc3 as the best move: −0.73 at depth 20, −0.66 at depth 24 (Black better), ahead of the quiet 13...b5 (−0.37, depth 20). The exchange (five points for three, by the 1/3/3/5/9 count) buys two half-open files against the king and a target on c3; the engine values the lines more than the material. Compare Chapter 6 on when an exchange sacrifice pays.

White then stormed the kingside with g4 and f5. By our definition White's storm arrived first (18.f5, ply 35); Black's ...a5-a4 arrived only at ply 48. But Black's pieces were already at work on the queenside, and by move 26 Stockfish gave −2.01 (depth 20). Caruana won on move 40.

Esipenko–Caruana after 25...fxg6: both storms have arrived; Black's is the one that matters.

♟️ Position: White Kb1, Qe1, Rd4, Rh1, Bc1, Nb3, a2, c2, c3, e4, g4; Black Kg8, Qc7, Rc8, Bg7, Nc4, Nd7, a4, b5, d6, e7, g6 — White to move. FEN: 2r3k1/2qnp1b1/3p2p1/1p6/p1nRP1P1/1NP5/P1P5/1KB1Q2R w - - 0 26

What the data says about the race

Script 03_opposite_castling_race.py replays every opposite-castling game in the OTB broadcast data (30,629 games) and a fixed random sample of 40,000 balanced Lichess games, and records the ply at which each side's storm arrives.

📐 Definition — storm arrival: the first ply, after both sides have castled on opposite wings, at which a side has a pawn on its own fifth rank or beyond on one of the three files around the enemy king. The side whose storm arrives first is the first stormer. (Piece attacks and exchange sacrifices are not counted — a deliberate simplification, as Esipenko–Caruana shows.)

Share of opposite-castling games in which at least one pawn storm arrived:
  broadcast: 81.3% of 30,629; both storms arrived: 41.5%
  lichess: 71.0% of 40,000; both storms arrived: 28.9%

=== Score of the FIRST stormer ===
                                  group     n  score   lo   hi  expected  adj  draw
                          broadcast all 24905   56.0 55.4 56.6      52.3  3.7  18.4
   broadcast first stormer castled LONG 13460   57.7 56.9 58.6      53.0  4.7  18.9
  broadcast first stormer castled SHORT 11445   54.0 53.1 54.9      51.6  2.4  17.8
  broadcast only one storm ever arrived 12670   62.2 61.3 63.0      54.7  7.5  17.9
 broadcast both arrived, gap <= 4 plies  1995   51.5 49.3 53.6      50.4  1.1  16.8
broadcast both arrived, gap >= 10 plies  7778   49.2 48.1 50.3      49.8 -0.6  20.0
                            lichess all 28410   53.3 52.7 53.8      50.1  3.2   3.8
    lichess only one storm ever arrived 17311   56.0 55.2 56.7      50.1  5.9   2.6
  lichess both arrived, gap >= 10 plies  6627   49.2 48.0 50.4      50.0 -0.8   7.1

First stormer's score vs Elo expectation, by band, Lichess and OTB.

📊 Figure (described): For each rating band, the first stormer's score (blue, with 95% interval) and its Elo-expected score (grey dashes). On Lichess the first stormer scores 52–55% in every band against an expectation of about 50%; over the board it scores 53–57% against 50–54%. The gap is small but present at every level from under 1000 to 2400+.

Three readings:

  • Arriving first helps — modestly. The first stormer scores 56.0% over the board (n = 24,905), +3.7 points above rating expectation; on Lichess +3.2 (n = 28,410). The edge is similar at every level.
  • The real decider is whether the opponent's storm arrives at all. When only one storm ever arrived, the stormer scored 62.2% (OTB, +7.5 above expectation). When both arrived ten or more plies apart, the first stormer scored 49.2% — no edge at all. Being first matters only if it stops the opponent from arriving.
  • Opposite castling is more decisive. The book's data snapshot shows the draw rate over the board at 19.4% with opposite castling (n = 30,629) against 26.8% with same-side castling (n = 219,796); among FIDE 2400+ players, 29.6% against 41.8%. On Lichess (balanced games) the gap is 3.3% vs 4.3%. If you need to win, opposite castling is one of the most reliable ways to unbalance a game.

Who scores better, the side that castled long or short? Over the board, the side that castled queenside in an opposite-castling game scored 51.9% (n = 30,629, +1.3 above expectation); on Lichess 50.6%. Hardly any difference — the side does not matter; the race does.

⚠️ Common pitfall: "The first attack wins" as a rule. In Case Study 2 we split the race by the evaluation at the moment both kings had castled: much of the first stormer's edge comes from positions where it was already better. Among level positions (|eval| ≤ 0.50) the OTB edge shrinks from +3.6 to +1.7 points. Storm first when you can, but don't burn a tempo pushing a pawn that the opponent can ignore.

At different levels. Under 1400 online, races are often decided by who notices the opponent's attack at all; simply counting "how many moves until his pawn touches my king?" every move is worth a lot. Around 1800–2000 OTB, the typical error is playing a slow prophylactic move in a race (16.Nde2 in Karpov–Korchnoi was flagged by the engine for exactly that: 16.Kb1 was preferred). At 2200+, races are decided by piece sacrifices that open lines — Rxc3, Bxh6, Nd5 — more than by pawns.

📋 Try it — Build the plan. In the Karpov–Korchnoi position after 12.O-O-O (diagram above), write a three-move plan for each side, then check it against the game.

Answer

White: h4-h5 to open the h-file (supported by g2-g4), Bh6 to exchange the g7-bishop, then Nd5 to remove the f6-knight, after which Qxh7 is mate or close to it. Black: ...Nc4 to exchange the light-squared bishop that defends White's king, ...Rxc4 and ...Qa5 to aim at c3 and a2, with ...Rxc3 as a possible exchange sacrifice. In the game Karpov played all three White ideas (14.h5, 17.Bh6, 22.Nxd5) and the engine's preferred Black move at move 12 was 12...h5, slowing White's pawn, rather than 12...Nc4.

🔄 Check your understanding 1. What is "storm arrival" in this book, and which kind of attack does it ignore? 2. When both storms arrived ten or more plies apart, what did the first stormer score over the board?

Answer

  1. The first ply, after opposite-side castling, at which a side has a pawn on its own fifth rank or beyond on one of the three files around the enemy king. It ignores piece attacks and exchange sacrifices such as Caruana's 13...Rxc3.
  2. 49.2% (n = 7,778) — no edge at all. Being first helps when it keeps the opponent's storm from arriving.

4.6 Same-Side Attacks: The h-Pawn and the Sacrifice on h7

The principle. When both kings are on the same wing, attacking with pawns weakens your own king. A same-side pawn storm is therefore justified only when (a) the centre is closed or stable, so the opponent can't counterattack there, and (b) your pieces are better placed for the coming fight on that wing. The h-pawn is the favourite battering ram because it is the pawn that matters least to your own shelter.

The reasoning. Of your three shelter pawns, the h-pawn shields the king least: after h2-h4 your king on g1 still has f2 and g2 in front of it, and the squares weakened (g3, g4) are hard for the opponent to reach. Meanwhile h4-h5-h6 attacks the opponent's g-pawn or fianchetto, pries open the h-file or the long diagonal, and gains space for your pieces. The g-pawn and f-pawn are much more expensive to advance.

The classic: Fischer–Sherwin, East Orange 1957

A young Bobby Fischer, playing a King's Indian Attack set-up against the Sicilian, shows the whole recipe: a centre where Black has no counterplay, pieces aimed at the kingside, and the h-pawn as a lever.

1.e4 c5 2.Nf3 e6 3.d3 Nc6 4.g3 Nf6 5.Bg2 Be7 6.O-O O-O 7.Nbd2 Rb8 8.Re1 d6 9.c3 b6 10.d4 Qc7
11.e5 Nd5 12.exd6 Bxd6 13.Ne4 c4 14.Nxd6 Qxd6 15.Ng5 Nce7 16.Qc2 Ng6 17.h4 Nf6 18.Nxh7 Nxh7
19.h5 Nh4 20.Bf4 Qd8 21.gxh4 Rb7 22.h6 Qxh4 23.hxg7 Kxg7 24.Re4 Qh5 25.Re3 f5 26.Rh3 Qe8
27.Be5+ Nf6 28.Qd2 Kf7 29.Qg5 Qe7 30.Bxf6 Qxf6 31.Rh7+ Ke8 32.Qxf6 Rxh7 33.Bc6+ 1-0

Fischer–Sherwin after 17...Nf6: White to move. The knight on g5 eyes h7; the h-pawn is ready to march.

♟️ Position: White Kg1, Qc2, Ra1, Re1, Bc1, Bg2, Ng5, a2, b2, c3, d4, f2, g3, h4; Black Kg8, Qd6, Rb8, Rf8, Bc8, Nf6, Ng6, a7, b6, c4, e6, f7, g7, h7 — White to move. FEN: 1rb2rk1/p4ppp/1p1qpnn1/6N1/2pP3P/2P3P1/PPQ2PB1/R1B1R1K1 w - - 1 18

Black's shelter is intact (6/6), but the queen on c2 hits the g6-knight, the knight on g5 hits h7, and the h-pawn is ready to evict the g6-knight with h4-h5. Fischer played 18.Nxh7!? Nxh7 19.h5, a knight for a pawn to drive away the last defenders.

🤖 Engine check: Stockfish 19 likes White's position but prefers the quiet 18.Qe2 (+2.79 at depth 20, +2.70 at depth 24), which threatens h4-h5 and Qxc4 without giving anything. Fischer's 18.Nxh7 is rated +1.97 (depth 20) — still clearly winning, just less so. After 18...Nxh7, 19.h5 is the engine's first choice (+2.49, depth 20). This is a pattern you'll meet again and again: the human's sacrifice is good, the engine's quiet move is better, and both win. The quiet move keeps the attackers and the material; the sacrifice trades a piece for open lines and time. In a game, the clearer path — the one you can calculate to the end — is often the right practical choice.

After 22.h6: the h-pawn has marched to the sixth rank; Black's king is about to lose its g-pawn.

♟️ Position: White Kg1, Qc2, Ra1, Re1, Bf4, Bg2, a2, b2, c3, d4, f2, h4, h6; Black Kg8, Qd8, Rb7, Rf8, Bc8, Nh7, a7, b6, c4, e6, f7, g7 — Black to move. FEN: 2bq1rk1/pr3ppn/1p2p2P/8/2pP1B1P/2P5/PPQ2PB1/R3R1K1 b - - 0 22

After 22.h6 (+2.00, depth 20) the g7-pawn falls, the h-file opens for a rook lift (Re4-e3-h3), and the attack converts. Note how White's own "shelter" — the g-pawn recaptured on h4, so White's king on g1 has no g-pawn — never matters, because Black has no pieces near it. That is condition (b) in action.

The modern example: Abdusattorov–Gukesh, Tata Steel 2026

The same lever appears at the very top today. In Abdusattorov–Gukesh (Case Study 1 annotates it in full), White played 19.h4 in a closed Ruy Lopez structure, followed by 24.h5. Stockfish 19 rated the position before 19.h4 as dead level (+0.01 at depth 20, +0.00 at depth 24) and the position after 24.h5 as slightly better for Black (−0.26 at depth 20, −0.21 at depth 24). The pawn storm didn't win by force; it posed problems, and on move 36 the world champion went wrong.

Abdusattorov–Gukesh after 18...b6: White to move. The plan is h4-h5.

♟️ Position: White Kh1, Qg3, Ra1, Rf1, Be3, Nc4, Nf5, a4, b2, c2, d3, e4, f2, g2, h2; Black Kh8, Qd8, Ra8, Re8, Bc8, Bf8, Ne6, a5, b6, c5, c7, e5, f6, g7, h7 — White to move. FEN: r1bqrb1k/2p3pp/1p2np2/p1p1pN2/P1N1P3/3PB1Q1/1PP2PPP/R4R1K w - - 0 19

What the data says: the h-pawn has come back into fashion

Script 05_rook_pawn_storms.py counts h-pawn storms in games where both sides castled kingside. It works on the move list alone — no board needed: after both O-O moves, does a side push its h-pawn to its own fifth rank (h5 for White, h4 for Black) without having captured with it?

=== Masters (slow events, both castled O-O): share of games with an h-pawn storm, by decade ===
 decade  games  white_storm  black_storm  any_storm  stormer_score  n_storms
   1950   2447         10.5          8.3       17.8           54.9       461
   1960   3446         10.0          8.5       17.6           58.3       638
   1970   3255          8.5          8.3       16.0           53.8       547
   1980   3650          8.8          8.6       16.4           55.9       636
   1990   4842         10.0         10.3       19.2           54.5       983
   2000   5196         11.9          9.3       20.3           55.8      1097
   2010   7305         13.1         10.1       22.1           55.4      1698
   2020   7674         15.9         13.6       27.4           55.1      2257

h-pawn storms by era (master games) and by rating band (OTB classical, Lichess).

📊 Figure (described): Left: in the great players' slow games, the share of O-O vs O-O games in which White pushes the h-pawn to h5 hovered around 8.5–11% from the 1950s to the 1990s, then climbed to 13.1% in the 2010s and 15.9% in the 2020s; Black's ...h4 rose the same way. Right: over the board (FIDE classical), White storms with the h-pawn in 11–13% of such games at every level; on Lichess the rate rises steadily from 4.7% under 1000 to 13.4% at 2400+.

In the master files, games with an h-pawn storm by either side rose from 16.0% in the 1970s to 27.4% in the 2020s (n = 7,674 games in the 2020s). The rise starts in the 2000s and accelerates in the late 2010s. It is tempting to credit the engines — the 2017 AlphaZero preprint and the Leela and NNUE-era engines that followed were widely noted for aggressive flank-pawn advances — and many commentators have; our data shows the timing is consistent with that story but cannot prove it (the master files also over-represent modern elite players, and the openings themselves changed).

Does the storm pay? Over the board in classical games the side that stormed scored 55.4% when the opponent did not storm back (n = 29,425, against 52.9% expected) and exactly 50.0% when both did (n = 3,286). On Lichess the stormer scores below expectation under 1600 (40.1% vs 49.8% under 1000, n = 222 storms; 47.2% vs 50.2% at 1400–1599) and above it from 1800 (53.7% vs 50.1% at 2200–2399). The h-pawn march is a strong player's weapon: it pays when the centre is under control and the pieces follow; pushed blindly, it just weakens your own king.

⚠️ Common pitfall: Pushing the g-pawn instead of the h-pawn. g2-g4 against a castled king tears open your shelter on the long diagonal and the g-file. Unless the centre is locked and the opponent has no pieces that can reach g4 and h3, start with the h-pawn.

🔄 Check your understanding 1. Name the two conditions that justify a same-side pawn storm. 2. Fischer's 18.Nxh7 was rated +1.97 and the engine's 18.Qe2 +2.79 (depth 20). Was Fischer's move a mistake?

Answer

  1. The centre is closed or stable (the opponent can't counterattack there), and your pieces are better placed on that wing than the defender's.
  2. No. Both moves are winning; the sacrifice trades material for open lines and time, the quiet move keeps both. In a game, the line you can calculate to the end is often the better practical choice.

4.7 Defending Your King

Attacking chess gets the books and the brilliancy prizes; defending wins as many points. Every game in this chapter had a defender, and most of them lost not to the attack itself but to one wrong decision inside it.

The principles of defence, each tied to a position we've already seen:

  1. Count, then trade attackers. Attack weight falls fastest when the most dangerous attacker leaves the board. In Karpov–Korchnoi, White's 17.Bh6 traded off Black's best defender, the g7-bishop; the defender's mirror-image task is to trade White's best attacker. When your opponent's attack needs a specific piece (the d3-bishop in a Greek gift, the h6-bishop in the Dragon), exchange it before it lands.
  2. Choose the king's square concretely. After Bxh7+ Kxh7 Ng5+, the three king moves differed by eight pawns in the hook (−4.27 / 0.00 / +3.86 at depth 24). "Activity" is not a reason to walk the king forward; counting the checks is. Ask, for each square: which enemy pieces can check me next move, and do I have a block or an escape?
  3. Counterattack where the attacker is weakest — often the centre or the other wing. A wing attack takes pieces away from somewhere. Esipenko–Caruana is the model: Black ignored White's kingside pawns and broke through on the queenside, where White's king actually lived.
  4. Don't move shelter pawns without a reason. Each pawn move in front of your king is permanent. But "never move them" is also wrong: a timely h3 (or ...h6) gives the king an escape square (luft) against back-rank mates and keeps a knight or bishop off g5/g4. The rule is: move a shelter pawn when it solves a concrete problem, not to "make space".
  5. Bring defenders back early. In Polugaevsky–Tal, Black's knight spent moves 14–18 travelling a5–c4–b2; at the moment of the sacrifice it was far from the kingside. A knight on f6 (or f8 in many structures) is worth more than a pawn grabbed on the queenside when your king is under fire.

📋 Try it — Find the defence. Shubin–Szpar, Çeşme Open 2026 (FIDE 2490 vs 2518 in the record). White has just sacrificed 14.Bxh7+ Kxh7 and played 15.Ng5+. Black to move: which of 15...Kg8, 15...Kg6 and 15...Bxg5 keeps the balance?

Shubin–Szpar after 15.Ng5+: Black to move.

♟️ Position: White Kc1, Qg3, Rd1, Rh1, Be3, Nc3, Ng5, a2, b2, c2, f4, g2, h2; Black Kh7, Qd8, Ra8, Rf8, Bc8, Be7, Nc5, Nc6, a6, b5, d5, e5, e6, g7 — Black to move. FEN: r1bq1r2/4b1pk/p1n1p3/1pnpp1N1/5P2/2N1B1Q1/PPP3PP/2KR3R b - - 1 15

Answer

Stockfish 19 at depth 20: 15...Kg8 +0.33 (roughly level), 15...Bxg5 +1.69, 15...Kg6 +7.51. 15...Kg6 walks into 16.Nxe6+, a discovered check from the g3-queen that also attacks the queen on d8. After 15...Kg8 the engine's line is 16.Qh3 Bxg5 17.fxg5 Nd3+ — Black gives the piece back only when it comes with a check and a counterattack against White's own king. Black played 15...Bxg5, the second-best move; after 16.fxg5 the f-file and the dark squares opened and White won on move 43. The king retreat is unglamorous — and it is the move.

🤖 Engine check: Why is 15...Kg8 better than taking the knight at once? After 15...Bxg5 16.fxg5, material is level again (bishop for knight plus a pawn) while Black's dark-squared bishop — the best defender of the king's dark squares — is gone and the f-file is open for White's rooks. After 15...Kg8, Black keeps that bishop and an extra piece, and White must spend a tempo (16.Qh3) to create a threat. The difference between +0.33 and +1.69 is the price of trading your best defender for an attacker that was not yet dangerous.

⚠️ Common pitfall: Panic exchanges. Defenders often give back material at the first check, as Black did here. Giving back the piece is right only if the attack is otherwise decisive. First count: how many attackers can reach my king zone in the next two moves, and how many defenders do I have?

🔄 Check your understanding 1. Give two reasons a defender should usually keep the dark-squared bishop when the attacker's knight lands on g5.

Answer

  1. It covers the dark squares next to the king (f6, g7, h6) that the knight and queen want to use, and trading it for the knight often opens the f-file (fxg5) for the attacker's rooks — Shubin–Szpar showed the cost: +0.33 after 15...Kg8 against +1.69 after 15...Bxg5 (depth 20).

4.8 King Safety at Different Levels

Pulling the chapter's data together by level (Lichess and FIDE bands are different scales — read each column within its own pool):

Question Lichess under 1000 / 1000–1199 Lichess 1800–1999 OTB FIDE 2400+
Side-games that castle at all 53.1% / 67.5% 83.4% 88.3%
Castled by move 10 29.5% / 37.5% 52.6% 59.1%
Median castling move 10 / 10 9 9
Not castled by move 15 (games > 30 plies) 47.2% / 36.1% 22.4% 18.1%
Greek gifts refuted by the eval 58.5% / 58.9% 40.5% 23.4%
Greek-gift sacrificer's score vs expectation 37.9 vs 48.2 / 44.6 vs 49.5 58.3 vs 50.4 48.9 vs 49.9
First stormer (opposite castling) vs expectation 53.9 vs 50.0 / 52.2 vs 50.2 54.2 vs 50.0 54.8 vs 50.5
h-pawn stormer (O-O vs O-O) vs expectation 40.1 vs 49.8 / 47.7 vs 50.0 50.4 vs 49.9 55.5 vs 52.6 (classical)

What changes as players improve is not the knowledge that the king needs shelter — the castling move barely moves — but judgement: castling reliably, sacrificing only with the preconditions, storming with the h-pawn only when the centre allows it. The beginner's king dies in the centre; the club player's king dies to a Greek gift he could have refuted; the master's king dies to a race lost by one tempo.

Lena: So the data says castling doesn't matter much? Two points?

Grace: Two points on average. Thirty-six percent when the centre's open. I've lost those games.

Dev: And the Greek gift is a coin flip without the e5-pawn — half of them are refuted with one precondition or none.

Sam: We used to say "count the attackers and the defenders" and leave it at that. Nice to see the numbers agree with us for once.

Lena: I sac on h7 because it looks pretty.

Grace: Under 1000 online the sacrificer scores 37.9%. Tick the five boxes first.

🪞 Learning check-in: Think about your last three losses. Did any of them end with an attack on your king? If so, which happened: (a) your king stayed in the centre while the position opened, (b) you moved shelter pawns without a reason, (c) you missed the moment the attackers outnumbered your defenders, or (d) you chose the wrong square for your king under fire? Write the letter next to each game. If one letter repeats, that is your king-safety training target — and Outpost's king_safety report will flag (a)–(c) automatically once you run it on your games. Then ask the reverse question about your wins: did you attack because the preconditions were there, or because it looked pretty?


Spaced Review

Before opening the answers, try each question from memory.

  1. Chapter 1 — win percentage. In the hook, 15...Kg8 was worth −4.27 for White (depth 24). Using the Lichess win-percentage model from Chapter 1, roughly what winning chance does that give Black?
  2. Chapter 2 — structure. The Greek gift's most informative precondition was a White pawn on e5. Which pawn structure from Chapter 2 produces that pawn most naturally, and why does that structure also keep Black's knight away from f6?
  3. Chapter 3 — activity. In Polugaevsky–Tal, Black's knight ended on b2. In Chapter 3's language, what kind of piece had it become, and what did that cost Black's king?
Answer
  1. win% = 50 + 50·(2/(1 + e^(−0.00368208·427)) − 1) ≈ 82.8% for the side 4.27 pawns ahead — so Black would have been winning more than four games in five by that model, instead of losing.
  2. The French chain (White pawns d4–e5 against Black's d5–e6). The e5-pawn takes f6 from Black's knight permanently, so the knight cannot return to its best defensive square — the structure itself prepares the Greek gift. That is Chapter 2's threshold concept, the structure dictates the plan, applied to the king.
  3. A bad, offside piece: on b2 it attacked a rook but defended nothing. Attack weight counts pieces aimed at the king zone and defenders count pieces covering it; the knight's journey cut Black's defenders to two at the critical moment. Piece activity is king safety's other face.

Project Checkpoint: king_safety.py

Dev's Outpost already knows where the pawns stand (Chapter 2's structure.py) and how active the pieces are (Chapter 3's activity.py). This chapter adds the module that tells him when a king — his or his opponent's — is in trouble. He writes project/outpost/king_safety.py with eight public functions:

Function Returns
king_zone(board, color) the king's square, its neighbours, and three squares two ranks ahead
castling_status(board, color) 'castled-short', 'castled-long', 'home' or 'moved'
shelter_score(board, color) shelter points 0–6 and the state of each file (home / advanced / far / missing)
open_files_near_king(board, color) open and half-open files beside the king
zone_pressure(board, color) attackers, attack weight, defenders, attacked zone squares
king_safety_report(board, color) everything above plus a verdict: solid / watch / danger
greek_gift_check(board) the five preconditions for Bxh7+ (or ...Bxh2+) for the side to move
castling_timeline(game) castling plies and sides, and each side's storm-arrival ply

The heart of the verdict is deliberately simple — a reading aid, not an evaluation:

danger = (zp["attack_weight"] >= 7 and zp["attack_weight"] - zp["n_defenders"] >= 4) or \
         (sh["points"] <= 2 and enemy_queen and status.startswith("castled") and zp["n_attackers"] >= 2)
verdict = "danger - check concrete lines" if danger else ("watch" if flags else "solid")

The threshold of 7 comes from Section 4.3's data: attack weight 7–9 is where the owner's mean evaluation turns clearly negative in both databases. Black's side is handled once, by board.mirror(), so greek_gift_check works for ...Bxh2+ without a second copy of the logic.

code/project_checkpoint.py runs the module on two games from the data (output trimmed):

Polugaevsky, Lev - Tal, Mihail, URS-ch37 1969: White to move
Black king g8 (castled-short): shelter 6/6 [f:home,g:home,h:home], attack weight 7 from 2 piece(s), 2 defender(s)
  verdict: danger - check concrete lines - heavy pressure (attack weight 7 vs 2 defenders)
Black king zone: ['f6', 'f7', 'f8', 'g6', 'g7', 'g8', 'h6', 'h7', 'h8']
attackers: ['Bd3', 'Qf4'] | defenders: ['rf8', 'qd8']

Greek-gift preconditions for the side to move:
  knight_to_g5     True
  g5_unguarded     False
  queen_to_h_file  True
  no_f6_knight     True
  e5_pawn          True
  n_preconditions  4

Karpov, Anatoly - Kortschnoj, Viktor, Candidats final 1974, round 2
castling timeline: {'white_castle': 'Q', 'white_castle_ply': 23, 'black_castle': 'K', 'black_castle_ply': 16, 'opposite': True, 'white_storm_ply': 27, 'black_storm_ply': None, 'first_storm': 'white', 'plies': 53}
  ply 30: White c1 4/6 aw  3 watch                          | Black g8 5/6 aw  5 solid
  ply 40: White c1 4/6 aw  8 danger - check concrete lines  | Black g8 5/6 aw  8 danger - check concrete lines
  ply 53: White c1 4/6 aw  7 danger - check concrete lines  | Black f8 3/6 aw  7 danger - check concrete lines

Notice that the report flags both kings in danger at ply 40 of Karpov–Korchnoi — which is exactly what an opposite-castling race looks like. The module can't say who wins the race; that is the engine's job, and yours.

How it plugs in later. Chapter 8's planner.py reads king_safety_report as one dimension of its position assessment. Chapter 12's dynamics.py tracks attack weight over a game as an attack-versus- defence indicator. Chapter 19's opening audit uses castling_status and castling_timeline to check when and where you castled. And the game review of Chapter 26 can call greek_gift_check whenever a bishop takes on h7 or h2, so a review says not only "the sacrifice was unsound" but which precondition was missing.

💻 Developer Track: Extend zone_pressure to count x-ray attackers (a rook behind a rook or queen on the same file). Rerun 04_shelter_and_eval.py with your version: does the rank correlation with the evaluation get stronger than −0.14?


Chapter Summary

Principles

Principle What it means at the board Evidence in this chapter
The king has two lives Hide it while queens are on; centralise it when they come off Queenless endings, equal material: king two steps more central scores 59.7% vs 36.6% (OTB)
Castle reliably, not necessarily early The median castling move is 9–10 at every level; levels differ in whether players castle Lichess 53.1% (<1000) → 86.6% (2400+) castle; OTB ≈ 88% from 1400 up
An uncastled king is as safe as its centre Open d/e-files turn the king into a target OTB uncastled king: 47.9% closed centre vs 36.5% open (n = 155)
Attackers matter more than pawn cover Count enemy pieces aimed at the king zone against your defenders Rank correlation with eval ≈ −0.14 (attack weight) vs +0.05 / +0.09 (shelter)
Learn the Greek gift's preconditions, not the move Knight to g5, g5 unguarded, queen to the h-file, no f6-knight, e5-pawn 0–1 preconditions: 50.1% refuted; 4–5: 61.6% winning
Opposite castling is a race Storm first — but above all stop the opponent's storm arriving First stormer +3.7 pts OTB; when only one storm arrived, 62.2%
Opposite castling is more decisive Choose it when you need to win OTB draw rate 19.4% vs 26.8% with same-side castling
The h-pawn is the modern lever Push it when the centre is stable and your pieces can follow Master-game h-pawn storms: 16.0% (1970s) → 27.4% (2020s) of O-O vs O-O games
Defend concretely Choose king squares by counting checks; keep your best defender Hook: Kg8 −4.27 / Bxg5 0.00 / Kg6 +3.86 (depth 24)

Decision checklist — before you castle, sacrifice, or storm

  1. Can the centre open in the next two or three moves? If yes, castle now.
  2. Which side? Where are the enemy pawns and pieces pointing — am I castling into an attack?
  3. For a Greek gift: tick the five preconditions. Fewer than three? Calculate every king reply, or don't.
  4. In opposite castling: count the moves until each storm arrives. Can one move slow his (…h5, h4, a piece blockade)?
  5. Same-side storm: is the centre stable, and are my pieces ready to follow the h-pawn?
  6. Under attack: count attackers against defenders, find the attacker to trade, and choose king squares by counting checks — not by instinct.

What's Next

A king needs room, and so does every other piece. Chapter 5 measures space — the squares behind your pawns that your pieces can use — and the key squares and colour complexes that decide where attacks can land. The dark squares around Black's king in Karpov–Korchnoi were a colour complex; next chapter you'll learn to see them before the bishop arrives.