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

Advertisements
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!

Author: skakos

Spiros Kakos (or Spyros Kakos or Spyridon Kakos) [Σπύρος Κάκος] is a thinker located in Athens, Greece. He has been the Chief Editor of Harmonia Philosophica since its inception. Spiros has a diploma in Chemical Engineering, an MSc in Advanced Materials' Technology, an MBA in Decisions' Science, a phD in the use of conductive polymers in PCB industry and is still learning. He also worked as a technical advisor and a researcher in the Advanced Materials sector for many years in the past. In his free time he develops software solutions and contributes to the open source community. He is the creator of Huo Chess, one of the smallest micro-chess programs ever that is perfect for educational purposes. He believes that science and religion are two sides of the same coin and is profoundly interested in Religion and Science philosophy, as well as the philosophy of the irrational. His philosophical work is mainly concentrated on an effort to free thinking of "logic" and reconcile all philosophical opinions under the umbrella of the "One" that Parmenides - one of the first thinkers - visualized. Since our thought is dictated by our assumptions, the only way to free it and know cosmos as it is, is to think irrationally and destroy everything we have built. The "Harmonia Philosophica" articles program is the tool that will accomplish that. Life's purpose is to be defeated by greater things. And the most important things in life are illogical. We must fight the dogmatic belief in "logic" if we are to stay humans. We should stop thinking in order to think. Credo quia absurdum!

Exit mobile version
%%footer%%