Created with text prompt to image AI (https://create.microsoft.com/en-us/features/ai-image-generator)
Parsing Chess Data to Discover Mating Patterns
Finding more training material in puzzles already available on lichess.orgParsing Chess Data to Discover Mating Patterns
Overview
In this article, I am going to discuss my recent experiences learning mating patterns, using:
- lichess.org,
- the lichess database,
- and the lichess extension LiChess Tools (available for Firefox and Chrome browsers),
- with a good portion of Python and CoLab
as a base of my endevour. This can be a bit technical in the way of software engineering, but I will try my best to explain everything on a non-technical level, such that everyone should be able to follow. And, if you cannot follow or have additional questions, you can always reach out to the forum link below.

There are about 37 mating patterns (see also lichess Checkmate Patterns I - IV) and knowing them is one of the most valuable and basic assets one can bring to the chess board. Because after all, everyone wants to check mate their opponent eventually. And knowing more than one way to do this, is a greater asset then knowing only 2 or 3.
So, first of all I have studied these patterns in theory by researching them on the Internet in various chess related sites. Then, after a while, I felt lost, because there are so many patterns and knowing them only in theory, without practicing, is a good base for forgetting fast. So, I turned to constructing private studies for each pattern that I had learned (e.g.: Discovered Check) and I also practiced mating patterns available on lichess.org Puzzle Themes.
But the experience with the construction of my own studies was rather slow and disappointing, because I manually copied each puzzle from a resource like a PDF or image into an FEN position and constructed an interactive puzzle from this information. And even though, the conversion step can be supported by software like Chess Converter or Chess Vision AI, it's still hard to find information on each pattern, let alone enough examples to actually gain a training advantage. This is why, I even played Mate in 2 puzzles here on lichess, bookmarking each pattern that I was interested in, and re-iterating later when it came to constructing a whole study on one pattern.
In this manual process, I was more busy sifting manually through data, than actually practicing mating patterns. So, something had to change to make this more effective. This is why I turned to reviewing the lichess database - Thinking: Mating puzzles are already tagged in this data, -what I am looking for is just a subset of the tagged items. What, if I could automate identifying those mating patterns (e.g.: Kill Box) in the available mating puzzles and be able to use those, in order to learn from real live examples?
I started to look at identifying patterns using Python as programming language and CoLab as freely available runtime environment, because there is no setup required here, and everything is available without any additional cost.
It turned out that some mating patterns are rather easy to identify using a Python parser. I was able to hack up the initial version of a parser for the Kill Box mating pattern in about 4-6 hours. And the whole script runs about 15 minutes to pull about 3700 Kill Box mating patterns out of a total of 3 million puzzles (1 million puzzles actually being mating puzzles).
So, in a nutshell, this Python script performs the following processing steps:
- Download the lichess database for processing in the CoLab environment
- Identify puzzles with mating patterns using the tagged items
- Load each puzzle with a mating pattern and process it in a Python Chess library to actually verify the mating position.
- The position of the pieces is then validated in terms of their relative position to each other, and most importantly, in relation to a king. This requires for a Kill Box mating pattern that a king is mated and relative to its position there needs to be a Queen and a Rook of the mating color (all this can be verified using Python Chess).
- The result of the above processing is then written out to a CSV file, which is just a simple text file that can be loaded into Microsoft Excel or its open source clone Open Office.
Now, I was all of a sudden bombarded with samples, while previously, it was hard to find a small number of these. My problem was now this: A study is limited to 64 chapters and defining each chapter is still hard work, if you would have to manually copy about 3700 mating patterns, you are looking at about 57 studies, each with 64 chapters(!).
I actually went through this process sometime last year. But I only got through it in a reasonable time, because the developer of the lichess extension LiChess Tools was willing to add a download PGN functionality for puzzles, which would make defining the content of study a simple point and click excercise.

I simply used the content of the final CSV file (sorted by rating) to start each puzzle and downloaded the PGN containing all moves via the the bluish arrow like icon next to the puzzle id (displayed in the above sample screenshot on the top left side). This forced me to review each single puzzle and I have learned quit a bit here. Specifically in those studies that are hardest to solve: Kill Box Mate 56.
We have added the above mating patterns at the beginning of this year as a new Kill Box puzzle theme. This seemed reasonable to me since there are so many patterns and I wanted to share them with everyone on lichess in the most appropriate way. Fortunately, Thibault Duplessis felt similarly. I am therefore, very thankful to him and the entire lichess crew, since we added these patterns via GitHub issue #16696.

Lesson Learned and Future Developments
The process of solving puzzles and these puzzles in particular have helped me to:
- Learn chess patterns by real examples that are otherwise not easy to find
- Recognize the shape of the pattern and its variations
- Recognize pre-stages of the pattern
- Find strategies to create situations to apply a mating pattern
And this has helped me in general to
- Improve at pre-calculating moves
- Train my vision on defended fields, blocks, pins, etc...
Of course I still have to apply this in my games, -but hey, this is work in progress and I am working on it. And in the meantime, I am also working on getting more mating patterns into the known. Namely, there are already:
and maybe there are more to come, later on, as I am getting intrigued into whether I can have a Python script to determine Damiano's Mates automatically.
The Code
I created a ChessMatingPatterns GitHub repository for the Python/CoLab code, and resulting CSV data files mentioned above, in case someone wants to take a look at this.
Conclusions
I wanted to share a bit of my experience here on lichess, because I think some of it should be interesting, even for chess coaches and students, who are probably always looking for more study material. I can recommend looking into LiChess Tools, if you are looking to enhance your experience with lichess.org as a whole or with interactive puzzles in particular. I am very thankful to the author of the extension since it makes writing this article (with images) much easier and he also supported me in the process of creating the studies based on existing puzzles.
I am glad that I can be part of the lichess community and wanted to share my story of how the Kill Box pattern became a part of the platform. I am hoping that we all can contribute something useful here or there, and thus, make this an even better place for meeting, discussing, and having fun with chess related content.
