1

I am using stockfish as a move calculator, and a tensorflow-chessbot, to get a FEN, from a game. It is getting moves for the white correct, but for black it fails. I am looking into this code, and can't see, why it could do that. It gives the trash moves for black like. For example - After white do e4, engine shows - e8c6, which is not a legal move

import os
import time
import chess
import chess.engine


def monitoring():
    engine = chess.engine.SimpleEngine.popen_uci("/root/Desktop/sf") #Set up an engine

    while True:
        f = open("/media/sf_vbox_Folder/trigger.txt", "r") #Make sure, that it works only when needed to
        st_trigger = f.read()
        print(str(st_trigger))
        st_trigger = st_trigger.replace('\x00', "") # Replace some random null bytes, if they are present
        if (int(str(st_trigger))) == 1:
            board = chess.Board() # Set up initial board
            first_fen = board.fen() # Save the first board FEN
            os.system("python /root/Desktop/tf/tensorflow_chessbot.py --filepath /media/sf_vbox_Folder/black.png") # Getting FEN from screenshot
            nf = open("/var/www/html/result.txt", "r") 
            readed_fen = nf.read()
            readed_fen = readed_fen.split(' ', 2)
            if readed_fen[0] != first_fen: # Make sure, engine does not calculate the same move twice
                board.set_board_fen(str(readed_fen[0])) # Discard the last part of FEN with side and en passant moves
                nf.close()
                f.close()
                result_engine = engine.play(board, chess.engine.Limit(time=0.1)) # Calculate a move
                f = open("/media/sf_vbox_Folder/move.txt", "w") 
                f.write(str(result_engine.move)) # Save it to the output folder
                f.close()

                f = open("/media/sf_vbox_Folder/trigger.txt", "w")
                f.write(str(0)) # Reset the trigger
                f.close()
            else:
                 time.sleep(0.1)
        else:
            time.sleep(0.1)
            f.close()


monitoring()
manlio
  • 18,345
  • 14
  • 76
  • 126
Raicha
  • 19
  • 1
  • 1
  • 5

0 Answers0