Search Comments and Ratings

go

Comments and Ratings

   
Date File Comment by Comment Rating
27 Feb 2009 Poker hand ranker Function that evaluates poker hands, returns ranks and text descriptions. Author: Rob Slazas MuffinMan

Great starting point for a hand evaluator however still has issues and does not rank all hands correctly. I discovered this several months ago but didn't want to bother with registering to post a reply. After a coworker mentioned using this evaluator to prove an argument, I mentioned the shortcomings. Unfortunately now I can't remember the cases it fails at, but I recall the error is due to the arbitrary method of ranking hands by hashing the card numbers. In some cases hands that should not have the same rank are hashed to the same value. A easy test is to use combs=nchoosek([1:52],5); ranks=rankp(combs,5); unique(ranks) and you will find that all possible hands gives 6987 possible ranks using rankp, which is incorrect, and instead you should get 7462.

Once the total ranks checks out, you should test and find that there are 10 straight flushes, 156 four of a kinds and full houses, 1277 flushes, 10 straights, 858 trips and two pairs, 2860 pairs, and 1277 high card ranks. Otherwise, there is still an error.

As an aside, the 2+2 evaluator can do unordered evaluations of 5-7 card hands, at blazing speeds, and can easily be ported to Matlab.

27 Feb 2009 Poker hand ranker Function that evaluates poker hands, returns ranks and text descriptions. Author: Rob Slazas MuffinMan

30 Aug 2008 Poker hand ranker Function that evaluates poker hands, returns ranks and text descriptions. Author: Rob Slazas S., Rob

Thanks Tim C., there was a hole in the conditional statement for hands with pairs. Nice catch, the update has it fixed.

22 Aug 2008 Poker hand ranker Function that evaluates poker hands, returns ranks and text descriptions. Author: Rob Slazas C, Tim

Pretty neat! But I can't seem to wrap my head around what's happening for the test case below. Using the input:

>> trick = [21, 22, 40, 33, 26, 42, 1, 7];
>> [ranks,descriptions,usedcards,unusedcards] = rankp(trick,5);

yields:

>> descriptions{1}
ans =
    'Two Pairs, Ace's and 8's with a(n) King'
>> usedcards
usedcards =
    21 40 33 1 7

But there are no kings in the 'trick' vector, let alone in the 'usedcards' output. Any hints where this is coming from? I'm using R2007a.

27 May 2008 Place one 2D matrix inside another Places a 2D matrix B into a larger 2D matrix A Author: Rob Slazas Le, Khai

Great!

03 Dec 2007 Poker hand ranker Function that evaluates poker hands, returns ranks and text descriptions. Author: Rob Slazas S, Rob

Daniel,

Thanks for the feedback. I don't get this error with handlength of 5. My first thought is that the random cards might sometimes create an erroneous hand, but that's a guess. Can you email me your complete code and we'll have a look please?

Regards,
Rob

02 Dec 2007 Poker hand ranker Function that evaluates poker hands, returns ranks and text descriptions. Author: Rob Slazas Schröter, Daniel

hi,
I was looking for a function which gives me the equity of two hands at a certain flop and two cards to come.
So i wrote a function which calls the rankp function 10000 times with a random turn and a random river and then looked which hand won how often. But the problem is when I ran rankp with a handlenght of five I always got an error saying:

Warning: Values other than 0 or 1 converted to logical 1
> In rankp>rankhand at 110
  In rankp at 71

Whats this error about? If I run it with a handlenght of two there is no problem at all.

Best regards
Daniel

28 Nov 2007 Poker hand ranker Function that evaluates poker hands, returns ranks and text descriptions. Author: Rob Slazas S, Rob

James,

Yep, a "Straight to the King" beats a "Pair of Jacks" all the time. The straight gets a rank of 80000 and the pair ranks at 801230000, like I think it should. Am I missing something you were pointing out? Please email me with more details if so. Thanks for testing out the function.

