6

I’m wondering about the possibility of there being a perfect chess game. The conventional answer which almost always shuts down the question quickly always seems to be something along the lines of, since there are more possible games than atoms in the universe, no computer could ever derive a solution. But it still leaves us with the question, and the doesn’t get at nature of the possible solutions. So I’d like to know:

  1. Imagining a universe big enough to have a stunningly powerful computer. Is there a consensus among mathematicians, game theorists, computer scientists and theoretical physicists at to whether a solution could, with sufficient resources, exist? Is the question completely open?
  2. While it’s true we can’t begin to address every possible game, it’s also true that we certainly would not have to. Many possible sets of moves and game starts could be ruled out as obvious dead ends, certain losses, draws, etc. Aren’t we overestimating how much computing power is needed by considering all possible sets of moves?
  3. It’s been said that the opening player is likelier to have an edge if a perfect game exists for either player. But is there a reason to assume this is true? If we’re so sure we can’t possibly know what black or white ought to do to win, how can we begin to speculate on who might be better positioned to have a perfect game?
  • 3
    https://en.chessbase.com/post/how-god-plays-chess This is worth reading. – NNN Feb 14 '25 at 04:52
  • 27
    I disagree with the notion this question isn’t in the “right community.” It’s about the mathematics of the game not the mechanics. – M. Alan Ross Feb 14 '25 at 04:59
  • 2
    You can construct a big tree where each node is a possible position in a chess game. The nodes in the first level correspond to possible opening moves for white, and so on. Each terminal node can be labeled as win for white, win for black, or draw. Now each parent of a terminal node can be labeled as win for white, win for black, or draw. And so on. So every possible game position can be labeled as win, lose, or draw for white. From any position, you know if a win is possible, and if it is you know how to make it happen. – littleO Feb 14 '25 at 05:00
  • https://math.stackexchange.com/questions/850111/solving-chess-alternatives-to-brute-force and https://math.stackexchange.com/questions/859212/why-do-people-lose-in-chess – Gerry Myerson Feb 14 '25 at 06:47
  • 1

8 Answers8

22

In fact, any "reasonable" game has a winning (or at least non-losing) strategy; this is Zermelo's theorem. However, the proof doesn't give any useful tools for finding such a strategy in concrete cases, even for games much simpler than chess. So we know it exists, but beyond that practically every question (including who has the winning strategy!) is completely open.

Noah Schweber
  • 260,658
  • I think what Zermelo's theorem says is that one of the two players has a winning (or non-losing) strategy. For example in connect 4, yellow has a winning strategy. Red can play perfect but will still lose, assuming yellow plays perfect. – SampleTime Feb 15 '25 at 18:02
  • 2
    @SampleTime "the game has a non-losing strategy" is a common, if odd, shorthand for "at least one player has a non-losing strategy in the game." – Noah Schweber Feb 15 '25 at 18:32
  • Sure but if OP knew this already he probably wouldn't ask the question. IMO, precise beats short. Same with "reasonable", that is just unnecessary fuzzy. – SampleTime Feb 16 '25 at 19:47
11

Yes

Zermelo's theorem tells us that for any finite two-person games of perfect information in which the players move alternately and in which chance does not affect the decision making process, one player has a winning strategy or either player can force a draw.

Chess is such a game. So is noughts and crosses (tic-tac-toe). The perfect strategy for the latter is easy to find (it’s a draw), the one for chess isn’t so easy. The one for go is even less easy.

Knowing that there is a perfect strategy doesn’t help us find it.

Dale M
  • 3,104
  • 1
    I consider a perfect go strategy more likely to be found then a perfect chess strategy (or rather, less hopeless). In chess it's easier to brute-force heuristics, but because of the many special cases in the rules there is very little chance for any kind of recursion that could be exploited for proving a solution perfect. – leftaroundabout Feb 15 '25 at 15:24
6

One route for thinking about questions of this form that computer scientists like is to generalize to an $n \times n$ board and ask: how difficult would it be to solve $n \times n$ chess as $n \to \infty$, or some such variant. This allows us to sort different kinds of games into complexity classes.

