python-chess icon indicating copy to clipboard operation
python-chess copied to clipboard

en passant target square not populated when pawn moves 2 sqares

Open sdxsharp opened this issue 1 year ago • 2 comments

import chess

print(chess.__version__)
board = chess.Board()
board.set_fen('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1')
board.push_san('e4')
print(board.fen())

output:

1.10.0 rnbqkbnr/pppppppp/8/8/4P3/8/PPP1PPPP/RNBQKBNR b KQkq - 0 1

the en passant sqare is not populated!!!

output should be:

rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1

sdxsharp avatar May 14 '24 11:05 sdxsharp

By default, the en passant square is only listed if there is a legal en passant move. If you want the usual FEN style, use print(board.fen(en_passant='fen')).

Board.fen() method parameter documentation

MarkZH avatar May 16 '24 05:05 MarkZH

Thanks! I wish I could've found it myself in the docs, but for someone who never used python docs the search result looks like a hot mess (due to lack of class information and hard to parse optional arguments or even identify what is going on) and the navigation is also not super obvious (not sure why I didn't look in Core) (and even if I'd found the right class the font size for the actual functions is tiny af). Only now that I know how things are supposed to look like in the docs it actually seems possible to find.

sdxsharp avatar May 16 '24 14:05 sdxsharp