Friday, December 4, 2020

The twists and turns of random turn chess

It's time for another item of the series Posts I wrote a while ago and "forgot" to publish.

Random turn chess is a chess variant where the move order is random: Before every move, a coin flip decides who will play. If you're lucky you get to play several moves in a row, but you never know, when you make a move, whether it's you or your opponent who will make the next one. There are no special rules for check (or checkmate or stalemate). Instead the goal is simply to capture your opponent's king. Whenever you give a check, you have a 50% chance of winning on the spot. And if you're struggling, your best chance might involve deliberately putting your king en prise - there's no rule that says you can't.

As the name suggests, random turn is quite random. It has a non-random cousin, bidding chess, where the players bid for the right to make the next move. I won't explain it here, but they're basically manifestations of the same game. For the background, see this article by Jay Bhat and Sam Payne.

A few years ago I wrote an article with former student Urban Larsson about endgames in random turn/bidding chess. It's in the book Games of No Chance 5 which is freely available online. 

One thing that sets random turn chess apart from most other chess variants is that the game is amazingly complex already with just the two kings and one more piece!

For instance, look at the following position:


In standard chess this would be a draw, as it's impossible to construct a checkmate. In random turn on the other hand, not only can White possibly win, but so can Black! 

Figuring out the best way to play is a challenge on several levels, even with a computer. One of the quirks is that even in theory, there might be a difference between playing for a win and playing for a draw. Conceivably it might be, for instance, that White's best winning probability is 60%, and that Black's best winning probability is 30%, but that White, in order to win with probability 60%, has to allow Black to win with probability 40%. Moreover, in many positions the best strategy will not force a conclusion of the game in any fixed number of moves.

My computer program eventually sorted out the king + knight versus king endgame (and it turns out that with three pieces, there is never a conflict between playing for a win and playing for a draw). But in order to do so it had to backtrack 2644 moves before the values stabilised. If we compare this to "half-moves" in standard chess, it's more than twice as long as the record forced checkmate of the current endgame databases!

In the diagram, White's winning probability with best play from both sides is exactly ... let's see how to write it on this page...

118149099210761088839658071450928865980708175943671062283570061370088990297242487312344048797827448187146592684262495193145202761460197371
\[\Big /\] 200453006658428905551436939930457127472327950605425153085344343480681727125595119114980629492845444447049929082740309543514434854453248000.

That's a rational number with a numerator and denominator of 138 digits each, approximately 0.5894104617. 

Finally a puzzle that makes sense to us humans. What will happen here, and what's Black's probability of winning? Hint: with best play, the game will end in at most 13 moves.


Spoiler alert
.
.
.
Black's winning chances are \[ \left(\frac34\right)^6\cdot \frac12 = \frac{729}{8192}.\] Can you see why?

Tuesday, August 11, 2020

Hastigheten i kvadrat ... eller ännu värre?

Nu tittade jag på ännu en Numberphilevideo med en tankeväckande räkneövning. Här vill jag återge den fast med lite snyggare siffror och utan videons brasklappar om "slightly dodgy".

Gåtan är följande: Två bilister i likadana bilar kör i 40 respektive 50 kilometer i timmen åt samma håll på en väg. När de är jämsides (dvs när den snabbare precis kör om) dyker ett hinder upp och båda tvärnitar. Vi bortser från reaktionstid, dvs vi antar att de är jämsides när de börjar bromsa. Vi antar också att de har likadana bilar med lika effektiva bromsar, däck osv. 

Om den långsammare bilen nätt och jämnt hinner stanna för att undvika en kollision, dvs stannar precis vid hindret, vilken hastighet har då den snabbare bilen när den kolliderar med hindret? 

Ett resonemang som nog de flesta inser är för naivt och optimistiskt är att om den långsammare bilen får ner hastigheten från 40 till noll, hinner den snabbare bromsa från 50 till 10. 

Det stämmer inte, men notera att vi faktiskt antar att bilarna hinner bromsa bort 40 km/h på samma tid. Detta är det antagande som ligger bakom standardfrågorna på körkortsprovet, som går ut på att dubbelt så hög hastighet ger fyra gånger så lång bromssträcka osv. Antagandet är att man bromsar med samma kraft vid alla hastigheter. Detta kan knappast stämma exakt, men är nog en hyfsat bra approximation för vanliga trafiksituationer.

Problemet för den snabbare bilisten är att han (det är oftast en man) hinner längre på denna tid. Så kraschen blir definitivt i mer än 10 km/h. 

Nästa tanke är att räkna ut hur bromssträckorna förhåller sig till varandra. När hastigheterna har förhållandet 4 till 5, blir bromssträckorna som 16 till 25. Det är egentligen ganska enkelt och hör som sagt till teoriprovet: Sträckan är tiden gånger hastigheten, och både tiden och den genomsnittliga hastigheten under inbromsningen kommer att ha förhållandena 4 till 5. 

När den snabbare bilen kraschar in i hindret har den alltså 9/25 av sin hypotetiska bromssträcka kvar. Kanske borde den då även ha nio tjugofemtedelar av sin ursprungliga hastighet? Det blir i så fall 18 km/h, rejält mycket mer än de 10 som det naiva tankesättet ledde till. 

Men det är faktiskt betydligt värre! När vi har 9/25 av bromssträckan kvar, får vi dra kvadratroten ur 9/25 för att få andelen av hastigheten vi har kvar. Detta enligt exakt samma princip som nyss! Och när vi drar roten ur ett tal mellan 0 och 1, får vi ett större tal, i det här fallet 3/5. 

Svaret är alltså att den snabbare bilen inte ens hinner halvera sin fart, utan kraschar in i hindret i 30 km/h! 

Det här kan vara något att tänka på när vi pratar hastigheter i tätorter. Det har ofta påpekats att riskerna för oskyddade trafikanter ökar dramatiskt i ett fönster runt 30-40 km/h, och då pratar vi alltså om hastigheten vid själva kollisionen (även om det nog är svårt att få fram exakta data). Men dessutom kan alltså hastigheten vid en kollision i sin tur öka dramatiskt även vid en liten skillnad i hastighet före inbromsning.

Men tillbaka till vår räkneövning. Den som kan sin Pythagoras sats känner säkert igen både förhållandena 3:4:5 och kvadrerandet följt av kvadratrotsutdragning. Och det stämmer generellt. Närhelst vi har en Pythagoreisk trippel, dvs tre tal som uppfyller \[ a^2 + b^2 = c^2,\] får vi motsvarande slutsats: Om bilarna hade hastigheterna $b$ och $c$ där $b$ är det mindre talet, kommer den snabbare bilen att ha hastigheten $a$ efter den sträcka som den långsammare bilen behövde för att stanna. 

Vi kan till exempel vända på det och jämföra två bilar med hastigheterna 30 kontra 50 km/h. Då blir slutsatsen att den som kör i 50 kraschar i 40 när den som kör i 30 hinner stanna!

Nästa Pythagoreiska trippel, $5^2 + 12^2 = 13^2$, handlar lika pedagogiskt om vad som händer när någon blir stående på motorvägen. 120 eller 130 kan väl kvitta kanske man tänker. Men händer det en olycka framför och den som kör i 120 precis hinner stanna, så kommer den som höll 130 att braka in med en kvarvarande hastighet av 50 km/h.



  

