mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
Route tablebase lookups through a piece-count backend seam (#27)
Add a Backend behaviour, a Lichess implementation, and a Router that picks a backend by piece count: five or fewer to the local slot, six or seven to the remote slot, and eight or more short-circuited as not covered with no network call. Both slots point at Lichess for now; the local Syzygy backend replaces the local slot when it lands. Map :not_covered to the existing 'not covered by the tablebase' message.
This commit is contained in:
@@ -57,6 +57,21 @@ defmodule ChesstrainerWeb.EndgameLive.PlayTest do
|
||||
})
|
||||
end
|
||||
|
||||
# >7-piece positions short-circuit to "not covered" before any backend, but
|
||||
# the changeset now rejects them, so insert one directly to exercise the path.
|
||||
defp insert_out_of_range_endgame do
|
||||
fen = "3k4/2n2B2/1KP5/2B2p2/5b1p/7P/8/8 b - - 0 1"
|
||||
{:ok, key} = Chesstrainer.Key.from_fen(fen)
|
||||
|
||||
Chesstrainer.Repo.insert!(%Chesstrainer.Endgames.Endgame{
|
||||
fen: fen,
|
||||
color: :black,
|
||||
key: key,
|
||||
result: :win,
|
||||
rating: 1500
|
||||
})
|
||||
end
|
||||
|
||||
# Plays one optimal move, applies the opponent's reply, then a losing move,
|
||||
# leaving a three-ply failed attempt to review.
|
||||
defp seeded_attempt(conn) do
|
||||
@@ -170,6 +185,16 @@ defmodule ChesstrainerWeb.EndgameLive.PlayTest do
|
||||
play_move(view, endgame, "d1", "d7", "Qd7+")
|
||||
assert render(view) =~ "cannot be graded"
|
||||
end
|
||||
|
||||
test "blocks an out-of-range endgame as not covered", %{conn: conn} do
|
||||
endgame = insert_out_of_range_endgame()
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/endgames/#{endgame}/play")
|
||||
|
||||
html = render(view)
|
||||
assert html =~ "Tablebase unavailable"
|
||||
assert html =~ "not covered by the tablebase"
|
||||
end
|
||||
end
|
||||
|
||||
describe "chess_fen_invalid" do
|
||||
|
||||
Reference in New Issue
Block a user