2

The following Python code gives the best move in coordinate notation:

import chess
import chess.engine
sfEngineTxt = "E:\Chess\Stockfish\stockfish_14_x64_modern"
sfEngine = chess.engine.SimpleEngine.popen_uci(sfEngineTxt)
sfInfo = sfEngine.analyse(chess.Board(), chess.engine.Limit(depth=11), info=chess.engine.INFO_ALL)
moveArray = sfInfo['pv']
moveTxt1 = str(moveArray[0])
print(moveTxt1)
sfEngine.quit()

This outputs e2e4. What I want is e4, I.e. algebraic notation or san notation.

1 Answer 1

3

There is Board.san() which gives you the algebraic notation. You can check the docs here.

You will need a Board object for it.

import chess

board = chess.Board()
move = chess.Move.from_uci("e2e4")
print(board.san(move))
# Output: e4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.