Skip to main content

Aggressiveness or defensiveness: The best way to play chess, a computer guide

 Different people play chess in different styles, no one knows the best way yet. This guide is perhaps useful to computers more than humans, although feel free to take a piece of life-long advice from this article on human behaviour.

Source: https://ar.casact.org/actuaries-versus-artificial-intelligence-what-do-actuaries-do-what-will-they-do/



The participants of this study are merely two chess programs I wrote. With the best of my abilities, I tried to give them some sort of personality that is reflected in their style of play. To understand how to create a "personality" in a program, it is helpful to understand the most common algorithms used in chess. Broadly speaking, designing a chess engine involves two parts: The Risk Assessment part and The Search part. For the latter, there is a pretty standard and efficient algorithm that searches for the best piece to move called the minimax. Thus I won't be altering the search algorithm much. I will, however, alter the risk assessment algorithm to give the so-called "personality".

Crude Intelligence 

At the crudest, basic level, the first thing to tell someone trying to play chess for the very first time is to capture as many opponent pieces as possible, presumably after learning how different pieces move, of course. To translate this to an algorithm that a computer understands will probably be in the form of this pseudocode:

             if it is my turn:

                     For moves in every possible move:

                                 Simulate moving a piece

                                  Rank how many points lost from the opponent for this move

                      Choose move with the highest point deduction from the opponent.


This chess program would behave somewhat like a greedy amateur with no foresightedness whatsoever –Yes, we've all been there. The most significant improvement to this algorithm would be for the program not only to calculate point deductions from the opponent but the possible risks for making such a move. We ought to design a proper metric to calculate the effectiveness of each move.

Designing a Metric

Probably, the first thing to tell someone new to chess is not to sacrifice their strong pieces immediately, that a queen is much more valuable than a pawn, for example. However, there is a bit of a grey area when considering whether a bishop is more valuable than a knight –I personally tend to believe that. Fortunately, assigning values to pieces is a well-studied problem and certain metrics have been quite common in the later years in the form of an Evaluation Function

But how do you tell the chess program to make a move when the move does not necessarily capture an opponent piece? say the opening moves? We make use of Piece-Square Tables, essentially assigning scores for each square on the board, so a program would tend to a certain square or move away from a certain square depending on the score on these squares. For example, here is a common Piece-Square table for pawns:

// pawn
 0,  0,  0,  0,  0,  0,  0,  0,
50, 50, 50, 50, 50, 50, 50, 50,
10, 10, 20, 30, 30, 20, 10, 10,
 5,  5, 10, 25, 25, 10,  5,  5,
 0,  0,  0, 20, 20,  0,  0,  0,
 5, -5,-10,  0,  0,-10, -5,  5,
 5, 10, 10,-20,-20, 10, 10,  5,
 0,  0,  0,  0,  0,  0,  0,  0


In the table above, we are assuming we have the white set, and the starting position for the pawns is the second row (where a score of 50 is given). This particular table is encouraging pawns to move one or two steps forward, but discouraging them from going too deep into the opponents ground (see negative scores  given toward the bottom of the table)

We don't have to stick to the standard tables, in fact, we should not stick to them in order to give "personalities" to the different chess programs. 


The Artificial Personality

Translating a personality into numbers is not straightforward. But my attempt to create an aggressive and defensive computer resulted in changing two parameters:

1) Encouraging the aggressive player to move the pieces forward using piece-square tables. More concretely, assigning positive values closer to the opponent –You could argue whether this is considered aggressive or dumb. The defensive player behaves in almost exactly the opposite manner.

2) Changing search depth. Search depth is one of the parameters of the minimax algorithm, essentially higher depth means simulating deeper into the game and more possibilities emerge leading to a better decision, but with the cost of having a slower system and more computational expenses. Aggressiveness isn't usually associated with foresightedness, thus I decided to give a slightly lower search depth for the aggressive player.


The Battle

As expected, having a higher search depth is way more advantageous to being aggressive, thus the "defensive" engine won, not as easy as I would have thought. Interestingly, by keeping the search depth constant, there's a significant advantage to the "aggressive" player.


The final move of the battle

This is by no means a rigorous study, but a mean to have fun by assigning logical personalities to programs. The goal is to have fun and get inspired.

I have run the battles on Google Colab, access to it is here. For more explanation on how to the code works, check out this post by Andreas Stöckle.






Comments

Popular posts from this blog

Mathematics as an art: Fourier epicycle library

If you are remotely interested in mathematics, you'd probably heard of Fourier, or Joseph Fourier . His name comes to mind whenever a physicist, electronic engineer or any technical person deals with frequencies . I don't need to praise Fourier anymore because there are tons of videos and articles about him all over the internet.  In this article, I will be talking about Fourier series and epicycles (Foucycle), seemingly two distinct branches of mathematics if you're unaware of Euler's famous formula . Epicycles are essentially circles within circles, they have been studied extensively by astronomers because it was thought planets' motion was perfectly circular (Not to mention how they were convinced the earth was the centre of the universe) until the inverse-square law of planet motion was introduced by Keppler and Newton . Fourier series is essentially a way to approximate any function as the infinite sum of scaled sins and cosines, simple yet revolutionary. 

Butlerian Jihad: The crusade against AI and hidden tech

Image 1: Mdjourney generated picture using the prompt: "cartoon of human soldiers fighting a small robot. it shows the defeated robot in the middle and human soldiers aiming their rifles at the robot" "We must negate the machines-that-think. Humans must set their own guidelines. This is not something machines can do. Reasoning depends upon programming, not on hardware, and we are the ultimate program! Our Jihad is a "dump program." We dump the things which destroy us as humans!" ' ― Minister-companion of the Jihad. [6] That quote will be recognizable if you have read Dune by Frank Herbert . I found it suitable to bring the novel up during the extreme mixture of excitement and fear among people given the recent advance in artificial intelligence. Even an open letter was signed by many extremely influential people to halt the progress of artificial intelligence research to avoid a situation like in the cartoon above in image 1 (which is ironically AI

What does flattening the curve mean mathematically?

As of today, most countries are on lockdown; a strategy devised by governments to help slow down the spread of the novel coronavirus COVID-19. Moreover, officials use the term flattening the curve to help the healthcare system cope with the expected large amount of patients, but what does that mean mathematically? I will go on an overview of how to construct a useful toy mathematical model to get a qualitative view of the dynamics of the virus. This is a typical SIR model appearing a lot lately in the media. I will go further to explain how to develop such a model and explain the power and limitations of such models. How to construct SIR models SIR stands for Susceptible, Infectious and Recovered (or Removed) agents. In our example, the agents are humans spreading the disease to each other. To simplify things, we model an agent as a node and the links between nodes represent social connections, as seen in the picture below: Figure 1: Modelling humans as nodes