Monday, July 27, 2020

Zero to the zeroth power

The question of the number zero raised to the zeroth power comes up often enough that finally I wanted to put my response to it on the blog for future reference. In short: \[ 0^0 = 1.\] This might not seem like such a big deal, but in the broader scheme the point is: 

We should not teach that mathematics is full of things that can go wrong and that one has to be "careful". We should teach that mathematics can be trusted even if some of it looks weird at first. 

It's the former approach that tends to depict mathematics as some incomprehensible wizardry, not the latter. 

I wouldn't have written this post if everyone already agreed on the status of $0^0$, but it seems that the idea that $0^0=1$ is still the minority view even in the teacher community. In a poll among mathematics teachers last year, about 85% of the responders chose the answer "0^0 is undefined" over the alternative "0^0 = 1".

But let's first review what the problem is, so we know what we're debunking. On one hand it's generally agreed that $x^0 = 1$, at least when $x>0$. This might itself require an explanation, but is rarely disputed. For instance, $10^3$ is $1000$, which is 10 times as much as $10^2$, which is 10 times as much as $10^1$, so it makes sense that $10^0 = 1$ and that $10^{-1}=1/10$ and so on. 

On the other hand $0^x = 0$, again at least if we assume that $x>0$. For instance, $0^3 = 0\cdot 0 \cdot 0 = 0$ and $0^{1/3} = \sqrt[3]{0} = 0$. 

So if $0^0$ is to have a specific value, there will be a clash between the two rules $x^0=1$ and $0^x=0$. One of them suggests that $0^0$ should be 1, the other that it should be zero. 

Moreover, this clash manifests itself in the exercises of the typical calculus course, where we're asked to compute things like \[ \lim_{x\to 0+} (\sin x)^{1/\log x} = e \approx 2.72.\] This limit has the form of something raised to a power, where both the base and the exponent tend to zero. Many textbooks make a big deal out of the fact that this doesn't determine the limit, listing $0^0$ as an "indeterminate form" along with truly meaningless expressions like $0/0$ and $\infty - \infty$. This has led to a widespread belief that $0^0$ can't consistently be assigned a value. 

Probably algebra has a part in this too: We're taught that \[ \frac{x^5}{x^2} = x^3,\] just subtract one exponent from the other. And lo and behold, \[ \frac{x^2}{x^2} = x^0 = 1,\] except there's a problem when $x=0$, because then there's a zero in the denominator of the left hand side. So it seems that whenever $0^0$ shows up, there's something fishy going on. 

It's just that that's not true. "Indeterminate forms" aren't really a thing, they're basically just lists of common beginner's mistakes. Or if we're a bit cynical, lists of ways an examiner might try to trick you on a test. We can't make $0^0$ agree with a limit of $x^y$ at $x=y=0$, but that's not a conundrum, that's a discontinuity. Discontinuities exist. There was never a theorem that everything is continuous in the first place. And denominators that might be zero is a different matter altogether. If that's the issue, the equation $x^5/x^2 = x^3$ is just as problematic.

In reality, zero to the zeroth power is virtually omnipresent, and the pattern is the same every time: We want $x^0$ to be equal to 1 always. And we want $0$ to a power to have the exceptional value 1 precisely when the exponent is zero.

Fundamentally this is because $0^n$ answers the question "If you put an apple on a table and then $n$ times perform the operation of removing all the apples from the table, how many apples are then on the table?" (answer: If you never removed it, it's still there, otherwise it's gone). If we trace mathematics down to its logical foundations, this is the sort of thing we encounter. Everything else, like $e^{i\sqrt{\pi}}$ and so on, is built on top of that. Therefore not only is it "often useful" to let $0^0=1$. It's also completely safe and the only option that doesn't leave us with a mess of exceptions. 

Famous examples where we can't really avoid $0^0$ include Taylor series like
\[e^x = \sum_{n=0}^\infty \frac{x^n}{n!},\] and the binomial theorem \[ (x+y)^n = \sum_{k=0}^n\binom{n}{k}x^ky^{n-k}.\] In both cases we want the factor $x^0$ to be 1 if $x=0$, otherwise we get the wrong thing.

More generally, $x^0 = 1$ is a building block of polynomials and power series, which play a major role in algebra, analysis, and discrete mathematics. Powers of zero on the other hand occur naturally only when the exponent is a nonnegative integer. Therefore there's no issue of continuity in the exponent, and $x^0=1$ takes precedence over $0^n=0$.  

I recently stumbled upon something involving so-called Stirling numbers, that count ways of partitioning $n$ objects into a given number of nonempty subsets. For instance, the number of partitions of $1, 2, \dots, n$ into 3 nonempty subsets is given by the formula \[\frac{3^n - 3\cdot 2^n + 3}6,\] or so it would seem. Here if we plug in $n=1, 2, 3, 4$, we get the numbers $0, 0, 1, 6$, which makes sense: We don't distinguish the three parts (hence the division by 6), but we do require them to be nonempty, which means $n$ must be at least 3 before it's possible at all.

But if we set $n=0$ we get the nonsense value $1/6$ which isn't even an integer. At this point I hear you asking why any sane person would consider partitioning an empty set into nonempty parts. Can I really complain about a nonsense answer to that? The problem was that this occurred inside a loop where my computer program added together some stuff that I didn't look at case by case myself. 

Or rather, that would have been the problem. But luckily I knew what the real formula is. It's not the one above, but rather \[ \frac{3^n - 3\cdot 2^n + 3\cdot 1^n - 0^n}6.\] Not only does this produce the correct value also when $n=0$, but it reveals the pattern that explains what the formula for any given number of parts will look like, as well as why it's true (if you don't see it, don't worry).  

Notice that the formula involving $0^n$ is the one that lets you sleep at night. It's if you would use the other one, or (imagine the horror!) if your computer algebra system wouldn't recognise that $0^0=1$, that you'd have to worry that something might go wrong.

But can we be certain that $0^0=1$ makes sense every time?  

A "foundational" answer (already hinted at) is yes, because arithmetic is built from just a few basic principles, one of which is that an empty product is equal to 1 (there are numerous ways of formulating the details). Since the more sophisticated stuff already rests logically on that basis, a fundamental thing like $0^0$ can't possibly jump up and bite us from behind. 

More philosophically, we can compare mathematics to things like, say, traffic regulations, English grammar, or a toolkit for the household. Those things are man-made and there's no fundamental reason they must work. If we're not careful they won't, and if something weird occurs, we might actually want to fix it with a patchwork of exceptions.  

Mathematics is not like that. It's not a mish-mash of compromises and conventions. It works whether or not we understand why. It doesn't break if we do something that wasn't intended, and it can be explored: If you establish a formula, it will give me the right answer even if I plug in some numbers that you never thought of. Like zero to the zeroth power.

Sunday, June 21, 2020

Lyssna på Greta Thunberg och sprid ordet!

När jag lyssnade på Greta Thunbergs sommarprat igår kom jag att tänka på detta med att upprepa något som låter orimligt, så att det till slut känns rimligt. Mycket finns skrivet om "gas-lightning", "illusory truth effect" mm, och exemplen handlar ofta om Hitler, valkampanjer, reklam, och sociopater i parrelationer. 

