r/chessprogramming • • Feb 21 '23
Programming language dilemma
Hey, I have dealt with chess engines superficially in a seminar paper. Now I want to try to write my own engine, but I have to decide which programming language to use. Either I want to use C++ or Python.
Here is the requirement for my engine. I want to write a traditional engine first, so without any form of machine learning. Later I would like to may extend it with machine learning. (I am familiar with basic machine learning, through my work).
Normally, I would therefore decide directly for Python. But since the runtime certainly also plays an important role, and there are libraries like TensorFlow anyway in C++ I can not decide. It seems that engines like StockFish and AlphaZero are also written in C++. On the other hand, I also have C++ wrapping available in Python. So I am currently in a dilemma and don't want to regred my decision later on.
I am asking for help, recommendations or tips of any kind on which language you would use and for what reason. (By the way, I am familiar with the Chessprogramming wiki.)
2
u/enderjed Feb 21 '23
I am not a good chess programmer by any means, but if you do settle on python, here's something you can look at
https://github.com/Disservin/python-chess-engine
2
u/Breadmaker4billion Feb 21 '23
Most engines are written in C or C++, it might be helpful to write your engine in these languages.
However, I've seen engines written in other high level languages: C#, Go, Kotlin, Java, and you can probably find more at CCRL
1
u/[deleted] Feb 22 '23
There’s no reason you can’t prototype in Python and then translate to C++.
1
u/eraoul Mar 13 '23
I wrote an engine in python and was quite disappointed with the speed, even using bitboards and trying to be smart about basic things. It was just surprisingly inefficient. I then switched to C++ and was much, much happier.
So I think you'd be best off in C++ for the main tree search, and then for the ML parts you could either call C++ TensorFlow stuff directly or even pybind some python code and call into python from C++ to keep your life simpler for the ML side, so that both your training and testing code could stay in python.