Implement tablebase parsing fixes and LFU cache

#5: normalise the full lichess tablebase category vocabulary (cursed-win
and blessed-loss classify as draws), return {:ok, tablebase} on a cache
hit, and unwrap the tablebase in game_from_fen.

#6: replace the LRU cache with an LFU cache storing
{key, value, frequency, last_access}, evicting the least-frequently-used
entry (LRU tie-break) and halving every frequency on a weekly sweep.
Persistence moves to a versioned v2 dets file, dropping the legacy
backup; the cache restores synchronously at startup.

Also updates stale tags enum and Play LiveView tests, and drops the
tracked legacy cache backup.
This commit is contained in:
2026-11-01 21:24:51 +01:00
parent 6f08cdd10f
commit 8b894465cc
14 changed files with 359 additions and 83 deletions
+10 -6
View File
@@ -102,12 +102,7 @@ defmodule Chesstrainer.Game do
game_type: game_type,
fen: fen,
game_state: :continue,
tablebase:
if game_type === :endgame do
Endgames.Tablebase.new(fen)
else
nil
end
tablebase: tablebase_for(fen, game_type)
}
{:ok, game}
@@ -142,4 +137,13 @@ defmodule Chesstrainer.Game do
{:error, :invalid_fen, game}
end
end
defp tablebase_for(_fen, game_type) when game_type != :endgame, do: nil
defp tablebase_for(fen, :endgame) do
case Endgames.Tablebase.new(fen) do
{:ok, tablebase} -> tablebase
_ -> nil
end
end
end