7 张牌扑克手牌评估器

发布于 2024-09-01 10:57:51 字数 87 浏览 4 评论 0原文

有谁知道评估 7 张牌扑克牌的快速算法吗?这比简单地暴力检查 7 张牌中每 21 个 5 张牌的组合更有效。

干杯,

Pete

Does anyone know a fast algorithm for evaluating 7 card poker hands? Something which is more efficient than simply brute-force checking a every 21 5-card combination of hands from a set of 7.

Cheers,

Pete

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

初心 2024-09-08 10:57:51

我用JavaScript写了一个。核心评估方法仅使用位操作,因此速度非常快。考虑到这一点,查看 21 种组合还是很快的。我们唯一需要深入研究的时候是平局发生的时候。当这种情况发生时,我们需要研究更多细节,看看哪一手 5 张牌实际上是最好的。这是我想出的解决方案:

hands=["4 of a Kind", "Straight Flush", "Straight", "Flush", "High Card",
       "1 Pair", "2 Pair", "Royal Flush", "3 of a Kind", "Full House" ];
var A=14, K=13, Q=12, J=11, _ = { "♠":1, "♣":2, "♥":4, "♦":8 };

//Calculates the Rank of a 5 card Poker hand using bit manipulations.
function rankPokerHand(cs,ss) {
  var v, i, o, s = 1<<cs[0]|1<<cs[1]|1<<cs[2]|1<<cs[3]|1<<cs[4];
  for (i=-1, v=o=0; i<5; i++, o=Math.pow(2,cs[i]*4)) {v += o*((v/o&15)+1);}
  v = v % 15 - ((s/(s&-s) == 31) || (s == 0x403c) ? 3 : 1);
  v -= (ss[0] == (ss[1]|ss[2]|ss[3]|ss[4])) * ((s == 0x7c00) ? -5 : 1);

  document.write("Hand: "+hands[v]+((s == 0x403c)?" (Ace low)":"")+"<br/>");
}

//Royal Flush   
rankPokerHand( [ 10, J, Q, K, A],  [ _["♠"], _["♠"], _["♠"], _["♠"], _["♠"] ] ); 

此处说明< /a>
此处演示

I wrote one in JavaScript. The core evaluating method uses only bit manipulations so is extremely fast. With this in mind, looking at 21 combinations is still very fast. The only time we need to go deeper is when a tie occurs. When this happens, we need to look into more details to see which 5 card hand is actually the best. Here is the solution I came up with:

hands=["4 of a Kind", "Straight Flush", "Straight", "Flush", "High Card",
       "1 Pair", "2 Pair", "Royal Flush", "3 of a Kind", "Full House" ];
var A=14, K=13, Q=12, J=11, _ = { "♠":1, "♣":2, "♥":4, "♦":8 };

//Calculates the Rank of a 5 card Poker hand using bit manipulations.
function rankPokerHand(cs,ss) {
  var v, i, o, s = 1<<cs[0]|1<<cs[1]|1<<cs[2]|1<<cs[3]|1<<cs[4];
  for (i=-1, v=o=0; i<5; i++, o=Math.pow(2,cs[i]*4)) {v += o*((v/o&15)+1);}
  v = v % 15 - ((s/(s&-s) == 31) || (s == 0x403c) ? 3 : 1);
  v -= (ss[0] == (ss[1]|ss[2]|ss[3]|ss[4])) * ((s == 0x7c00) ? -5 : 1);

  document.write("Hand: "+hands[v]+((s == 0x403c)?" (Ace low)":"")+"<br/>");
}

//Royal Flush   
rankPokerHand( [ 10, J, Q, K, A],  [ _["♠"], _["♠"], _["♠"], _["♠"], _["♠"] ] ); 

Explanation Here
Demo Here

撧情箌佬 2024-09-08 10:57:51

该网站列出了一堆扑克牌评估器库并提供了一些详细信息关于他们每个人。其中大多数适用于 5 张牌,但至少有一个适用于 7 张牌,名为 Snezee7 评估器。此外,该网站还全面概述了用于快速分析扑克手牌的不同技术和算法。

我在几个不同的 扑克项目 中使用了 Pokersource Evaluator 的 Keith Rule C# 端口,并且认为它是一个优秀的图书馆。您可以使用许多巧妙的技巧来制作真正快速的手动评估器,但编写代码需要大量工作,我强烈建议使用现有的库。

This site lists a bunch of Poker Hand Evaluator libraries and gives a few details about each of them. Most of them are for 5 card hands, but there is at least one for a 7 card hand called The Snezee7 Evaluator. Plus the site give a great overview of the different techniques and algorithms used to analyze poker hands quickly.