Generalized $n \times n$ chess is known to be what is called EXPTIME-complete (due to Fraenkel and Lichtenstein), where EXPTIME is the complexity class of problems that can be solved in exponential time, and complete means, roughly, "as hard to solve as any other EXPTIME problem." EXPTIME-completeness is a very high level of difficulty, although of course this doesn't directly tell us anything about the case $n = 8$, since this is an asymptotic result. Various results of this form are known, see game complexity for more, e.g. generalized $n \times n$ go is also known to be EXPTIME-complete.

Qiaochu Yuan
  • 468,795
  • 4
    Conceding that you are not answering question for $n=8$ is in effect a concession that you are not answering the question. Noah's answer is far more to the point. – MathematicsStudent1122 Feb 14 '25 at 11:36
  • 8
    @MathematicsStudent1122 that comment seems shortsighted. n=8 is big enough for the implications of this theory to be relevant in understanding the problem. This is not a case where we expect some magical algorithm for n=8 that is much faster than the general best case because n is only 8. If you prove a mountain is extremely steep, this can potentially tell you a lot about the first mile of the climb. – usul Feb 14 '25 at 23:54
4

Regarding structure of the optimal: I believe it's fair to say that we don't expect there to be an essentially faster algorithm than brute-force search. The brute-force search algorithm is:

  • Try every legal opening move for white. For each move you try...
    • Try every legal opening move for black. For each move you try...
      • Try every legal second move for white, given the first two moves. For every move you try...
  • ... eventually, find out if the sequence ends in checkmate. If so, go back a step and try to see if there's another move for the previous player to avoid checkmate. If so, go back a move...

So the brute-force algorithm essentially searches all possible legal positions one by one. It classifies a move in a position as leading to checkmate if that player can force checkmate for all possible replies, etc. (This is backward induction.) So you can see why the number of possible legal positions is relevant. You can speed this up a tiny bit by pruning out provably lost positions early, but it barely matters when the numbers are so large.

We don't know how to generally solve the game much faster than this, and we kind of doubt it's possible since chess is EXPTIME-complete. A faster algorithm would have to somehow prove that a certain move guarantees to lead to checkmate without working out all the actual possible replies to that move, and we just don't know how to do that in general.

usul
  • 4,084
  • 1
    "We don't know how to generally solve the game much faster than this" - yes we do, brute force tree search is slow because it can visit each position many times (because there are vast numbers of sequences of moves to reach each position). Instead it is theoretically better to use the method of endgame tablebases, which starts from an end position and works backwards, memoizing the results. That at least only visits each position a small constant number of times. (Although, of course, neither method can solve chess in practice due to limits on time and space.) – causative Feb 15 '25 at 21:14
  • @causative true, I was trying to explain backward induction (the method you refer to) informally -- hence my comment below about visiting legal positions one-by-one -- but my description suggests the (non-memo-ized) brute force method. I can edit to be more precise about that. – usul Feb 16 '25 at 05:17
2

Captain Obvious

Others have given a good general answer, so I would just like to address this point in particular:

While it’s true we can’t begin to address every possible game, it’s also true that we certainly would not have to. Many possible sets of moves and game starts could be ruled out as obvious dead ends, certain losses, draws, etc. Aren’t we overestimating how much computing power is needed by considering all possible sets of moves?

If you follow chess problems, you will quickly notice that a good deal of them entail a brilliant sacrifice. And what makes a sacrifice brilliant is that it is not obvious that giving up a piece for position is, in fact, advantageous. Humans tend to think in terms of material, because that is the easiest metric to track. Part of what makes AlphaZero so powerful is that it has an ability to observe positional value much more accurately than humans can. So there are many board positions where you might say: "Oh, nobody would move the bishop there. That is an obvious blunder!" While AlphaZero says: "Actually, that move will lead to loss of black's queen in 7 moves with perfect play."

