generate rudimentary moves list from SAN notation
This commit is contained in:
@@ -34,12 +34,11 @@ export const ChessBoard = {
|
|||||||
const move = this.chess.move({ from: orig, to: dest, promotion: 'q' });
|
const move = this.chess.move({ from: orig, to: dest, promotion: 'q' });
|
||||||
|
|
||||||
if (move) {
|
if (move) {
|
||||||
const san = move.san
|
|
||||||
this.pushEvent("move_played", {
|
this.pushEvent("move_played", {
|
||||||
from: orig,
|
from: orig,
|
||||||
to: dest,
|
to: dest,
|
||||||
san: san,
|
fen: this.chess.fen(),
|
||||||
fen: this.chess.fen()
|
san: move.san,
|
||||||
});
|
});
|
||||||
|
|
||||||
const nextTurnColor = this.chess.turn() === 'w' ? 'white' : 'black';
|
const nextTurnColor = this.chess.turn() === 'w' ? 'white' : 'black';
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ defmodule ChesstrainerWeb.ChessTestLive do
|
|||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def mount(_params, _session, socket) do
|
def mount(_params, _session, socket) do
|
||||||
{:ok, assign(socket, last_move: "None yet", total_moves: 0, san: "None yet")}
|
{:ok, assign(socket, last_move: "None yet", san: "None yet", move_list: [])}
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
@@ -17,10 +17,13 @@ defmodule ChesstrainerWeb.ChessTestLive do
|
|||||||
<p class="text-sm text-gray-600 font-semibold">Last Played Move:</p>
|
<p class="text-sm text-gray-600 font-semibold">Last Played Move:</p>
|
||||||
<p class="text-lg font-mono text-blue-600">{@last_move}</p>
|
<p class="text-lg font-mono text-blue-600">{@last_move}</p>
|
||||||
<p class="text-lg font-mono text-blue-600">{@san}</p>
|
<p class="text-lg font-mono text-blue-600">{@san}</p>
|
||||||
</div>
|
<p class="text-lg font-mono text-emerald-600">
|
||||||
<div>
|
{if length(@move_list) == 0 do
|
||||||
<p class="text-sm text-gray-600 font-semibold">Total Moves:</p>
|
"No Moves"
|
||||||
<p class="text-lg font-bold">{@total_moves}</p>
|
else
|
||||||
|
Enum.reverse(@move_list) |> Enum.join(", ")
|
||||||
|
end}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -43,10 +46,12 @@ defmodule ChesstrainerWeb.ChessTestLive do
|
|||||||
%{"from" => from, "to" => to, "fen" => _fen, "san" => san},
|
%{"from" => from, "to" => to, "fen" => _fen, "san" => san},
|
||||||
socket
|
socket
|
||||||
) do
|
) do
|
||||||
|
current_moves = socket.assigns.move_list
|
||||||
|
|
||||||
{:noreply,
|
{:noreply,
|
||||||
socket
|
socket
|
||||||
|> assign(:last_move, "#{from} ➔ #{to}")
|
|> assign(:last_move, "#{from} ➔ #{to}")
|
||||||
|> assign(:san, san)
|
|> assign(:san, san)
|
||||||
|> assign(:total_moves, socket.assigns.total_moves + 1)}
|
|> assign(:move_list, [san | current_moves])}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user