I've used the Keith Rule C# Port of the Pokersource Evaluator in a few different poker projects and think that it is an excellent library. There are many clever tricks you can use to make really fast hand evaluators, but writing the code is a lot of work and I would highly suggest using an existing library.

月光色 2024-09-08 10:57:51

很高兴你问:)是的,这是一个全新的解决方案,可能只是门票:

代码:http:// /code.google.com/p/specialkpokereval/
博客:http://specialk-coding.blogspot .com/2010/04/texas-holdem-7-card-evaluator_23.html

此评估器的商业级改进版可通过 iTunes Store 用于 iPhone/iPod Touch。它被称为“扑克王牌”。

James Devlin 的博客“编码轮子上提供了各种解决方案的精彩总结以及链接”。

尚未讨论的一位评估者是 Klaatu 的

祝你好运!

Glad you asked :) Yes, here's a brand new solution that may be just the ticket:

Code: http://code.google.com/p/specialkpokereval/
Blog: http://specialk-coding.blogspot.com/2010/04/texas-holdem-7-card-evaluator_23.html

A commercial-grade evolution of this evaluator is available for the iPhone/iPod Touch via iTunes Store. It's called "Poker Ace".

An excellent summary of various solutions complete with links is found on James Devlin's blog "Coding The Wheel".

One evaluator not yet discussed there is Klaatu's.

Good luck!

原谅我要高飞 2024-09-08 10:57:51

我开发了一种用于 7 张牌手牌评估的算法,无需迭代所有 21 种组合。

基本上,它将 7 张牌分为两类:同花和非同花。如果是同花,则很容易在包含 8192 个条目的表中查找该值。如果不是刷新,它将使用动态编程技术运行哈希函数,然后在包含 49205 个条目的哈希表中查找该值。

如果您有兴趣,请查看我在 github 上的工作。

https://github.com/HenryRLee/PokerHandEvaluator

I developed an algorithm for 7-card hand evaluation without iterating all 21 combinations.

Basically, it splits the 7-card hand into two categories: flush and not a flush. If it's a flush, it would be easy to look up the value in a table of 8192 entries. If it's not a flush, it'll run a hash function with techniques of dynamic programming, and then look up the value in a hash table of 49205 entries.

If you are interested, please check my work at github.

https://github.com/HenryRLee/PokerHandEvaluator

岁月静好 2024-09-08 10:57:51

我认为你应该做 21 种组合并使用某种 7462 表。
第一:任意7张牌有21种不同的5张牌组合
第二:每个可能的最终扑克手牌 (2.598.960) 代表 7462 种不同手牌之一
所以,这很容易。

您只需查看每 21 种卡牌组合,然后查看每一种卡牌的 7462 排名表的排名即可。 http://www.sendspace.com/file/pet0dd

然后,对于每 7 张卡片,您将我制作的 7462 表中有 21 个不同的排名。 21 种组合中排名最高的就是您想知道的那一种。

要理解该表:在每一行中,您都有 5 张牌(Z 代表同花,Y 代表非同花),并且您有它的排名。那只是你需要的。我为您提供了表格和示例算法。这不是真正的代码。它是 Visual Basic 格式,我现在编写了它。可能不起作用,但你应该明白。代码将是这样的:

'############### 1st: Define your hand, for example "2c2d2h2s3c3h3s" #############################################################################################

Dim mycard As New ArrayList

mycard(1).Add("2c")
mycard(2).Add("2d")
mycard(3).Add("2h")
mycard(4).Add("2s")
mycard(5).Add("3c")
mycard(6).Add("3h")
mycard(7).Add("3s")
mycard.Sort() '################# you need to sort in alphabeticall order to match it later with 7462 table #############################################



' ################## 2nd: Let´s transform it to every kind of 5 cards combinations (21). It will also preserve the alphabeticall order ##################################

Dim myHand5 As String = ""
Dim suited as String = ""
Dim ranking as Integer = 0
Dim myranking as Integer = 7462
Dim mystring as String = ""