Men psykologin är nog densamma även när påståendena är sanna. Så låt oss göra som Greta Thunberg och sprida klimatvetenskapens rön. 

Ska vi klara de mål som Sverige och de flesta andra länder har enats om i Parisavtalet, har vi motsvarande 7-8 år av dagens nivå kvar av hela koldioxidbudgeten. 

Det handlar alltså inte om att minska utsläppen med si eller så många procent. Det handlar inte om hur mycket vi kan släppa ut per år. Vi måste ner på väsentligen noll om vi ska undvika kollaps av klimat och ekosystem, och det måste hända saker före år 2030 om det inte ska bli väldigt, väldigt bekymmersamt. Fossila bränslen har ingen framtid överhuvudtaget. De måste fasas ut helt.

Det låter orimligt. Men om vi upprepar det tillräckligt ofta kommer det att bli så bekant att du kan säga det till vem som helst, till och med om du är politiker, utan att folk tror att du har blivit tokig.

Och till stor del är minskning av utsläppen inte ens svårt, eftersom vi kommer långt bara med att sluta göra onödiga saker. Vi behöver inte shoppa hållbart eller resa klimatsmart. Vi kan skippa det mesta helt och hållet. 

Vi avslutar med en räkneövning. Fem-sex minuter före slutet nämner Greta Thunberg en ny rapport som visar att vi måste minska våra utsläpp med 12-15% varje år för att vara i linje med Parisavtalet. Låt oss säga att vi skulle minska med 12.5% varje år. Det är en åttondel. Om vi jämför med nuvarande årliga utsläpp skulle det bli 7/8 nästa år, och 7/8 av 7/8 året därpå, och så vidare. Den totala mängden för all framtid skulle då bli

\[ 1 + 7/8 + (7/8)^2 + (7/8)^3 + \dots \]

Detta är en så kallad geometrisk serie, och summan blir inte oändlig utan stannar vid precis 8. Summan från år 2 och framåt är nämligen 7/8 av det hela, vilket innebär att den första termen är en åttondel av totalsumman. 

De 12-15 procenten stämmer alltså bra med de 7-8 år som nämndes tidigare. Med den takten skulle vi efter 10 år vara nere på 26%. Det är svårt att hävda att detta är orimligt, med tanke på att många av världens fattigare regioner aldrig har varit uppe på motsvarande 26% av vår nivå.

 

Thursday, September 26, 2019

Beatboxing and the Shannon number

There is a famous number called the Shannon number, which "estimates" the number of possible games of chess. In mathematics and computer science, when you estimate something, it doesn't necessarily mean you find a number that's fairly close to it. It means that you compare it to something where you can say with absolute certainty whether is greater or smaller. If you're thinking about how long it would take for a snail to crawl to the moon, one estimate is that it must take at least one second, since the moon is more than one light-second away.

In the same spirit, Claude Shannon pointed out in a pioneering paper on computer chess that the number of possible games of chess is at least $10^{120}$. Let's write that out just for fun:

1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.

As we will see, Shannon's estimate is off by several thousands of orders of magnitude. In comparison, given that it took only a few hundred million years for slimy creatures to evolve into astronauts, the snail versus speed of light estimate is pretty good, just 16 or 17 orders of magnitude away from best possible.

The Shannon number turns out not to be that important to the question of how hard chess is. But I while ago it turned up in another context: People asking Siri to compute one trillion to the tenth power!

Shannon's number was just mentioned in a remark in his paper, but went viral, as we would say today.

In Shannon's calculation, a game of chess means a sequence of moves from the start to the end of the game, like for instance 1. e2-e4  e7-e5, 2. Bf1-c4 Bf8-c5, 3. Qd1-h5 Ng8-f6, 4. Qh5xf7#. That's one game in the space of all chess games, and another one is 1. e2-e4  e7-e5, 2. Qd1-h5 Bf8-c5, 3. Bf1-c4 Ng8-f6, 4. Qh5xf7#. Even though they reach the same position after White's third move, they get there through different move orders and are therefore counted as two different games. On the other hand it doesn't matter how many times the same sequence of moves has been played throughout chess history. If it's exactly the same sequence, it counts as one game.

The assumption in Shannon's paper is that the 50-move rule and the rule of threefold repetition ensure that a game of chess cannot go on forever, and that therefore the number of possible games is finite. This isn't strictly valid under standard tournament play, since one of the players must claim a draw in order for the rules to apply. But let's go with the assumption that a game ends as soon as the same position is repeated three times or 50 moves (100 consecutive "ply") are made without a capture or a pawn move.

Shannon's idea was that a normal game lasts about 40 moves (40 for each player, so 80 ply), and that in an ordinary position there are about 30-35 move options. That gives roughly 1000 possibilities for a pair of a white and a black move, and $1000^{40} = 10^{120}$ is Shannon's number.

What he wanted to point out was just that the obvious algorithm of recursively tracing through the whole game tree of chess isn't practical. He must surely have been aware that the estimate of $10^{120}$ is ridiculously off the mark. The true number of games is way way, way, larger. Notice that the 50-move rule and the rule of threefold repetition didn't even enter Shannon's calculation, and without them the number of games would have been infinite.

Anyway, let's imagine that we are navigating through the space of all chess games, inspecting various specimens at random. What do we see? The first thing we notice is that the games don't make sense from a player's point of view, since the pieces just move aimlessly. The next thing that strikes us is that most games are really long. This is because there are many more different ways of playing hundreds of moves than there are ways of playing 30 or 40 moves.

A back-of-the-envelope calculation shows that if we start by pushing all the white pawns to the third rank and the black pawns to the sixth rank to create some space, and then just shuffle the pieces around, pushing a pawn every 50 moves, we can keep going for well over 2000 moves capturing only two white and two black pawns. Even though this puts some restrictions on the number of move options available, we can make sure that each piece except the pawns always has at least one move option. Avoiding threefold repetition is a little bit of a hassle, but still there must easily be more than $10^{4000}$ different games.

An equally rough estimate (!) shows that the games that last at most 700 moves don't give more than $10^{3500}$ possibilities, meaning they are outnumbered by the longer games by a mind-boggling factor of at least $10^{500}$. According to a list of world records in chess, the longest known tournament game lasted for 269 moves. But as we fly through the space of all chess games, we never encounter a game as short as that one.

And how does a "typical" game start? In tournament play, 1. e2-e4 has been the most common first move throughout most of chess history, with 1. d2-d4 being about equally popular in the last century. But from our spaceship, we don't see a single game starting with a pawn move! The games we see from our window all start with White making one of the four possible knight moves, and Black responding similarly with a knight.

This is because for every game that starts with some pawn move, for instance 1. e2-e4, there is a corresponding astronomical number of games that start with the players developing their knights, then moving them around for a while, finally returning them to their original squares just before move 50, and White only then playing e2-e4.

