Arimaa Forum (http://arimaa.com/arimaa/forum/cgi/YaBB.cgi)
Arimaa >> Bot Development >> c++ vs c#
(Message started by: JimmSlimm on Sep 23rd, 2013, 3:46pm)

Title: c++ vs c#
Post by JimmSlimm on Sep 23rd, 2013, 3:46pm
I am moving my Arimaa projects from C# to C++, its alot of work.

I'm not even close to being as proficient in c++ as c#, but I am impressed by the speed gains so far.

To generate a full ply of unique moves 1000 times from a board position with ~39k possible unique moves timings:
C#: ~30 seconds (optimized as good as I possibly could make it)
C++: on first try: ~20 seconds
second try: ~15 seconds, with the use of BOOST library for c++
Third try: ~10 seconds, with the use of x64 intrinsics for Bitboard manipulation. And pre-allocating memory for vectors(same as List<> in c#)

So, overall from ~30seconds to ~10seconds for move generation, amazing!

Next up is the alpha-beta algorithm migration. It'll be fun to see if there's any speed gain there as well :)

So for those who are thinking about making a bot, I recommend c++ over c# simply for the speed gain

Has anyone else migrated their code from a language to another?

Title: Re: c++ vs c#
Post by Druzil on Sep 24th, 2013, 8:38pm
Did you profile the c# code - what were the bottlenecks that c++ alleviated?

Title: Re: c++ vs c#
Post by JimmSlimm on Sep 25th, 2013, 10:25am
Yeah I profiled both, in c# I can't really blame any specific part of the code as being a bottleneck anymore.

In c++ the bottleneck is checking/adding zobrist hashes to transposition table for duplicate board states. I am using boost::unordered_set for that. And I will not even try to improve that part. I think the most effort-efficient way to improve speed now would be to upgrade my PC (I suspect RAM speed is more important than CPU for transposition tables usage)

Title: Re: c++ vs c#
Post by Janzert on Sep 25th, 2013, 1:08pm
I'm not much of a C++ coder and have never used boost at all, but I would be surprised to find that unordered_set is good for an efficient transposition table. The desired behavior is just too different.

I would start by trying a simple array of entries. With entry look up being a simple zobrist_hash % array_size. There are then a lot of ways this can be made more complicated, any of which may or may not improve performance depending on the specifics of your program.

In case you haven't found it yet the chess programming wiki (http://chessprogramming.wikispaces.com/) is a great resource for techniques that are also commonly used in Arimaa bots. The Transposition Table entry (http://chessprogramming.wikispaces.com/Transposition+Table) has a pretty good overview of variations that have been used.

Janzert

Title: Re: c++ vs c#
Post by rbarreira on Sep 25th, 2013, 1:17pm

on 09/25/13 at 13:08:28, Janzert wrote:
I'm not much of a C++ coder and have never used boost at all, but I would be surprised to find that unordered_set is good for an efficient transposition table.


Since he's only talking about move generation I'm not sure that he's talking about an actual transposition table - perhaps just a set of already generated moves indeed, in which case unordered_set is probably OK to use.

Title: Re: c++ vs c#
Post by JimmSlimm on Sep 25th, 2013, 1:25pm
Thanks Janzert, I am aware of that site, it's indeed very useful. I didn't have success with the "zobrist_hash % array_size" in C#, so I used HashSet<ulong> instead

I'll try it in c++, it's a good idea to try different solutions on the transposition table since it's the bottleneck for move generation at the moment

edit: rbarreira yea that's exactly what I meant

Title: Re: c++ vs c#
Post by Janzert on Sep 25th, 2013, 1:36pm
Ahh yes, if you're looking to store generated moves and don't want to merely overwrite/forget entries on collision, then unordered_set is probably appropriate.

Janzert

Title: Re: c++ vs c#
Post by Druzil on Sep 25th, 2013, 5:41pm
I'm quite surprised by the amount of the speedup - just to clarify this was on windows? You weren't using mono?

Title: Re: c++ vs c#
Post by JimmSlimm on Sep 26th, 2013, 3:15am
Yeah windows 7 64-bit. Singlethreaded.
I'm also suprised by the amount of speedup



Arimaa Forum » Powered by YaBB 1 Gold - SP 1.3.1!
YaBB © 2000-2003. All Rights Reserved.