who to start as black in stockfish python

177 Views Asked by At

I'm trying to start the Stockfish module in Python as the black player instead of the default white. I've been looking for parameters or other information on how to do this, but haven't been able to find anything that works. Can you please help me figure out how to start Stockfish as black in Python?

1

There are 1 best solutions below

0
ferdy On

The module has set_fen_position method. You can use this to set stockfish to play as black.

Take the start fen:

fen = "rnbqkbnr/pppp1ppp/4p3/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 0 2"

Change the side to move from w to b.

fen_b = "rnbqkbnr/pppp1ppp/4p3/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 2"

Finally use this fen in the method.

stockfish.set_fen_position(fen_b)