For instance, the famous Opera game started 1. e2-e4, and ended with White checkmating with 17. Rd1-d8#. That's one game. But it has 16 siblings that start with White and Black each making a knight move, then going back with the knights, and continuing 3. e2-e4, ... 19. Rd1-d8#. And it has several hundred cousins that start by the knights jumping around for another two moves before playing 5. e2-e4, ... , 21. Rd1-d8#, and so on. The number of ways that the knights can jump around (and rooks move back and forth) returning to the starting position at move 48 is astronomical (quiz: in how many ways can they return after move 49?).

So the typical citizen in the space of all chess games is a game where the first 45 or so moves by each player are made by knights and rooks, and where in the next few hundred moves, a pawn is pushed only about every 50 moves.  

So given that there are more than $10^{4000}$ games, does this mean that to play perfect chess we would need a computer capable of performing that many logical operations?

Actually no. We could solve chess completely with far fewer than $10^{120}$ operations, so in that sense, the Shannon number is completely off in the other direction too!

This is because the number of chess positions is much smaller than the number of games. To see this, notice that in a chess position, each of the 64 squares can be in only 13 different states: empty, or occupied by a black or white piece of one of the six types. In addition, we need to keep track of who is about to move, castling rights, and possible captures by en-passant. But all this can be encoded if we let the squares have 14 states instead of 13. Even without taking into account that each player must have exactly one king, at most 16 pieces and so on, we easily estimate (!) the number of chess positions to be at most $10^{74}$.

The idea that a chess endgame can be understood by considering just the positions it can lead to, rather than the much larger number of lines of play, is what lies behind endgame databases. But long before computers it was implicit in the concept of corresponding squares. In particular, it's interesting that the winning strategy from the famous Lasker-Reichhelm position can be completely understood by a human, despite the vast number of possible lines of play.

Even $10^{74}$ is a very rough upper bound, and in order to play perfect chess we probably don't have to examine more than a tiny fraction of the space of all positions. Presumably there is a much smaller set of key positions that would suffice for a complete "endgame database" from the starting position.

At a dinner a couple of years ago I discussed with Anders Sandberg whether solving chess would be feasible. We agreed that yes, we probably have enough resources already in our own solar system! We just need to send a swarm of self-replicating robots to Jupiter, transforming the planet into a giant chess computer, and most likely we'll get the answer!

Tuesday, August 20, 2019

Testing the chess clock!

In my last blog post I described a new type of chess clock, or rather a new type of time limit: the double-flag system. In short, this is a format of time control where bonus time can only be used in order to obtain a draw, not for playing for a win.

After the publication of that post, we actually tested the clock at Solrosen ("The Sunflower", a vegetarian restaurant and chess club in Gothenburg). I had written a Python hack (code below!) that allowed us to use my laptop as a chess clock. The layout is similar to the display of an ordinary digital chess clock, and to press the clock you press the keys 'P' and 'Q' respectively. In order for those keys to be clearly visible I had attached pieces of red paper on them. It's not as convenient as a real chess clock, but it works.


In order to put the clock to the test, we played with a time limit that's in reality too short for us patzers: 5 minutes each plus a bonus of 5 to 30 seconds. The "5 to 30 seconds" means (as explained in the previous blog post) that when your 5 minutes of main time have run out, you get another 30 seconds, but now your opponent has the right to claim a draw at any time (and it counts as a draw even if you checkmate your opponent on the board). When playing on the extra time, you also get a bonus "increment" of 5 seconds per move, under the constraint that your accumulated extra time will never exceed 30 seconds (details in the earlier post).

This means that in any single game, at most one player will reach the phase of extra time. Whenever the other player runs out of their main time too, the game is automatically drawn.

Normally we want to focus on the board and not the clock (this is the point of the new system!), but this time the purpose was to see if the double-flag clock makes sense in practice.

I met with my friends Anders and Bertil at Solrosen, and later some spectators joined us.

In the first game I had the black pieces against Anders, who launched the four pawns attack against my king's indian. My position was a bit cramped in the opening, but eventually I could untangle my pieces. I won an exchange when Anders missed a nasty Bd4+ Kh1 Nf2+ Rxf2 Bxf2. After that he had a difficult position with the seconds ticking away. When his five minutes had run out and he was playing on extra time, I had a minute or so left. It was still not clear if I would be able to checkmate in time. I found a queen check on the first rank, first thinking it would force a queen exchange, but as Anders realized before me, it was impossible to prevent a back-rank mate!

In the second game I was white against Bertil and chose the Tarrasch variation against his French defence. Bertil played aggressively and tried a line where he gave two minor pieces for a rook and two pawns by taking twice on c3 and forking my rooks on a1 and e1 (is this winning or sacrificing material?!). In any case it slowed down my development, but I had four minor pieces against his two in the middle-game. Eventually I got some play against his king, but at that point none of us had much time left. Bertil was the first to run out of the main five minutes, meaning I could play for a win without risk. I didn't have enough time to grind down a long endgame, but there were possibilities like the bishop sacrifice Bxh6 followed by coordinating the queen and a knight. But Bertil calmly defended. With 10 seconds or so left I thought I'd try the piece sacrifice anyway since I had nothing to lose. But then Bertil threw in a queen move threatening a perpetual check. I had to find a defensive move, and those last seconds ran out. That meant that the new possibility, draw on time, had now been realized!

In the third game Bertil played white against Anders. I was talking to some of the bystanders and didn't follow the game closely, but took a couple of photos that show Anders playing the Budapest gambit.


Eventually Bertil got the upper hand with pressure against Anders' king as well as a dangerous pawn on the queenside. Bertil could play faster and had more than two minutes when Anders went into extra time. Anders kept fighting, but 5 seconds per move isn't much in a difficult position. Finally Anders lost on time in a position that must have been very hard to defend.

After these three games we chatted with the other guys and didn't play any more that evening. But I felt that the clock had passed the first test, and several people thought it was an interesting idea!

Python code

Below is the Python code for the clock. As I said it's a hack, and it was translated from a prototype written in another language. Anyway, for what it's worth...

To try it out, even if you don't know any programming, just download a Python programming environment (for instance PyCharm) for free, check out how to create a python file, and copy-paste the code into it. And if you do know some programming, you might want to tell me how the program should have been written...

The clock has a simple layout with digital displays and six buttons for various time controls. You start it by pressing 'P' or 'Q'. It can be paused (and resumed) with the space bar.

