mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
Implement tablebase move grading in the play view
#7: prefetch the tablebase at mount and grade a played move locally against its moves list (optimal / winning / losing), blocking the attempt when the tablebase is rate-limited or unavailable. The client now reports prev_fen and promotion, and the trainer board locks after a graded move until reset. Fix the 429 clause ordering in the tablebase parser so the cooldown actually fires, and use the HTTPS endpoint. Add dialyxir to the dev/test deps.
This commit is contained in:
@@ -4,6 +4,7 @@ defmodule Chesstrainer.Endgames.TablebaseTest do
|
||||
alias Chesstrainer.Endgames.Tablebase
|
||||
alias Chesstrainer.Endgames.Tablebase.Cache, as: TablebaseCache
|
||||
alias Chesstrainer.Endgames.Tablebase.Parser
|
||||
alias Chesstrainer.Ratelimiters
|
||||
|
||||
describe "normalize_category/1" do
|
||||
test "maps winning categories to :win" do
|
||||
@@ -68,6 +69,19 @@ defmodule Chesstrainer.Endgames.TablebaseTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "Parser.parse_response/1" do
|
||||
test "a 429 sets the cooldown and returns a rate-limit error" do
|
||||
Ratelimiters.lichess_reset_cooldown()
|
||||
on_exit(fn -> Ratelimiters.lichess_reset_cooldown() end)
|
||||
|
||||
assert {:error, {:too_many_requests, 429, "rate limited"}} =
|
||||
Parser.parse_response({:ok, %Req.Response{status: 429, body: "rate limited"}})
|
||||
|
||||
assert {:cooldown, remaining} = Ratelimiters.lichess_check_cooldown()
|
||||
assert remaining > 0
|
||||
end
|
||||
end
|
||||
|
||||
describe "new/1" do
|
||||
test "returns {:ok, tablebase} on a cache hit" do
|
||||
fen = "8/8/3k4/8/8/3K1R2/8/8 w - - 0 1"
|
||||
|
||||
Reference in New Issue
Block a user