Skip to content

Instantly share code, notes, and snippets.

@tors42
Last active May 1, 2024 09:51
Show Gist options
  • Save tors42/41e449469c071a009f1b9490c05eab1e to your computer and use it in GitHub Desktop.
Save tors42/41e449469c071a009f1b9490c05eab1e to your computer and use it in GitHub Desktop.
JShell script to get the FEN of a puzzle
if (! Files.exists(Path.of("chariot.jar"))) {
Files.write(Path.of("chariot.jar"), URI.create(
"https://repo1.maven.org/maven2/io/github/tors42/chariot/0.0.83/chariot-0.0.83.jar"
).toURL().openStream().readAllBytes());
}
/env --class-path chariot.jar
import chariot.Client;
import chariot.util.Board;
String puzzleId = "EC8uc";
String moves = Client.basic().puzzles().byId(puzzleId).map(puzzle -> puzzle.game().pgn()).orElse("");
String fen = Board.fromStandardPosition().play(moves).toFEN();
System.out.println("Moves: " + moves);
System.out.println("FEN: " + fen);
/exit
@tors42
Copy link
Author

tors42 commented Jan 7, 2024

Example run (running jshell from https://jdk.java.net/21/)

$ jshell puzzle-fen.jsh
Moves: e4 c5 Nc3 Nc6 Bb5 a6 Ba4 b5 Nxb5 axb5 Bxb5 Bb7 Nf3 Nf6 d3 e6 O-O Be7 Bg5 h6 Be3 O-O c4 d6 Qb3 Ng4 Rfe1 Nxe3 Rxe3 Bg5 Nxg5 Qxg5 Rg3 Qf6 Re1 Nd4 Qd1 Rxa2 b3 Qxf2+ Kh1 Qf6 Rf1 Qe7 Rf4 Rfa8 Ba4 Bc6 Rfg4 g6 h4 Bxa4 bxa4 R8xa4 Kh2 h5 Rg5 Kh7
FEN: 8/4qp1k/3pp1p1/2p3Rp/r1PnP2P/3P2R1/r5PK/3Q4 w - - 2 30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment