# On chess logic

I caught myself thinking again about the algorithms behind chess thinking, both human and computer. Why is it so hard for people to play chess well? Why is it so easy for computers to come up with winning solutions? Why are they playing so weird? What is the real difference between computer and human thinking? And I know the knee-jerk reaction is to say "well, computers are fast and calculate all possibilities, humans do not". But it's not that simple.

You see, for a while, the only chess engine logic was min-max. A computer would have a function determining the value of the current board position, then using that function, determine what the best move would be by exploring the tree of possibilities, alternating between what a player would most likely do and what the reply would most likely be. Always trying to maximize their value and minimize the opponent's. The value function was determined from principles derived by human masters of the game, though, stuff like develop first, castle, control the center, relative piece value, etc. The move space also increases exponentially, so no matter how fast the computer is, it cannot go through all possibilities. This is where pruning comes in, a method of abandoning low value tree branches early. But how would the computer determine if a branch should be abandoned? Based on a mechanism that also takes into account the value function.

Now humans, they are slow. They need to compress the move space to something manageable, so they only consider a bunch of moves. The "pruning" is most important for a human, but most of it happens unconsciously, after a long time playing the game and determining a heuristic method of dismissing options early. This is why computer engines do not play like humans at all. Having less pruning and more exploring, they come with solutions that imply advantage gains after 20+ moves, they don't fall into traps, because they can see almost every move ahead for three, four or more moves, they are frustrating because they limit the options of the human player to the slow, boring, grinding pathways.

But now a new option is available, chess engines like Alpha Zero and Leela, which use advances in neural network technology to play chess without any input from the humans. They play with themselves millions of games until they understand what the best move is in a position. Unsurprisingly, as neural networks are what we have in our brain, these engines play "more human" but also come up with play strategies that amazed chess masters everywhere. Unencumbered by education that fixed piece value or limited by rigid principles like control the center, they revolutionized the way chess is being played. They also gave us a glimpse into the working of the human brain when playing chess.

In conclusion, min-max chess engines are computer abstractions of rigid chess master thinking, while neural network chess engines are abstractions of creative human thinking. Yet the issue of compressing the move space remains a problem for all systems. In fact, what the neural network engines did was just reengineer the value functions for board evaluation and pruning. Once you take those and plug them into a min-max engine, it wins! That's why Stockfish is still the best engine right now, beaten by Alpha Zero only in very short move time play modes. The best of both worlds: creative thinking (exploration) leading to the best method of evaluating a chess position (exploitation).

I've reached the moment when I can make the point that made me write this post. Because we have these two computer methods of analyzing the game of chess, now we can compare the two, see what they mean.

A min-max will say "the value of a move is what I will win after playing the best possible moves of them all (excluding what I consider stupid) and my opponent will play their best possible moves". It leads to something apparently very objective, but it is not! It is the value of a specific path in the future, one that is strongly tied to the technology of the engine and the resources of the computer running it. In fact, that value has no meaning when the opponent is not a computer engine or it is a different one! It is the abstraction of rigid principles.

A neural network will say "based on the millions of games that I played, the value of a move is what my statistical engine tells me, given the current position". This is, to me, a lot more objective. It is a statistical measure, constructed from games played by itself with itself, at various levels of competence. Instead of a specific path, it encompasses an average, a prescient but blurred future where many paths are collapsed into a value. It is the abstraction of keeping one's mind open to surprises, thus a much more objective view, yet less accurate.

Of course, a modern computer chess engine combines the two methods, as they should. There is no way for a computer to learn while playing a game, training takes a lot of time and resources. There are also ways of directing the training, something that I find very exciting, but given the computational needs required, I guess I will not see it very often. Imagine a computer trained to play spectacular games, not just win! Or train specific algorithms on existing players - a thing that has become a reality, although not mainstream.

The reason why I wrote this post is that I think there are still many opportunities to refine the view of a specific move. It would be interesting to see not a numerical value for a move, but a chart, indicating the various techniques used to determine value: winning chances, adherence to a specific plan, entertainment value, gambit chances, positional vs tactical, how the value changes based on various opponent strengths, etc. I would like to see that very much, to be able to choose not only the strength of a move from the candidate moves, but also the style.

But what about humans? Humans have to do the same thing as chess engines: adapt! They have to extract principles from the new playing style of neural network engines and update the static, simplistic, rigid ones they learned in school. This is not simple. In fact, I would say this is the most complex issue in machine learning today: once the machine determined a course of action, how does one understand - in human terms - what the logic for it was.

I can't wait to see what the future brings.