Jan 11, 2019

Artificial Intelligence

The beautiful thing about the internet for me is the presence and easy availability of forums (fora?) with people discussing one particular thing or hobby. If, for example, you are a cricket fanatic, then you don't need to look too far in India. You can literally stop every passerby and debate whether India trounced Australia in Australia because this Indian team is so good, because the current Australian team is weakened and demoralised or a bit of both? Is this India's strongest fast-bowling attack ever? Is it India's strongest bowling line-up overall ever?

What if there exists a huge community across the world who watches one show or plays one game, but they're rarely in physical contact? That's where the internet comes in. And this has most had an impact on me through chess. Yes, it's not quite an esoteric pursuit and once you start talking about it, you will realise that there are a really huge number of committed amateur chess players in the world who are watching analysis of classic chess games, trying tactics puzzles and best of all, playing each other! But they're rarely in the same room or at the same table.

On the chess.com app, there are 15 different time schemes for the games. All you need to do is log on to this app, select your favourite time scheme and within 3 seconds, you are matched with another person who also is looking for a game with the same time scheme whose chess.com rating is similar to yours. Perhaps, you say, all the chess enthusiasts of this world (with no lives otherwise) are on this one app, so it's a concentration not truly reflective of the actual, meagre popularity of chess in the world. Actually, it is but one of about a handful of extremely popular chess apps. 

Chess  is one of those in-between things. You don't see too much of it in real life or in your "screen life", but if you go looking for it, it is hard to miss it. Perhaps playing chess is as popular as supporting Arsenal or Barcelona, but nowhere near as popular as football as a whole. 

To describe my relationship with chess would be impossible without using the word "addicted". And I realise that to be really into something, you don't necessarily have to be really good at doing it (one look at me on a football field would destroy this illusion once and for all). Yes, if a beginner played chess against me, they would probably get routed, but any player with a modicum of seriousness about their game would either stretch my game or, more likely, beat me with relative ease. 

There is one aspect of this game that I love which just keeps bringing me back to it. Chess is a highly constrained game where, relative to the total possible moves that can possibly be made (the maximum possibility is where every piece can move to every square), the number of moves a piece can actually make is miniscule. A pawn can move to a maximum of 3 squares at once, a knight to 8 and even the mighty queen, when ideally situated, can strike a mere 27 squares out of 64. And such an ideal situation only happens at the very end of games with few pieces remaining on the board. 

In spite of this, the number of possible moves is mind-mindbogglingly large and colossal. The first 10 moves, according to a calculation, has some 10 to the power of 29 possibilities within the rules of chess. That's a 100 billion billion billion possibilities. (and seemingly all of them end in me being checkmated)

So would a chess player's mind have to grasp all of this? Every single move? Thankfully not. These are only possibilities. The moves that make sense are far fewer. A significant number of these possibilities certainly involve stupid moves that a child would know is wrong. 

In reality, there are certain well-known and not so well-known principles in chess which help beginners to rapidly improve their games. The best-known principle is that the player who controls the central squares generally has a better chance of winning. So from these 100 billion billion billion (HBBB) possibilities, perhaps the vast majority lead to one player losing a lot of material or not making progress towards the centre of the board. In all professional games, the players actually memorise and prepare, with help from older games, chess theory and off-late, supercomputers, to understand which openings yield the greatest advantage, position-wise and material-wise.

So from a HBBB, in reality, we are dealing with a few hundred well studied, sensible and practical openings. Very often, players don't even think about the first 5-6 moves, as the best move for every variation is studied in great detail and this forms the background "homework" for any great chess player. There are whole books dedicated to particular variations of particular openings and what kind of patterns can emerge from this, the weaknesses and strengths of different move sequences. To be very honest, when I first learnt this, I was rather disappointed. I thought chess is a game based only on pure imagination and logic, but actually a huge part of it is rote study.

But here's the amazing bit that I love - this number I've been throwing at you - HBBB. It is just so huge, that even with all the opening theory and preparation and supercomputer guidance during practice, down there, on the board, every single game is unique! Every game starts with the players knowing exactly what the opponent will do 2 moves in, 3 moves in. Player A knows that Player B knows, Players B knows that Player A knows that Player B knows. It is all planned out. Yet, at some point, because players have a finite memory, because players can't always guess what the opponent likes, what he/she has prepared, at some point it diverges from every single game known to mankind.

Quite similar, sure. Many similarities exist between 2 ongoing games that vary by just one move. But this one extra move is a wildcard. It opens up god knows how many billion more possibilities. And from then on, the players are on their own. It is just their minds against each other. Their preferences, their biases, their imagination and their luck.

So you must be wondering - does this guy have a point? And why is he rambling about chess in a blog post with a title like "Artificial Intelligence"? I think I have a point, but in a while. So bear with me.

