1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { lichessPgn } from "https://esm.town/v/jdan/lichessPgn";
export const lichessGameAscii = async (id: string) => {
const { Chess } = await import("npm:chess.js@1.0.0-beta.6");
const chess = new Chess();
const pgn = await lichessPgn(id);
chess.loadPgn(pgn);
const ascii = chess.ascii()
// .replace(/\./g, " ")
.replace(/K/g, "♔")
.replace(/Q/g, "♕")
.replace(/R/g, "♖")
.replace(/B/g, "♗")
.replace(/N/g, "♘")
.replace(/P/g, "♙")
.replace(/k/g, "♚")
.replace(/q/g, "♛")
.replace(/r/g, "♜")
// Don't turn the b in "a b" into a bishop lol
.replace(/(?<!a )b/g, "♝")
.replace(/n/g, "♞")
.replace(/p/g, "♟");
// Append the players to the ascii
const lines = ascii.split("\n");
lines[4] = lines[4] +
` ♙ ${chess._header["White"]} (${chess._header["WhiteElo"]})`;
lines[5] = lines[5] +
` ♟ ${chess._header["Black"]} (${chess._header["BlackElo"]})`;
return lines.join("\n");
};