LoginSignup
8
2

More than 3 years have passed since last update.

ポーカー(6-plus hold'em)のハンドの強さ判定

Posted at

6-plus hold'em

6+ Hold’em is a popular 'short deck' poker format that plays much like Texas Hold’em, but with a few differences:
All cards lower than a six are removed from the deck.
A flush beats a full-house and Ace, 6, 7, 8, 9 is classified as a straight.

今回はこのルールにおける5枚のハンドの役の強さを高速で判定することを考えます。

役判定プログラム

5枚のカードの組み合わせはn=36, k=5として以下の式より376992通りあります。

\binom nk=\frac{n!}{k!(n-k)!}

すべての場合に対して役の強さを整数にして並び替えてみると、ハンドの強さとしてあり得る数値は1404通りでした。

ハンドの強さを最も強いものを1403、 最も弱いものを0として表すことにします。

すべてのカードの組み合わせに対して、与えられた5枚のハンドを1つのIDで表し、それぞれのIDに対応するハンドの強さ(0-1403)を辞書で与えます。

ID_to_Strength.csv

ハンドはソートした上で文字列として結合され、重複のないIDとして表されています。
この辞書には376992通りのすべてのハンドに対して、0-1403で表された役の強さが与えられています。
これで、任意の5枚に対してソートして文字列として辞書に入れることで、一瞬で役の強さを得ることができるようになりました。

7枚の役判定は、作れるすべての5枚の組み合わせに対して役を判定する必要がありますが、5枚の判定を高速化したことで7枚の場合の判定も比例して高速になっています。

6plusholdem_dic.py

8
2
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
2