# The unicorn hunt: 8 × 8, the first move and smaller boards

Part of [`research/chess-proof`](../README.md). Scripts are in the parent folder, results in `../data/`, figures in `../figures/`.

## The unicorn hunt: hidden moves that rise with depth

A move that breaks the draw would have to be invisible to levels 1–3, which scored every move at depths 14–20. It would
look bad to a shallow search and keep rising as the search deepens: the signature of a sacrifice or a deep plan.
`unicorn.py` hunts for exactly that. A win for the side that did not deviate only refutes the deviation, so the pool
is every spine position (either side may break the draw), plus the first 30 positions of each rib where the side to
move is the side that deviated: 1 283 positions and 45 036 moves.

- **Screen:** 188 moves (0.4%) are hidden. Each scored at least 0.8 pawns below the move played at depth 8, then rose
  to within 0.3 pawns of it at depth 16.
- **Depth 28:** each hidden move searched alone against the move played. 109 end within a quarter pawn of it, 74 fall
  back by more, and 5 improve by a quarter pawn or more. On the spine itself all 7 hidden moves fall back, by 0.06 to
  0.36 pawns. The shallow search's "blunders" were mostly its own error, not hidden wins.
- **Depth 32 and played out:** four of the five keep their gain. All five are White moves inside ribs where White
  deviated:

| hidden move | rib | score at depth 8 → 16 → 28 → 32 | move played, depth 32 | played out |
|---|---|---|---|---|
| 25.c5 (instead of Bd2) | 17.Rb1 | −0.30 → +0.29 → +0.73 → +0.75 | +0.15 | draw |
| 30.Qh3 (instead of Qg3) | 23.Bh6 | −0.06 → +0.75 → +2.17 → +2.28 | +1.79 | draw by repetition |
| 24.Qc3 (instead of c4) | 16.Qd2 | −0.64 → −0.39 → −0.09 → −0.08 | −0.54 | draw |
| 29.Bxe4 (instead of a5) | 15.Bxe4, already lost | −5.18 → −5.00 → −4.97 → −5.06 | −5.40 | still lost |
| 41.Qc2 (instead of Qc6) | 29.Qc1 | +0.22 → +0.50 → +0.52 → +0.47 | +0.30 | draw (gain under a quarter pawn at depth 32) |

**No unicorn.** The closest is 25.c5: it looks like a blunder at depth 8 and climbs to three quarters of a pawn,
the shape a breaking move would have, but the game is still a draw. 30.Qh3 is the sharper lesson. It scores +2.28 at
depth 32 and is still held to a repetition. An engine score, even a large one, is a forecast, not an outcome. A real
break would have to win when played out, starting from a position where the losing side never left best play. Nothing
in 45 036 moves near the perfect game does.

## Chasing the unicorn: deeper play-outs, best defence, and the first move

**The near-unicorns, played out deeper.** `unicorn_chase.py` played the three draws with a real gain out again at depth
24 (the hunt used depth 20). It also checked every earlier move of the losing side, back to where the line left the
spine, at depth 22.

- **24.Qc3** draws.
- **30.Qh3** wins, but Black could have avoided the position: 25...f5 was a mistake (25...Qh5 is better by 1.13
  pawns), so the win punishes that mistake.
- **25.c5** wins, and none of Black's 8 earlier moves had a better alternative. The line is the spine to 16...Qe5,
  then **17.Rb1** (instead of 17.g3) Nf6 18.b4 Bb6 19.c4 Rae8 20.Bd2 Bd4 21.g3 Nh5 22.Rf3 f5 23.Bh6 Rf7 24.Qa4 a6
  **25.c5**.

**Certifying 25.c5.** If 25.c5 really wins, 17.Rb1 beats the spine and this Berlin position is lost for Black, so the
bar is high.

- A 15-minute search of the position after 25.c5 reaches depth 46 and scores it **+0.76**: an edge, not a win
  (25...Nf6 26.Kg2 Bxf2 27.cxd6 Bb6 28.dxc7 Bxc7 29.b5).
