Advantages of C++11 for Chess?

Discussion of chess software programming and technical issues.

Moderator: Ras

MOBMAT
Posts: 412
Joined: Sat Feb 04, 2017 11:57 pm
Location: USA

Re: Advantages of C++11 for Chess?

Post by MOBMAT »

As far as whether or not you should try to write a "pure" OO C++ app....

I will paraphrase a quote from Toy Story where when Buzz and Woody are flying and trying to land back in the truck, Woody exclaims to Buzz, "your flying!". Buzz responds with, "No, I'm falling with style".

I take the same approach to C++. as mentioned, you can really over do it.

i like to code "C with class" !

meaning, i'll add classes, such as for position or the move generation, but will use global methods where it is appropriate. I also have a class to support PolyGlot book usage, FEN parsing, Hash Table, etc. as classes are a good way to encapsulate code.

you can feel less guilty and put some common code into namespaces, if that helps.

You can try to be a OO purist if you want, but you'll probably spend a lot more time trying to achieve that goal.

As far as templates go, they can be useful in the right circumstances. I find that if I have something that needs to handle different data types, I'll just write an overload function, such as these off the cuff examples:

BitSet(U64 *b, int sqr); // this works for a bitmap...
BitSet(U8 *s, U8 bit); // this is used for castling flags

you would still have to write two templates to handle both of these (unless I am missing something), so I take full advantage of the great overload capabilities of C++.
i7-6700K @ 4.00Ghz 32Gb, Win 10 Home, EGTBs on PCI SSD
Benchmark: Stockfish15.1 NNUE x64 bmi2 (nps): 1277K
User avatar
xr_a_y
Posts: 1872
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Re: Advantages of C++11 for Chess?

Post by xr_a_y »

I use atomic too for some counters and boolean values. With more than 4 or 6 threads and too much of those atomic (say 20 or 25), they become the bottleneck. I used to gather statistic during search, atomic will not work for that, you need a map/reduce kind of thing ; otherwise, atomic are simple and fun to use.