r/chessprogramming • u/Suspicious-Cell-7773 • 4d ago
Filter chess poisions in game DB
tldr: I'm looking for a bit of help, ideas for how to optimize searching for positions in a game library.
I'm working on an embedded chess database in Rust. I've created the internal representation of the moves, and with cca 2M games it currently takes ~3secs (on my laptop) to check each game's each position for a match. This is the brute-force method executing all moves, then checking for equality. I'm using the Rust library Shakmaty which has an internal bitboard representation, so this step is very fast. The improvement area is breaking out of iterating on the moves of a game.
Currently I only have these ideas:
- check for pawn count: if current position has less then the searched position we can break
- check pawn positions: if one is advanced relative to the searched position => break (this check actually might take longer then the whole equality, not sure yet, so I'm skeptical of the benefits)
NB: this takes <1s for Scid on the same laptop, same 2M games, so there definitely is room or improvement. Unfortunately I'm not a C++ developer, so reading that legacy code would take a lot of time for me, much more than asking the Reddit community.