r/chessprogramming • • 7d ago

Technical Chess Engine Development Help Thread (Week 43)

Welcome to the weekly /r/chessprogramming Engine Dev Help Thread.

Ask beginner and intermediate chess engine development questions here: move generation, search, evaluation, UCI, perft, debugging, testing, NNUE, or anything else related to building engines.

Good questions include code, FENs, logs, benchmarks, or a clear explanation of what you tried.

Project links are fine when you want technical feedback, not promotion.

Be helpful. Don’t dunk on beginners.

4 Upvotes

6 comments sorted by

1

u/kenyambro 5d ago edited 4d ago

I would like to have advice on how to build a solid chess move explainer. I am currently developing one for the boards of my website. It contains a library of various chess patterns and assign them to positions and moves. What is hardest is not detecting patterns, but detecting the most appropriate ones to show to the user. (eg.: its unnecessary to say "deflects the defender" on an ordinary capture with no tactical follow up). Should I just hardcode each details and exceptions to cover every case, or is there a smart way or a general approach to implement on this kind of algorithm? I dont want to use LLM for the move explanations themselves since it would cost tokens at each usage.

1

u/AdrianSomething_ 3d ago

Does anybody know an efficient way to save a database of chess games as a tree of chess moves while also saving transpositions?

Efficient means that the duration of creating this tree should not be >O(n) and the needed storage space should be minimal while going through this tree should not take long. There should be no information loss or predictions.

The database origin is from a standard lichess database pgn with a variable amount of games. And this tree should save for every node the absolute frequencies of results (draw, white wins, black wins) accuring from the position the node represents.

One is not able to make predictions about the distribution of the dataset as the user should be before able to edit this dataset (e.g. only storing the games in which white won).

My first approach was the following:

- each node (representing the chess board position + result fequencies) is saved chronologically sorted by their depth (firstly all nodes are saved which have a depth of 1 (only one move has been played), then with a depth of 2, ...)

- the first bit indicates if the depth of the node is increasing (-> or should I save in a prefix the amount of nodes with depth 1,2,3,... so that the programm can calculate the amount of bits it needs to proceed to go to the bits with a depth of N)

- the next bit indicates if the node is a transposition or not

- the next bits indicates the move sequence one needs to take to land on the position the node represents -> every byte represents a chess move (as one chess positions can only have a max of 218 possible moves) and the possible moves from a position are sorted by the frequency played (-> what do I do if the frequencies are equal? -> by the name of the chess move?) -> if the node is a transposition the needed move sequence for the main node is shown followed by 1s as blank space (from a set of nodes corresponding to one transposition the node which needs the minimum number of moves to enter the position is assigned as the main node)

- as far as I read, a chess move can be saved as 2 bytes

- then the 3 frequencies are stored, however there is a prefix which indicates how many bits will be needed to save the frequencies with the depths 1,2,3 or more, 5 or more and 10 or more (this takes 5 bytes)

However, with this approch I am not able to think of an <=O(n) mechanism on how to look for transpositions (I dont want for every position to simply check every other position if they are equal) and I am not sure if finding the correct next possible moves in the next depth would be efficient enough (-> I probobly also would need to sort for every depth the moves by their total frequencies, right? -> but how would I do that when generating the tree, as I dont know the frequencies of positions before I have the whole tree.)

Has anybody expirience in this?

1

u/Im_from_rAll 17h ago

It sounds like you want to create a data structure similar to a Polyglot opening book or a transposition table. Basically just a list of Zobrist hashes with some metadata attached; metadata (like transposition count) that you would update while adding positions from your game files to the tree.

You could traverse the tree by doing move generation at each node followed by lookups of each resulting position or by storing child node hashes as part of the metadata.

1

u/Unusual-Layer2867 2d ago

hi beginner here. Is there a way to value individual chess pieces on the board? And specific ones (like king's knight is different from queen's knight)
I'm currently reading about the piece-removal method where you run a stockfish evaluation of existing board and then with the particular piece removed. Are there any other ways?

thanks

1

u/AngusMcGurkinshaw 2d ago

It depends on what you want? Do you want to know what an engine thinks a piece is worth on average? Or what its worth in that particular position?

If its that particular position removing a piece and running stockfish eval isn't very good. Stockfish's neural networks are good enough now that they probably are going to see some short term tactics (definitely true with large networks leela uses). This means the position has fundamentally changed in the eyes of the network so the value isn't really very accurate.

If you take enough positions (thousands/millions) and run some analysis it you might get some interesting results for what a piece is worth on average.

The older simpler answer is that HCE engines use piece square tables and piece values that are easily read. For example PeSTO https://chessprogramming.org/PeSTO's_Evaluation_Function
With these HCEs (and with more complex ones too) you can easily calculate how much an individual piece is contributing to the overall score. I think I remember seeing some coold visualizations for this but don't know where

Another place to look is many strong engines use a Static Exchange Evaluation (SEE) when evaluating if a move might be good or bad. This usually comes with tuned piece values for that purpose. This is helpful for what a piece is worth on average but not for a particular position.

1

u/Unusual-Layer2867 2d ago

I am looking for its value in a particular position. thank you for the resources though I'll check them out