James Stanley


A Strange Chess Clock

Thu 2 May 2019
Tagged: chess

A chess clock is a device that has 2 countdown timers, used to place a limit on each player's thinking time in a chess game. White's clock is counting down while it's white's turn. After white plays his move, he hits the clock, and his clock pauses, and black's clock now counts down. Once black has played a move, he hits the clock, and white's clock resumes counting down, and so on.

My "Chess Clock" is not like that, it's this:

Chess Clock

Peter and I were talking at the weekend about deliberate misinterpretations of the phrase "chess clock", and came across an interesting idea.

The idea is that we could use a chess board to encode the time of day. Each second in a 24-hour period would be represented by a corresponding board position, and we just need some lookup tables to convert back and forth. But it's easy to come up with 86400 unique random board positions, so let's try making the transitions from one position to the next form a legal chess game! Then the board starts in the starting position at 00:00:00, and at 00:00:01 white plays the first move, at 00:00:02 black responds, and so on, until 23:59:59, and the board is reset again at 00:00:00 the next day. We "just" need to find an 86400-turn game (or 43200 moves per side).

Unfortunately, a chess game is automatically drawn if there are 75 consecutive moves from both sides without a capture or pawn move, so that places an upper bound on the possible length of a chess game. There are 96 possible pawn moves and 30 possible captures (notwithstanding the fact that not all the pawn moves are possible without some pawn moves that are also captures, otherwise the pawns can't get past each other). 126 * 75 = 9450 moves per side = 18900 positions. This is not enough to have one position for every second in the day, although if we could reach just 4320 moves, that would be enough for one board position every 10 seconds.

I wrote a Perl script to depth-first search random moves trying to find a game exactly 4320 moves long, and ending with white delivering checkmate. That gives a unique board position for every 10 seconds throughout a 24 hour period. We need to make sure to do pawn moves and piece captures to prevent the game from being drawn by the 75-move rule, and since there are only a small number of pawn moves and piece captures available, we need to ration them carefully. So there are just a few heuristics required:

Whether this algorithm finds a solution quickly depends on random chance. If it makes some unlucky choices early on, it tends to get stuck. I just restarted it and tried again every time it got stuck, until I got a valid solution.

An amusing consequence of only allowing the pawns to move every 74 moves is that the first 74 moves just consist of moving the knights around the board randomly, and shuffling the rooks back and forth, because all of the other pieces are hemmed in by pawns which aren't allowed to move:

So to avoid this, I hardcoded the opening moves as 1. d4 Nf6 2. Bf4 d5. I also allowed any captures and pawn moves past move 4260 as this can't possibly prevent the game from running to full length, and actually helps with finding checkmate.

Having found a suitable 4320-move game, I encoded all 8640 positions in FEN, bundled them into a Javascript file, and used chessboard.js to render them in the browser. So that's our solution: we have a clock that represents the time of day using a chess position, to the nearest 10 seconds, and the transition from each position to the next is a legal move, and the entire game is a legal game. You can look at the full Chess Clock page if you want.

The game ends with 4320. a8=Q# at 23:59:50 every day, before resetting to the starting position at 00:00:00. Most of the moves are pretty bad, but no problem.

Converting between different formats

To make it easier to work with the Chess Clock positions, I made a tool to conveniently convert between Chess Clock time and ordinary time:

Chess Clock Time Converter

The board is editable (click and drag the pieces), and you can also edit the text boxes for the time, position ID, or FEN of the board position.

What we've got here is actually a bit more general than a clock. We can use the board positions to represent any number from 0 to 8639. For example, you could use this to represent a PIN number (as long as it's less than 8640) by entering the PIN in the "position ID" field, and writing down a drawing of the board position. To recover the PIN, you just need to recreate the board position in the Time Converter and read out the "position ID".

You could represent a 12-word BIP39 mnemonic seed for a Bitcoin wallet by storing the 12 Chess Clock board positions corresponding to the BIP39 word numbers of the mnemonic seed. For example the word "coffee" is number 361 (indexed from 0), which is board position 1r2qb1r/pppkpppp/4n3/3pR3/1Q1PN3/2P5/PP2PPPP/1b1KNBnR:

(And if you're interested in this sort of thing, you may enjoy my Chess Steganography project).

Learning to tell the time

At first glance the positions appear completely random. How could you possibly learn to tell the time on this clock?

But remember that captured pieces never reappear (modulo pawn promotion), and pawns never move backwards. So we just need to memorise the order of captures and pawn moves, and then we can get a coarse approximation of the time of day just by looking at where the pawns are and which pieces have been captured. Here's a guide to telling the time to the nearest hour.

Starting from the top row, see if the next row could have happened (for example, if white's c pawn is on c2, then c3 couldn't have been played; if white's c pawn has gone then c3 could have been played). If it's possible, move down a row and repeat. If not, read off the time of the row you finished up on.

TimeNotable changes from 1 hour previous
00:00-
01:00white: c3,d4; black: d5
02:00white c pawn has been captured
03:00white: exf3; black: bxa6
04:00white: g3; black: fxe6
05:00black: g6,h6
06:00white: h3; black: h5
07:00white: h4; black: g5
08:00white only has 1 rook
09:00white: b4; black: a5
10:00white b pawn has been captured; black: c6
11:00black: g4
12:00white: f4,f3; black: e5
13:00white: a3; black: c5
14:00white: f5, black: c4
15:00black: e5
16:00white: f6, white g pawn has been captured
17:00white d pawn has been captured, white only has 1 f pawn
18:00black g pawn has been captured
19:00white f pawn has been captured, black only has 1 a pawn, black: c3
20:00black: c2
21:00black c and h pawns have been captured
22:00black: e4
23:00white: h5

Further work

It might be cool to make a physical implementation of the clock, either using one of those Square Off boards that can move the pieces using magnets, or using a 6-axis robot like Chris Annin's 3d-printable AR2 to physically pick up the pieces and move them, perhaps as some sort of art installation. Although, in either case, it might struggle to reset from the checkmate position to the starting position in the requisite 10 seconds.

A "Chess Clock Chess Clock" would be funny. This would be like a traditional chess clock, in that it keeps track of the remaining time for 2 players, except the time is displayed using the 4320-move "Chess Clock" game. It would probably have to count up instead of down, so that your time starts in the starting position, and runs out when move 4320 is played. It could make one move every 100ms, for example, for a ~15-minute game.

If we wanted to encode the day of year in addition to the time, we'd need to have 365 unique games, with no common board positions between the games. This is impossible as the first move for each colour only has 20 possibilities, so the maximum number of dates we could cover is 20. This could be solved by choosing 365 of the Chess960 starting positions, and then I think it should be relatively easy to get 365 games with no common board positions.



If you like my blog, please consider subscribing to the RSS feed or the mailing list: