Page 1 of 1

Implementing Contempt For The Draw

Posted: Mon Jul 27, 2020 12:41 am
by ChessRenewal
I am writing a C language chess engine using FirstChess as a base. Please provide some insight on how to implement Contempt For The Draw in the code.

Re: Implementing Contempt For The Draw

Posted: Mon Jul 27, 2020 8:51 am
by odomobo
It doesn't look like FirstChess will evaluate a draw for repetition or 50 move rule, so it will actually blindly stumble into those without realizing they terminate the game. The only draw FirstChess can see is stalemate, which I see on line 623.

For contempt, there are 2 things to take into account.
  1. The draw value changes sign depending on which color the engine is playing as.
  2. Since Search() is negamax, draw value also changes sign depending on which color is currently being evaluated.
So let's say you have contempt of 20 centipawns. This mean the engine views a draw the same as if it was down by 20 centipawns. In absolute terms, if the engine was white, it would give the position an evaluation of -20 centipawns.

However, within a negamax search, score is always given from the perspective of the side being evaluated (so if it's black's turn, a positive value means black's winning). So, if the engine is playing as white, and black gets stalemated, then it needs to be evaluated as +20 centipawns.