For cicle1 = 0 to 2
     For cicle2 = cicle1 + 1 to 3
          For cicle3 = cicle3 + 1 to 4
               For cicle4 = cicle3 + 1 to 5
                    For cicle5 = cicle4 + 1 to 6
                         myhand5 = left(mycard(cicle1),1) & left(mycard(cicle2),1) & left(mycard(cicle3),1) & left(mycard(cicle4),1)  & left(mycard(cicle5),1)
                         suited = left(mycard(cicle1),2) & left(mycard(cicle2),2) & left(mycard(cicle3),2) & left(mycard(cicle4),2)  & left(mycard(cicle5),2)
                         if suited = "ccccc" or suited = "ddddd" or suited = "hhhhh" or suited = "sssss" then myhand5 = myhand5 & "Z" Else myhand5 = myhand5 & "Y"  
                          ranking = 0                              
                          FileOpen (1, "7462.txt", Input)
                          Do
                               ranking = ranking + 1
                               Input(1, mystring)
                               Input(1, ranking)
                               If mystring = myhand5 Then 
                                    If ranking < myranking then myrankin = ranking
                               End If
                          Loop Until EOF(1)
                          FileClose(1)
                    Next cicle5
               Next cicle4
          Next cicle3
     Next cicle2
Next cicle1

最终排名是 myranking 变量。您应该在一秒钟之内就熟悉了自己的手牌。与其他手牌进行比较也是很好的,因为你拥有的是排名值而不是它的名称。如果你想用扑克算法做一些事情,这就是你应该开始的地方。有了排名值,一切都变得快速而简单。

注意:我不是程序员。我是一个想成为的人。我了解一些视觉基本功能。我希望我知道如何制作真正的程序。如果算法有效,请发表评论。如果你想让它非常非常快,我不知道该怎么做。我希望我有一个超快的算法,可以让我在游戏的每个阶段(实时)检查我对任何对手的赔率。我尝试了很多算法来实时计算翻牌圈的赔率,但我能做到的最快是 30 秒。现在,我可以在 3 秒内计算翻牌圈的赔率,但我使用 150 GB 的数据库,其中许多内容都是预先计算好的。如果您想实时了解赔率,您应该预先计算很多事情。我就是这么做的。

I think you should do the 21 combinations and use some kind of 7462 table.
1st: any 7 cards have 21 different 5 cards combinations
2nd: every possible final poker hands (2.598.960) represents one of 7462 different kind of hands
so, it´s easy.

You just have to look at every 21 combinations of your cards and, for each one, see the ranking of 7462 ranking table. http://www.sendspace.com/file/pet0dd

Then, for each 7 cards you will have 21 different rankings from this 7462 table i made. The highest ranking of 21 combinations is the one you want to know.

To understand the table: In every line you have the 5 card hand (Z for suited, Y non-suited) and you have the ranking of it. That´s only you need. I give you the table and an example algorithm. It´s not really the code. It´s visual basic format and i wrote it now. probably doesn´t work but you should understand. The code would be something like this:

'############### 1st: Define your hand, for example "2c2d2h2s3c3h3s" #############################################################################################

Dim mycard As New ArrayList

mycard(1).Add("2c")
mycard(2).Add("2d")
mycard(3).Add("2h")
mycard(4).Add("2s")
mycard(5).Add("3c")
mycard(6).Add("3h")
mycard(7).Add("3s")
mycard.Sort() '################# you need to sort in alphabeticall order to match it later with 7462 table #############################################



' ################## 2nd: Let´s transform it to every kind of 5 cards combinations (21). It will also preserve the alphabeticall order ##################################

Dim myHand5 As String = ""
Dim suited as String = ""
Dim ranking as Integer = 0
Dim myranking as Integer = 7462
Dim mystring as String = ""

For cicle1 = 0 to 2
     For cicle2 = cicle1 + 1 to 3
          For cicle3 = cicle3 + 1 to 4
               For cicle4 = cicle3 + 1 to 5
                    For cicle5 = cicle4 + 1 to 6
                         myhand5 = left(mycard(cicle1),1) & left(mycard(cicle2),1) & left(mycard(cicle3),1) & left(mycard(cicle4),1)  & left(mycard(cicle5),1)
                         suited = left(mycard(cicle1),2) & left(mycard(cicle2),2) & left(mycard(cicle3),2) & left(mycard(cicle4),2)  & left(mycard(cicle5),2)
                         if suited = "ccccc" or suited = "ddddd" or suited = "hhhhh" or suited = "sssss" then myhand5 = myhand5 & "Z" Else myhand5 = myhand5 & "Y"  
                          ranking = 0                              
                          FileOpen (1, "7462.txt", Input)
                          Do
                               ranking = ranking + 1
                               Input(1, mystring)
                               Input(1, ranking)
                               If mystring = myhand5 Then 
                                    If ranking < myranking then myrankin = ranking
                               End If
                          Loop Until EOF(1)
                          FileClose(1)
                    Next cicle5
               Next cicle4
          Next cicle3
     Next cicle2
Next cicle1