The question that bugs me is this. We have two players whose "wits" are pitted against each other. Let us assume they're thrown into a unique game where black and white have an equal position to the extent to which that is possible so that their match preparation and opening theory knowledge don't prove very useful (though there is an equal amount of literature dedicated to mid-game theory as well, but let's imagine these players are just using their "intelligence"). Who would win? Would the smarter player always win? What constitutes smartness here?

A strongly logical person would be an intuitive guess. Perhaps the guy with a photographic memory stands a great chance, since he can hold the images of the board several moves in advance and can work with less effort on this mental chessboard. Maybe the more imaginative person, the guy who thinks out of the box, prodding to see if that seeming blunder of giving the queen in exchange for a bishop can actually open up a match-winning sequence of moves, will win out as he confuses his opponent every time.

Luckily, we don't have to rely completely on our instinct to give us the answer to this question. We don't have to rely completely on people to give us a part of this answer. Today, all the top-ranked chess players in the world are computers. The cold, hard logic of a machine always wins. Well, not always cold.

There are essentially two kinds of chess-playing computers (usually supercomputers), or chess engines. Let us call them Rama and Sita (since you know, there is RAM in every computer).

The way Rama works is, he considers the current board position and then takes every single possible move. For every single move, he assesses the position and gives it a score, depending on the new position. Then, he looks at every possible reply to each of these moves and gives each of them a score. Depending on time-restrictions and the computing power, Rama decides to stop assessing the possibilities a certain number of moves in advance. Maybe he just looks one move ahead and evaluates the positions. Or goes far ahead. Given just how rapidly the number of possibilities proliferate (10 moves is HBBB possibilities at the beginning), there is a physical limit on how many moves ahead Rama will be able to assess every single option. The best chess engines can assess up to a depth of 30 moves ahead! This is a testament to the sheer computing power it has at its disposal.

But the main question is - how does Rama assess each position? How does he know one is better than the other? Rama has a creator (Brahma, duh). The evaluation of a position is hard-coded into Rama. Somebody tells Rama at the beginning, this piece is worth so many points, that piece is worth so many. A pawn past the central square is worth more than an ordinary pawn. A king safely tucked in behind a pawn barrier is good. Additionally, Rama doesn't bother calculating the moves initially. He just looks up a manual on openings which are excellently studied by his sentient cousins, the human beings.

Now you must be jumping! This is misleading - because when you're playing Rama, you're not really playing Rama. You're playing some really good chess player hired by Rama's creator (probably IBM) to give him an evaluation scheme. This great player certainly has his biases. He may be more uncomfortable defending against rooks, so he rates rooks highly. He has his favourite opening, so even Rama plays this opening more often than an actual position assessment would suggest playing it.

Enter Sita. She is stupid, but at least she is her own person. And she learns rapidly. Sita only knows the rules of chess, nothing else. She isn't great at looking too many moves into the future either. But she has one fundamental advantage - she is flexible.

Sita has a ritual before playing anyone else. She sits by herself and moves for both white and black. She merely knows how the pieces are allowed to move, she has no idea that taking a piece to the centre is good. No one whispered in her ear that a passed pawn is especially dangerous even though a pawn is by itself a rather weak piece.

Slowly, yet steadily, she begins to notice patterns in the games she is playing against herself. She starts to see that some positions are advantageous for her and she starts to make her own evaluation schemes. Initially, her evaluation is really rudimentary - I mean who takes so long to understand that the queen is the strongest piece! But then she gets better. And even better. Now she has grasped everything about chess that every human being has ever known and a whole bunch of other positional evaluations. Yes, Sita's intelligence is "Artificial". No one has ever taught her anything, except how to learn. Yet she knows more than anyone else and every single time, she learns more as well.

So who wins in a chess game between Rama and Sita? It depends. Which model? What kind of computing power? What kind of evaluation schemes? Screw that, you say. Just give me the strongest Rama and the strongest Sita made. Now who wins? This has been done, and the answer is definitive. Sita. Hands down. Even though Rama can see 30 moves ahead and Sita doesn't bother trying so hard. Even though Rama assesses a few million positions per second while Sita assesses some 80 thousand only. Rama plays hard, Sita plays smart. Rama has intelligence, Sita has intuition with only a smattering of intelligence. Sita has imagination.

It's even better if you think about it this way. Take your phone. Now invite the best chess players and programmers to make a Rama type chess engine out of this. Will this engine beat you? Yes (unless some chess grandmaster has stumbled upon my blog). Will it beat the current world chess champion? It depends on which phone you have. Let us say you have a rather primitive phone and the world champion is in fact stronger. No matter how many times they play each other, the human will win. (Most current smartphones are actually stronger than the DeepBlue computer that beat the human world chess champion for the first time ever in 1997)

But with your phone, you now make a Sita type chess engine. Will she beat the human? Given enough time, yes. At some point, she will be the world chess champion.

Are human chess players Rama or Sita? That's a hard one. Sita makes billions of moves every minute while playing on her own. A human can make maybe hundred. Sita records every game she plays. A human has a finite memory and doesn't necessarily choose the most important thing to remember. Rama is taught what positions are better and what positions are worse. Humans study this as well. Humans have intuition, Rama doesn't. Sita has something that seems a lot like it. Sita learns on her own, Rama learns nothing, humans learn from each other. But Sita too learns when she plays humans. Humans can write poetry, paint, build and tell stories. Rama can't. Nor can Sita - at least she hasn't yet learnt how to.