generating FEN string from reed sensor chess board and only getting next best move from stockfish engine

776 views Asked by At

I am building a chess playing robot, so after getting an 8x8 matrix of 1's and 0's from the reed switch sensors, how do I convert this matrix to a FEN string so that I can send this to the Stockfish engine?

Also, I am having a lot of trouble in writing a Python script that can send the FEN string as input through UCI protocol and get the next best move.

As of now, I don't really care about move validation/checking for check mate/promotion. I just want to get the next move.

I have already gone through a lot of links about UCI protocol/API, Stockfish engine working, and programming with python, etc., but none of them have really helped me out.

I would appreciate anyone's help!

1

There are 1 answers

0
TheSlater On

First try to control Stockfish via console. Then you understand what to send to it and how the format of the next move will look like.

Start Stockfish. Then type on the console:

Start UCI mode:

uci

Set the Position to calculate via FEN-String, e.g.:

position fen N7/P3pk1p/3p2p1/r4p2/8/4b2B/4P1KP/1R6 w - - 0 34

Print the board for debug (d is a stockfish command and not in the UCI protocol):

d

Calculate beste move within 3s time:

go movetime 3000

Now you get the best moves in different search depths. Get the score and the name of the move out of the last String.

Please provide more info how a board of 0's and 1's has the information of the pieces. Where is the information about what piece is on what square? Then I can help you to translate it in a FEN-String.