Welcome, Guest. Please Login or Register.
Apr 19th, 2024, 8:58pm

Home Home Help Help Search Search Members Members Login Login Register Register
Arimaa Forum « c++ vs c# »


   Arimaa Forum
   Arimaa
   Bot Development
(Moderator: supersamu)
   c++ vs c#
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: c++ vs c#  (Read 4596 times)
JimmSlimm
Forum Guru
*****




Arimaa player #6348

   


Gender: male
Posts: 86
c++ vs c#
« on: Sep 23rd, 2013, 3:46pm »
Quote Quote Modify Modify

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 Smiley
 
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?
IP Logged
Druzil
Forum Junior Member
**



Arimaa player #6252

   


Gender: male
Posts: 6
Re: c++ vs c#
« Reply #1 on: Sep 24th, 2013, 8:38pm »
Quote Quote Modify Modify

Did you profile the c# code - what were the bottlenecks that c++ alleviated?
IP Logged
JimmSlimm
Forum Guru
*****




Arimaa player #6348

   


Gender: male
Posts: 86
Re: c++ vs c#
« Reply #2 on: Sep 25th, 2013, 10:25am »
Quote Quote Modify Modify

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)
IP Logged
Janzert
Forum Guru
*****



Arimaa player #247

   


Gender: male
Posts: 1016
Re: c++ vs c#
« Reply #3 on: Sep 25th, 2013, 1:08pm »
Quote Quote Modify Modify

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 is a great resource for techniques that are also commonly used in Arimaa bots. The Transposition Table entry has a pretty good overview of variations that have been used.
 
Janzert
IP Logged
rbarreira
Forum Guru
*****



Arimaa player #1621

   


Gender: male
Posts: 605
Re: c++ vs c#
« Reply #4 on: Sep 25th, 2013, 1:17pm »
Quote Quote Modify Modify

on Sep 25th, 2013, 1:08pm, 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.
IP Logged
JimmSlimm
Forum Guru
*****




Arimaa player #6348

   


Gender: male
Posts: 86
Re: c++ vs c#
« Reply #5 on: Sep 25th, 2013, 1:25pm »
Quote Quote Modify Modify

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
« Last Edit: Sep 25th, 2013, 1:26pm by JimmSlimm » IP Logged
Janzert
Forum Guru
*****



Arimaa player #247

   


Gender: male
Posts: 1016
Re: c++ vs c#
« Reply #6 on: Sep 25th, 2013, 1:36pm »
Quote Quote Modify Modify

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
IP Logged
Druzil
Forum Junior Member
**



Arimaa player #6252

   


Gender: male
Posts: 6
Re: c++ vs c#
« Reply #7 on: Sep 25th, 2013, 5:41pm »
Quote Quote Modify Modify

I'm quite surprised by the amount of the speedup - just to clarify this was on windows? You weren't using mono?
IP Logged
JimmSlimm
Forum Guru
*****




Arimaa player #6348

   


Gender: male
Posts: 86
Re: c++ vs c#
« Reply #8 on: Sep 26th, 2013, 3:15am »
Quote Quote Modify Modify

Yeah windows 7 64-bit. Singlethreaded.
I'm also suprised by the amount of speedup
IP Logged
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

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