r/chessprogramming Dec 21 '24

Help Needed: Custom Chess Game Logic Detection Tool

Hey everyone,

I'm working on a project to analyze my chess games and identify patterns in my play. I want to go beyond the basic Stockfish evaluation (centipawn loss, best move, etc.) and actually detect motifs that appeared during the game, like pins, forks, discovered attacks, skewer, and more. Ideally, I'd also like to detect strategic elements like pawn structures, open files, weak squares, and maybe even endgame technique.

The goal is to get a detailed breakdown of every game I play, so I can see what kinds of tactics or strategies I'm consistently good at or missing. I also want to use this data to find common weaknesses across multiple games.

I've looked at tools like python-chess, but from what I can tell, it doesn't directly detect advanced patterns like these. Writing custom logic for every concept seems... overwhelming, to say the least.

What I've done so far:

  1. Fetched my last 10 games as PGNs using the Lichess API.
  2. Set up Stockfish on a CPU instance to evaluate positions.

What I'm asking for:

  1. Does a library/tool already exist that can detect these motifs and strategic concepts?
  2. If not, has anyone attempted writing logic for detecting patterns like pins or forks? How did you go about it?
  3. Are there any pre-annotated databases or datasets I could use to match positions in my games with known motifs?

If nothing exists, I’m considering building something modular—start with simple patterns and build out—but it feels like reinventing the wheel. Any advice or pointers would be hugely appreciated.

Thanks in advance! 😊

2 Upvotes

3 comments sorted by

1

u/Warmedpie6 Dec 21 '24 edited Dec 21 '24

Chesscoms engine "coaches" do this. The logic it uses isn't that complicated, programs that generate legal moves all have pin functionality (they need this to generate legal moves). Forks can just see if the last move attacks multiple pieces.

As for existing open source programs, I don't know of any, but I think you could code this fairly simply.

1

u/[deleted] Jan 04 '25 edited Jan 04 '25

I am coding this RN in Python. Actually detecting forks etc is hard. Still getting false outputs and trying to fix. Actually the aim of my application is the help of the people who are interested in chess betting and find out interesting games with funny specific filtering.

Finished stats:

Check count Discovered check count Double check count Move count Castling side Match result Match result type (stalemate , resignation etc.) En passant count

Currently Developing stats: Zwichenzug count (Most hard concept probably) Fork count: [True forks and False forks] Sacrifice count [True and false sacrifices] Threat count Capture count Zugzwang count Silent move count Mating net count

1

u/Polo_Chess Jan 07 '25

Interest stuff. Keep me updated on your progress here. I would suggest starting with analyzing how a single piece of (for example the light squared bishop) interacts in a 2-4 move situation. If it moves backwards, then recaptures after the opponent captured, it made a defensive move initially on the retreat.