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
@@ -33,6 +33,17 @@ defmodule Chesstrainer.Endgames.TablebaseTest do
end
end
describe "normalize_wdl/1" do
test "maps Fathom WDL atoms, treating 50-move-rule draws as draws" do
assert Tablebase.normalize_wdl(:win) == :win
assert Tablebase.normalize_wdl(:loss) == :loss
assert Tablebase.normalize_wdl(:draw) == :draw
assert Tablebase.normalize_wdl(:cursed_win) == :draw
assert Tablebase.normalize_wdl(:blessed_loss) == :draw
assert Tablebase.normalize_wdl(:unknown) == :unknown
end
end
describe "struct shape" do
test "Tablebase carries only the fields the trainer reads" do
assert %Tablebase{} |> Map.from_struct() |> Map.keys() |> Enum.sort() ==