software – Why dont chess engines use Node.js? – Chess …

Posted: December 29, 2021 at 10:05 am

This is more of a question for Stack Overflow if you ask me... But since I've come here from there and I'm a software engineer and avid chess player, I'll try to explain.

This basically boils down to two factors, history and speed of execution. I'll handle them separately.

History

Javascript (the language Node uses) is a relatively young language. It was developed in 1996. Node, is even younger, being released in 2009. In comparison, C came out in 1972 and C++ in 1985.

The first major breakthrough in chess engines occurred when Deep Blue (written in C++) became the first chess engine to beat a grandmaster in 1997. At that point, it had been in active development for a few years and Javascript (then JScript) was a fledgling language that could do just the most basic web-based things.

As a result of this, it seems like a natural progression that future chess engines would build on the existing work and continue with C based languages. Not to mention the fact that the number of software engineers that could program in C/++ also vastly exceeded the number of JS engineers until well into the new millenium.

Speed

Chess is a hard problem computationally. It has a game-tree complexity score of 123 (exactly what this means is beyond the scope of this answer, but Noughts and Crosses has a score of 5, for comparison). As such, unless you want to be hanging around for a really long time while the computer works out its next move, your engine needs to run fast.

Javascript (and by extension Node) is an interpreted language. That means at runtime, it needs to be parsed and compiled before it can be executed. It also means that there's no opportunity for compile time optimisations to take place.

In direct juxtaposition to this, C based languages are precompiled. This means that they can execute directly at runtime with no intermediary steps and little overhead. There is also a plethora of compile-time optimisations that take place.

The end result of this is that for any given program, C/++ will perform approximately an order of magnitude faster on average. Admittedly, this has improved in the last few years somewhat, but they are still incomparable in terms of raw speed.

It must be noted, however, that speed and efficiency were far more important in previous decades. With today's computing power, even the most inefficient chess engine will run in a reasonable manner (unless it's just a dumb, extensive brute force - that will just never finish). Hence, why there are now Javascript based chess engines.

Conclusion

When you consider the history of the two languages along with the amount of computational power (and therefore the importance of efficiency) required to run a chess engine, it becomes clear why most of them are written in C based languages.

I will also add some personal opinion. C and C++, as strongly typed, procedural languages are simply far more suited to writing code for something like a chess engine. Sure, it can be done in Javascript but that was designed primarily for sending requests to a server and displaying results on a website, it's not designed for complex algorithms and the structures it uses show that.

Read more here:

software - Why dont chess engines use Node.js? - Chess ...

Related Posts