The main time is displayed with black digits (or green, but we'll get to that in a moment), and extra time with red digits. Depending on how much time is left, it displays either hours:minutes.seconds, just minutes.seconds, or minutes.seconds.tenths.

The "Rapid", "Blitz", and "Bullet" options are quite simple, with time limits given on the buttons. There's also a "Test" option giving each player just 15 seconds, for demonstrating how the clock works.

The "Classical" option has two periods of main time (and then extra time as usual): 1h 45min for the first 40 moves, and 15 more minutes for the rest of the game. To distinguish the periods, the first one is displayed in green and the second in black. The clock doesn't count moves: When the green time is out, it just switches to the black 15 minutes (and finally to the red extra time).


There is also a "Customized" option. It's initially set to the rather serious mode of 2 hours for the first 40 moves followed by 30 minutes for the remaining game, with extra time of 30 seconds to 10 minutes. To actually customize this option, you can go into the program code, lines 208-210 in my code editor. It's in the class "Game" and under the definition of the "new_custom" method. Just below the line that says "def new_custom(self):", there are three lines that currently read:

        self.leftTime, self.rightTime = 7200, 7200
        self.A, self.b = 600, 30
        self.leftExtra, self.rightExtra = 1800, 1800

The first of these three lines determines the length of the first period of main time, in seconds (7200 seconds = 2 hours). This can be set individually for the left and right player by the way. The second line sets the initial batch of extra time and the increment per move, in this case 600 seconds (=10 minutes) and 30 seconds. As the program is designed, these are the same for both players. The third line sets the length of the (optional) second period of main time. To avoid a second period, just set it to zero.

Alright, the code. Have fun!


from tkinter import *
import time

root = Tk()
root.title("Double-Flag Chess Clock")

mainBackground = "light blue"

root.geometry("950x360+0+0")
root.configure(background=mainBackground)

leftDisplay = Label(root, font=("Typewriter", 96), bg="light yellow")
leftDisplay.place(x=50, y=50, width=400, height=150)

rightDisplay = Label(root, font=("Typewriter", 96), bg="light yellow")
rightDisplay.place(x=500, y=50, width=400, height=150)

qLabel = Label(root, font=("System", 18), anchor=W, bg=mainBackground)
qLabel.place(x=50, y=20, width=400)
qLabel.config(text='Q to press clock')

pLabel = Label(root, font=("System", 18), anchor=E, bg=mainBackground)
pLabel.place(x=500, y=20, width=400)
pLabel.config(text='P to press clock')

modeLabel = Label(root, font=("System", 18), anchor=W, bg=mainBackground)
modeLabel.place(x=50, y=200, width=400)
modeLabel.config(text="Mode: Blitz")


def reset_display():
    leftDisplay.config(fg="black")
    rightDisplay.config(fg="black")
    pLabel.config(text="P to press clock")
    qLabel.config(text="Q to press clock")


classicalString = "Classical: 1h 45min + 15min + (30s to 5min)"
rapidString = "Rapid: 15min + (10 to 60s)"
blitzString = "Blitz: 5min + (5 to 30s)"
bulletString = "Bullet: 2min + (5 to 10s)"
customString = "Customized"
testString = "Test"


def classical_callback():
    if g.paused or g.gameOver or (not g.leftRunning and not g.rightRunning):
        g.new_classical()
        reset_display()
        modeLabel.config(text="Mode: Classical")
        leftDisplay.config(fg="dark green")
        rightDisplay.config(fg="dark green")


classicalButton = Button(root, text=classicalString,
                         highlightbackground=mainBackground,
                         command=classical_callback)
classicalButton.place(x=50, y=240, width=400)
classicalButton.config(bg="green")


def rapid_callback():
    if g.paused or g.gameOver or (not g.leftRunning and not g.rightRunning):
        g.new_rapid()
        reset_display()
        modeLabel.config(text="Mode: Rapid")


rapidButton = Button(root, text=rapidString,
                     highlightbackground=mainBackground,
                     command=rapid_callback)
rapidButton.place(x=500, y=240, width=400)


def blitz_callback():
    if g.paused or g.gameOver or (not g.leftRunning and not g.rightRunning):
        g.new_blitz()
        reset_display()
        modeLabel.config(text="Mode: Blitz")


blitzButton = Button(root, text=blitzString,
                     highlightbackground=mainBackground,
                     command=blitz_callback)
blitzButton.place(x=500, y=270, width=400)


def bullet_callback():
    if g.paused or g.gameOver or (not g.leftRunning and not g.rightRunning):
        g.new_bullet()
        reset_display()
        modeLabel.config(text="Mode: Bullet")


bulletButton = Button(root, text=bulletString,
                      highlightbackground=mainBackground,
                      command=bullet_callback)
bulletButton.place(x=500, y=300, width=400)


def test_callback():
    if g.paused or g.gameOver or (not g.leftRunning and not g.rightRunning):
        g.new_test()
        reset_display()
        modeLabel.config(text="Mode: Test")
        if g.leftExtra > 0:
            leftDisplay.config(fg="dark green")
            rightDisplay.config(fg="dark green")


testButton = Button(root, text=testString,
                    highlightbackground=mainBackground,
                    command=test_callback)
testButton.place(x=50, y=300, width=400)


def custom_callback():
    if g.paused or g.gameOver or (not g.leftRunning and not g.rightRunning):
        g.new_custom()
        reset_display()
        modeLabel.config(text="Mode: Customized")
        if g.leftExtra > 0:
            leftDisplay.config(fg="dark green")
            rightDisplay.config(fg="dark green")


customButton = Button(root, text=customString,
                      highlightbackground=mainBackground,
                      command=custom_callback)
customButton.place(x=50, y=270, width=400)


def enable_modes():
    classicalButton.config(state=NORMAL)
    rapidButton.config(state=NORMAL)
    blitzButton.config(state=NORMAL)
    bulletButton.config(state=NORMAL)
    testButton.config(state=NORMAL)
    customButton.config(state=NORMAL)


def disable_modes():
    classicalButton.config(state=DISABLED)
    rapidButton.config(state=DISABLED)
    blitzButton.config(state=DISABLED)
    bulletButton.config(state=DISABLED)
    testButton.config(state=DISABLED)
    customButton.config(state=DISABLED)


class Game:
    def __init__(self):
        self.leftTime, self.rightTime = 300, 300
        self.reference = 0
        self.leftRunning, self.rightRunning, self.paused = FALSE, FALSE, FALSE
        self.nLeftFallen, self.nRightFallen = 0, 0
        self.gameOver = FALSE
        self.A, self.b = 30, 5
        self.leftExtra, self.rightExtra = 0, 0   # Time added after 40 moves

    def new_classical(self):
        self.leftTime, self.rightTime = 6300, 6300
        self.reference = 0
        self.leftRunning, self.rightRunning, self.paused = FALSE, FALSE, FALSE
        self.nLeftFallen, self.nRightFallen = 0, 0
        self.gameOver = FALSE
        self.A, self.b = 60, 10
        self.leftExtra, self.rightExtra = 900, 900

    def new_rapid(self):
        self.leftTime, self.rightTime = 900, 900
        self.reference = 0
        self.leftRunning, self.rightRunning, self.paused = FALSE, FALSE, FALSE
        self.nLeftFallen, self.nRightFallen = 0, 0
        self.gameOver = FALSE
        self.A, self.b = 60, 10
        self.leftExtra, self.rightExtra = 0, 0

    def new_blitz(self):
        self.leftTime, self.rightTime = 300, 300
        self.reference = 0
        self.leftRunning, self.rightRunning, self.paused = FALSE, FALSE, FALSE
        self.nLeftFallen, self.nRightFallen = 0, 0
        self.gameOver = FALSE
        self.A, self.b = 30, 5
        self.leftExtra, self.rightExtra = 0, 0

    def new_bullet(self):
        self.leftTime, self.rightTime = 120, 120
        self.reference = 0
        self.leftRunning, self.rightRunning, self.paused = FALSE, FALSE, FALSE
        self.nLeftFallen, self.nRightFallen = 0, 0
        self.gameOver = FALSE
        self.A, self.b = 10, 5
        self.leftExtra, self.rightExtra = 0, 0

    def new_test(self):
        self.leftTime, self.rightTime = 15, 15
        self.A, self.b = 15, 5
        self.leftExtra, self.rightExtra = 0, 0
        self.reference = 0
        self.leftRunning, self.rightRunning, self.paused = FALSE, FALSE, FALSE
        self.nLeftFallen, self.nRightFallen = 0, 0
        self.gameOver = FALSE

    def new_custom(self):
        self.leftTime, self.rightTime = 7200, 7200
        self.A, self.b = 600, 30
        self.leftExtra, self.rightExtra = 1800, 1800
        self.reference = 0
        self.leftRunning, self.rightRunning, self.paused = FALSE, FALSE, FALSE
        self.nLeftFallen, self.nRightFallen = 0, 0
        self.gameOver = FALSE


g = Game()


def key_pressed(event):

    if event.char == 'p' and not g.paused and not g.leftRunning and not g.gameOver:
        disable_modes()
        g.rightRunning = FALSE
        pLabel.configure(text="")
        if g.nRightFallen == 1:
            if g.rightTime > g.A - 2*g.b:
                g.rightTime = (g.A + g.rightTime) / 2
            else:
                g.rightTime += g.b
        g.reference = g.leftTime + time.time()
        g.leftRunning = TRUE
        qLabel.configure(text="Q to press clock")

    if event.char == 'q' and not g.paused and not g.rightRunning and not g.gameOver:
        disable_modes()
        g.leftRunning = FALSE
        qLabel.configure(text="")
        if g.nLeftFallen == 1:
            if g.leftTime > g.A - 2*g.b:
                g.leftTime = (g.A + g.leftTime) / 2
            else:
                g.leftTime += g.b
        g.reference = g.rightTime + time.time()
        g.rightRunning = TRUE
        pLabel.configure(text="P to press clock")

    if event.char == ' ' and (g.leftRunning or g.rightRunning):
        g.paused = not g.paused
        if g.paused:
            enable_modes()
        else:
            disable_modes()
        if not g.paused and g.leftRunning:
            qLabel.configure(text="Q to press clock")
            g.reference = g.leftTime + time.time()
        if not g.paused and g.rightRunning:
            pLabel.configure(text="P to press clock")
            g.reference = g.rightTime + time.time()
        if g.paused and g.leftRunning:
            qLabel.configure(text="Paused")
        if g.paused and g.rightRunning:
            pLabel.configure(text="Paused")


root.bind("<Key>", key_pressed)


def update_clock():
    if g.leftRunning and not g.paused and g.nLeftFallen == 0:
        g.leftTime = g.reference - time.time()
        if g.leftTime < 0:
            if g.leftExtra > 0:
                g.leftTime = g.leftExtra
                g.leftExtra = 0
                leftDisplay.configure(fg="black")
            else:
                g.leftTime = g.A
                g.nLeftFallen = 1
                leftDisplay.configure(fg="red")
                if g.nLeftFallen + g.nRightFallen >= 2:
                    g.gameOver = TRUE
                    g.leftRunning = FALSE
                    g.rightRunning = FALSE
                    qLabel.config(text="1/2")
                    pLabel.config(text="1/2")
                    enable_modes()
            g.reference = g.leftTime + time.time()

    if g.leftRunning and not g.paused and g.nLeftFallen == 1:
        g.leftTime = g.reference - time.time()
        if g.leftTime < 0:
            g.leftTime = 0
            g.nLeftFallen = 2
            g.gameOver = TRUE
            g.leftRunning = FALSE
            g.rightRunning = FALSE
            qLabel.config(text="0")
            pLabel.config(text="1")
            enable_modes()

    if g.rightRunning and not g.paused and g.nRightFallen == 0:
        g.rightTime = g.reference - time.time()
        if g.rightTime < 0:
            if g.rightExtra > 0:
                g.rightTime = g.rightExtra
                g.rightExtra = 0
                rightDisplay.configure(fg="black")
            else:
                g.nRightFallen = 1
                g.rightTime = g.A
                rightDisplay.configure(fg="red")
                if g.nLeftFallen + g.nRightFallen >= 2:
                    g.gameOver = TRUE
                    g.leftRunning = FALSE
                    g.rightRunning = FALSE
                    qLabel.config(text="1/2")
                    pLabel.config(text="1/2")
                    enable_modes()
            g.reference = g.rightTime + time.time()

    if g.rightRunning and not g.paused and g.nRightFallen == 1:
        g.rightTime = g.reference - time.time()
        if g.rightTime < 0:
            g.rightTime = 0
            g.nRightFallen = 2
            g.gameOver = TRUE
            g.leftRunning = FALSE
            g.rightRunning = FALSE
            qLabel.config(text="1")
            pLabel.config(text="0")
            enable_modes()
    lh = int(g.leftTime / 3600)
    lm = int(g.leftTime / 60) % 60
    ls = int(g.leftTime) % 60
    lt = int(g.leftTime * 10) % 10
    rh = int(g.rightTime / 3600)
    rm = int(g.rightTime / 60) % 60
    rs = int(g.rightTime) % 60
    rt = int(g.rightTime * 10) % 10
    if lh > 0:
        leftDisplay.config(text=f'{lh:01}' + ':' + f'{lm:02}' + '.' + f'{ls:02}')
    elif lm > 0:
        leftDisplay.config(text=f'{lm:02}' + '.' + f'{ls:02}')
    else:
        leftDisplay.config(text=f'{lm:02}' + '.' + f'{ls:02}' + '.' + f'{lt:01}')
    if rh > 0:
        rightDisplay.config(text=f'{rh:01}' + ':' + f'{rm:02}' + '.' + f'{rs:02}')
    elif rm > 0:
        rightDisplay.config(text=f'{rm:02}' + '.' + f'{rs:02}')
    else:
        rightDisplay.config(text=f'{rm:02}' + '.' + f'{rs:02}' + '.' + f'{rt:01}')
    root.after(20, update_clock)  # run itself after given number of milliseconds


# run first time
update_clock()

root.mainloop()




Tuesday, June 11, 2019

The double-flag chess clock, a timer for games with reversible moves

A new type of chess clock could improve the game. By allowing bonus time only in order to play for a draw, we can avoid meaningless time scrambles and at the same time have fewer long-winded games.

Moreover, the "double-flag" system would let us abandon the 50-move rule and the rule of threefold repetition. Apart from opening the possibility of playing out certain winning lines, this would allow players in long endgames to focus on the position on the board without counting moves and repetitions.

Game clocks


Many abstract strategy games are played in organized tournaments and international championships: Chess, Go, Backgammon, Scrabble, Draughts, Othello, Magic the Gathering and so on.

Competitions in such games require some method of restricting the amount of time that the players can spend on their moves. For this purpose, chess clocks were introduced in the late nineteenth century as the first international chess tournaments were arranged.


A chess clock has one clock and one button for each player. After making your move, you press your button, thereby stopping your own clock and starting your opponent's. A traditional analog clock has a flag (hinged at a couple of minutes before 12 o'clock) for each player that shows indisputably whether or not they have run out of time.

