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
Post a Comment