Page 1 of 4

Engine programming

Posted: Sat Mar 14, 2020 9:51 pm
by Gejsi Marku
Hello chess friends,
I have been a lurker in this forum for years because I love the game of chess and its advancement from chess engines, and playing on ICCF I have come to know people who also are familiar with this forum.

I finally decided to join this community since I'm taking a new side hobby. I've decided to get into chess engine programming since I find the field very interesting.
I am not aiming to start a new career as a programmer/developer, but from research I've come to realize I need really good knowledge in the field to be a chess programmer.

I am a bit confused though. I don't know where to start. There are so many programming languages out there, that I kinda feel lost. So I want to ask the senior programmers here for tips. Where should I start as a total beginner?
Which language should I focus? Is there any specific libraries that I should get to know? Are there any specifics that I need to know which apply only to chess programming?

I'm not worried of the difficulty of the field. So if you tell me how hard it is for a total beginner to reach a level of competence enough to program a working chess engine I tell you right now that I know. I'm not on a deadline and since it will be a new hobby for me I am aware it might take months or years. As per learning capabilities I believe it is well within my range.

I just need some guidance. Over years I have gathered some very good ideas from most of you successful in the field, as well as I have a lot of my own that I'd really love to implement. My lack of programming skills is the only thing that gets in my way, and I want to take care of it.

Thank you in advance for all your help, and I must say I find this an amazing community

Cheers,
Gejsi :)

Re: Engine programming

Posted: Sat Mar 14, 2020 10:19 pm
by bob
Normally you should start with the programming language you know best. Unless it is COBOL or an interpreted language. At that point, you should look at the languages you know, and which one you would really like to get familiar with, since chess programming is going to force you to use more than basic compiler tools like loops and arithmetic operations...

Hard for someone other than yourself to answer the above...

Re: Engine programming

Posted: Sat Mar 14, 2020 10:30 pm
by Daniel Anulliero
I wrote my first chess program with QuickBasic 4.5 long time ago : very weak, very slow :)
Then I switched to C , my préférence.
As bob wrote : it is your personnal choice ,

Re: Engine programming

Posted: Sat Mar 14, 2020 10:42 pm
by Alayan
A good way to get more comfortable with engine programming is to try and contribute to existing engines, e.g. through fishtest or openbench.

Re: Engine programming

Posted: Sat Mar 14, 2020 10:46 pm
by Gejsi Marku
I see most engines are written in C++, so I think that will be my aim.

Re: Engine programming

Posted: Sat Mar 14, 2020 10:48 pm
by Leo
Glad you joined the gang.

Re: Engine programming

Posted: Sun Mar 15, 2020 6:03 am
by phhnguyen
IMHO, there are a few suggestions:
1) Programming language: C++ is the best of the best for programming chess engines.
2) Directions: there are two main ways to program a chess engine:
a) Traditional way: search via AlphaBeta algorithms. You may write an Evaluation function to score a given chess position, a search based on AlphaBeta algorithms to find the best moves. You will deal with a lot of specific functions/terms such as quiescence search, hash keys, hash tables, move orders...

If you want to start from some open sources, you may study the source code of TSCP and FirstChess. When you are at a higher level, you may start studying Stockfish.

For knowledge and suggestions, you need to read chess programming wiki (https://www.chessprogramming.org) and/or ask here (but it's better to post in forum Programming and Technical Discussions)

b) Learning way: learn and play chess via neural networks. You won't deal much with chess functions/terms. Instead, you will work with typical techniques of neural networks, then test and optimizing them for chess.

At the moment, even there are some simple source codes for chess neural networks, I suggest you ignore them all but go directly to the source code of Lc0 - the best one.

For knowledge and suggestions, you may go to Lc0 website and study from that. It can give you a long list of papers/articles to ready, a forum and Discord to ask/chat - all are very active.

BTW, the most important is to keep fun and working. Good luck and have fun :D

Re: Engine programming

Posted: Sun Mar 15, 2020 12:37 pm
by JohnW
C++ is probably the best for writing a good chess engine, but for learning your first programming language I would suggest starting out with either VB.NET or C# because they are more English like. With that try creating a simple game, like tic-tac-toe.

Re: Engine programming

Posted: Sun Mar 15, 2020 2:24 pm
by jdart
I agree, C++ is quite difficult for a beginning programmer, and if you are learning the language, a chess program probably shouldn't be your first project.

--Jon

Re: Engine programming

Posted: Sun Mar 15, 2020 3:04 pm
by abulmo2
Gejsi Marku wrote: Sat Mar 14, 2020 9:51 pm Where should I start as a total beginner?
www.chessprogramming.org is where to look if you are seeking for an algorithm and its explanation.
Which language should I focus?
Any compiled language is good. Now most languages: C, C++, D, Go, Rust to name a few, can use the same backend (LLWM) and produce executable of the same quality. Beside the compiler and building tools, you probably need to know how to use profilers and debuggers.
Is there any specific libraries that I should get to know?
For a chess engine, the standard library of the language should be enough. If you want to use your graphic cards for computational purpose, a framework like CUDA or OpenCL may be needed.
Are there any specifics that I need to know which apply only to chess programming?
In a chess engine, you may want to use some machine specific code, like popcnt, bmi2, etc. Usually they are provided as an extension of the standard libraries.