A chess clock is also convenient for casual play. It allows the players to agree in advance on how long the game should take, and to allocate their own time as they wish. You don't have to be annoyed when your opponent spends a lot of time on a move, and you don't have to apologize when you do the same.

And the clock can be used for a variety of games, look for instance at Chess Clock Jenga!

Games with reversible moves


Some games, by the nature of their rules, progress inevitably towards their conclusion. In Othello a new disc is placed on the board at every move, and the discs are never removed. Not counting pass moves, there can therefore be at most 60 moves in a game.

For such games, the simplest form of time limit makes sense: A fixed amount of time, for instance 30 minutes per player, for the whole game.

In other games like chess and draughts, pieces can move back and forth and there is no practical upper limit on the number of moves in a game. In such games, a fixed time limit for the whole game doesn't necessarily work well: The clock provides a new way of winning, and this can be abused.

Suppose for instance that in a game of chess, a position is reached where each player has only a king and a rook:


In such a position it's impossible to make any kind of progress unless the opponent makes a very unlikely blunder. But neither can anyone force the game to end. It ought to be a draw, but a player determined to try to win can keep moving indefinitely. If the game is played with a fixed time limit, a player with better manual dexterity can keep moving until the opponent runs out of time.  

One might have thought that something as silly as this couldn't take place in serious tournament play, but it can actually occur at the highest level. The infamous game between Monika Soćko and Sabina-Francesca Foisor from the women's world championship in 2008 (which can be seen around 1.30 to 2.30 into this video) led to the even more ridiculous king and knight versus king and knight endgame, which White eventually won by playing on until Black ran out of time.

