ENTUAL Chessbot Part 1

Chess, the royal game, is one of the oldest board games in the world. For centuries, chess enthusiasts have been testing their strategic thinking and moving the 32 pieces with intense concentration; the Entual team is, of course, no exception. 

While in the pre-digital era players like Bobby Fischer and Boris Spassky dominated the action on the board, today it is AI-powered chess programs that are unbeatable. Even current grandmasters like Magnus Carlsen and Hikaru Nakamura have long since had to admit defeat in the face of modern technology.

The most prominent and currently strongest chess program is Stockfish, which uses neural networks, among other things, to find the best moves in every position.

 

But how does a chess computer actually work? What algorithms are used to defeat even the strongest human players? Is it possible to program a chess computer yourself without much trouble?

Entual explored these questions over the summer. The result is a prototype chess computer, powered by Ab Initio, that will give even fairly advanced players a run for their money. 

https://www.pexels.com/photo/man-holding-chess-piece-277124/

What to expect

In our upcoming blog series, we’d like to share the results of our summer chess experiments with you. First, we’ll explain the basics of how a chess computer works. We’ll assume that readers are already familiar with the rules of chess, so we’ll focus primarily on the aspects that are relevant to a chess computer.

In this blog post, we will first analyze what is known as FEN notation, which is used by computers to efficiently store all relevant information about a chess position. 

In upcoming posts, we will explore how to identify all possible moves and how to quantitatively evaluate a board position using the evaluation function.

Next, we will analyze the minimax algorithm, a game-theoretic algorithm used to calculate the best moves in a two-player game.

In the final section, we will discuss the implementation details of the chess computer in Ab Initio as thoroughly as possible.

https://stockfishchess.org/

Fen-Notation

The primary task of a chess computer is to determine the best possible move for any given board position. 

For a computer to systematically analyze such a board position, a compact representation is first needed that a program can efficiently process. This representation must include both the positions of all pieces on the board and meta-information about the game, such as the number of moves, castling rights, or en passant moves.

A FEN string (Forsyth-Edwards Notation) provides exactly such a representation. A FEN string contains the following information, separated by spaces: piece positions, move rights, castling rights, en passant captures, half-moves played since the last pawn move or capture of a piece (50-move rule), and move number.

For example, the following FEN is generated for the Italian game:

“r1bqkbnr/pppp1ppp/2n5/4p3/2B1P3/5N2/PPPP1PPP/RNBQK2R b KQkq – 3 3”

 

In the FEN string, the figure positions specified for all ranks on the chessboard, starting with rank 8, with the information for individual ranks separated by a “/”. A rank on a chessboard refers to the squares that lie on the same horizontal line.

The pieces are notated from White's perspective, from left to right—that is, starting from the a-file and ending at the h-file. A file refers to the squares that lie on the same vertical line.

A lowercase letter represents a black piece, and an uppercase letter represents a white piece. Each letter stands for a specific piece: K for king, Q for queen, N for knight, B for bishop, R for rook, and P for pawn. If there are no pieces on one or more adjacent squares of a row, this is indicated by the number of empty squares.

The first substring of the piece positions, “r1bqkbnr,” therefore describes the 8th rank and is interpreted as follows:

Black rook, open file, black bishop, black queen, black king, black bishop, black knight, black rook.

The right to move is indicated either by "w" for White or "b" for Black.

A short castling rule White’s castling is abbreviated as “K”, and White’s long castling as “Q”; for Black, the abbreviations are “k” and “q”, respectively. If a castling move is merely temporarily prevented, possibly by a current check by the opponent, this does not affect the castling right in FEN notation. If neither side has a castling right, this is indicated by “-”.

This indicates the square a pawn has just moved over, assuming it initially moved two squares forward. This information is provided regardless of whether an opponent’s pawn is in the necessary position to make an en passant capture. The field contains "-" if no initial two-square move by a pawn occurred on the previous turn.

The number of half-moves played since the last pawn move or the last capture of a piece. This information is primarily needed in endgames for the 50-move rule to be enforced.

The move count is specified at the end of the FEN string.

 

A more complex FEN example:

Below, we will examine a possible sequence of moves that could follow the opening described above and analyze a few aspects of the resulting FEN string:

 

“1r4r1/bp1q1p1k/p2p1B1p/1Pp5/P3P3/5Q2/5PPP/3R1RK1 w – c6 0 22”

Let’s take a closer look at the sixth rank: “p2p1B1p”

A black pawn, two empty squares, a black pawn, an empty square, a white bishop, an empty square, a black pawn.

In this position, neither side has the right to castle, since both White and Black have already castled. This is indicated by the string “-”.

A possible en passant move is indicated by the string “c6,” since Black has just made the pawn move c7-c5 and there is a white pawn on the b5 square.

Outlook

In the next blog post , we’ll explore how a chess computer can calculate all possible moves in a given board position.

We also examine the evaluation function, which quantifies a board position and indicates which of the two players currently has the advantage. It forms the basis for the minimax algorithm used to determine the optimal next move.