mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
add visual rating guide (#48)
This commit is contained in:
@@ -16,9 +16,7 @@ defmodule ChesstrainerWeb.EndgameLive.Play do
|
||||
{@endgame.color |> Atom.to_string() |> String.capitalize()} to move · Rating: {round(
|
||||
@endgame.rating
|
||||
)} · Attempts: {@endgame.times_attempted ||
|
||||
0} · Solved: {@endgame.times_solved || 0}<span :if={@user_rating}> · Your rating: {round(
|
||||
@user_rating
|
||||
)}</span>
|
||||
0} · Solved: {@endgame.times_solved || 0}
|
||||
<p class="text-xs text-muted flex items-center mt-1">
|
||||
<span>FEN: {@endgame.fen}</span>
|
||||
<button
|
||||
@@ -42,6 +40,10 @@ defmodule ChesstrainerWeb.EndgameLive.Play do
|
||||
</:actions>
|
||||
</.header>
|
||||
|
||||
<div :if={@user_rating} class="mb-4">
|
||||
<.rating_guide rating={@user_rating} deviation={@user_deviation} />
|
||||
</div>
|
||||
|
||||
<PlayComponents.play_surface
|
||||
endgame={@endgame}
|
||||
status={@status}
|
||||
|
||||
@@ -32,6 +32,7 @@ defmodule ChesstrainerWeb.EndgameLive.PlayCore do
|
||||
|> assign(:page_title, Keyword.get(opts, :page_title, "Play endgame"))
|
||||
|> assign(:endgame, endgame)
|
||||
|> assign_new(:user_rating, fn -> user_rating(socket.assigns.current_scope) end)
|
||||
|> assign_new(:user_deviation, fn -> user_deviation(socket.assigns.current_scope) end)
|
||||
|> assign(:fen, endgame.fen)
|
||||
|> assign(:tablebase, nil)
|
||||
|> assign(:status, :loading)
|
||||
@@ -441,6 +442,7 @@ defmodule ChesstrainerWeb.EndgameLive.PlayCore do
|
||||
socket
|
||||
|> assign(:endgame, endgame)
|
||||
|> assign(:user_rating, user.rating)
|
||||
|> assign(:user_deviation, user.rating_deviation)
|
||||
|> assign(:last_rating_delta, delta)
|
||||
|
||||
{:skipped, _attempt} ->
|
||||
@@ -460,6 +462,9 @@ defmodule ChesstrainerWeb.EndgameLive.PlayCore do
|
||||
defp user_rating(%{user: %{rating: rating}}), do: rating
|
||||
defp user_rating(_), do: nil
|
||||
|
||||
defp user_deviation(%{user: %{rating_deviation: deviation}}), do: deviation
|
||||
defp user_deviation(_), do: nil
|
||||
|
||||
defp pick_best_move(tablebase), do: tablebase |> best_moves() |> List.first()
|
||||
|
||||
defp best_moves(%Tablebase{moves: moves} = tablebase) when is_list(moves) do
|
||||
|
||||
@@ -134,7 +134,7 @@ defmodule ChesstrainerWeb.EndgameLive.Train do
|
||||
<div>
|
||||
<h2 class="text-lg font-semibold">Choose a difficulty</h2>
|
||||
<p class="mt-1 text-sm text-muted">
|
||||
Your rating: {round(@user_rating)} · bands of ±{Puzzles.band_width()}
|
||||
Difficulty bands are ±{Puzzles.band_width()} around your rating.
|
||||
</p>
|
||||
</div>
|
||||
<.link
|
||||
@@ -146,6 +146,9 @@ defmodule ChesstrainerWeb.EndgameLive.Train do
|
||||
<.icon name="hero-x-mark" class="size-5" />
|
||||
</.link>
|
||||
</div>
|
||||
<div class="mt-4">
|
||||
<.rating_guide rating={@user_rating} deviation={@user_deviation} />
|
||||
</div>
|
||||
<div class="mt-4 grid gap-2">
|
||||
<%= for {difficulty, label, description} <- difficulty_options(@user_rating) do %>
|
||||
<.button
|
||||
@@ -179,7 +182,8 @@ defmodule ChesstrainerWeb.EndgameLive.Train do
|
||||
|> assign(:last_session, nil)
|
||||
|> assign(:puzzle_started_mono, nil)
|
||||
|> assign(:puzzle_counted, false)
|
||||
|> assign(:user_rating, socket.assigns.current_scope.user.rating)}
|
||||
|> assign(:user_rating, socket.assigns.current_scope.user.rating)
|
||||
|> assign(:user_deviation, socket.assigns.current_scope.user.rating_deviation)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
|
||||
Reference in New Issue
Block a user