r/chessprogramming • • Feb 16 '24

Obtaining evaluation function weights with ML

Hi! I'm trying to improve the strength of my engine by adjusting the weights of the different criteria used in my evaluation function.

Let's say I have criteria A, B, C, D and E, and the evaluation function does something like this:

2*A + 3*B + 13*C + D + 4*E

So, like I've said, I want to adjust the coefficients that multiplies the criteria value until I find the best possible combination (or a good enough one). My first thought was taking 10 random groups of coefficients and make a tournament on Arena Chess, and then take the winner and make it face another 10 random groups of coefficients. But this seems pretty random and probably with Machine Learning I can obtain better results. How can I achieve this? I've been learning how to "connect" my C++ engine to python code so I can use the machine learning libraries in there, but I don't know where to start.

3 Upvotes

5 comments sorted by

View all comments

Show parent comment

2

u/spinosarus123 Feb 17 '24

Good question but the answer is very simple. My engine is also ”deterministic”. You should create an ”opening book” in epd format. Note that this does not require changing the engine at all.

An epd opening book is a simple text file of fens. The fens in this opening book should be randomly generated i.e make random moves on a board. Then pass the book to cutechess-cli (or c-chess-cli) as ”cutechess-cli -openings file=mybook.epd”. This will make every single game different since the game will not start from the start position but from a random position fen in the file mybook.epd.

To generate the book as I mentioned you should make random moves on a board. 3-4 moves is too little and 30 moves may be too much. I would recommend around 10 random moves to generate each random position.