Implementing Contempt For The Draw

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

ChessRenewal
Posts: 15
Joined: Thu Jul 25, 2019 7:13 pm
Full name: Jay Warendorff

Implementing Contempt For The Draw

Post 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.
odomobo
Posts: 96
Joined: Fri Jul 06, 2018 1:09 am
Location: Chicago, IL
Full name: Josh Odom

Re: Implementing Contempt For The Draw

Post 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.