- A second depth-24 play-out, on 4 threads instead of 2, reached ply 220, the throughput cap the rib runs used, and was
  first scored as a draw. That was wrong. The position there has 6 pieces (two bishops and a pawn against a rook), and
  the lichess tablebase says White wins, mate in 89, with one winning move, Ba4+. So both depth-24 play-outs end in a
  White win. `unicorn_certify.py` now finishes such games and looks endings of 7 pieces or fewer up in the tablebase.
- **The decisive test** (`unicorn_duel.py`): two engines play on from 25.c5, White with 8 seconds a move and Black with
  32 (4 threads each; median depths 32 and 42). Endings of 7 pieces or fewer would be looked up in the tablebase.
  White's score peaks at **+0.89** around move 29, then wears down to 0.00. The game is adjudicated drawn at move 60
  with 10 pieces, both engines reading 0.00 at depth 50–60.

**25.c5 is a false unicorn.** It beats a depth-24 defender and not a deeper one. It is the level-two lesson one notch up:
the crack was the defender's horizon, not the position.

**From the first move.** `unicorn_pn.py` runs an engine-guided proof-number search: one prover move at each of its
turns (the top 6, depth 12), every defender reply that does not lose at once, and a win counted at +3 pawns.

- **White to win:** 2 500 expansions, 24 846 positions. The proof number (how many more positions must be proved) rose
  steadily, to 1 362. Black has about 20 replies that hold at each turn (20 after 1.d4, 21 after 1.d4 Nf6 2.c4), and the
  most promising line never got past move 2.
- **Black to win:** 25 946 positions, proof number 2 834, about twice as far.
- Both searches pass a self-check: with only real checkmates counted as wins, the same search proves 1.Ra6! bxa6 2.b7#
  (`test_chess_proof.py`).

**The other perfect games.** `unicorn_others.py` plays Stockfish's own perfect games at depths 16, 18, 20 and 22 to the
end. They are a Sicilian and three Berlin-type games, and all four are draws: depth 16 by tablebase, the others by
repetition (at depths 18 and 22 as early as moves 25 and 23). Every position in them comes from best play, so a hidden
win for either side would count. The hunt screened 232 new positions and 6 944 moves and found 27 hidden moves. At
depth 28 none improves on the move played: the best gain is 0.06 pawns, and most end at exactly 0.00 next to an equally
drawn move played.

**Every route ends the same way.** No unicorn exists within reach of these methods. Near the perfect game, the best
candidate dissolves once the defender searches deeper. From the first move, every White try leaves about 20 Black
replies to beat, and that number does not shrink. All of this is engine evidence with known limits, not a proof.

## Smaller boards: where a forced win comes within reach

`unicorn_mini.py` runs the same proof-number search on 8 files and H ranks: the rules of `minichess.py`, Fairy-Stockfish
11.1 scoring at depth 12, and every proof or disproof leaf re-scored at depth 20 before a verdict is accepted. On the
full board the proof number only grows. The question is whether that changes when ranks are removed. In the engine
games of [04-minichess.md](04-minichess.md), White won 16 of 20 on 5 ranks and 20 of 20 on 6.

| board | expansions | positions | proof number | disproof number | trend |
|---|---|---|---|---|---|
| 8 × 8 (chess, `unicorn_pn.py`) | 2 500 | 24 846 | 1 362 | 130 | the proof number rises steadily |
| 8 × 5 | 1 000 | 4 613 | 139 | 18 | a near-proof (4 at 300 expansions) dissolved; Black is closer to holding |
| 8 × 6, first run | 4 500 | 24 093 | **36** | 277 | the proof number falls from 101 at 2 200 expansions |
| 8 × 6, second run | 4 300 | 24 216 | **60** | 240 | the same shape: about 90 until 4 000, then falling |
| 8 × 6, second run, repetitions cut | 5 020 | 27 212 | 68 | 143 | see below |
| 8 × 6, second run, after the depth-20 check | 6 700 | 36 250 | 81 | 107 | a depth-12 proof overturned (below) |
| 8 × 6, second run, after the second check | 13 100 | 71 279 | 88 | 132 | a second depth-12 proof overturned |

- **8 × 5:** after 300 expansions one White line was 4 positions from a proof. Deeper, Black's replies held, and the
  disproof number fell to 7–20. Black is nearer to showing that White cannot reach +3 than White is to forcing it.
