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

Converting UCI to SAN. #1088

Closed GabrieleBattaglia closed 3 months ago

GabrieleBattaglia commented 3 months ago

Hi. I need to have the SAN move of the last pushed.

import chess
b=chess.board()
b.push_san('Nf3')
...
# other pushes
...
l=b.peek()

Could I have this l in SAN format instead of UCI?

Many thanks. Gabe.

niklasf commented 3 months ago

Creating SAN requires the position for context. So instead of

b.peek().uci()

you would have to do something like

b.san_and_push(b.pop())

which undoes the last move, creates SAN, and reapplies the move.

GabrieleBattaglia commented 3 months ago

Fine. I'll try it. Thanks.