defmodule ChesstrainerWeb.PlayComponents do @moduledoc """ The shared board and side panel for playing an endgame. Used by the standalone play screen and by a training session, which adds the "Next puzzle" action via `session={true}`. """ use ChesstrainerWeb, :html alias ChesstrainerWeb.EndgameLive.PlayCore attr :endgame, :any, required: true attr :status, :atom, required: true attr :blocked_reason, :string, default: nil attr :best_move, :string, default: nil attr :plies, :list, required: true attr :line, :list, required: true attr :reviewing, :boolean, required: true attr :review_index, :integer, required: true attr :review_tablebase, :any, default: nil attr :review_blocked, :string, default: nil attr :awaiting_reply, :boolean, required: true attr :last_grade, :atom, default: nil attr :awaiting_best_line, :boolean, default: false attr :session, :boolean, default: false def play_surface(assigns) do ~H"""
Best move unavailable here
{@review_blocked}
<% @review_tablebase -> %>Best move:
{PlayCore.best_move_text(@review_tablebase) || "—"}
<%= if played_ply = played_ply_at(@line, @review_index) do %>Played: {played_ply.san}
<% end %> <.tablebase_options tablebase={@review_tablebase} /> <% true -> %>No best move.
<% end %>{turn_label(@status, @awaiting_reply)} You play {colour_name(@endgame.color)}
Loading tablebase…
<% @status == :blocked -> %>Tablebase unavailable
{@blocked_reason}
<% @status == :solved -> %>{if @endgame.result == :draw, do: "Draw held!", else: "Solved!"}
<% @status == :failed -> %>Failed
{if @endgame.result == :draw, do: "That move loses the draw.", else: "That move throws away the win."}
<%= if @best_move && @plies != [] do %>You played {List.last(@plies).san}; best was: {@best_move}
<% end %> <% @awaiting_reply -> %>Opponent is replying…
<% @last_grade == :optimal -> %>Optimal move
<% @last_grade == :winning -> %>{if @endgame.result == :draw, do: "Keeps the draw — but not the sharpest", else: "Winning — but not the sharpest"}
<% @last_grade == :losing -> %>{if @endgame.result == :draw, do: "Losing move — this loses the draw", else: "Losing move — this throws away the win"}
<% @last_grade == :unknown -> %>Could not grade that move
<% true -> %>Make a move to have it graded.
<% end %>Puzzle rating: {round(@endgame.rating)}
Moves:
No Moves
<% else %> <%= for {[white_ply, black_ply], move_no} <- move_rows(plies, @endgame.color) do %>Tablebase
{label}
| {move.san} | {dtz_text(move)} |