The very beginning and end of a game have many moves that are likely "obvious blunders" (for the beginning, this would be something like moving a piece back and forth to deliberately give up tempo). But for the middle of the game, hardly any move can be called an "obvious dead end", given how many viable game trees can follow from it. And the middle is exactly where the greatest branching factors occur, and where you need to trim the branching the most. That is to say, the places where you can trim the game tree most confidently are also the places where it matters the least. It's a bit like saying: "Can't we chop down this entire forest by cutting the saplings at the edges?"

Graph Drawing

An equally hard problem that is easier to visualize is the Travelling Salesman Problem. Pick a collection of points, and draw a Hamiltonian cycle through them of minimum length. If you play any video game with a gathering/collecting mechanic (like chopping down trees or collecting rocks, for instance), you are actually solving this problem in real time (or rather, you are drawing the graphs, but almost certainly not producing the minimal cycle). Here, too, it is tempting to say: "This problem isn't very hard. I can exclude a bunch of cycles like ones where I walk back and forth across the map to collect one item, when I could simply collect locally instead." And here, too, you will quickly find that eliminating these "no brainer" cycles doesn't get you very far. They encapsulate a locality heuristic (try to connect nearby points) which will get you decently far, but will by no means ensure an optimal cycle.

That being said, for many NP-complete problems, the majority of problem instances are relatively easy to approximate well (and TSP is one of them, due to things like locality heuristics). You might assume chess is not one of these problems, because all of the instances seem hard. But that is not true. To really explore the full space of chess games, we need move randomly. And indeed, any grandmaster playing against an opponent who chooses random moves should be able to absolutely dominate them without God's algorithm. In this sense, chess is also "easy".

The reason it seems hard is because the players themselves choose instances which are "pathological". So the moves which can be eliminated with simple heuristics are, by and large, the ones which occur most often in the "random forest" portion of the game space. They occur with trivial frequency in the "competitive" part of the space. Now, is there a comparable situation with graphs? Indeed, there is.

Easy graphs are ones with lots of clusters joined by a few "bridge" points. You can mostly solve it recursively by finding "local cycles" and connecting them at higher and higher levels. Hard graphs are ones with very little structure. The points are all at the same distance order, with only smaller perturbations between them. There are numerous local cycles which differ by only a small length, so picking the best one to connect at the higher level becomes quite intractable. You will have many good choices of entry and exit points, and indeed, there is no obvious structure to the entire graph that lets you partition it into locally manageable chunks in the first place. It will not take you long to convince you that such a graph is not solvable by hand, even with a small number of points. Finding a cycle is easy. Finding a minimal cycle is mind-numbingly hard.

Structure

The conclusion for us to take away is that simple rules and heuristics are very good at identifying structure within a problem. If the structure of the state space is simple, then a rule that removes a bunch of the state space is possible and effective. But when the state space becomes convoluted, the symmetry disappears, and simple rules can no longer give much advantage. The random portion of the chess space has lots of structure that can be easily exploited. But the competitive subset is a lot more fractal-like. The higher-level structure evaporates quickly, and details dominate. Here, simple heuristics will give close to 0 value, because violating a heuristic is often the key to making a strong move.