Final ranking is myranking variable. You should know your hand in less than a second. And also is good to compare with other hands, because you have the ranking value not the name of it. And if you want to do something with poker algorithms, this is where you should start. With ranking values everything is quick and easy.

Note: I´m not a programmer. I am a wanna be. I understand some visual basic functions. I whish i knew how to make real programs. If the algorithm works, please leave a comment. If you want it to be very very fast, i don´t know how to do it. I whish i have an ultra fast algorithm that allows me check (in real time) my odds against any opponents in every stage of the game. I tried many algorithms to calculate my odds at the flop in real time but the fastest i can is 30 seconds. Now, i can calculate my odds at the flop in 3 seconds but i use a 150 gigabytes database with many things pre-calculated. If you want to know your odds in real time you should have many things pre-calculated. That´s how i did.

流年已逝 2024-09-08 10:57:51

我在此处中为扑克评估器创建了一个测试平台。在我测试的评估器中,poker-eval 库是获胜者。 Steve Brecher's Holdem Showdown 速度也相当快,并且内存要求也显着降低。我自己的 ACE_Eval 拥有它自己的。

我欢迎帮助添加其他评估者,以及其他机器的测试结果的贡献。

I've created a testbed for poker evaluators in C here. Of the evaluators I tested, the poker-eval library was the winner. Steve Brecher's Holdem Showdown was also quite fast and had significantly less memory requirements. My own ACE_Eval held it's own.

I'd welcome help adding other evaluators, and contributions of test results from other machines.

把梦留给海 2024-09-08 10:57:51

当然,如果你想做得很快的话。我之前提出的算法太慢了。

table7462 应该位于数组中,而不是文件中。

然后,您应该预先计算每手不同的 7 张牌并将其存储到数据库中。有 133.784.560 种不同的 7 张牌组合。

您应该使用以下格式(按字母顺序排列):

“2c2d2h2s3c3d3h”并对其进行排名

存储每 133.784.560 个不同的组合。您执行 52C7 cicles,对其进行排名并将其存储在数据库中。
也许几天后你就准备好了。
准备好后,您不再需要 21 种组合,只需将您的手按字母顺序排序并在数据库中搜索即可。

如果您这样做,您会发现您可以在需要时实时计算与对手的赔率。

相信我。我不是程序员,但我可以做到。我在翻牌圈 3 秒内就知道自己的赔率。

Of course, if you want to do it very fast. The algorithm i put before is too slow.

The table7462 shoul be in an array, not in a file.

Then, you should precalculate every different 7cards hands and store it to a database. There are 133.784.560 different 7cards combinations.

You should use this format (alphabeticall order):

"2c2d2h2s3c3d3h" and rank it

Store every 133.784.560 different combinations. You do 52C7 cicles, rank it and store it in a database.
Maybe in a few days you have it ready.
When you have it ready, you don´t need 21 combinations anymore, just put your hand sorted alphabetically and search for it in your database.

If you do that, you´ll see that you can calculate your odds against your opponents in real time whenever you need.

Believe me. I am not a programmer and i can do it. I know my odds at the flop in 3 seconds.

霞映澄塘 2024-09-08 10:57:51

我开发了一个德州扑克模拟器,在开发过程中我发现翻牌圈有 7462 个独特组合(52 - 5/5 张牌)。反过来,这个数字下降到 6075 (5/6),河牌圈则下降到 4824 (5/7)。这是因为 1 或 2 张牌与对扑克牌进行分类无关。一个例子是:
76543QK = 7654332 顺子(3 到 7)

我的模拟器名为 Easy Poker,可在我的网站 http://crvltda.webs 中找到.com

参考号Pokersoftware.com/forum

I developed a simulator Texas hold'em and during this development I found the number of 7462 unique combinations (52 - 5/5 cards) on the flop. In turn, this number drops to 6075 (5/6) and in the river to 4824 (5/7). This is because 1 or 2 cards are irrelevant in classifying the poker hand. An example is:
76543QK = 7654332 a straight (3 to 7)

My simulator is called Easy Poker and is available in my site http://crvltda.webs.com

Ref. Pokersoftware.com/forum

天赋异禀 2024-09-08 10:57:51

我可以推荐 https://github.com/chenosaurus/poker-evaluator/

它是用 JavaScript 编写并使用 128 MB HandRanks.dat 文件。

代码只有几行,并且很容易移植到任何其他语言。

May I recommend https://github.com/chenosaurus/poker-evaluator/

It is written in JavaScript and uses a 128 MB HandRanks.dat file.

The code is just a few lines and very easy to port to any other language.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文