- Blind mode tutorial
lichess.org
Donate

Questions regarding making a chess engine.

There's a tutorial on Youtube by Bluefever Software titled "Programming A Chess Engine In Pure Javascript" - could be useful if you're starting a brand new project. I used his VICE chess engine written in C as the basis for my own engine @MagiC-engine which performs at almost 2200 CCRL blitz!

If you are completely new to computer chess programming (or just programming in general), it is important to make sure you take time to actually understand the code, rather than just quickly zip through the tutorial :) Only then will you be able to optimize the code and improve the chess engine strength.

I recommend writing a chess engine in C or C++ as it will generally be faster, and in addition the online resources for chess programming in C and C++ are plentiful (most of the CCRL engines are either C or C++).

Good luck!

There's a tutorial on Youtube by Bluefever Software titled "Programming A Chess Engine In Pure Javascript" - could be useful if you're starting a brand new project. I used his VICE chess engine written in C as the basis for my own engine @MagiC-engine which performs at almost 2200 CCRL blitz! If you are completely new to computer chess programming (or just programming in general), it is important to make sure you take time to actually understand the code, rather than just quickly zip through the tutorial :) Only then will you be able to optimize the code and improve the chess engine strength. I recommend writing a chess engine in C or C++ as it will generally be faster, and in addition the online resources for chess programming in C and C++ are plentiful (most of the CCRL engines are either C or C++). Good luck!

@zzhangb4 Thanks. Do you have an idea of why C or C++ are better ones and what would be the further advantages of using those both in contrast with other languages such as JavaScript or Python?

@zzhangb4 Thanks. Do you have an idea of why C or C++ are better ones and what would be the further advantages of using those both in contrast with other languages such as JavaScript or Python?

I think C and C++ are better for a number of reasons, the most obvious being that those languages are inherently very fast (especially C). C is a 'low-level' language, meaning that it closely resembles assembly and machine code. (High-level languages such as Python and JavaScript must be translated to machine code before execution, which takes some time.) Therefore C code can be compiled and interpreted very quickly, which lets your program run faster. Additionally, when writing C code, you will constantly be exploring various memory allocation functions, all of which can help you understand how the computer stores information, and how one can extract information. Being able to understand how the computer handles information at the most basic level is one of the many skills needed to produce efficient code.

If you are new to coding, I recommend learning Python. The syntax is easy-to-read and you can do many great things with the various libraries :)

I think C and C++ are better for a number of reasons, the most obvious being that those languages are inherently very fast (especially C). C is a 'low-level' language, meaning that it closely resembles assembly and machine code. (High-level languages such as Python and JavaScript must be translated to machine code before execution, which takes some time.) Therefore C code can be compiled and interpreted very quickly, which lets your program run faster. Additionally, when writing C code, you will constantly be exploring various memory allocation functions, all of which can help you understand how the computer stores information, and how one can extract information. Being able to understand how the computer handles information at the most basic level is one of the many skills needed to produce efficient code. If you are new to coding, I recommend learning Python. The syntax is easy-to-read and you can do many great things with the various libraries :)

Yeah, doing computationally intensive stuff in Python is basically my day job, native Python is fundamentally just one or two orders of magnitude slower than something like C or C++ for that sort of thing, and as far as I can tell, chess engines are about as computationally intensive as it comes.

There are ways around this, but they generally involve calling down into code that's written in a faster language, either by you or by someone else. In the case of code written by someone else, this can be great if there's a good library for the thing you want to do - the reason that Python is usable for scientific modelling and for machine learning is that it has good resources for those things - but I'm not sure how easy it'd be to get all the alpha-beta algorithms and evaluation functions and whatever into one of those frameworks. Javascript, as far as I can tell, has all the slowness with none of the high performance libraries, so you'd be even more stuck.

That said, if you already know Javascript reasonably well, it might be worth getting a feel for the algorithms by implementing them in Javascript before worrying about speed and efficiency and starting to learn a low level language - it's normally easier to handle a new language and a whole new problem domain one at a time rather than both at once.

FWIW I'd consider Rust as a language if I was looking at learning a low-level language specifically to write a chess engine. It's maybe still in the "language hipster" phase, but it seems to be comparable to C++ in terms of performance while giving you fewer opportunities to shoot yourself in the foot.

