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.Board.PositionText alias ChesstrainerWeb.EndgameLive.PlayCore attr :endgame, :any, required: true attr :fen, :string, default: nil 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 attr :move_input, :string, default: "" attr :move_input_error, :string, default: nil attr :last_check, :boolean, default: false attr :last_checkmate, :boolean, default: false def play_surface(assigns) do assigns = assigns |> assign( :can_input, assigns.status == :playing and not assigns.awaiting_reply and not assigns.reviewing ) |> assign(:move_hint, move_hint(assigns.status, assigns.awaiting_reply)) ~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 %>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 -> %>Thinkin...
<% @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.
You play {colour_name(@endgame.color)}
<% 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}
| {dtz_text(move)} |