ChessPresso extract FEN

Keywords: chess database application, candidate move selector, pgn format, current position, extract, chesspresso, create, board, greatest. Powered by TextRank.

Chesspresso is a great library for processing chess games stored in PGN format. One of the greatest uses I have found for chesspresso is using it to extract FENs of the current position on the board. I’ve used this for example to create a candidate move selector in a chess database application. Here is a an example usage to extract the FENs from a game PGN given as a String:

ByteArrayInputStream bis = new ByteArrayInputStream(singleGame.getBytes());
PGNReader pgnReader = new PGNReader(bis, "");
Game game;
game = pgnReader.parseGame();
if (game == null) return null;
game.gotoStart();
Move[] mainLine = game.getMainLine();
for (int i = 0; i < mainLine.length; i++) {
    Move move = mainLine[i];
    String fen = game.getPosition().getFEN();
    System.out.println(fen);
    game.getPosition().doMove(move);
}


Metadata

Similar posts

Powered by TF-IDF/Cosine similarity

First published on 2018-05-09

Generated on May 5, 2024, 8:48 PM

Index

Mobile optimized version. Desktop version.