Yeah, doing computationally intensive stuff in Python is basically my day job, native Python is fundamentally just one or two orders of magnitude slower than something like C or C++ for that sort of thing, and as far as I can tell, chess engines are about as computationally intensive as it comes. There are ways around this, but they generally involve calling down into code that's written in a faster language, either by you or by someone else. In the case of code written by someone else, this can be great if there's a good library for the thing you want to do - the reason that Python is usable for scientific modelling and for machine learning is that it has good resources for those things - but I'm not sure how easy it'd be to get all the alpha-beta algorithms and evaluation functions and whatever into one of those frameworks. Javascript, as far as I can tell, has all the slowness with none of the high performance libraries, so you'd be even more stuck. That said, if you already know Javascript reasonably well, it might be worth getting a feel for the algorithms by implementing them in Javascript before worrying about speed and efficiency and starting to learn a low level language - it's normally easier to handle a new language and a whole new problem domain one at a time rather than both at once. FWIW I'd consider Rust as a language if I was looking at learning a low-level language specifically to write a chess engine. It's maybe still in the "language hipster" phase, but it seems to be comparable to C++ in terms of performance while giving you fewer opportunities to shoot yourself in the foot.

@RamblinDave Do you think it could be a good idea for me to make a simple chess engine in any language at the beginning, and then pass it to another low level one the measure I learn it, or I first should learn the low level language to after that make my chess engine? By the way, what would be the ideal language to make a chess engine? Rust,C+,C,C++,Rust,Python,what? I am perfectionist. Thanks.

@RamblinDave Do you think it could be a good idea for me to make a simple chess engine in any language at the beginning, and then pass it to another low level one the measure I learn it, or I first should learn the low level language to after that make my chess engine? By the way, what would be the ideal language to make a chess engine? Rust,C+,C,C++,Rust,Python,what? I am perfectionist. Thanks.

Personally I'd start by writing a simple engine in a language that I know, and then rewrite it in a lower-level language as part of the learning process.

I don't know about the absolute best language, although I'm pretty confident that it's not going to be Python!

Personally I'd start by writing a simple engine in a language that I know, and then rewrite it in a lower-level language as part of the learning process. I don't know about the absolute best language, although I'm pretty confident that it's not going to be Python!

C++ is a good system language to make chess engines, and C# also works. Java is kind of similar. You can make a engine from scratch, or you can use a game engine to do the basic tasks. Rust won't be a good language. I am a python programmer myself, and it is versatile with such works, but it is a bit slow and won't work up to your expectations

C++ is a good system language to make chess engines, and C# also works. Java is kind of similar. You can make a engine from scratch, or you can use a game engine to do the basic tasks. Rust won't be a good language. I am a python programmer myself, and it is versatile with such works, but it is a bit slow and won't work up to your expectations

If you are good at machine learning and neural network programming, you should use python. Computational power won't be important then because the engine can find efficient patterns very easily with enough training

If you are good at machine learning and neural network programming, you should use python. Computational power won't be important then because the engine can find efficient patterns very easily with enough training

#27 I'm curious as to why you think Rust won't be good, especially given that a bit more digging turns up at least a couple of 2900+ rated engines written in it...

#27 I'm curious as to why you think Rust won't be good, especially given that a bit more digging turns up at least a couple of 2900+ rated engines written in it...

1- Maybe. The current answer seems to be yes, if your goal is to make the strongest engine possible. But there might be a breakthrough in the (near) future which opens a complete different approach.
2- You can write an engine in most general purpose languages. Different languages have different advantages. If you want a lot of raw power, I'd look at C, which is hardly more than glorified assembler. And even look into writing fragments in assembler for the really hot parts of your code. But you have to work harder to do something.
3- An answer to that question cannot be simply given -- that's the heart of all chess engines. And the answer will be very different on whether you are writing an engine based on deep learning (where you are studying patterns) and the more classical approach (where you are evaluating positions).

I'd say, start with something simple. Start with writing a program which can play a game, even if it's terrible moves each time. A next step could be to pick the best move out of all moves, without looking ahead. Then you do 1 half-move ahead. Then 2 half-moves. And only then you start worrying about pruning.

1- Maybe. The current answer seems to be yes, if your goal is to make the strongest engine possible. But there might be a breakthrough in the (near) future which opens a complete different approach. 2- You can write an engine in most general purpose languages. Different languages have different advantages. If you want a lot of raw power, I'd look at C, which is hardly more than glorified assembler. And even look into writing fragments in assembler for the really hot parts of your code. But you have to work harder to do something. 3- An answer to that question cannot be simply given -- that's the heart of all chess engines. And the answer will be very different on whether you are writing an engine based on deep learning (where you are studying patterns) and the more classical approach (where you are evaluating positions). I'd say, start with something simple. Start with writing a program which can play a game, even if it's terrible moves each time. A next step could be to pick the best move out of all moves, without looking ahead. Then you do 1 half-move ahead. Then 2 half-moves. And only then you start worrying about pruning.

This topic has been archived and can no longer be replied to.