Print best move with python_chess

2.4k Views Asked by At

Easy question, but I'm doing something wrong and don't know what :( I'm using the python-chess libary and want to print the best move to the engine (Stockfish).

I'm able to print the score from the engine with

board = chess.Board(fen)
info = engine.analyse(board, chess.engine.Limit(time=0.1))
print(info["score"])

but I'm not able to print the move

best_move = chess.engine.PlayResult(chess.Move, chess.engine.Limit(time=0.1),  draw_offered=False, resigned=False, )

I alway get something like this: PlayResult at 0x1ef108495e0

The documentation (https://python-chess.readthedocs.io/en/latest/_modules/chess/engine.html#Protocol search for "best move") didn't help, alway get some errrors.

1

There are 1 best solutions below

0
On

If you use Stockfish, pip install stockfish, and you can get the best move by using :\

from stockfish import Stockfish
stockfish = Stockfish('the stockfish place in your computer')
stockfish.set_fen_position("your FEN")
stockfish.get_best_move()

See the page of the project here.