- **8 × 6:** both runs show the same shape (the engine runs on several threads, so the two runs are not identical). The
  disproof number climbs steadily, so Black's ways to hold disappear. The proof number peaks near 100 and then falls.
  The most promising lines all start 1.e2e4 d5xe4 2.a2a4: on six ranks the pawns are in contact from the first move.
  An earlier 1 500-expansion run (`unicorn_mini_6_1500.json`) ended at 83 and 93.
- **A bug, found and fixed.** Up to 5 020 expansions the minichess search did not detect repeated positions. One
  branch of the second run's most promising set was a perpetual check 107 plies long, with Black's queen shuttling
  b1–d3 against White's king, which the search treated as still open. A repeated position now counts as a draw
  (`test_chess_proof.py` checks this). Cutting the 3 repetitions in the saved tree removed 635 positions. White's proof
  number stayed at 68, but Black's disproof number fell from 284 to 143. The rising disproof numbers in the table were
  partly this bug: Black was closer to holding than they showed.
- **A proof, overturned.** After the fix the proof number fell steadily: 47 at 5 500 expansions, 21 at 6 000, then 3–5.
  Between 6 600 and 6 700 it reached 0: every final position of one White strategy scored +3 or more at depth 12. Its
  main line was 1.e4 dxe4 2.a4 b3 3.Ba6 Nf4 4.Nc3 Ng2+ 5.Kf1 Nf4 6.h3 c4 7.Rh2 bxc2 8.Qxc2 Qd3+ 9.Qxd3 exd3 10.Ra3
  e4 11.b4 cxb3 e.p. 12.f3. A root does not count until its 416 proof leaves have been re-scored at depth 20. Enough
  of them fell below +3 that the proof number went back to 81 and the disproof number dropped to 107. The main line
  moved to 2...Nxa4. It is the level-two lesson again: a shallow search sees wins that a deeper one does not.
- **And again.** The search went on from the corrected tree: the proof number climbed back down to 9 at 12 200
  expansions, to 3 at 13 000, and reached 0 a second time. Re-scoring 324 more leaves at depth 20 (740 in all)
  overturned this proof too: proof number 88, disproof number 132. Of the 687 depth-20-checked leaves still in the
  tree, 571 (83%) hold at +3 or more and 116 do not. Most of those drop only to +2 to +3, and 7 drop to between 0 and
  +1. A proof needs every one of its several hundred leaves to hold, so a 17% failure rate at the margin is enough to
  sink it.

- **Proofs keep forming and failing.** By 17 500 expansions, five more depth-12 proofs had failed the depth-20
  check. The search now checks a proof one leaf at a time and stops at the first leaf that fails. After that, the proof
  number sat between 10 and 25 for thousands of expansions. The open leaves were long endgames in which White is +1.6 to
  +2.7 and needs many moves to reach +3, which proof-number search handles badly.

**Certification: a search-and-check loop.** The +3 threshold only marks where the search hands over to a deeper
check. So a branch (`unicorn_mini_6_w200`) copies the tree at 20 958 expansions and moves the hand-off to +2. The
certifier, `unicorn_mini_certify.py`, then tests a proved tree three ways:

1. At every Black node of the proof, Black's best reply among those the search cut is found at depth 20. If it leaves
   White below +2, it is a *hole*.
2. Every proof leaf is played out with both sides at depth 16: White must win. A game ends by the rules, or when
   Black's search sees a forced mate, or when White stays at +10 or more for 4 Black moves.
3. Black's best cut reply at every Black node is played out the same way, and White must win that too.

Every hole and every game White does not win goes back into the tree. A hole becomes a new open reply; a game White
fails to win marks its position as not won and cuts the subtree below it. Both can only make a proof harder. Then the
search re-proves the root and the certifier runs again.

