To build a perfect endgame database, do not search forward — work backward from the end. Mark every terminal position won or lost, then repeatedly propagate: a position is a loss if every move leads to a won position for the opponent, a win if some move reaches a lost one. Iterate to a fixed point and every position carries its exact result and distance-to-mate. It is how chess tablebases were built — and how checkers was solved.
The demo builds the win/loss labels of a subtraction game by backward induction: live demo
“Endgame tablebases store best moves from analysis.” — they are computed backward from mate to the fixed point; no forward search or heuristics. cited
The future of a game, computed from its end. algorithm
On i-13, backward induction on subtraction {1,2} puts losses at multiples of 3 and wins elsewhere: