Maciej Janicki's website

2020-05-03 own-projects chess

Announcing chesstools

The long weekend has been very fruitful for me: after some hours of coding, I can proudly announce version 0.1 of chesstools - a suite of minimalist tools for chess study following the UNIX philosophy. The main component of the package is pgnvi - a vi-like editor and browser for PGN files. It comes with a simple graphical application for drawing the chess board and a few other tools. You can get the package from my Gitlab or Github pages.

Recently I was trying to get better in chess, but I’ve always found the educational materials hard to use. Replaying games on the board while reading a book is slow and clumsy, while computer programs for browsing PGN files typically come with terrible bloated GUIs (couldn’t find any counterexample). I noticed that I would need something simple and keyboard-driven, ideally with Vi keybindings, which would integrate well into the terminal-based workflow. It’s just reading text files and drawing a simple picture, shouldn’t be that complicated, right? So I ended up writing it.

Originally I wanted to make a single TUI application, in which the position would be drawn using Unicode symbols for chess pieces (yes, there are such!). It turned out to be an impractical idea, because the resulting board is very small and barely readable. And if you enlarge the terminal font, all the other text in the window becomes too huge.

Then I had this awesome idea: why not delegate the drawing to a separate program that does only this? Simply read the position in FEN notation from stdin (it’s even a single line) and draw it! A text-based PGN browser could then call this program as a subprocess and write positions to its stdin. That’s how drawboard came about on one evening after work.

The main component of the package is pgnvi - a text mode browser and editor for PGN files. It features a tree view that you can use as an opening explorer with large databases. This is how pgnvi’s tree view and drawboard look together in action:

pgnvi tree view

Of course you can also use pgnvi to watch and edit games - all using the vi keybindings:

pgnvi tree view

Instead of an “insert mode”, pgnvi features an “append mode”, in which you can append the moves at the end of the game or delete the moves from a certain position onwards. This is enough for editing - why would you change a chess game in the middle? As the validity of moves and positions is constantly checked, this would quickly result in an invalid state.

The append mode features another interesting functionality. The three main rows of the keyboard (those with letters) are completely remapped to the following layout:

+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|  1  |  2  |  3  |  4  |  +  | O-O |  5  |  6  |  7  |  8  |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
 |  a  |  b  |  c  |  d  |     |     |  e  |  f  |  g  |  h  |
 +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
  |  R  |  N  |  B  |  Q  |     |  x  |  K  |  B  |  N  |  R  |
  +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+

Note how the 8 ranks and 8 files used in chess ideally match the 8 fingers that we use for typing (not counting thumbs). The layout corresponds visually to the chessboard and makes the frequently used combinations easily reachable. It will surely have a somewhat steep learning curve, but I’m pretty sure that once mastered, it will make entering moves enormously efficient.

But, I didn’t spend the whole long weekend programming. It’s nice to breathe some fresh air in between. Taking a break between long hours of coding, I did a 20km hike in Finnish woods.

me in the woods

Chesstools is still at an early alpha stage: plagued with bugs, missing important functionality (especially comments and variants!) and exhibiting an ugly and impoverished user interface. But I’ve already used it to transcribe a couple of games - both my own and from books - and to browse a couple of game collections. And it clearly is the chess toolkit that I need. I hope it will be useful for others, too.

And when it achieves maturity, maybe I can finally focus on chess.