Open FalcoGer opened 2 years ago
Hi, thanks for this - I think going from human notation --> stockfish notation (and the other way around) would be a nice feature to add. I can definitely get started on including this for the library, but are you sure you don't want to make the PR? It's quite a bit of work you've done here, and I doubt I would be modifying much.
I have written a little script that converts chess notation into valid moves for stockfish.py. Maybe someone can refine it a bit and put it in?
The goal of my implementation wasn't to make it correct but to make it convenient for user entry. But I'm sure it can be adopted to make it more rigid. For example I tried to remove capitalization requirements, but that resulted in only bishops needing to be capitalized to make it work. If you want to be more stringent you could enforce all piece descriptions. The code should be pretty self explanatory, but if you have questions, feel free to ask.
Here's a brief overview The function will take the stockfish board, a move string in chess notation and a color argument. The color argument, when set to not False will output messages in color. It is not important for this function for the purpose of translating chess notation to stockfish notation. It is there because in my program whenever something is referenced to one side or another, I use the colored library to provide colored text on the terminal, in this case for the returned error messages. It will either return a valid move, or an error message.
See a working example here: https://github.com/FalcoGer/pychess but you might have to adjust the stockfish path. Feel free to take any code you want from that.