How to get a string of the FEN position

849 views Asked by At

After I do

import chess
board = chess.Board()

how can I have a string with the FEN of the position? In other words, how can I extract from board the FEN of the position as a string, with the same output as if I did

a='rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'

?

1

There are 1 answers

0
merlyn On BEST ANSWER

You can use the fen function.

board = chess.Board()
a = board.fen()