5

I saw this thread: Converting square notation to algebraic notation programmatically

Unfortunately, it's the reverse of what I need to do.

Given a FEN and an Algebraic move, I need to generate the coordinate notation of said move.

I realize that you need the position (FEN) in order to reverse engineer the starting position of the pawn/piece being moved.

I'm hoping there is some utility or library/function that does this. If not, a description/outline of the basic algorithm would be great too.

5

You can do this easily in python using the python-chess module and using the parse_san function of chess.Move.

Let's call the script algebTocoord.py:

import chess

testfen = 'rnbqkb1r/pppppppp/5n2/8/3P4/8/PPP1PPPP/RNBQKBNR w KQkq - 1 2'
board = chess.Board(testfen)
algmove = 'Nf3'
coordmove = str(board.parse_san(algmove))
print coordmove

the printed output is:

'g1f3'

This was tested using Python version 2.7.16 and the 0.22.1 version of python-chess.

  • Thanks that will do the trick! – David Bandel Jul 2 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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