Another good problem to consider is Sudoku. Easy problems have lots of clues and can be solved quickly using the simplest strategies. The hardest problems resist the simplest strategies because they lack the structure which makes it easy to advance. They reduce to a kind of linear search through the possible solutions (players call this "brute force search" and it is very taboo...it's considered an admission of defeat). This is the common theme of NP-complete problems: the hardest instances have numerous lookalike paths, only one of which leads to the optimal solution. There are no easy shortcuts to examining them one by one. At least, nobody has found these shortcuts. You could say that finding such a shortcut, at least a universal one, is equivalent to proving that P = NP.

  • 1
    There are often huge shortcuts possible but still too many cases left. For example, for a problem of size n you might reduce the cases from n! to 2^n which is an enormous saving but still much too much to solve the problem. – gnasher729 Feb 15 '25 at 13:08
  • @gnasher729 those shortcuts are almost always in the "trivial" portion of the problem space. I should have mentioned that there is usually a phase transition between one side of a problem space and other, and that the transition is where the interesting and hard problems reside, and where the structure becomes very fractal in nature, eliminating the kinds of symmetries which make shortcuts possible. – Lawnmower Man Feb 16 '25 at 06:37
2

As has been said, chess with perfect play is either a draw, a win for white, or a win for black. It is only a matter of resources that prevents us from knowing which one is true and what perfect play is, and the required resources are so great that we will most likely never know with mathematical certainty.

But chess opening theory and has advanced so far that practically every expert expects the answer to be that chess is a draw.

I’m wondering about the possibility of there being a perfect chess game.

Not only do we know from a mathematical standpoint that a perfect chess game is possible, but, from the "chess expert standpoint", it is very likely that perfect chess games are regularly played. If chess is indeed a theoretical draw, then every chess game that never reaches a position that is not a theoretical draw is a perfect game. Among high-level games, even heavily fought games, it is quite common that the computer evaluation never gets outside of a range that is thought to represent a theoretical draw (of course, this is not a proof).

Stefan
  • 7,185
0

You can make a table of all possible positions. Many are impossible because the moving player is checkmate. Many are draws because the moving player is in stalemate. Those where the moving player can set the opposing player checkmate are won. Those where every move leads to the moving player neon mate are lost.

Then you check further, anything where some move leads to a lost position for the opponent is won; if every move leads to a winning position for the opponent then the position is lost. If we can’t find any more won or lost situations then the remaining positions are drawn, and we must avoid repeating moves.

Now the algorithm is simple: Take the table of won, lost and drawn positions, pick a winning move if possible, otherwise a drawing move if possible, otherwise any other move.

The only problem is that the number of positions is absolutely huge, so you can’t build the table in practice.

gnasher729
  • 10,611
  • 20
  • 38
0

The best we have in practice are endgame tablebases up to 7 pieces. The idea of retrograde analysis, proposed by Richard Bellman, is instead of starting from the starting position, for which there are too many pieces to be feasible to play all games to completion, start from all possible game endings with up to a certain amount of material, and then work backwards all possible moves, until every possible starting position up to that amount of material is recorded. Since these are exhaustive, starting with 1 ply (half-move), then 2 plies, then 3 plies, and so on until all positions up to the material limit are covered, they produce optimal mates in terms of plies. Some nice quotes from the linked Wikipedia article:

The moves leading to mate have been found by the database technique, initiated in 1970 by the German Ströhlein, and later developed mainly by Ken Thompson of Bell Laboratories. The idea is that a database is made with all possible positions with a given material. Then a subdatabase is made of all positions where Black is mate. Then one where White can give mate. Then one where Black cannot stop White giving mate next move. Then one where White can always reach a position where Black cannot stop him from giving mate next move. And so on, always a ply further away from mate until all positions that are thus connected to mate have been found. Then all of these positions are linked back to mate by the shortest path through the database. That means that, apart from 'equi-optimal' moves, all the moves in such a path are perfect: White's move always leads to the quickest mate, Black's move always leads to the slowest mate.

-- Tim Krabbé, STILLER's MONSTERS or perfection in chess

Playing over these moves is an eerie experience. They are not human; a grandmaster does not understand them any better than someone who has learned chess yesterday. The knights jump, the kings orbit, the sun goes down, and every move is the truth. It's like being revealed the Meaning of Life, but it's in Estonian. On Thompson's Website, where this and other endgame databases can be found, he has named the link to them: 'Play Chess with God.'

-- Tim Krabbé

To illustrate the exponential nature of computing and storing these tablebases, even with clever compression techniques and ignoring "obvious" positions:

  • 5-piece endings: 7 GB
  • 6-piece endings: 1.2 TB
  • 7-piece endings: 140 TB
  • 8-piece endings (estimated): 2 PB

Also note that some tablebases ignore the 50-move rule. So a position may be a technical win in 200 moves, but impossible for a human to use in a FIDE game as the opponent can claim a draw after 50 moves.

qwr
  • 11,362