Engine programming

Discussion of anything and everything relating to chess playing software and machines.

Moderators: bob, hgm, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Gejsi Marku
Posts: 20
Joined: Wed Mar 11, 2020 3:02 pm
Full name: Gejsi Marku

Engine programming

Post by Gejsi Marku » Sat Mar 14, 2020 8:51 pm

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

Gejsi :)

Posts: 20916
Joined: Mon Feb 27, 2006 6:30 pm
Location: Birmingham, AL

Re: Engine programming

Post by bob » Sat Mar 14, 2020 9:19 pm

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...

Daniel Anulliero
Posts: 705
Joined: Fri Jan 04, 2013 3:55 pm
Location: Nice

Re: Engine programming

Post by Daniel Anulliero » Sat Mar 14, 2020 9:30 pm

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 ,

Posts: 407
Joined: Tue Nov 19, 2019 7:48 pm
Full name: Alayan Feh

Re: Engine programming

Post by Alayan » Sat Mar 14, 2020 9:42 pm

A good way to get more comfortable with engine programming is to try and contribute to existing engines, e.g. through fishtest or openbench.

Gejsi Marku
Posts: 20
Joined: Wed Mar 11, 2020 3:02 pm
Full name: Gejsi Marku

Re: Engine programming

Post by Gejsi Marku » Sat Mar 14, 2020 9:46 pm

I see most engines are written in C++, so I think that will be my aim.

Posts: 957
Joined: Fri Sep 16, 2016 4:55 pm
Location: USA/Minnesota
Full name: Leo Anger

Re: Engine programming

Post by Leo » Sat Mar 14, 2020 9:48 pm

Glad you joined the gang.
Advanced Micro Devices fan.

User avatar
Posts: 847
Joined: Wed Apr 21, 2010 2:58 am
Location: Australia
Full name: Nguyen Hong Pham

Re: Engine programming

Post by phhnguyen » Sun Mar 15, 2020 5:03 am

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
A freeware chess GUI, based on opensource Banksia - the chess tournament manager

Posts: 201
Joined: Wed Nov 21, 2012 11:20 pm
Location: New Hampshire

Re: Engine programming

Post by JohnW » Sun Mar 15, 2020 11:37 am

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.

Posts: 3995
Joined: Fri Mar 10, 2006 4:23 am
Location: http://www.arasanchess.org

Re: Engine programming

Post by jdart » Sun Mar 15, 2020 1:24 pm

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.


Posts: 273
Joined: Fri Dec 16, 2016 10:04 am

Re: Engine programming

Post by abulmo2 » Sun Mar 15, 2020 2:04 pm

Gejsi Marku wrote:
Sat Mar 14, 2020 8: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.
Richard Delorme

Post Reply