This is not in the spirit of the game, and hardly compatible with ideas of everyone, young, old or physically disabled, competing on the same premises.

Even with many pieces on the board, a game can pass a point of no return after which it becomes obvious that none of the players has enough time to finish the game. The 2008 US women's championship was decided by a tie-break game between Irina Krush and Anna Zatonskih where, after a number of nonsense moves on the side of the board closest to the clock, Zatonskih won on time in a lost position with one second left on her clock.

As was pointed out in an excellent article by Tom Braunlich written shortly after the Soćko - Foisor game, this sort of thing is a consequence of the rules, not something nefarious that the players are doing to cheat.

These games were played more than ten years ago, but so-called armageddon games are still used as tie-break in international championships. Something equally absurd could have decided last year's world championship match between Magnus Carlsen and Fabiano Caruana, and no amount of sportsmanship on the part of the players would have resolved the issue.

Bonus time and rules for claiming a draw


In order to avoid meaningless "time scrambles", practice since the early days of tournament chess is to allow more time as the game progresses. A system like 2 hours for the first 40 moves and then another hour for every 20 moves (plus time remaining) is easily implemented with a mechanical clock: Every time a flag falls, the player must have made at least the prescribed number of moves.

Nowadays games are required to finish quicker, but digital clocks allow for systems of bonus time (also called increment or add-on) per move, where for instance 30 seconds are added to a player's time at every move.

But this still doesn't solve the problem of how to claim a draw. Special rules (50-move rule, threefold repetition) are required in order to make it possible to claim a draw in a position where an opponent keeps playing without making progress.

The 50-move rule is a compromise which is somewhat flawed at both ends: On one hand it means that some endgames become drawn even though they could otherwise be won. These endgames famously include some positions with king, rook and bishop against king and rook. And something like K+B+B+N vs K+R would even be an easy win for a moderately skilled player, were it not for the 50-move rule. There are also examples with many pieces on the board where the 50-move rule has been highlighted. In the beginning of this video, Magnus Carlsen explains that (in this game against Veselin Topalov, London 2015) he had to allow the exchange of a pair of knights, thereby severely diminishing his winning prospects, because the 50-move limit was approaching.

On the other hand, the 50-move rule is often insufficient and difficult to implement, especially at fast time controls but also in endgames with mobile pawns.

Even though the old article 10.2 has now been removed, the official FIDE rules (Guidelines III) still include situations where an arbiter may have to assess whether a player makes "sufficient attempts to win by normal means".

There have been, over the years, extensive discussions and several changes in regulation of time controls and situations in which a player can claim a draw (see for instance this discussion of the history of the 50-move rule by Edward Winter).

Distractions in long endgames


We have mentioned some rather spectacular situations, but the rules for time control and claiming draws are influencing many games. Let's look at a fairly common situation: We are far into an endgame and one player has an advantage, say queen versus rook. There is nothing special about this, the same remarks would apply to many other endgames.


Although K+Q vs K+R is a well-known theoretical win for the stronger side, it's quite challenging against good defence. But under current rules there will always be distractions from trying to play the endgame well. Suppose first that the game is played under a fixed time limit, so-called "sudden death". Since this sort of position only occurs near the end of an unusually long game, the rule rather than the exception is that both players are short of time. 

If White has better time, they might try to win by moving aimlessly but quickly. When it succeeds, the result will appear to be fair since after all White had a theoretical win. Again notice that White may have had the best intentions, but they too were in time trouble and could have lost if they had spent the time trying to play with precision.

Assuming that White tries to win on the board, another problem presents itself: How long does White dare to play for a win? If White is down to only a few seconds, there is suddenly a risk of losing. This means that White might have to keep an "emergency exit" by playing in such a way that they can force an exchange of the last pieces or a perpetual check if needed. 


If on the other hand the game is played with a classical time limit and a 30 second bonus, there are other distractions. White can now start by rattling off a number of aimless checks, this time in order to accumulate time of their own rather than to make their opponent spend theirs. In the position of the diagram, White could for instance (depending on where the black king moves) give checks on g5, g6, h5, h6 and then g5 again, collecting a couple of minutes of extra time.

But all of a sudden the players have to try to keep track both of the number of moves played since the last pawn move or capture, and of the positions that have occurred before (and those that have occurred twice). And White has to manage a trade-off between gaining time on the clock and staying within the 50-move limit.

The double-flag chess clock


The purpose of this post is to describe a simple system for time control that solves all the problems we have mentioned at once. I'd like to call it the double-flag chess clock. The idea is to have a system of bonus time, but to allow the bonus to be used only in order to obtain a draw.

Let's first look at how this might work in a simple example setting of rapid chess. First the players are given a fixed amount of time, say 15 minutes, that we call the main time. In order to win the game, you have to checkmate your opponent without using more time than this (unless they resign or overstep both their main and their extra time).

If a player uses up their 15 minutes before the end of the game, their first flag falls. They can now no longer win the game (even if they checkmate their opponent!) but are allowed to play on for a draw. At this point they are given a batch of extra time, let's say 1 minute. In this new phase of the game, they (but not their opponent!) will be given a bonus per move that guarantees they always have at least a certain minimum, say 10 seconds, for every move. But the bonus system will be designed so that they can never accumulate more extra time on the clock than 60 seconds (the initial amount).

There are a couple of different ways of implementing this idea (as discussed below). What I will suggest is that when a player using extra time presses the clock, the full bonus of 10 seconds will be added if they have up to 40 seconds left, while if they have between 40 and 60 seconds, the bonus is half of what remains up to 60. For instance, if they have 44 seconds before pressing the clock, 8 seconds will be added and the display will read 52 seconds once they have pressed the clock.

