我正在使用 stockfish 作为移动计算器和 tensorflow-chessbot,从游戏中获得 FEN。它正在为白色正确移动,但对于黑色它失败了。我正在研究这段代码,但看不到它为什么可以这样做。它使垃圾像黑色一样移动。例如 - 白做 e4 后,引擎显示 - e8c6,这是不合法的举动
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()