niklasf / python-chess

A chess library for Python, with move generation and validation, PGN parsing and writing, Polyglot opening book reading, Gaviota tablebase probing, Syzygy tablebase probing, and UCI/XBoard engine communication
https://python-chess.readthedocs.io/en/latest/
GNU General Public License v3.0
2.4k stars 526 forks source link

en passant target square not populated when pawn moves 2 sqares #1082

Closed sdxsharp closed 4 months ago

sdxsharp commented 4 months ago
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

MarkZH commented 4 months ago

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

sdxsharp commented 4 months ago

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.