Let's say that Black runs out of their 15 minutes of main time while White still has some of their main time left. Now White can, whenever they wish, stop the game and claim a draw. If White chooses to play on, there are a couple of possibilities. If the game ends on the board with a white win or a draw, then that is the result of the game. But if Black wins on the board while playing on their extra time, the game counts as a draw.

If Black oversteps time again, by failing to move within the stipulated extra time, then they have actually lost the game on time. The final possibility is that White too oversteps their main 15 minutes. If this happens, the game is drawn regardless of the position on the board.

Features of the double-flag system


Let's see how the double-flag system solves the problems we have mentioned. Suppose first that we arrive at a "meaningless" endgame like king and one piece against king and the same sort of piece. Since a player using their extra time can never be forced to overstep it, the outcome if their opponent insists on playing is that eventually they too will run out of their main time and the game will be drawn.

If in a complicated position both players are about to run out of their main time, there will not be a nonsense time scramble for a full point. Instead the logical conclusion is again a draw. If both players are down to only a few seconds of main time, it doesn't matter who runs out of it first, and there is no point in making quick nonsense moves. You might try to bamboozle your opponent with a surprising king's attack though!

Since the game cannot go on indefinitely anyway, the 50-move rule is no longer needed. And neither is the rule of threefold repetition, which too is a hassle in cases other than direct repetition. This means for instance that if a player reaches K+B+N against a bare king with 5 minutes of main time remaining, they will have 5 minutes to try to figure out how to checkmate, regardless of whether it takes them 30 or 60 moves. On the other hand they can't hope to win on time and there is no point in even trying.

In a normal but long endgame, players will be able to focus on the board without being unnecessarily distracted by having to look at the clock or the protocol. There is no need to count moves or repetitions.

Long-winded play and repetition of positions can never increase winning chances, but favours a player trying to draw. This gives the players the correct incentives: In a position like K+Q vs K+R discussed earlier, White is the one who has to try to make progress in order to win, while Black will be happy to give repeated checks or retain status quo. And if White runs out of time, they can, for all practical purposes, claim a draw just like they could if Black didn't have checkmating material.

Designing the bonus system


There are systems of time control already in use that limit the accumulation of bonus time. With Bronstein delay, a player can get back the time they spent on the last move, but not more than that. In Go, a system called byo-yomi has a similar effect: A certain minimum time per move is guaranteed, but bonus time cannot be accumulated.

The bonus system for the double-flag clock can be regarded as a hybrid between delay and add-on: Bonus time can be accumulated, but only up to a certain threshold.

The reason it shouldn't be possible to accumulate bonus time beyond the initial amount is that a player whose first flag is about to fall should never be able to gain anything by letting their main time run out in order to get more quickly to the bonus per move. With the initial amount as an upper limit on the accumulation of extra time, it will always be better to run out of main time at a later stage: You obtain the initial batch of extra time when your main time runs out, and you could not have had more at that point in the game if your first flag had fallen earlier.

Let's look at some possible implementations, assuming again (as an example) that the minimum time per move is 10 seconds and the maximum accumulated bonus is 60 seconds.

1. Truncated bonus: The simplest implementation of a bonus system satisfying the requirements is just truncating the extra time at 60 seconds. When you make a move playing on extra time, the full 10 second bonus will be added, except if you already have more than 50 seconds, in case the extra time will be set to 60 seconds. The addition of the bonus follows the formula
\[ t \mapsto \min(t+10, 60).\]
A slight flaw of the truncated system is that a player with more than 50 seconds of extra time has no incentive of moving immediately, even if they have decided what to play.

2. Linear bonus: We might therefore prefer the added bonus to decrease gradually as the accumulated time approaches the 60 second limit. An alternative to a truncated system is a linear one, where the added bonus decreases linearly from 10 seconds when the time remaining is essentially zero, to nothing if you already have 60 seconds. This is the same thing as saying that the time added always takes you one sixth of what remains up to 60 seconds. Mathematically:
\[ t \mapsto t + 10 - \frac{10}{60}\cdot t.\]
But with a purely linear system, it might be annoying that the bonus decreases too quickly even at moderate levels of accumulated extra time.

 3. Hybrid linear: What I suggest, again to minimize distraction of the players, is a hybrid system where the full 10 seconds are added as long as the player has at most 40 seconds (the initial amount minus two times the minimum per move) when pressing the clock. Above that, the bonus decreases linearly, which means that the time on the clock is taken half-way up to 60 seconds. With mathematical notation,
\[ t \mapsto \min\left(t+10, \frac{t+60}{2}\right).\]
For example, if a player presses the clock with 42 seconds of extra time, the new time is 51 seconds, while if they press it with 58 seconds remaining, the time is adjusted to 59 seconds.

Classical time limit


The double-flag system can be implemented on all time-scales. For a classical game we normally want to encourage good endgame play by adding extra time at move 40. One possibility would be to let the main time consist of an initial 1h 30 min, or perhaps 1h 45 min to better suit players accustomed to the "90+30"-tempo, and a secondary 15 or 30 minutes added after 40 moves.

With such a system, no mercy needs to be given a player who oversteps the time for the first 40 moves. Only after the final period of main time should there be extra time available for holding a draw. For the extra time we might have a bonus of the usual 30 seconds per move, and a maximum accumulated bonus of 5 or perhaps 10 minutes.

New possibilities


Apart from the advantages already mentioned, the double-flag clock offers new possibilities at both ends of the spectrum from bullet to classical games.

Abandoning the 50-move rule will allow players to treat certain endgames correctly, but there are other consequences: In a game where one player has run out of their main time, the other player might try a dangerous line in order to stir up winning chances in a position where they would normally have played safely to secure a draw. This could lead to interesting play that would otherwise not have occurred on the board.

At the faster end of the spectrum, the double-flag system offers possibilities of playing interesting games even at "bullet" or "lightning" time controls (1-2 minutes). Under traditional rules, the game deteriorates to a parody of chess as the time is decreased. With the double-flag system, sensible (but aggressive) play is rewarded, and the game remains a miniature version of chess. At extremely fast time controls it just becomes drawish.

Since the double-flag system would allow serious competition at very fast time controls, we can even imagine bullet chess becoming recognized as an e-sport!

Related ideas


The idea that one doesn't necessarily lose the game when time runs out seems historically to have preceded the more modern notion that the game is immediately lost when the flag falls.

The primitive chess clocks of the late 19:th century weren't very exact, and the first consequence of overstepping time seems to have been that a tournament director requested you to play faster. According to this article, you could also be fined.

principle that has been applied in Othello (IV 6. Time Defaults) is that if your flag falls, you are given two minutes of extra time that can only be used in order to minimize the margin of loss. If the player who lost on time later wins or draws on the board, the score will be 33-31 (the smallest possible win) in favour of their opponent. My guess is that the reason for this rule is that rewarding a player with a 64-0 victory for their opponent's bad time management might be considered unfair to a third party.

Advantages of the double-flag system, in short


Games are finished in time.

No nonsense time scrambles.

Long-winded play never increases winning chances.

Allows us to abandon the 50-move rule and the rule of threefold repetition.

Promotes good play and focus on the board.

Allows sensible blitz and bullet games.