Is Ada a good choice to develop a chess engine?

In this article I want to share my opinion regarding the choice of Ada as a programming language to be used for a chess engine. This article targets both at programmers who already know Ada and programmers who don’t. While reading please do not forget that I will not say that Ada is the best choice but I want readers to know what really Ada can do for you if you are a chess engine developer or, more in generale, just hobbyst programmer.

The choice of a language to start writing your engine

If we look at the strongest chess engine, they are written in C/C++. According to CPW the strongest chess engine in non C/C++ is Booot, written in Delphy, and the second one is CuckooChess, written in Java. In the moment I’m writing, Booot is the 8th in the computer chess rating list ranking with 3200+ Elo and CuckooChess is at 128th place with 2500+ Elo.

It’s not that hard to figure it out why C/C++ is absolute the preferred way. It’s the fastest language in terms of speed of execution and there is a very huge literature on the internet written in C/C++. All of us know the limits of both C and C++ but also we all know the features of those languages. Therefore, if you are looking for a language to start your work from scratch, by choosing either C or C++ you will never make a “mistake”.

Thanks to the great work of Alex Morozov we know that yes, it is possible to write a very strong chess engine also in other compiled language than C. And if you look on the internet you can find many beautiful engines written also in Python (that is well known to be very “slow”) or in Basic or in other “slow” languages. They are not very strong, maybe, but… there is a “but”.

In my expirience, I see that the choice of C/C++ is overrated. Many people, without any knowledge of chess programming, immediately start by choosing one of them because of the speed of execution. If you read chess programming forums you will also find easily that many chess engines have never seen the light because some kind of bug was too hard to find and the programmer gave up.

It is my opinion that those programmers thinks that C/C++ is the only choice available to write a strong engine and they don’t realize that their engine will most certainly never be so strong. Even if they can do it, it is my opinion that they can do it with any other compiled language. If someone thinks that a 2500+ elo chess engine is not enough strong, he’s wrong.

There is an incredible amount of work behind a chess engine. A great number of engines are so called derived, that means that the programmer started by cloning another engine. I don’t say that it is easy. But I can say that is much harder to write a chess engine from scratch.

The process involves a lot of coding, bug fixing and most of the time is spent in debugging some fucking code that does not do what you want it to do. That means that if you want to have a chance to finish your first draft you need a serious good debugging enviroment. That means, also, to be able to write easily debuggable code. Just to give you and idea, a chess engine can evaluate more than 500k positions per seconds in a common laptop (billions of positions in a match). Do you have the slightest idea what does it mean if you code blows up in the middle of a game and you have to look into a recursion depth of 7-8 function calls to find what the hell has happened? Well, those numbers are referred to a very basic chess engine like TSCP is.

It is even harder in the measure of how strong your engine is. Improving a chess engine is relatively easy in the beginning but after that you need to work hard for getting just a bunch of elo points. In my opnion programmers should consider this obstacles with more focus than they do in the choise of the language for the “speed of execution”.

I want to encourage you to think that, being an hobby project, you should first try to design a project by thinking that maybe it is better to have a working engine in Python that a non-working one in C/C++. And maybe one day, with more experience and knowledge, you can switch to another language as part of the improvement of the engine.

So, why Ada is a good choice? and why not?

If you don’t agree with my premise I won’t blame you. I am quite sure, anyway, that most of the people will agree with many of my ideas.

I choosed Ada for one, simple, reason: I love that language.

AdaChess, in the moment I’m writing, is the strongest chess engine written in Ada (well… the fact that it is the only one should not be mentioned…). If I would have loved one other language, I would have written an engine by using that language. I don’t care how strong the engine is, I just care what I can do by feeling satisfied of my work. I care to have a working engine and improving it, writing cool algorithms and yes, I care also make it stronger but not as the only and final target of the project, rather as a way to misure it.

I have many features in AdaChess that makes the engine slower (and therefore weaker) than the equivalent without those features. But they are those features that makes the identity of AdaChess. I am confident that I could also write a stronger engine in C. But it would not be fun, neither would worth it.

So you like Ada but is a good choice or not?

Well, that’s a good question. In my opinion Ada is very powerful and it has an incredible amount of features that makes it an interesting option.

First of all, let me say that Ada is compiled by the gcc, therefore you have the same debugger as C/C++ and the same code profiler. Ada has also it’s own development environment, called GPS, but you can use Emacs, Vim or Eclipse too.

Ada is also really fast, in terms of speed of execution. When you compile your software by using the full optimization you can obtain a source code that is in the average 1,7x slower than C – as you can see in those benchmark. According to the meaning of the branching factor, a 2x speed can be translated in chess engine that search 1 ply deeper and that – see Ferreira – is less than to 100+ elo points. Does C really worth those 100 elo points? It’s up to you.

Ada has a lot of features that helps you write good code. Ada source is really clear and the language itslelf has a very high readability, that is a good thing for reducing the danger of hidden bugs. Ada, also, has a lot of features to detect and solve bugs at compile time and at run time, like overflow checks and all the problems commons in pointers and arrays. By using Ada, you will spend more time in coding cool things than in fixing annoying bugs.

Ada, if you don’t know, is object oriented and the code is organized in packages and subpackages. It supports all the features that you desire in a compiled language: operator overloading, pointers (called access types in Ada), templates (called generics in Ada). Ada has a very advanced exceptions handling system (like Java has too), it support – of course – the function overloading (also by return type) and inlining and, by being a strong typed language, Ada inherit all the benefits related to this feature. Ada has, in general, all the features that also C/C++ and Java they have too.

And that’s only the first half. Ada is much, much more. It has native support for multithreading – i.e. compiler helps you – and comes with a huge library and features for parallel programming. It handle preconditions and postconditions to let you develop high level contract-based code and it has and incredible amount of tools to help you and the compiler detect any kind of error in your code.

One of my favourite features of Ada is the ability to handle default values for variables to avoid problems with uninitialized data.

Ada is, in general, really a great designed language.


It should be clear that Ada has been a nice idea for writing my engine.

As I wrote many lines before, it is my opinion that the ability – and therefore the choice – of C/C++ as language for chess programming is overrated. Only the strongest engine can argue of it. The others, in my opinion, could choose their favourite one. If you’re favourite is C, then it’s ok, if not don’t worry! Don’t think that C itself will make your engine strong, it’s your code that does it.

In this article I tried to explain not only why Ada is a good idea but why I think that mostly every language is a good choice if you enjoy your hobby. Any computer language comes with some idioms in their mind: lear them, use it and have fun! You can do an excellent work, have a lot of challenges and fun even if your engine will not beat Kasparov!

Alessandro Iavicoli

I am an italian computer software developer. I am passionate about Ada and the game of chess, and as a consequence I do also chess program in Ada. I like very much dancing cuban salsa, which I am a certificated teacher too.

Leave a Reply

Your email address will not be published. Required fields are marked *