mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
The Endgame key is now a canonical, colour-agnostic material signature derived from the FEN instead of a hand-typed field: each side's pieces, strongest side first by material value (e.g. "KQ v KR"). This fixes the seed ordering inconsistency and guarantees the key always matches the position. - Add Chesstrainer.Key.from_fen/1. - Compute the key in the Endgame changeset; drop the manual input and its regex validation. - Index endgames.key and derive keys in the seeds. - Document the Key term and the decision (ADR 0003). Closes #13
43 lines
1.2 KiB
Elixir
43 lines
1.2 KiB
Elixir
defmodule Chesstrainer.EndgamesFixtures do
|
|
@moduledoc """
|
|
This module defines test helpers for creating
|
|
entities via the `Chesstrainer.Endgames` context.
|
|
"""
|
|
|
|
@doc """
|
|
Generate a unique endgame FEN.
|
|
|
|
Endgames have a unique constraint on :fen, so tests need
|
|
distinct FENs when inserting more than one. Each call
|
|
shifts the white king's file to avoid FEN collisions.
|
|
"""
|
|
def unique_endgame_fen do
|
|
# White king on rank 1 in columns b..g, leaving 1-6 empty squares
|
|
# before and 6-1 after. Both before_king and after_king are valid
|
|
# single digits (1-8), and the rank sums to 8.
|
|
offset = System.unique_integer([:positive]) |> rem(6)
|
|
before_king = offset + 1
|
|
after_king = 7 - before_king
|
|
"4k3/8/8/8/8/8/8/#{before_king}K#{after_king} w - - 0 1"
|
|
end
|
|
|
|
@doc """
|
|
Generate an endgame.
|
|
|
|
A simple K v K position with a unique FEN, color, rating, and result.
|
|
"""
|
|
def endgame_fixture(attrs \\ %{}) do
|
|
{:ok, endgame} =
|
|
attrs
|
|
|> Enum.into(%{
|
|
fen: unique_endgame_fen(),
|
|
color: :white,
|
|
result: :win,
|
|
rating: 1500
|
|
})
|
|
|> Chesstrainer.Endgames.create_endgame()
|
|
|
|
endgame
|
|
end
|
|
end
|