lichess.org
Donate
Old rusty engine

The Birth of an Engine

Chess botChess engineSoftware DevelopmentChess
The journey of coding my very own chess engine

Making my own engine because why not?

As a software developer and a hobby chess enthusiast it was only a matter of time until I would try my hand at chess engines. As my professional background was mostly in PHP/MySQL chess was never a realistic option. But as I made a switch to Golang in my professional career I started working on a simple chess engine as a hobby-learning project.

Play it now

Simply challenge likeawizard-bot to a game with unlimited time (Time control play will come soon*). If it's not responding it's offline as it's currently running on my personal computer or it might have crashed.

The project scope and goals.

Being a mediocre player myself my primary target is to make an engine that could outplay myself. At that point I could say- the bloody thing knows how to play chess.
What I am not aiming for is to make a highly competitive engine. So it will most likely never include:

  • Rely on existing UCI engines like stockfish
  • Use existing opening books
  • Use any pre-generated endgame tables

The use of any of those would diminish the ownership and satisfaction of calling it really my own.

Where are we at right now?

image
It works... ?

Simply put at the very beginning of the road. The engine mostly respects the rules of the game. However, there are a few known bugs of it not completely respecting being in check at some points. So it might play an illegal move- in such cases it will just resign.
The current issues with the highest priority:

  • Aforementioned bug with handling being in check. While currently I have not explicitly coded the meaning of 'check' or 'checkmate' the evaluation function should return +/- infinity score on either King being captured. With the idea being - if possible it should prefer playing anything else that avoids a king being captured.
  • Evaluation function. At the heart of every chess engine is the evaluation function. It takes a chess position as an input and calculates a score for the position that denotes an evaluation of the position. In simple words it answers the question "Who is better here?" with a numeric value where positive values favor white and negative values favor black. For now the function is very basic. All it does it counts the material and assigns small bonuses to pieces depending on the number moves/captures a piece has. As any chess player knows there are many many more metrics that we use naturally like: King/Queen safety, pawn structure (connected, center control, isolated, doubles, passed), space etc.
  • It is painfully slow at the moment. Having zero previous chess programming knowledge I went for an object oriented approach and the board representation is stored in a 8x8 integer array. However, most engines use what is known as a bitboard representation. Which stores the positional data as bits in a 64bit number and uses various different bitwise operations to manipulate and extract info from that data. If you have no computer science background that might sounds like a lot of gibberish to you. If you have some comp sci background it probably still is gibberish. So in short implementing a bitboard structure of the board can give massive performance boost at the cost of being human readable and much more bug-prone.
  • Lack of time control. As of right now the bot only accepts unlimited time control games. This is mostly due to the lack of efficiency of the search and simply lack of code. Right now it only looks at certain depth and that search can't really be hurried or interrupted with meaningful results. Hopefully by improving the search speed and algorithms it will be able to search more and faster and most importantly produce meaningful intermediate results. Such that I could take the clock situation and allocate a fixed time for search.

Why publish a broken and weak engine now?

It's a journey and a training montage. Right now the engine only relies on material and mobility to guide its play. With such simplistic thinking it does what many beginners do- it loves to move its Queen to improve its mobility and create simple threats. Any player who knows the basics of opening development principles will get a huge advantage early on. By releasing it now in it's baby steps I am able to see and hopefully tweak its behavior based on more data from public games. And also spot critical bugs faster. Measure its performance capabilities for future scaling and improvements.

Having talked at length about it I would like to share a game played by the bot against a buddy of mine where it ended up in a hopelessly lost position...

https://lichess.org/p3fZMcwn/black

image
One day maybe?

GitHub Repository