Wire Fathom into the local tablebase backend (#30)

Add Backend.Fathom: probes positions with five or fewer pieces via the Fathom NIF, maps WDL/DTZ to the trainer structs (flipping per-move perspective), generates SAN, sorts moves best-first, and falls back to Lichess on any failure. The local directory is configured with TABLEBASE_PATH; local answers are no longer cached.

Add Tablebase.normalize_wdl/1 and flip/1, plus tests for the WDL mapping, SAN, checkmate, fallback, and a cache-free end-to-end local probe.
This commit is contained in:
2026-11-03 14:23:46 +01:00
parent e60c161a3a
commit cb35351f8c
11 changed files with 430 additions and 5 deletions
@@ -11,14 +11,14 @@ defmodule Chesstrainer.Endgames.Tablebase.Router do
"""
alias Chesstrainer.Endgames.Tablebase
alias Chesstrainer.Endgames.Tablebase.Backend.Fathom, as: FathomBackend
alias Chesstrainer.Endgames.Tablebase.Backend.Lichess
alias Chesstrainer.FEN
@max_local_pieces 5
@max_pieces 7
# The local Syzygy backend will replace Lichess here once it exists.
@local_backend Lichess
@local_backend FathomBackend
@remote_backend Lichess
@spec backend(String.t()) :: {:ok, module()} | {:error, :not_covered | :invalid_endgame}
@@ -31,6 +31,12 @@ defmodule Chesstrainer.Endgames.Tablebase.Router do
end
end
@doc """
True when the position is answered by the remote (Lichess) backend.
"""
@spec remote?(String.t()) :: boolean()
def remote?(fen), do: backend(fen) == {:ok, @remote_backend}
@spec probe(String.t()) ::
{:ok, Tablebase.t()} | {:cooldown, non_neg_integer()} | {:error, term()}
def probe(fen) do