18

Disclaimer: I know very little about chess: basically, how to put pieces on the board, how to move them, and how to lose (I'm a pro at this). I have no idea about my Elo rating, but I guess it's in the two digits range. Thus, please be forgiving of possible blunders in my question.

One of the few things I thought to know was that today computers are stronger than humans at chess. Programs such as Stockfish, Komodo and Leela Chess Zero should be able to regularly beat GrandMasters, and even give the World Champion a hard time. However, an acquaintance who is a way better player than me,, told me that you can draw against any computer chess program just by using threefold repetition. In other words, you make your move, the chess program makes its own, you go back, the chess program does the same (??), repeat three times and voilà, you get your draw. He said he used this strategy against chess engines you can play with on the Internet, and it works.

This seems unbelievable:

  1. Even I could write a program which doesn't fall in such a trap. Just compare the current move with the preceding one: if they're the same, increase a counter, otherwise set it to 0. When the counter gets to 2, remove this move from the list of candidate moves. In other words, never perform the same move three times. Of course, there may be cases where actually performing the same move three times could be the best strategy: in that case, just offer a draw to the human opponent. But on the average, just avoid making the same move three times consecutively.

  2. Different chess engines also use very different algorithms (e.g., Leela Chess Zero is based on neural networks, RL, and MCTS, while Stockfish and Komodo use other approaches, including opening databases, list of hard-coded heuristics, etc.), so it seems highly unlikely that a single approach could exist which can force a draw against all existing chess engines.

  3. A chess engine's next move doesn't obviously depend only on my (the human opponent's) current move. I guess it depends on the full move history of the current game, as well as on the estimation, done by the chess engine, of which moves are more likely to lead to victory further down the game. Why should my current move be so important for the chess engine, that it would keep repeating the same move just because I do so?

I conclude that this is "fake news", or at most a silly bug in the chess engines this acquaintance played against (maybe not a major bug, because people who play chess on the Internet probably are not interested in a cheap trick to draw against the computer, but still a bug). But definitely not something that happens when playing against the major chess engines, such as the three I mentioned initially. Am I right?

10
  • 12
    You've basically answered your own question already. You just need to be more sure of yourself.
    – NotThatGuy
    Jan 4, 2020 at 20:08
  • 2
    @NotThatGuy The current board is not always enough to determine the current state of the game in chess. The rule for castling refers to past history: did the king or the relevant rook move previously? So does the rule for en passant captures: did the pawn being captured advance two squares on the immediately previous move? Jan 4, 2020 at 23:44
  • I never before heard of this three fold rule, so if I was the one writing a chess bot, I would probably introduce this exact bug. Jan 6, 2020 at 13:32
  • 4
    You may be interested to know that there is a dedicated Chess Stack Exchange. A question being on-topic on another Stack doesn’t make it off-topic on this one, and this question is fine here, just thought you might want to take a look at that one. (I’m not actually familiar with the Chess Stack and don’t know for certain that this question is on-topic there; it probably would be, but it’s always best to familiarize yourself with a new site’s rules before posting.)
    – KRyan
    Jan 6, 2020 at 19:31
  • 1
    I would just want to point out that computer program would not just "give the World Champion a hard time". They can easily beat any player in the world, for them playing against me (or you) or Magnus Carslen (current World Champion, maybe the best chess player ever) is exactly the same.
    – bznein
    Jan 7, 2020 at 17:07

8 Answers 8

44

What your friend is saying isn't "fake news", it's outright bull****. Of course computers can recognize 3-fold draws, in fact just about the first step of writing a new engine is to tell the engine what the rules of the game are.

Here're the relevant lines in Stockfish's code:

bool Position::is_draw(int ply) const {

 if (st->rule50 > 99 && (!checkers() || MoveList<LEGAL>(*this).size()))
     return true;

 // Return a draw score if a position repeats once earlier but strictly
 // after the root, or repeats twice before or at the root.

 if (st->repetition && st->repetition < ply)
     return true;

 return false;
}
8
  • 3
    @Mark Perhaps it's not "fake news" when it's not "news"?
    – gerrit
    Jan 6, 2020 at 15:20
  • 7
    I agree with the gist of your answer, but this code is simply identifying whether a draw has (or will) occur due to the repetition rule, it is not the code (if any exists in Stockfish) that uses that as a factor in selecting a move. (Strategically, the computer should seek a draw if it is behind, but avoid a draw if it is ahead).
    – BradC
    Jan 6, 2020 at 20:09
  • 7
    @BradC computer always makes the move that maximizes its evaluation. Drawn positions have 0.00 eval. Naturally, if the computer is behind then its eval (assuming it's White) would be negative, and 0.00 > negative values; similarly if it's ahead then its eval would be positive and 0.00 < positive values.
    – Allure
    Jan 6, 2020 at 20:16
  • 8
    Shouldn't !checkers() always be true in a chess engine? Jan 7, 2020 at 11:49
  • 3
    @MateenUlhaq - I thought the same thing! I can't find any reference to a secret checkers-mode in the engine, so it's probably just the other definition of checkers, as in "things that check [something]."
    – Justin
    Jan 7, 2020 at 15:37
20

Point 1 is the crucial one. Unless the coders have omitted the repetition rule altogether, then the bot will calculate its third repetition as leading to a draw. It may still choose it, but only when it calculates that no other alternative is any better - that is, that a draw is the best it can play for assuming you don't blunder. In this situation, either a draw is truly inevitable anyway, or you're throwing away the chance to play for a win by making the repetition.

17

It's possible that your friend has hit upon a sequence that works against a particular engine running at a particular difficulty. But this will almost certainly not generalize.

Engines can have something called a "contempt factor" which causes them to try to avoid draws if they evaluate the position as slightly negative. Whether this is present, and how large this factor is, depends on the individual engine.

Engines do know about threefold repetition, and take it into account. If the engine thinks it is winning, or losing by less than the contempt factor, it will avoid a move that results in threefold repetition, even if that might otherwise be the move it evaluates as best.

Also, strong engines will not always play the same opening. For one engine, if you start with 1.e4, the computer will play 8 different possible replies to that move, with probabilities anywhere from 49% to 2%. There's no way your friend has a line which causes the engine to repeat for all of them.

2
  • 3
    Thanks for bringing up this "contempt factor" - I'd never heard of it and it's a neat idea! On further reading it looks like it is sometimes actually used in both directions - either (as you talk about) to preferentially avoid draws under the assumption that the opponent is weaker than it, or to preferentially seek out draws under the assumption the opponent is stronger! Jan 4, 2020 at 23:07
  • 2
    @BenjaminCosman Maybe OP's friend found an engine with a negative contempt factor, then? That would explain why it seems eager to repeat...
    – D M
    Jan 5, 2020 at 0:15
6

Well, first of all, going "back" is often not an option. Pretty much every opening involves pawn moves, and you can't take those back. You also can't undo captures. So clearly you'll have to do some work just to get into a situation where the computer can take its move back, let alone will.

The computer generally has a attributes that it's working towards, and it will make moves "forward" with respect to those goals, and taking a move back would be going backwards.

During the opening, one of the major goals is development, which generally involves moving pieces towards the center. The computer is going to need a good reason to move its pieces away from the center, and "I just moved my pieces back" hardly qualifies.

In the end game, the computer will be working towards moving its pawns forward, and moving your king away from the center. The first of these can't be undone, and the second can, but the computer has no reason to.

Even I could write a program which doesn't fall in such a trap. Just compare the current move with the preceding one: if they're the same, increase a counter, otherwise set it to 0.

Such a test would be of limited value. Suppose the computer assigns a score to each position equal to the probability it thinks it will win in that position, minus the probability it thinks it will lose. Presumably the computer will choose the move with the highest score. If the computer is choosing the same move over and over again, that means that it thinks that all other moves have a lower score. Since moving over and over again is drawing, that means its score is at most zero. So it thinks that every other move has a negative score, i.e. it thinks every other move will likely result in a loss. So why should it avoid the draw, when the alternative is a loss?

Now, this does assume that the computer is weighting a draw the same as a win plus a loss, i.e. it values "50% chance of a win and 50% chance of a loss" the same as "100% chance of draw", and this could indeed not be the case, and it would be rather complicated to get into when it would make sense to not weight them equally, but to first approximation, we can make this assumption.

2
  • "Pretty much every opening involves pawn moves, and you can't take those back." I'm sure you're aware of knights being able to move and then return to their starting position during the opening, but I feel obliged to point it out down here.
    – user45266
    Jan 6, 2020 at 4:39
  • @user45266 I said "pretty much every opening". Moving knight back and forth is a tiny percentage of possible openings, and any decent AI is not going to be doing that. Jan 6, 2020 at 20:07
6

Even if there was no rule that entering the same position was a draw, a decent chess engine would add it as a rule.

You cannot win if you keep repeating positions. For a checkmate, you must stop repeating positions at some point. So if you enter the same position a second time, limited depth evaluation of the position might tell you that the best move will lead to the same position again with a positive value, but the evaluation will be wrong: Entering the same position again and again will lead to a draw and therefore should be considered to have zero value.

Entering the same position again once can be correct: In position X, evaluation with limited depth may tell you that a is the best move and b is the second best. With moves performed and your evalution going further you find that optimal game enters the same position. At this point you should use move b, or check if doing a again then breaking the loop is better.

2

I want to add from experience that against weaker engines there can be a sequence of moves that will lead to a certain outcome. I remember playing Ruy-Lopez as white against an old chess engine (7 years ago) with the engine always making the same move. After a certain point, I learnt a combination of moves which made the engine resign. The important point is that the engine replied with the same sequence of moves every time. I would certainly lose against the engine if there was some randomness employed by the engine.

Perhaps your friend encountered such a sequence in the engine he played against. A nice way to search for such a sequence is to start with an opening, and then let engine play against itself. Now memorize this sequence and see the engine actually repeats the sequence (it's not too hard to program some randomness which can make thigs tricky.) You may end up getting a sequence of moves that lead to a draw or a victory every time you play.

1

As the other answers suggest, your acquaintance is entirely wrong and every functional chess engine (not to mention the strongest ones available) understands draws by threefold repetition.

Moreover, according to this Wikipedia article, there was a match in 2015 when Komodo played several grandmasters with odds, i.e. starting down material, and did not lose a single game, from objectively losing positions against grandmasters (instead, most of them were drawn). Here is also a video of Hikaru Nakamura, rated No. 1 in the world in Blitz chess, playing increasingly strong versions of Komodo, and then playing full-strength Komodo with odds, and even when Komodo had no pieces except knights, he could not win.

Of course, none of this can conclusively prove that no one could theoretically forcibly draw an engine, but it shows to illustrate just how vastly superior engines are to humans at chess, and also that no one is even seriously trying to play top engines at full strength without a handicap. And all those matches were years ago! Engines have improved even more since, so the general consensus seems to be that no human would have any realistic chance of drawing (let alone winning) a game against a top engine.

-1

Only from my personal experience but in case it helps: Many chess computers and even really old portable ones can avoid the trap of 3 fold repetition. As suggested above they should only do it ( but I haven't seen one personally do it because I wouldn't let it maybe?) if it is best for them to draw. It is a basic rule of chess so no surprise they are equipped to handle it. I have tried to force a draw through repetition quite a few times over the years and not succeeded. We also need to factor in here how hard it can be to get a computer into a position... that trying to force a draw is even an option. ( with any reasonable degree of set difficulty anyway)

Extra: I learnt to play chess using computers and still have my first one. A Hanimex 1550. ( good luck finding one haha - although the 1500 is still available on ebay) Pretty basic little unit but quite strong game and still works 37 years later. The way to beat this one in particular is to assume it will castle and prepare in advance. Works a treat. even works on all 8 difficulty settings. My point here is there is a way to beat all programs. There is now amazingly good software though that I wouldn't be able to find flaws in. I do believe they are still there though.

I got cocky some years ago and went to the local chess club and asked to get beaten. after winning a couple of games they put me up against the club champion who beat me 3 times in 5 minutes....then replayed all the moves we both made from memory. He went on to point out where I had gone wrong and then told me I played like a computer. respect

1
  • 2
    re "My point here is there is a way to beat all programs.": If you're talking about all chess programs that will ever exist, Zermelo's Theorem guarantees there is an unbeatable program one could write, maybe it's forever beyond our ability and tech to write but I doubt it. If you're talking about all chess programs that exist today, there are already several (inc. AlphaZero) which are far beyond any chess master; they are still technically beatable, but certainly not by modern humans. May 10, 2021 at 13:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .