有没有人知道一种快速算法来评估七张扑克牌的手牌?这种算法比从七张牌中检查每个21个五张手牌组合更有效率。
谢谢,
Pete
有没有人知道一种快速算法来评估七张扑克牌的手牌?这种算法比从七张牌中检查每个21个五张手牌组合更有效率。
谢谢,
Pete
我用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], [ _["♠"], _["♠"], _["♠"], _["♠"], _["♠"] ] );
很高兴您提出了问题 :) 是的,这里有一个全新的解决方案可能正是您需要的:
代码: 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。它被称为“Poker Ace”。
关于各种解决方案的优秀总结以及链接,可以在James Devlin的博客“Coding The Wheel”中找到。
那里还没有讨论的一个评估器是Klaatu's。
祝你好运!
'############### 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
0
..C
代表“2”..‘A’。它们表示组成手牌等级的牌的值。末尾的0
将被忽略。您需要查看等级以确定要拉出多少个值。因此,对于带有7牌踢出的4个A,您将拥有C5000
。对于Kings over 3s的Full House,您获得B1000
。两对,8和4带有Queen kiker是62A00
。依此类推。一个高牌手将使用所有5个字节。ACE_Eval.h
使用类似的表示。请参见ACE_decode()
以获取获胜卡片的一种方法。 - AShelly我可以推荐https://github.com/chenosaurus/poker-evaluator/
它是用JavaScript编写的,并使用了一个128 MB的HandRanks.dat文件。
这段代码只有几行,非常容易移植到任何其他语言。
当然,如果你想要做得非常快。我之前提供的算法太慢了。
table7462应该是一个数组,而不是文件中。
然后,你应该预先计算每一种不同的7张牌的组合,并将其存储到数据库中。共有133,784,560种不同的7张牌组合。
你应该使用这个格式(按字母顺序):
"2c2d2h2s3c3d3h" 并排名
存储每一个133,784,560种不同的组合。你可以做52C7次循环,对它们进行排名,并将它们存储在数据库中。 也许几天后你就可以准备好了。 当你准备好了,你就不再需要21种组合,只需将手牌按字母顺序排序,然后在你的数据库中搜索即可。
如果你这样做,你会发现你可以随时实时计算出你与对手之间的胜率。
相信我。我不是程序员,但我可以做到。我知道三秒内翻牌后我的胜率。