Best Regards,
Rob

28 Nov 2007 Poker hand ranker Function that evaluates poker hands, returns ranks and text descriptions. Author: Rob Slazas B, James

Is this working properly??? In the example
change the last line of trick to

15 29 43 45 20 9 31
which is a K high straight....it returns a
ranking number greater (ie lower ranking value) than for the first line which is a pair of jacks???

20 Nov 2007 Poker hand ranker Function that evaluates poker hands, returns ranks and text descriptions. Author: Rob Slazas S, Rob

James,

Thanks for the suggestion. In rev 2 (now posted) we actually did replace the bweuler call with something simpler and faster. I like the idea of using sum(diff), but there are some cases that it appears not to work. Check out the any(sum(logical)) method that Doug came up with. I think this is much closer to elegant than my original approach.

So, the image processing toolbox requirement is gone. But there is still a call to combnk, which is from the statistics toolbox. Besides pasting that m-file in as a subfunction, I haven't found a better way.

If you have an interest in simulating poker hands, or the associated stats, please share your work. There are lots of neat combinatorial things to do with card games.

Best,
Rob S

20 Nov 2007 Poker hand ranker Function that evaluates poker hands, returns ranks and text descriptions. Author: Rob Slazas Kemp, James

Pretty neat, but it's a bit of shame that it uses toolboxes just to test for a straight. Couldn't the test:

(bweuler(rowsum(1:13))==1)

be replaced with something like

(sum(diff(rowsum(1:13))==-1)==1),

it's a bit unwieldy and not nearly as elegant as that in the code, but it seems to works. (Although I only tested it with two hands!)

20 Nov 2007 Poker hand ranker Function that evaluates poker hands, returns ranks and text descriptions. Author: Rob Slazas S, Rob

Marcelo,
Thanks for the input. I considered several ways to identify the cards. The numbered list seemed simple and flexible. Maybe you could write a wrapper script that converts to the type of input you want to use before calling rankp?

Doug,
Thanks for the speed tips, they're included in rev.2. Also, the usedcards and unusedcards output suggestions are there so it should be useful in a variety of apps, depending on how it's called. If you base some Monte Carlo on this, which I employ from time to time, please share.

Best,
Rob

19 Nov 2007 Poker hand ranker Function that evaluates poker hands, returns ranks and text descriptions. Author: Rob Slazas Perlin, Marcelo

Agreed Doug,

Also, I just spotted an error at my msg. The input should be:

{'A','spades' ; 2,'Diamonds'...}

forming a total of 7 rows and 2 columns.

Another idea, which is similar to the monte carlo simulation, is to use the code to play poker against matlab in a GUI environment.

You can also extend it by allowing to computer to make rational choices over the game considering probabilistic measures (maybe given by monte carlo?).

19 Nov 2007 Poker hand ranker Function that evaluates poker hands, returns ranks and text descriptions. Author: Rob Slazas Hull, Doug

Marcelo,

I agree that this would be very useful for simulation, that is in fact why I made the request for it on my blog:

http://blogs.mathworks.com/pick/2007/11/13/lazyweb-on-the-file-exchange/

I think that the engine should be separate from the Monte Carlo, so this structure is perfect.

19 Nov 2007 Poker hand ranker Function that evaluates poker hands, returns ranks and text descriptions. Author: Rob Slazas Perlin, Marcelo

This is nice, but I think the input is not very intuitive, Why dont you make it as

[number,suite;number;suite ...]

e.g.

[A,Spades;2,Diamonds ...]

Also, another suggestion to make things interesting is to write functions and scripts for a monte carlo experiment and see how much % of the simulations you can beat with your current hand. Such function could take as input:

- number of players in the table
- you current hand

and the output would be the number of simulations where you beated the other players (or n of the others).

Then you can use the simulation function and play poker with your players assisted by Matlab power. Cool, isn't it?

 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com