Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i want to write a program that calculate poker hand ranks for omaha poker and holdem poker
i search on github but i can not find a good algorithm
i need an algorithm that do it very fast

What I have tried:

i am trying to write a good algorithm but i am worry about the speed of it

it is what i think :

Algorithm->
0-start
1-get flop cards and player cards
2-copy all cards to an array (int allCards[7 for holdem 9 for omaha])
3-if(isroyalflash(allCards)) return royalflash;
4-else if(isFourOfKind(allcards)) return FourOfKind;
5-else if ...
6-...
.
.
.
- return highCard

in this i should write functions for calculate each hands (royalflash , straight , fullhouse etc...)

the other way that i think is

i create a 2d array (boolean flags[4][13])
and set all of them to false but set true where we have a card
this 2d array is all 52 cards (all false) for my 7 or 9 cards set true in this array
then i calculate each hand for example count all true value of flag[0][j] (j from 0 to 12)
if count is 5 it is a flash
and count other cards for other situations

can you help me to write a goood algorithm to do this job
thanks
Posted
Updated 23-May-16 21:44pm
v2
Comments
jeron1 23-May-16 14:23pm    
IMHO, pick the one that you're most comfortable with and code it up. Don't worry about speed optimizations yet, get the program working as intended first. Sometimes you'll find that speed optimizations are not necessary.

1 solution

you can go one step further and work with bits. And because you only need 13 you can use DWORD

C++
struct CARDS
{
  DWORD caro;
  DWORD red;
  DWORD spades;
  DWORD black;
};

Than work with the great old school paradigm of lightning fast bitshifting and get a real coder. :-) This tutorial will provide the needed knowledge.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900