| pass | first move | Black nodes | leaves | holes | leaves not won | best cut replies not won | gaps |
|---|---|---|---|---|---|---|---|
| 1 | 1.e4 | 785 | 910 | 8 | 38 | (not played yet) | 46 |
| 2 | 1.e4 | 728 | 821 | 3 | 11 | | 14 |
| 3 | 1.e4 | 701 | 796 | 4 | 8 | | 12 |
| 4 | 1.e4 | 713 | 816 | 3 | 2 | | 5 |
| 5 | 1.e4 | 710 | 816 | 1 | 0 | | 1 |
| 6 | 1.e4 | 709 | 815 | 0 | 0 | 11 of 700 | 11 |
| 7 | 1.a4 | 79 | 157 | 4 | 10 | 2 of 71 | 16 |
| 8 | 1.a4 | 79 | 163 | 2 | 4 | 1 of 72 | 7 |
| 9 | 1.a4 | 101 | 179 | 6 | 3 | 0 of 88 | 9 |
| 10 | 1.a4 | 99 | 180 | 3 | 2 | 2 of 90 | 7 |
| 11 | 1.a4 | 132 | 204 | 4 | 5 | 0 of 122 | 9 |
| 12 | 1.a4 | 131 | 204 | 4 | 0 | 0 of 118 | 4 |
| 13 | 1.a4 | 154 | 214 | 0 | 1 | 0 of 146 | 1 |
| **14** | **1.a4** | **134** | **204** | **0** | **0** | **0 of 126** | **0** |

- The first play-outs gave White depth 12 against Black's depth 16. White then lost or drew leaves it should have won,
  some of them scored +3.8, which says more about the weak White than about the leaves. All play-outs since have
  equal depth on both sides.
- Two more blind spots surfaced along the way and were closed:
  - Black nodes where every reply had been scored lost at depth 20, but whose game White did not win.
  - The cut replies themselves, which until pass 6 had been scored but never played out.
- **Pass 6 had no holes, and White won all 815 leaves.** Then the new check (3) played out Black's best cut reply at
  every node. 11 of 700 were not won, among them **1.e4 h5–h3!**: a pawn thrust the search had cut as losing (+2 for
  White at depth 20), after which Black won the game. That refuted 1.e4, so the search switched to **1.a4**, a younger
  and less tested proof.

**Pass 14 passes all three checks** (`unicorn_mini_6_w200_certify_pass14.json`, tree in `unicorn_mini_6_w200.pkl`,
30 118 expansions). The strategy has 303 White nodes, 134 Black nodes and 204 leaves.

- **Every Black reply is accounted for.** At each Black node a reply is either in the tree, with a strategy of its own
  below it, or cut. 2 445 replies are cut, and at every node Black's best cut reply still leaves White at +2 or more
  at depth 20 (the tightest: +2.01, +2.06, +2.09). The separate rules engine `minichess_ref.py` replays the whole
  tree and agrees at every node: every move is legal, and the positions and legal-move lists match.
- **Every leaf is won.** All 204 leaves, and the positions after all 126 best cut replies, were played out with both
  sides at depth 16, and White won all 330 games. 302 were adjudicated when Black's own search put White at +10 or more
  for 4 Black moves in a row. In the other 28, Black's search saw a forced mate against itself. The median game ran 48
  plies past the leaf, the longest 114.
- **The strategy:** 1.a4. Black has 19 replies: 15 are answered in the tree and 4 are cut, the best of them 1...d5–d3
  at +4.09 for White. Against most replies White plays 2.axb5 or 2.e4: 1...h5–h3 2.Nxh3, 1...Nxa4 2.e4, 1...c5–c4
  2.axb5, and so on. 1.e4 and 1.d4 are marked not won, and the other first moves are far from proved.

**What this is, and what it is not.** It is an engine-certified strategy for White in 8 × 6 minichess. Every Black
reply at every turn is covered, and every way the tree ends has been won in an equal-strength engine game. That is
strong evidence that 8 × 6 minichess is a forced win for White, and the closest thing to a unicorn this project has
found. It is not a mathematical proof:

- a cut reply is judged by one depth-20 search, and only the best of them at each node is played out;
- a leaf is judged by one game each at depth 16, decided by engine adjudication rather than mate on the board;
- one engine, Fairy-Stockfish 11.1, does all of it.

A deeper engine could still find a defence somewhere in the 134 Black nodes, as 1...h5–h3 did against 1.e4. Nor does
it say anything about chess: on 8 × 8 every method here ends in a draw. `python unicorn_mini.py 6 99999 4 7 200` and
`python unicorn_mini_certify.py 6 4 200 7` run one resumable 7-minute piece of the search and of the certifier.
