In uci protocol, there is a command position <info>
that is sent to the engine. This command has an info which side to play.
Example:
position startpos
That tells the engine to play white because the startpos has white to move.
The word startpos is just equal to a position rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
which is a FEN notation for chess start position.
It is similar to:
position fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
The w
in FEN means white. So it is white to move.
Another command from position with moves can be different.
Example:
position startpos moves e2e4
The startpos is white to move, but there is a move e2e4
. With that the side to move is now black because from startpos, the move e2e4 is moved on the board. After the move e2e4, the side to move is now black.
You may need to handle position fen <> with moves.
Example:
position fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 moves e2e4 c7c5
That is white to move because there are 2 moves pushed on the board from the FEN rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
.
You also need to handle a FEN with black to move.
Example:
position fen r1bqkbnr/pppp1ppp/2n5/4p3/4P3/2N2N2/PPPP1PPP/R1BQKB1R b KQkq - 3 3
That means it is black to move because of b
before KQkq
.
And if there is a move on it, the side to move may change.
Example:
position fen r1bqkbnr/pppp1ppp/2n5/4p3/4P3/2N2N2/PPPP1PPP/R1BQKB1R b KQkq - 3 3 moves g8f6
Now it is white to move.