x
Chess - Play & Learn

Chess.com

FREE - In Google Play

FREE - in Win Phone Store

VIEW

Creating a chess engine (Part 4 - position evaluation)

zaifrun
May 5, 2010, 1:03 PM 0

 

I have finally started working a bit more on the position evaluation part of the engine. This part will focus on how a computer evaluates a chess board position. The evaluation in my engine was quite primitive at first, now it is better - still plenty of room for improvement though. A chess engine is composed of so many different things and so many details that it seems there are always things you can improve somewhere! However, the position evaluation is a big part of any chess engine.
This part of a chess engine is more or less a black art (or black magic). Its really difficult to come up a position evaluation that is good for all positions. In fact even the best engines today are not as good as super GMs in evaluating a position in my opinion - but they compensate for that in search speed which gives them the advantage to look more moves ahead than humans. There is also a trade-off here between having a simple evaluation part in an engine which is fast to compute, thereby allowing greater search depth, or having a more advanced but slower evaluation part, which decrease the amount of computation available for searching but may be better in evaluating positions accurately. Difficult to find an optimal strategy for an engine here - balance is probably the best answer here.

 

1. Basic position evaluation.

 

An engine gives a numerical score to all positions. A value of 0.0 indicates the position is equal, a negative value indicates black is better and a positive value indicates that white is better in the position. Basic engine position evaluation simple assigns a value to each piece (for instance 1.0 to a pawn, 3.0 to a Knight and Bishop, 5.0 to a Rook, and 9.0 to a Queen) and then adds up all the values. Checkmate is usually indicated as +1000 or -1000 depending on whether black is check mated or white is check mated. Naturally this is a very bad evaluation function for an engine, but it covers the basic and all engines incorporate this as the basis and then adds advanced features.



2. Advanced position evaluation.


This is really the black art stuff - this is where you can make your engine different than other engines. In my engine I have included the following advanced evaluation methods (at the time of writing - the list is changing rapidly).

* bonus for king safety - i.e. castling and pawn shields in front of the king
* bonus for having the bishop pair.
* increase value of bishops and rooks when the number of pawns decrease - i.e. more open games.
* decrease value of knights when the number of pawns decrease - knights are not good in open games.

* decrease value if a pawn is a double pawn - usually not good.

* penalty for moving the queen too early in the game - do not want it to be chased around by the opponent.

* bonus for mobility - i.e. if a piece have more squares to move to it makes it more valuable.
* bonus for threats - i.e. if a piece is threatening to capture an enemy piece it gets a bonus.
* bonus for protecting own pieces - i.e. if it covers other pieces of the same color it get a defensive bonus.
* different activity bonus based on wether it's the opening, middlegame or endgame. For instance a king should not be active in the opening, but should be active in an endgame.
* penalty if there is many pawns of the same color as a bishop on the same color squares - i.e. a bad bishop vs a good bishop.
* bonus for pawns far advanced - i.e. close to promotion to a queen or other piece.
* bonus for development speed of minor pieces in opening game.

 

...and some other even more advanced pattern matching stuff. I should not spill all my secrets here..:-)

 

How do you fine-tune all those bonus/penalty parameters? Well, you can try statistically fine-tuning by letting the engine play lots of games and then see what gives the best results. However, I do not think this will give substantially better results than just fine-tuning the parameters manually (by a good human player). It is really difficult to find an optimal set of parameter values that will work in all positions.
Bottom line: position evaluation is not en exact science and I think humans are better than computers in the evaluation part of playing chess (at least for now).

Online Now