kekavigi.xyz

Analyzing Chess Repertoire

You're an entry-level chess player who didn't have enough time to study opening or review past games. But, somewhere inside your mind, you wonder, how can I get a glance at my chess game history? What type of opening do I like, and what sequence of moves often trip me? And isn't it fun if that-same-thing can be applied to Stockfish (or Leela or the like) -- so that I can compare my gameplay accuracy to 'theoretical' baseline?

Ditulis tanggal oleh A. Keyka Vigiliant. Konten diterbitkan dibawah lisensi CC BY-SA 4.0.


Acknowledgment at the beginning: I’m rarely write something in English, so bear with me if I make ambiguous sentences. This essay/diary is also a work-in-progress, so yeah.

You’re an entry-level chess player who didn’t have enough time to study opening or review past games. But, somewhere inside your mind, you wonder, how can I get a glance at my chess game history? What type of opening do I like, and what sequence of moves often trip me? And isn’t it fun if that-same-thing can be applied to Stockfish (or Leela or the like) – so that I can compare my gameplay accuracy to ‘theoretical’ baseline?

Well, at least for my problem, the answer is both yes and no. Yes, some great sites let you view your (or someone else) games histories, such as OpeningTree.com and Tailuge’s chess-o-tron. But also no, because OpeningTree didn’t spread all alternative moves like Taligue’s site, while Taligue didn’t visualize each node as a chessboard (also its only available for Lichess users). I need a blend of both to satisfy my need.

First, I need to figure out how to translate Taligue’s JavaScript codes to work for the Chess.com database. Because I never ‘touched’ Javascript since middle school, the answer is simple: impossible. I found that Taligue used Rob Schmuecker’s code to visualize game histories as a tree. So, I grab Rob’s code and rewrite it “in such a way that” gives the same effect as Taligue’s site did. Then, I wrote a Python script to download Chess.com game histories (for a user), parse all PGN gameplays and relevant information, then exported it to JSON. Not bad for an MVP (Minimum Viable Product). Finally, using python -m httpserver, I can see my game histories as a tree.

The next step is changing node shape to reflect chessboard position. So there are three+one things to revise:

Using some hour of brain work, it works! (not bad for an MVP).

Game histories visualized with chessboard.
"Game histories visualized with chessboard.."

Then, how to apply it to Stockfish? Assuming there is some opening line as input, Stockfish needs to output some (best) principal moves at each step (evaluated at depth 20). I figured that five alternative moves are enough if Stockfish is playing the same color as us. Whereas ten best moves (may include some mistakes/blunders) is good to reflect opponent gameplay. We also need to stop exploring when the absolute value of the evaluation bar exceeds 5.0 (that’s roughly equal to a Rook or two Pawns plus a Knight). For the sake of comparison, we should output the W/D/L metrics at each step. So yeah, let’s write some script.

As a 1. Nc3 practitioner, I love playing 1. Nc3 ... 2. d4. That’s maybe not a good opening based on the theory. But move as 2. ... Bf5 or 3. Qxd4 is fun to play. I wonder what Stockfish want to say about this opening:

The final step is, of course, rewriting and refactoring all scripts. This is WIP, and I wonder if I should upload it as a Flask app, or something like that.