mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
Key the tablebase cache by position instead of full FEN (#28)
Add FEN.position_key/1 (board, side, castling and en-passant; clocks dropped) and have Tablebase.new/1 key cache reads and writes on it, so transpositions and clock-only differences share an entry. The Lichess category is a position property, so dropping the clocks is safe. Update the cache docs and tests, and give the play fixture's after_first/after_losing distinct positions since they previously differed only by the halfmove clock.
This commit is contained in:
@@ -12,6 +12,7 @@ defmodule Chesstrainer.Endgames.Tablebase do
|
||||
"""
|
||||
|
||||
alias Chesstrainer.Endgames.Tablebase
|
||||
alias Chesstrainer.FEN
|
||||
|
||||
@type result :: :win | :draw | :loss | :unknown
|
||||
|
||||
@@ -49,7 +50,9 @@ defmodule Chesstrainer.Endgames.Tablebase do
|
||||
| {:error, :invalid_endgame}
|
||||
| {:error, term()}
|
||||
def new(fen) do
|
||||
case Tablebase.Cache.get(fen) do
|
||||
key = FEN.position_key(fen)
|
||||
|
||||
case Tablebase.Cache.get(key) do
|
||||
{:ok, tablebase} ->
|
||||
{:ok, tablebase}
|
||||
|
||||
@@ -65,7 +68,7 @@ defmodule Chesstrainer.Endgames.Tablebase do
|
||||
{:error, :invalid_endgame}
|
||||
|
||||
{:ok, tablebase} ->
|
||||
Tablebase.Cache.put(fen, tablebase)
|
||||
Tablebase.Cache.put(key, tablebase)
|
||||
{:ok, tablebase}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user