CHESS PROGRAMMING: Evaluating Material – Episode 1: Bishop vs. Knight

Photo by Pixabay from Pexels

Small chess programming lesson summary

Overview: This is a short chess programming lesson, part of the ‘How to develop a chess program’ tutorials series in Harmonia Philosophica for total beginners. The goal of this lesson is to discuss the very basics of position evaluation.

Tutorials on how to develop a chess program in Harmonia Philosophica include:

Supporting material: Please use the Huo Chess source code to support you in your reading. Huo Chess is one of the most known micro-chess open source programs for educational purposes. Start by the major page of Huo Chess here to view the code.

Evaluating Material – Episode 1: Bishop vs. Knight

One of the most important tasks in chess programming is to properly and cleverly evaluate the positions the computer thinks of. This evaluation consists of two aspects: Material and Positional/ Strategic aspects.

In this article we will show the most basic ideas for evaluating the position from a material aspect.

First thing is to assign values to pieces. The standard values look something like…

  • Queen: 9 points
  • Rook: 5 points
  • Bishop: 3 points
  • Knight: 3 points
  • Pawn: 1 point

Calculating the total score of a position based only on material is pretty straightforward: You have a loop that iterates through all squares of the chessboard and simply adds the value of each piece to the total score of the position. The evaluation is the number you come up with after you have added the values of all the pieces on the board (the terms ‘evaluation’ and ‘score’ and sometimes used interchangeably to refer to that total sum of the values of all pieces).

Another important thing to keep in mind is that the values of black pieces have the same values but with a negative sign. In that way, if the total score of a position is positive then white is winning material, while if the total value of the position is negative then black is winning. So by simply checking the sign of the total position evaluation your program can know if the position is winning for the colour of the computer – that could come in handy in chess programming.

View the CountScore function of Huo Chess to see a simple way to do that. Note though that the Huo Chess also utilizes some other criteria as well to evaluate the position – which we will discussed in next episodes.

Even though such a simple calculation of the position’s score will give you an idea of the material aspect of the board, even that is not so straightforward as it seems. The material is indeed easy to calculate, but the truth is it can never be viewed completely independently from the positional aspect.

For example, a bishop could have the same value as a knight, however when the position has locked pawn structures as below, then the knights become invaluable while the bishops useless…

Knights being better than bishops…

Another last thing to keep in mind for now is that tweaking the values of the pieces in your evaluation function could alter the playing style of the chess program you build. For example, if you increase the value of the queens, let’s say from 9 to 9.5, then your program will more aggressively hunt down the queen of the human opponent and will also more harshly defend its own queen from attacks.

Experimenting with these values is a nice way to gain a first hand understanding on how your program behaves. If you have not yet built your own program, simply use Huo Chess code to change the CountScore function.

Remember: Coding is all about experiments!

(after you have a good backup of your working code…)

Until next time…

Keep coding!

Exit mobile version
%%footer%%