What is the meaning of the terms in this evaluation function for chess?

I'm trying to improve my evaluation and I saw this here

materialScore = kingWt  * (wK-bK)
+ queenWt * (wQ-bQ)
+ rookWt  * (wR-bR)
+ knightWt* (wN-bN)
+ bishopWt* (wB-bB)
+ pawnWt  * (wP-bP)


How do I get the value, let's say wK? Do I get the position of the king and score it relative to the board? For example, wK is more safe than the bK, so let's say wK - bK = 1 - 0.5. So, the result will be 90 * (0.5). Is this really how it works?

2 Answers

Is this really how it works?

Yes and no. An evaluation function based on pure material advantage is a perfectly legal function. It's certainly better than nothing. However, it's too simple in practice.

The state-of-the-art methods involve neural network. Google "Stockfish NNUE" for details.

The function you are showing (from this website) only calculates the score of a position based on how many pieces are on the board. It does not take into account where the pieces are located. So wK, bK, wQ, bQ, etc. are simply the number of the specific pieces that are on the board. The weights rank the pieces according to their importance.

So for example if white has 8 pawns and black has 6 pawns, the last term of the score would be pawnWt * (wP-bP) = 1 * (8-6) = 2. (assuming the value of a pawn to be 1) That leads to a relative advantage for white only based on pawns, but according to how many of the other pieces are on the board, black might still have an advantage.