Poker-AI.org
http://poker-ai.org/phpbb/

Best hand evaluator for C# bot?
http://poker-ai.org/phpbb/viewtopic.php?f=24&t=2553
Page 1 of 3

Author:  Seikez [ Mon Aug 12, 2013 9:33 pm ]
Post subject:  Best hand evaluator for C# bot?

I need a reliable, easy to use and fast (in that priority order) hand evaluator for my Holdem C# Bot. Preferably with documentation and usage examples.

It should handle preflop, flop, turn and river (2, 5, 6 and 7 cards). It should handle 1 - 9 opponents. I also need functions to calculate win probability, EV and other things my bot might need.

The alternatives I have found are all several years old, which makes me unsure which is the best choice today.

I therefore turn to you guys for some advice, it will be greatly appreciated!

Author:  vlad2048 [ Mon Aug 12, 2013 10:00 pm ]
Post subject:  Re: Best hand evaluator for C# bot?

I don't know the best answer.
I've ported the poker-eval 7 card evaluation function to c# (exactly the same with all the table lookups) and it's 10x slower :(
I wonder why ?

Author:  shalako [ Mon Aug 12, 2013 10:06 pm ]
Post subject:  Re: Best hand evaluator for C# bot?

I use Timmys available here for absolute equity and hand state info. For range equity I use propokertools which has a nice shell script but its a bit slow. There are probably faster native or DLL based range equity calculators that you could use.

Author:  Seikez [ Tue Aug 13, 2013 8:27 am ]
Post subject:  Re: Best hand evaluator for C# bot?

Quote:
I don't know the best answer.
I've ported the poker-eval 7 card evaluation function to c# (exactly the same with all the table lookups) and it's 10x slower
I wonder why ?

Make sure you time it with VisualStudio set to Release configuration, it makes a big difference compared to Debug. And remember highly optimized C++ will always be faster than C# (about 1.5 - 3 times I think).

If you are still 10 times slower, try to use some kind of profiler (for instance Red-gate or Jetbrains) to track down where your CPU spends it's time and optimize that part. If that doesn't help, I think you can write IL code directly in your C# program, which is sort of like the asm directive in some C/C++ compilers.
Also check this page for C# optimization: http://www.dotnetperls.com/optimization

Author:  LOLWorld [ Tue Aug 13, 2013 5:04 pm ]
Post subject:  Re: Best hand evaluator for C# bot?

http://www.codeproject.com/Articles/19091/More-Texas-Holdem-Analysis-in-C-Part-1

Author:  vlad2048 [ Tue Aug 13, 2013 7:38 pm ]
Post subject:  Re: Best hand evaluator for C# bot?

Hey thanks Seikez, release mode made it 40% faster, I'll look into the rest when I'll need the speed later.
I remember doing some tests at work comparing C++ and C# speed, I used a simple matrix multiplication and got roughly the same speed in both. In one of the tests C# was even a tiny fraction of time faster.
So I think with a bit of looking into it I should be able to get very similar performance in C# for simple arithmetic operations like hand evaluation.

Author:  OneDayItllWork [ Tue Aug 13, 2013 9:08 pm ]
Post subject:  Re: Best hand evaluator for C# bot?

You'll also get more speed running without the debugger attached.

Author:  Seikez [ Wed Aug 14, 2013 10:37 am ]
Post subject:  Re: Best hand evaluator for C# bot?

Quote:
http://www.codeproject.com/Articles/19091/More-Texas-Holdem-Analysis-in-C-Part-1

Yes, that is one alternative I will have a closer look at. Do you have any experience with it, LoLWorld? Is it reliable and bug free, thread safe?

Author:  Seikez [ Wed Aug 14, 2013 10:46 am ]
Post subject:  Re: Best hand evaluator for C# bot?

Anyone know the status of the XpokerEquity functions? See here: http://www.codingthewheel.com/archives/ ... n-poker-1/

I have found the source, but what is the status? Are there bugs in it (someone said it doesn't return the same Equity as pokerstove)?

Anyone have a C# wrapper for it?

Any alternative that does the same, but in C# ?

Author:  OneDayItllWork [ Wed Aug 14, 2013 11:49 am ]
Post subject:  Re: Best hand evaluator for C# bot?

I use this:
http://www.codeproject.com/Articles/122 ... d-Analysis

Lots of features - there are a few speed improvements that can be made too.

Author:  Seikez [ Wed Aug 14, 2013 12:54 pm ]
Post subject:  Re: Best hand evaluator for C# bot?

Quote:
I use this:
http://www.codeproject.com/Articles/122 ... d-Analysis

Lots of features - there are a few speed improvements that can be made too.

Yes, I know about that. Still collecting info so haven't yet started locking closer at it, but will soon.

It is based on this (http://www.codeproject.com/Articles/19091/More-Texas-Holdem-Analysis-in-C-Part-1) isn't it?

Quote:
there are a few speed improvements that can be made too

Are they secret? Want to share them with the rest of us?

Author:  Seikez [ Wed Aug 14, 2013 4:05 pm ]
Post subject:  Re: Best hand evaluator for C# bot?

Quote:
I use this:
http://www.codeproject.com/Articles/122 ... d-Analysis

Lots of features - there are a few speed improvements that can be made too.

I have run the benchmark included in this, and I am not impressed by the speed. On my i7 2600K running @ 4.2GHz I get 40-50M hands/sec for the first test on view menu (Evaluate) in Release mode. Debug mode 30-40M hands/sec.

In release configuration, I am getting an exception for most of the other tests: "A first chance exception of type 'System.Threading.ThreadAbortException' occurred in HandEvaluator.dll"

Managed to run last test on view menu (Thread Pool Evaluate/Iterate) in Debug mode and are getting 80-100M hands/sec. This is slooooow compared to some other evaluators.

@OneDayItllWork, What speeds are you getting with the Keith Rule c# evaluator?

Author:  OneDayItllWork [ Wed Aug 14, 2013 4:54 pm ]
Post subject:  Re: Best hand evaluator for C# bot?

Can't say I've timed it. I use custom lookups in any time critical code. I posted the code for those on the old forum somewhere.

When you run your tests, are you pre-populating a list of random hands and running though that? If not, you should be.

Author:  spears [ Wed Aug 14, 2013 5:07 pm ]
Post subject:  Re: Best hand evaluator for C# bot?

Quote:
Managed to run last test on view menu (Thread Pool Evaluate/Iterate) in Debug mode and are getting 80-100M hands/sec. This is slooooow compared to some other evaluators.


If you just want a good 6 and 7 card evaluator you could use the 2p2 C code or the java port to generate a lookup table file and then write your own very small evaluator in C#. The speed of that should be as fast as it gets. Maybe one hour's work for someone who is fluent in C# and C.

Author:  Seikez [ Wed Aug 14, 2013 9:47 pm ]
Post subject:  Re: Best hand evaluator for C# bot?

Quote:
When you run your tests, are you pre-populating a list of random hands and running though that? If not, you should be.

Well, actually I am not sure exactly what I am doing. I am running the program named 'Benchmark' and just select a menu item to pick a test to run. The benchmark program comes in the code you can download from this link: http://www.codeproject.com/Articles/19091/More-Texas-Holdem-Analysis-in-C-Part-1 If I understand it correctly, this article is a follow-up to the article in the link you gave me, OneDayItllWork.

I will give it one more try, because the exception suggests something isn't quite right. I suspect the Evaluator dll isn't built because of a dependency that is missing. This means the benchmark is compiled with net 4.0 and the evaluator is compiled for some much older .NET version but run under 4.0, which might hurt it's speed, that's my theory anyway. I will try to fix it so the evaluator dll builds and will then run the benchmarks again. After that I will report back.

Author:  Seikez [ Thu Aug 15, 2013 9:54 am ]
Post subject:  Re: Best hand evaluator for C# bot?

I have now changed build target from .Net 2.0 to .NET 4.0 for all the projects in the Keith Rule C# Evaluator Analysis Part 1 code. No significant speed change compared to earlier results. I don't think the exception is the problem. This is how slow it is (well, actually it's amazingly fast, but it's slow compared to some other evaluators).

It is well documented and I have no reason to doubt it's reliability, but I feel the speed difference compared to other alternatives is too big to be ignored. What a pity! :(

Author:  LOLWorld [ Thu Aug 15, 2013 10:47 am ]
Post subject:  Re: Best hand evaluator for C# bot?

Did you try http://www.codeproject.com/Articles/19092/More-Texas-Holdem-Analysis-in-C-Part-2
Keith adds MonteCarlo analysis and multicore support.

Author:  OneDayItllWork [ Thu Aug 15, 2013 3:07 pm ]
Post subject:  Re: Best hand evaluator for C# bot?

Are you not getting a little hung up on the speed of the evaluator? My bot (apparently) spends 0.13% of it's time in Keith's code... hence, I don't really care about the speed of the evaluator. If I got an evaluator that was twice as fast I'd make next to no difference.

Author:  Seikez [ Fri Aug 16, 2013 8:37 am ]
Post subject:  Re: Best hand evaluator for C# bot?

Quote:
Did you try http://www.codeproject.com/Articles/190 ... n-C-Part-2
Keith adds MonteCarlo analysis and multicore support.

I have tested with the code from part 1 of that article, and if I am not mistaken the download link for the two articles point to exactly the same code. So yes, I have tried that link.


Quote:
Are you not getting a little hung up on the speed of the evaluator?

Ahh, hmmm, well... yes, maybe I am. Thank you for bringing me back to reality. I think what I will do is use Keith's evaluator for a first version of my bot. Then if I find I need more speed, I will have another look at this. Thanks! :)

Author:  shadehs [ Fri Aug 16, 2013 1:16 pm ]
Post subject:  Re: Best hand evaluator for C# bot?

Seikez wrote:
Anyone know the status of the XpokerEquity functions? See here: http://www.codingthewheel.com/archives/ ... n-poker-1/

I have found the source, but what is the status? Are there bugs in it (someone said it doesn't return the same Equity as pokerstove)?

Anyone have a C# wrapper for it?

Any alternative that does the same, but in C# ?

I use this in my bot with a wrapper. Don't know if it's fast or not, anyway it works good for my needs. Also you need to manually free the memory, not a difficult task anyway.

Page 1 of 3 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/