ENTUAL Chessbot Part 3
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.
This summer, we took an in-depth look at various aspects of chess in relation to Ab Initio and its implementation. We’ve already covered FEN notation and the basic functionalities of a chess computer in our first blog post, as well as move calculation and evaluation functions in our second blog post .
In the third part of our blog series on the Entual Chessbot, we will discuss the technical aspects of its implementation using Ab Initio. The focus will be on implementing a web service graph with Ab Initio, enhanced with chess-specific features.

https://www.pexels.com/photo/man-holding-chess-piece-277124/
Basic Functionality of an Ab Initio Web Service Graph
The Entual Chessbot is implemented in Ab Initio as a continuous graph and includes the basic functionalities of a web server:
First, there is a component that processes incoming HTTP requests. The requests are then forwarded to components with dedicated functionalities, depending on their content. These components can provide information for rendering the user interface via HTML files or the results of determining the best move. Finally, there is a component that sends the retrieved HTTP responses back to the browser.
Figure 1 below provides a rough schematic overview of the individual components of the graph:

All information required to render the user interface, such as HTML and CSS files, is stored in the Graph Sandbox and is delivered to the browser by Ab Initio.
When the website “chess.entual.de” is accessed, the browser sends a GET request for an initial HTML file to the Continuous Graph. This request is processed via Thread 1, as shown in Figure 1. As a result, the Continuous Graph searches the sandbox for the “main.html” file. The browser receives the requested file and sends additional GET requests to the Continuous Graph for all links within it that point to resources such as CSS stylesheets or other HTML files. This process continues until the entire page content has finished loading.
This is shown schematically in Figure 2 below:

Basic login functionality
When you enter a nickname and click the Submit button, HTMX sends a POST request to the Continuous Graph. This request is then processed via Thread 3 in Figure 1. In the process, a session object is created that contains information such as the name, the time of login, and an ID calculated from this data.
The session object is stored in a shared variable collection. This is a type of in-memory database in Ab Initio that can be accessed by all components within the same runtime process.
In addition, a Set-Cookie header containing the ID just determined is sent back to the browser via the response header. When the browser makes subsequent requests to the Continuous Graph, including this ID causes the user’s game statistics to be displayed.
Clicking the logout button takes you back to the initial page, and the cookie is marked as deleted.
The workflow described above is illustrated schematically in Figure 3 below:

The core of the chessbot lies in determining, executing, and displaying the best move. We will discuss this in more detail below.
Finding the next move
After a player moves and places a piece on the board, a series of actions take place in the background:
A JavaScript function checks the validity of the move just made and, if the move complies with the rules of the game, generates the FEN string for the new board position.
This FEN string is sent to the Graphen web server via a GET request, where it is processed via path 2 in Figure 1.
The Minimax algorithm, which was described in the second blog post , is now used to determine the next move. The move calculated by the chess computer is sent back to the browser in algebraic notation, where it is then executed.
After that, game information—such as the current FEN or the game history so far—is updated in HTML.
When a game ends in a checkmate, the players' names and the game result are stored in a shared variable collection so that this information can be displayed on the game interface.
In pseudocode, it looks like this:
def find_abinitio_chessbot_move(source, target):
is_valid = check_valid_move(source_target)
if (is_valid):
new_fen = create_new_fen(current_fen, source, target)
answer_move = call_http_chessbot_minimax(new_fen)
execute_chessbot_move(answer_move)
update_ui(answer_move)
else:
undo_move(source, target)
The workflow for determining the force described above is shown schematically again in Figure 4:

A Look Back and a Look Ahead
The Entual Chessbot is a rudimentary, stripped-down version of a chess computer. Although it can likely defeat most chess beginners, it stands little chance against amateur players with knowledge of openings and tactical skills. So what sets it apart from more powerful chess computers like Stockfish, and where might one start to improve it?
In our opinion, the main focus should be on optimizing the performance of the parts of the algorithm used to determine the best move. In the recursive minimax algorithm, a large number of function calls are made to determine all possible moves in a given position. To do this, we use a matrix in which the positions of all the pieces are recorded. Each time the function is called, all the possible moves for all the pieces within the matrix are calculated. If you want to calculate several moves ahead, you have to call this function several million times, which requires an immense amount of computational power.
Alternatively, you could perform the move calculation using a bitboard. This is a 64-bit integer, where each bit represents a square on the board.
Each piece and each color is assigned its own board. Possible moves are then determined by bit shifts and bitboard overlaps. By optimizing the move calculation, the Minimax algorithm could search deeper, which would improve the computer's playing strength.
Another option is an improved optimization function that takes into account not only the pieces on the board but also their qualitative value based on their positions. A central knight or an advanced passed pawn would therefore be rated higher than a knight on the edge of the board or a pawn on its starting square. The computer would then be more likely to make moves that lead to positions of higher qualitative value.
That, and much more, is what our backlog holds in store for a future iteration of the Entual Chessbot powered by Ab Initio. We hope you enjoyed reading this as much as we enjoyed writing and developing it.
Feel free to keep playing a game of chess—challenge him: Entual Chessbot powered by Ab Initio .
If you'd like to read the other blog posts again:
In second blog post , we explored how a chess computer can calculate all possible moves in a given board position and how a rating function for those moves is implemented.
In our first blog post , we covered the basics of programming a chess computer, which we implemented using Ab Initio.