mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
Motifs describe the kind of problem, independent of the material family. One local tablebase probe returns the root WDL, the DTZ and every legal move with its own WDL, so each motif is proved without a search or a remote lookup. - only move: more than one legal move and exactly one preserves the 50-move-aware result, for wins and draws. - underpromotion: a preserving underpromotion exists while no preserving queen promotion does. - 50-move draw: cursed/blessed WDL, or a win whose DTZ exceeds the remaining halfmove budget. Motif links are recorded as derived and refreshed as a whole, scoped to the motif themes, so material, curated and community links survive. Loss endgames are skipped because only-move is undefined there. Stalemate is deferred: a stored endgame cannot itself be terminal, so it can only describe a line and needs a definition before it becomes a predicate. Release helpers run the derivation without starting the web application, so `bin/chesstrainer eval` works on the server. Closes #188
53 lines
1.3 KiB
Elixir
53 lines
1.3 KiB
Elixir
defmodule Chesstrainer.Release do
|
|
@moduledoc """
|
|
Used for executing DB release tasks when run in production without Mix
|
|
installed.
|
|
"""
|
|
@app :chesstrainer
|
|
|
|
def migrate do
|
|
load_app()
|
|
|
|
for repo <- repos() do
|
|
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
|
|
end
|
|
end
|
|
|
|
def rollback(repo, version) do
|
|
load_app()
|
|
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
|
|
end
|
|
|
|
@doc """
|
|
Derives material family themes for the whole library.
|
|
|
|
Runs in the release without starting the web application: `with_repo/2`
|
|
starts just the repository, which is all the derivation needs.
|
|
"""
|
|
def derive_material, do: with_repo(&Chesstrainer.Endgames.MaterialThemes.derive/0)
|
|
|
|
@doc """
|
|
Derives motif themes from the local tablebase for the whole library.
|
|
"""
|
|
def derive_motifs, do: with_repo(&Chesstrainer.Endgames.MotifThemes.derive/0)
|
|
|
|
defp with_repo(fun) do
|
|
load_app()
|
|
|
|
for repo <- repos() do
|
|
{:ok, result, _} = Ecto.Migrator.with_repo(repo, fn _repo -> fun.() end)
|
|
result
|
|
end
|
|
end
|
|
|
|
defp repos do
|
|
Application.fetch_env!(@app, :ecto_repos)
|
|
end
|
|
|
|
defp load_app do
|
|
# Many platforms require SSL when connecting to the database
|
|
Application.ensure_all_started(:ssl)
|
|
Application.ensure_loaded(@app)
|
|
end
|
|
end
|