Hazel reports · ^report(62) · Hazel’s search · 2026-11-21, revised 2026-11-21 12:41 MST · work in progress · after ^report(61)
One Search Tree for Two Players
^report(61) found that Hazel’s two Checkers players, each looking six moves ahead, never ask each other’s questions. Matthew asked next: “is there a way to make a ‘canonical search space’ that’s not POV, so that each person’s view of it matches each other persons?”; “we want a memo policy that does not match exactly, but instead uses a partial ordering”; “a way of asking for a shallow depth, getting a full match, and then separately asking for a deeper match that reuses that entire shallow match, without redoing it”; “we need a way to treat the matches as streams, whose heads can be reused … tree-streams”. This is a prototype of that design, in the Checkers lab, measured on the 503 positions of ^report(61)’s 3 games.
Every count is exact, from the lab’s mirror of the Checkers rules; the times are one run each on a laptop and only compare the ways with each other (how). Every way that keeps Hazel’s way of looking ahead chose every move exactly as Hazel does.
Outline#
- The design: one tree of boards, and two streams on each board, its moves and its answers.
- Lined up, the players share: when two searches end on the same move, the second does about half the work.
- Lining up costs a move of look-ahead: one player looks one move further, or one less.
- Keeping the tree: half the moves worked out, no time saved, more memory.
- Shallow first, then deeper: nothing saved here, and why.
- The partial order: ranges are what make any answer reusable; further answers for nearer ones add a little.
- Every way, in one table, the answer, what next, and how this was put together.
The design#
One tree of boards that both players grow and read. A node is a board (the pieces and whose turn it is), the same node whoever reaches it, and each node carries two streams: its moves, worked out the first time anyone asks and kept, and its answers, one range of values for each look-ahead. A board’s answer is its value to the side to move there, so it means the same thing to both players: nothing has to be turned round for one or the other. That is the canonical search space, with no point of view in it.
A search asks a board a question: “looking 5 ahead, is your value more than 3?” Alpha-beta asks that kind of question, a value inside a window, rather than “what exactly is your value”. The memo answers it with any entry that settles it, not only an exact match: an entry “between 4 and 9” for 5 ahead settles “more than 3”. That is the partial order: a narrower range knows more than a wider one, and one that settles the question is good enough. Optionally, an entry for a further look-ahead may stand for a nearer one (below).
Three more parts of the prototype: each board remembers which of its moves was best last time, and that move is tried first next time (the head of the last answer, reused by the next question); a search may first look 2 ahead, then 3, and so on, before the full depth (deepening); and boards at the very edge of a search are only valued, never kept, since valuing a board costs less than finding it in the tree. Boards no search has visited in the last two moves are let go, so the tree keeps what is near the game as it goes on.
Lined up, the players share#
When two searches end on the same move, the one that comes second does about half the work with one table shared: black, coming second, looks at 1,996 positions a move instead of 3,917 (49% fewer, 11.1 ms to 5.4 ms); white, coming second the other way round, 746 instead of 1,451 (49% fewer, 3.9 ms to 2.1 ms). ^report(61) showed why Hazel’s two players never meet: black at move 10 looks to move 16, white at move 11 to move 17, so a board they both reach is asked about with different distances still to look. Line their finish lines up, and they ask the same questions. Black looking 6 ahead and white 7: white at move 11 looks to move 18, black at move 12 looks to move 18, and every board both reach is asked the same question. Or black 6 and white 5: black at move 10 and white at move 11 both look to move 16.
The second search’s head start is the first one’s work along the line it expected: the first search tried every one of its moves with the whole window, so every board the second player can be facing already has an exact answer, out to the same finish, and the second player’s replies have at least ranges. Not everything carries over: the second player still wants an exact value for each of its own moves (Hazel breaks ties between equal moves at random), and many of the first search’s answers are only ranges.
Lining up costs a move of look-ahead#
Two searches can end on the same move only if one of the two players looks one move further than the other, or one less, so the sharing is paid for in look-ahead: white looking 7 costs more than the sharing saves (17.1 ms a move with one table, against 10.7 for Hazel’s 6 and 6 with a table each), while white looking 5 costs less (6.2 ms a move, 43% less than 6 and 6 with a table each and 63% less than Hazel now, 16.8 ms). One move more is expensive: white looking 7 with no table takes 48.0 ms a move against 19.6 for 6. One move less is cheap, and the sharing then lands on white, the player looking 5. Whether white playing 5 ahead plays noticeably worse, or white playing 7 better, is not measured here (what next).
Keeping the tree#
Keeping the tree (each board’s moves worked out once, its best move tried first) halves the moves worked out (1,647 a move with a table, 782 with the tree, 52% fewer) and looks at 13% fewer positions, but in JavaScript it is no faster (10.8 ms a move against 10.7) and keeps three to four times the memory (522 MB against 125). Working out a board’s moves again turns out to cost about what finding the board’s node and its kept moves costs; and a node, with its board, its moves and its answers, is heavy to keep. Trying the best move first is the part that pays: lined up 6 and 7, it brings white’s positions looked at from 10,095 to 8,110 a move (20% fewer; 18.7 ms a move to 16.4). It needs only the best move of each board kept, which a table can keep too.
Shallow first, then deeper#
Looking 2 ahead first, then 3, and so on up to the full depth, saves nothing here (16.8 ms a move, against 16.4 without), because a deeper answer cannot be built on top of a shallower one. A board’s value looking 6 ahead comes from its children’s values looking 5 ahead, not from its own value looking 5 ahead; so what the shallow searches leave for the deep one is the tree (white’s moves worked out drop from 2,396 to 2,078 a move) and the order to try moves in, and the shallow searches themselves cost about what that order saves. Chess programs gain from deepening mostly by searching the first move with the whole window and the rest with a narrow one; Hazel’s players want an exact value for every move (for their random tie-breaks), which leaves that gain unused. The streams’ heads that pay off are the ones shared between the two players, not the ones a player passes to its own deeper search.
The partial order#
The order by ranges is the memo’s baseline: every table in ^report(61) and ^report(62) answers a question with any range that settles it, which is how alpha-beta’s answers, often only ranges, can be reused at all. Letting an answer for a further look-ahead stand for a nearer one adds little: 2% less time (16.4 to 16.0 ms a move), and 1 of 503 moves chosen differently. A further answer is a better-informed one, but it is no longer the answer the nearer search would have found, so it changes the player a little; here the change was small both ways.
Every way, in one table#
| way | ms a move | black’s | white’s | positions looked at, a move | moves worked out, a move | answered by the memo, a move | moves chosen differently | boards or entries kept, most | memory, MB |
|---|---|---|---|---|---|---|---|---|---|
| Hazel now: 6 and 6, no table | 16.8 | 14.1 | 19.6 | 9,454 | 2,442 | 0 | 0 | 0 | 5 |
| 6 and 6, a table each | 10.7 | 10.1 | 11.3 | 4,541 | 1,647 | 440 | 0 | 354,202 | 125 |
| 6 and 6, one table, shared | 10.6 | 9.9 | 11.3 | 4,541 | 1,647 | 440 | 0 | 354,202 | 125 |
| 6 and 6, the shared tree | 10.8 | 9.5 | 12.2 | 3,969 | 782 | 369 | 0 | 246,997 | 522 |
| 6 and 7, no table | 31.2 | 14.4 | 48.0 | 15,887 | 5,704 | 0 | 0 | 0 | 4 |
| 6 and 7, a table each | 19.7 | 11.1 | 28.4 | 7,057 | 3,282 | 978 | 0 | 701,399 | 225 |
| 6 and 7, one table, shared | 17.1 | 5.4 | 28.9 | 6,031 | 2,876 | 920 | 0 | 577,440 | 192 |
| 6 and 7, the shared tree, the rules' order | 18.7 | 5.7 | 31.7 | 6,039 | 1,606 | 918 | 0 | 231,917 | 477 |
| 6 and 7, the shared tree | 16.4 | 6.3 | 26.5 | 5,201 | 1,424 | 763 | 0 | 172,665 | 350 |
| 6 and 7, the shared tree, deepening | 16.8 | 5.4 | 28.2 | 6,693 | 1,210 | 886 | 0 | 157,818 | 327 |
| 6 and 7, the shared tree, further answers | 16.0 | 5.5 | 26.6 | 5,125 | 1,421 | 761 | 1 | 172,145 | 349 |
| 6 and 5, no table | 9.2 | 14.2 | 4.1 | 4,700 | 1,523 | 0 | 0 | 0 | 5 |
| 6 and 5, one table, shared | 6.2 | 10.2 | 2.1 | 2,317 | 993 | 283 | 0 | 211,812 | 71 |
| 6 and 5, the shared tree | 7.0 | 12.0 | 1.9 | 2,209 | 556 | 253 | 0 | 184,399 | 384 |
| 6 and 5, a table each | 7.2 | 10.6 | 3.9 | 2,686 | 1,119 | 289 | 0 | 253,147 | 89 |
Build 1 (the lab), the same 503 positions each way. “Moves chosen differently”: against the plain search with the same look-ahead for each player (Hazel’s own moves, for 6 and 6). Memory: what the way keeps at the end of a game, after a collection.
The answer#
Yes, the two players can share one search: with the board as the node and its answers as ranges found by a partial order, the space has no point of view in it, and once the two searches end on the same move, the second one does about half the work. The price is a move of look-ahead for one player. Of the design’s other parts, trying each board’s best move first pays; keeping the tree’s moves, and deepening a step at a time, do not pay in this lab, because the deeper answer is built from the children, not from the shallower answer, and most of the work is always the new bottom of the tree.
What next#
- Does it play as well? Play black 6 and white 5 (and 6 and 7) against Hazel’s 6 and 6, many games each way round, to see what a move of look-ahead is worth against the time saved.
- In Hazel itself. The compiled rules work out moves far more slowly than this JavaScript (
^report(60)), which may change the tree’s balance: kept moves might pay there. A memo in Hazel needs a persistent map keyed by the board; measure it in the compiled rules. - Go. Go’s boards repeat within a search far more than Checkers’ (stones placed in any order), so both the shared table and the tree should do more there.
How this was put together#
| build | what | where |
|---|---|---|
| Build 1, the lab | node tools/checkers-lab.mjs tree 3 6: Hazel’s 3 games recorded (6 and 6, no table, seeded tie-breaks), then each way searching the same 503 positions in the same order | hazeljs-examples commit 1f0270c; the driver is in this report’s drivers/ |
| Build 2, the compiled rules (checked against) | checkers/compiled.js: node tools/checkers-lab.mjs check 1 6, 223 positions of a game, every move and every list of legal moves the same as the lab’s | hazel-jit at hazelgrove/hazel d15466c7b1 (trial/794-games-aot) |
The lab mirrors checkers/rules/Checkers.hz step for step (^report(61)’s method): the moves in the same order, the same values, the same alpha-beta. Its new tree mode adds the shared tree (a node a board searched past the edge; its moves, its children made as first visited, an entry of lo and hi for each look-ahead; boards untouched for two searches let go past 300,000), best-first order, deepening, and the three ways of setting each player’s look-ahead. Counts by side: moves worked out (calls of legal), positions valued, positions searched past the edge, answers from the memo. Times: one run each, Node 22 on a 13th-gen Intel i7-1370P laptop, two cores, at low priority. The data is in data/tree.json and data/tree-65.json, and embedded in this page.
The data#
- The numbers, for programs too: every table in this report, and what its numbers measure, is also in this page as JSON, in its
<script type="application/json" id="report-data">element, so a reader or an agent that fetches the page alone has the dataset. The same, with any raw files that survive, is in062/data/.