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.

about half
the work of the search that comes second in each pair, when the two players' searches end on the same move and share one table
63% less
time a move, black looking 6 ahead and white 5, sharing a table, against Hazel now (white sees one move less)
52% fewer
moves worked out when the tree is kept, but no faster in JavaScript, and three to four times the memory

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#

  1. The design: one tree of boards, and two streams on each board, its moves and its answers.
  2. Lined up, the players share: when two searches end on the same move, the second does about half the work.
  3. Lining up costs a move of look-ahead: one player looks one move further, or one less.
  4. Keeping the tree: half the moves worked out, no time saved, more memory.
  5. Shallow first, then deeper: nothing saved here, and why.
  6. The partial order: ranges are what make any answer reusable; further answers for nearer ones add a little.
  7. 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 board(the pieces,whose turn)the same for bothits moves: worked out once, each child made when first visitedmove 1move 2move 3 …move 4 …its answers: for each look-ahead, a range (at least, at most)1 ahead= 123 ahead≥ 45 ahead4 … 97 ahead?a question: “5 ahead: is it more than 3?”answered by any entry that settles it: “4 … 9” does,whichever player's search left it there
A board’s node in the shared tree (Build 1). Its moves stream: worked out once; each child board made the first time a search goes there (dashed: not yet). Its answers stream: for each look-ahead, a range (exact, at least, or between two values), filled in by whichever search came by.

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.

101112131415161718196 and 6Hazel now6 and 7lined upsame finish6 and 5lined upsame finishthe move each search starts at (● black, ○ white), and the move it looks ahead to
Which searches end on the same move. Hazel now (6 and 6): none. Black 6, white 7: white’s search and black’s next one. Black 6, white 5: black’s search and white’s next one. The second of each pair reads what the first left in the table. (A diagram of the rule, not of a build.)

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).

now: 6 and 6, no tableblack: 14.1 ms a move14.1white: 19.6 ms a move19.66 and 6, a table eachblack: 10.1 ms a move10.1white: 11.3 ms a move11.36 and 6, one table, sharedblack: 9.9 ms a move9.9white: 11.3 ms a move11.36 and 6, the shared treeblack: 9.5 ms a move9.5white: 12.2 ms a move12.26 and 7, a table eachblack: 11.1 ms a move11.1white: 28.4 ms a move28.46 and 7, one table, sharedblack: 5.4 ms a move5.4white: 28.9 ms a move28.96 and 7, the shared treeblack: 6.3 ms a move6.3white: 26.5 ms a move26.56 and 5, a table eachblack: 10.6 ms a move10.6white: 3.9 ms a move3.96 and 5, one table, sharedblack: 10.2 ms a move10.2white: 2.1 ms a move2.16 and 5, the shared treeblack: 12.0 ms a move12.0white: 1.9 ms a move1.9black's moveswhite's moves, ms a move
Build 1 (the lab): milliseconds a move, black’s and white’s, over the same 503 positions, for Hazel’s way of looking ahead (6 and 6) and the two lined-up ways, each with a table for each player, one table shared, and the shared tree. Lined up, the second search of each pair (black’s for 6 and 7, white’s for 6 and 5) gains from sharing; with 6 and 6, sharing changes nothing.

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#

wayms a moveblack’swhite’spositions looked at, a movemoves worked out, a moveanswered by the memo, a movemoves chosen differentlyboards or entries kept, mostmemory, MB
Hazel now: 6 and 6, no table16.814.119.69,4542,4420005
6 and 6, a table each10.710.111.34,5411,6474400354,202125
6 and 6, one table, shared10.69.911.34,5411,6474400354,202125
6 and 6, the shared tree10.89.512.23,9697823690246,997522
6 and 7, no table31.214.448.015,8875,7040004
6 and 7, a table each19.711.128.47,0573,2829780701,399225
6 and 7, one table, shared17.15.428.96,0312,8769200577,440192
6 and 7, the shared tree, the rules' order18.75.731.76,0391,6069180231,917477
6 and 7, the shared tree16.46.326.55,2011,4247630172,665350
6 and 7, the shared tree, deepening16.85.428.26,6931,2108860157,818327
6 and 7, the shared tree, further answers16.05.526.65,1251,4217611172,145349
6 and 5, no table9.214.24.14,7001,5230005
6 and 5, one table, shared6.210.22.12,3179932830211,81271
6 and 5, the shared tree7.012.01.92,2095562530184,399384
6 and 5, a table each7.210.63.92,6861,1192890253,14789

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#

  1. 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.
  2. 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.
  3. 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#

buildwhatwhere
Build 1, the labnode 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 orderhazeljs-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’shazel-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#