|
|
The Rating Algorthm The rating algorithm is the 'personality' of a chess program. While most of the number crunching takes place in the search routine, the rating algorithm's task is to identify and evaluate good positions on the board.
With all rating algorithms, there's a trade-off between speed and complexity, and it's one of the key decisions that chess programmers must make: do you have a relatively simple rating algorithm, to allow you to search further; or do you have a complicated rating algorithm, to improve the strength of a more limited search?
This decision was pretty much made for me, the RCX only has 32K of memory, so a complicated rating algorithm is pretty much out of the question.
The Rating Techniques
Piece count The most common rating technique, and indeed the simplest useful rating algorithm, is to add up the piece value of all the pieces on the board for each colour, subtract one from the other, and return this value. For example, if I have a King (rating 6000), and the CPU has a King and a Queen (total rating 6900), then obviously the CPU is in a better position than I am. I use this technique with values of King:6400, Queen:1280, Rook:768, Bishop:416, Knight:384, Pawn:128. Why these values? Well, if you're a programmer, you might recognise that these values have high bits set and low bits clear. This means that I can use the quick division trick of shifting the bits, rather than needing a proper division. I'll explain why I do division later.
Miscellaneous bonuses Another common rating technique is to add bonuses for the development of pieces. I currently have bonuses/penalties for:
- how far advanced a pawn is.
- how far a piece is from the center of the board, doubled for knights
- how far a piece is from it's king and the enemy king
- if a pawn is blocked
- castling status
My unique rating technique I also have added a technique, which as far as I know is unique. It's pretty multipurpose and quick. For sliding peices, we test each direction the piece can slide. We test each square until we fall off the edge of the board, adding a bonus for each piece intersected. We store a divisor for the bonus, and increase this each time we intersect another piece. This has the effect of adding a bonus for covering (protecting) another piece, attacking an enemy piece, preparing for a discovered attack (ie moving a piece out of the way to allow another piece to attack an enemy). For example, in a file we have the pieces
R--Q--b- now for the Rook, we look along the file and see that we intersect a queen. We add a bonus of the queen score shifted left by 6 bits (ie 320). We then keep going and see a bishop, so add a bonus of the bishop score shifted left by 7 bits (ie 83), and then keep going until we fall off the end of the file. The score is independant of the colour. I've only really started playing with this technique, and it can probably be extended quite a bit (for example to add a bonus for freedom of movement), but it's powerful enough at present to play quite a strong game quite quickly. Note that I also do something similar for Knight King and Pawn captures, but there's only one square to check each time. I also use a different piece rating array, with kings lower valued, as it's not much use protecting a king by threatening to take whatever captures it (although it is very useful to threaten a king by discovered attack).
|
|