PokerKit 是一個開源軟體庫,由多倫多大學電腦撲克學生研究小組開發,以純 Python 編寫,用於模擬遊戲、評估牌局和促進統計分析。 PokerKit 支援廣泛的撲克變體,並為用戶定義其自訂遊戲提供了靈活的架構。這些設施透過直覺的統一高階程式 API 公開。該庫可用於各種用例,從撲克人工智慧開發、工具創建到線上撲克賭場實施。 PokerKit 的可靠性是透過靜態類型檢查、廣泛的文件測試和單元測試建立的,實現了 99% 的程式碼覆蓋率。
PokerKit 庫需要 Python 版本 3.11 或更高版本,可使用 pip 安裝:
pip install pokerkit
PokerKit 的範例用法如下所示。
下面顯示了 Phil Hellmuth 和 Loose Cannon Ernest Wiggins 之間的 4 局比賽。
連結:https://youtu.be/cnjJv7x0HMY?si=4l05Ez7lQVczt8DI&t=638
請注意,某些玩家的起始堆疊被設定為math.inf
因為它們沒有被提及。
from math import inf
from pokerkit import Automation , Mode , NoLimitTexasHoldem
state = NoLimitTexasHoldem . create_state (
# Automations
(
Automation . ANTE_POSTING ,
Automation . BET_COLLECTION ,
Automation . BLIND_OR_STRADDLE_POSTING ,
Automation . HOLE_CARDS_SHOWING_OR_MUCKING ,
Automation . HAND_KILLING ,
Automation . CHIPS_PUSHING ,
Automation . CHIPS_PULLING ,
),
False , # Uniform antes?
{ - 1 : 600 }, # Antes
( 200 , 400 , 800 ), # Blinds or straddles
400 , # Min-bet
( inf , 116400 , 86900 , inf , 50000 , inf ), # Starting stacks
6 , # Number of players
mode = Mode . CASH_GAME ,
)
以下是翻牌前的發牌和行動。
state . deal_hole ( 'JsTh' ) # Tony G
state . deal_hole ( 'Ah9d' ) # Hellmuth
state . deal_hole ( 'KsKc' ) # Wiggins
state . deal_hole ( '5c2h' ) # Negreanu
state . deal_hole ( '6h5h' ) # Brunson
state . deal_hole ( '6s3s' ) # Laak
state . fold () # Negreanu
state . complete_bet_or_raise_to ( 2800 ) # Brunson
state . fold () # Laak
state . check_or_call () # Tony G
state . complete_bet_or_raise_to ( 12600 ) # Hellmuth
state . check_or_call () # Wiggins
state . check_or_call () # Brunson
state . check_or_call () # Tony G
以下是翻牌圈發牌和行動。
state . burn_card ( '??' )
state . deal_board ( '9hTs9s' )
state . check_or_call () # Tony G
state . complete_bet_or_raise_to ( 17000 ) # Hellmuth
state . complete_bet_or_raise_to ( 36000 ) # Wiggins
state . fold () # Brunson
state . fold () # Tony G
state . complete_bet_or_raise_to ( 103800 ) # Hellmuth
state . check_or_call () # Wiggins
下面是選擇跳動的數量。
state . select_runout_count ( 4 ) # Hellmuth
state . select_runout_count ( None ) # Wiggins
下面是第一個運行。
state . burn_card ( '??' )
state . deal_board ( 'Jh' ) # Turn
state . burn_card ( '??' )
state . deal_board ( 'Ad' ) # River
下面是第二次運行。
state . burn_card ( '??' )
state . deal_board ( 'Kh' ) # Turn
state . burn_card ( '??' )
state . deal_board ( '3c' ) # River
下面是第三次運行。
state . burn_card ( '??' )
state . deal_board ( '7s' ) # Turn
state . burn_card ( '??' )
state . deal_board ( '8s' ) # River
下面是第四次運行。
state . burn_card ( '??' )
state . deal_board ( 'Qc' ) # Turn
state . burn_card ( '??' )
state . deal_board ( 'Kd' ) # River
下面是最終的堆疊。
print ( state . stacks ) # [inf, 79400, 149700, inf, 37400, inf]
下面展示了湯姆·德萬 (Tom Dwan) 和菲爾·艾維 (Phil Ivey) 之間的第一場電視轉播的百萬美元彩池。
連結:https://youtu.be/GnxFohpljqM
請注意,Patrik Antonius 的起始堆疊設定為math.inf
,因為沒有提及。
from math import inf
from pokerkit import Automation , NoLimitTexasHoldem
state = NoLimitTexasHoldem . create_state (
# Automations
(
Automation . ANTE_POSTING ,
Automation . BET_COLLECTION ,
Automation . BLIND_OR_STRADDLE_POSTING ,
Automation . HOLE_CARDS_SHOWING_OR_MUCKING ,
Automation . HAND_KILLING ,
Automation . CHIPS_PUSHING ,
Automation . CHIPS_PULLING ,
),
True , # Uniform antes?
500 , # Antes
( 1000 , 2000 ), # Blinds or straddles
2000 , # Min-bet
( 1125600 , inf , 553500 ), # Starting stacks
3 , # Number of players
)
以下是翻牌前的發牌和行動。
state . deal_hole ( 'Ac2d' ) # Ivey
state . deal_hole ( '????' ) # Antonius
state . deal_hole ( '7h6h' ) # Dwan
state . complete_bet_or_raise_to ( 7000 ) # Dwan
state . complete_bet_or_raise_to ( 23000 ) # Ivey
state . fold () # Antonius
state . check_or_call () # Dwan
以下是翻牌圈發牌和行動。
state . burn_card ( '??' )
state . deal_board ( 'Jc3d5c' )
state . complete_bet_or_raise_to ( 35000 ) # Ivey
state . check_or_call () # Dwan
以下是回合發牌和行動。
state . burn_card ( '??' )
state . deal_board ( '4h' )
state . complete_bet_or_raise_to ( 90000 ) # Ivey
state . complete_bet_or_raise_to ( 232600 ) # Dwan
state . complete_bet_or_raise_to ( 1067100 ) # Ivey
state . check_or_call () # Dwan
下面是河牌交易。
state . burn_card ( '??' )
state . deal_board ( 'Jh' )
下面是最終的堆疊。
print ( state . stacks ) # [572100, inf, 1109500]
下面顯示的是Xuan 和Phua 之間的全押。
連結:https://youtu.be/QlgCcphLjaQ
from pokerkit import Automation , NoLimitShortDeckHoldem
state = NoLimitShortDeckHoldem . create_state (
# Automations
(
Automation . ANTE_POSTING ,
Automation . BET_COLLECTION ,
Automation . BLIND_OR_STRADDLE_POSTING ,
Automation . HOLE_CARDS_SHOWING_OR_MUCKING ,
Automation . HAND_KILLING ,
Automation . CHIPS_PUSHING ,
Automation . CHIPS_PULLING ,
),
True , # Uniform antes?
3000 , # Antes
{ - 1 : 3000 }, # Blinds or straddles
3000 , # Min-bet
( 495000 , 232000 , 362000 , 403000 , 301000 , 204000 ), # Starting stacks
6 , # Number of players
)
以下是翻牌前的發牌和行動。
state . deal_hole ( 'Th8h' ) # Badziakouski
state . deal_hole ( 'QsJd' ) # Zhong
state . deal_hole ( 'QhQd' ) # Xuan
state . deal_hole ( '8d7c' ) # Jun
state . deal_hole ( 'KhKs' ) # Phua
state . deal_hole ( '8c7h' ) # Koon
state . check_or_call () # Badziakouski
state . check_or_call () # Zhong
state . complete_bet_or_raise_to ( 35000 ) # Xuan
state . fold () # Jun
state . complete_bet_or_raise_to ( 298000 ) # Phua
state . fold () # Koon
state . fold () # Badziakouski
state . fold () # Zhong
state . check_or_call () # Xuan
下面是翻牌圈發牌。
state . burn_card ( '??' )
state . deal_board ( '9h6cKc' )
下面是回合發牌。
state . burn_card ( '??' )
state . deal_board ( 'Jh' )
下面是河牌交易。
state . burn_card ( '??' )
state . deal_board ( 'Ts' )
下面是最終的堆疊。
print ( state . stacks ) # [489000, 226000, 684000, 400000, 0, 198000]
下面顯示了 Patrik Antonius 和 Viktor Blom 之間有史以來最大的線上撲克底池。
連結:https://youtu.be/UMBm66Id2AA
from pokerkit import Automation , PotLimitOmahaHoldem
state = PotLimitOmahaHoldem . create_state (
# Automations
(
Automation . ANTE_POSTING ,
Automation . BET_COLLECTION ,
Automation . BLIND_OR_STRADDLE_POSTING ,
Automation . HOLE_CARDS_SHOWING_OR_MUCKING ,
Automation . HAND_KILLING ,
Automation . CHIPS_PUSHING ,
Automation . CHIPS_PULLING ,
),
True , # Uniform antes?
0 , # Antes
( 500 , 1000 ), # Blinds or straddles
1000 , # Min-bet
( 1259450.25 , 678473.5 ), # Starting stacks
2 , # Number of players
)
以下是翻牌前的發牌和行動。
state . deal_hole ( 'Ah3sKsKh' ) # Antonius
state . deal_hole ( '6d9s7d8h' ) # Blom
state . complete_bet_or_raise_to ( 3000 ) # Blom
state . complete_bet_or_raise_to ( 9000 ) # Antonius
state . complete_bet_or_raise_to ( 27000 ) # Blom
state . complete_bet_or_raise_to ( 81000 ) # Antonius
state . check_or_call () # Blom
以下是翻牌圈發牌和行動。
state . burn_card ( '??' )
state . deal_board ( '4s5c2h' )
state . complete_bet_or_raise_to ( 91000 ) # Antonius
state . complete_bet_or_raise_to ( 435000 ) # Blom
state . complete_bet_or_raise_to ( 779000 ) # Antonius
state . check_or_call () # Blom
下面是回合發牌。
state . burn_card ( '??' )
state . deal_board ( '5h' )
下面是河牌交易。
state . burn_card ( '??' )
state . deal_board ( '9c' )
下面是最終的堆疊。
print ( state . stacks ) # [1937923.75, 0.0]
下面顯示了 Yockey 和 Arieh 之間的慘敗。
連結:https://youtu.be/pChCqb2FNxY
from pokerkit import Automation , FixedLimitDeuceToSevenLowballTripleDraw
state = FixedLimitDeuceToSevenLowballTripleDraw . create_state (
# Automations
(
Automation . ANTE_POSTING ,
Automation . BET_COLLECTION ,
Automation . BLIND_OR_STRADDLE_POSTING ,
Automation . HOLE_CARDS_SHOWING_OR_MUCKING ,
Automation . HAND_KILLING ,
Automation . CHIPS_PUSHING ,
Automation . CHIPS_PULLING ,
),
True , # Uniform antes?
0 , # Antes
( 75000 , 150000 ), # Blinds or straddles
150000 , # Small-bet
300000 , # Big-bet
( 1180000 , 4340000 , 5910000 , 10765000 ), # Starting stacks
4 , # Number of players
)
以下是翻牌前的發牌和行動。
state . deal_hole ( '7h6c4c3d2c' ) # Yockey
state . deal_hole ( '??????????' ) # Hui
state . deal_hole ( '??????????' ) # Esposito
state . deal_hole ( 'AsQs6s5c3c' ) # Arieh
state . fold () # Esposito
state . complete_bet_or_raise_to () # Arieh
state . complete_bet_or_raise_to () # Yockey
state . fold () # Hui
state . check_or_call () # Arieh
以下是第一次抽籤和行動。
state . stand_pat_or_discard () # Yockey
state . stand_pat_or_discard ( 'AsQs' ) # Arieh
state . burn_card ( '??' )
state . deal_hole ( '2hQh' ) # Arieh
state . complete_bet_or_raise_to () # Yockey
state . check_or_call () # Arieh
以下是第二次抽籤和行動。
state . stand_pat_or_discard () # Yockey
state . stand_pat_or_discard ( 'Qh' ) # Arieh
state . burn_card ( '??' )
state . deal_hole ( '4d' ) # Arieh
state . complete_bet_or_raise_to () # Yockey
state . check_or_call () # Arieh
以下是第三次抽籤和行動。
state . stand_pat_or_discard () # Yockey
state . stand_pat_or_discard ( '6s' ) # Arieh
state . burn_card ( '??' )
state . deal_hole ( '7c' ) # Arieh
state . complete_bet_or_raise_to () # Yockey
state . check_or_call () # Arieh
下面是最終的堆疊。
print ( state . stacks ) # [0, 4190000, 5910000, 12095000]
下面顯示了來自維基百科的巴杜吉手的範例。
連結:https://en.wikipedia.org/wiki/Badugi
請注意,起始堆疊設定為math.inf
因為未提及它們。
from math import inf
from pokerkit import Automation , FixedLimitBadugi
state = FixedLimitBadugi . create_state (
# Automations
(
Automation . ANTE_POSTING ,
Automation . BET_COLLECTION ,
Automation . BLIND_OR_STRADDLE_POSTING ,
Automation . HAND_KILLING ,
Automation . CHIPS_PUSHING ,
Automation . CHIPS_PULLING ,
),
True , # Uniform antes?
0 , # Antes
( 1 , 2 ), # Blinds or straddles
2 , # Small-bet
4 , # Big-bet
inf , # Starting stacks
4 , # Number of players
)
以下是翻牌前的發牌和行動。
state . deal_hole ( '????????' ) # Bob
state . deal_hole ( '????????' ) # Carol
state . deal_hole ( '????????' ) # Ted
state . deal_hole ( '????????' ) # Alice
state . fold () # Ted
state . check_or_call () # Alice
state . check_or_call () # Bob
state . check_or_call () # Carol
以下是第一次抽籤和行動。
state . stand_pat_or_discard ( '????' ) # Bob
state . stand_pat_or_discard ( '????' ) # Carol
state . stand_pat_or_discard ( '??' ) # Alice
state . burn_card ( '??' )
state . deal_hole ( '????' ) # Bob
state . deal_hole ( '????' ) # Carol
state . deal_hole ( '??' ) # Alice
state . check_or_call () # Bob
state . complete_bet_or_raise_to () # Carol
state . check_or_call () # Alice
state . check_or_call () # Bob
以下是第二次抽籤和行動。
state . stand_pat_or_discard ( '??' ) # Bob
state . stand_pat_or_discard () # Carol
state . stand_pat_or_discard ( '??' ) # Alice
state . burn_card ( '??' )
state . deal_hole ( '??' ) # Bob
state . deal_hole ( '??' ) # Alice
state . check_or_call () # Bob
state . complete_bet_or_raise_to () # Carol
state . complete_bet_or_raise_to () # Alice
state . fold () # Bob
state . check_or_call () # Carol
以下是第三次抽籤和行動。
state . stand_pat_or_discard ( '??' ) # Carol
state . stand_pat_or_discard () # Alice
state . burn_card ( '??' )
state . deal_hole ( '??' ) # Carol
state . check_or_call () # Carol
state . complete_bet_or_raise_to () # Alice
state . check_or_call () # Carol
下面是對決。
state . show_or_muck_hole_cards ( '2s4c6d9h' ) # Alice
state . show_or_muck_hole_cards ( '3s5d7c8h' ) # Carol
下面是最終的堆疊。
print ( state . stacks ) # [inf, inf, inf, inf]
print ( state . payoffs ) # [-4, 20, 0, -16]
PokerKit 具有廣泛的測試覆蓋範圍,透過嚴格模式下的 mypy 靜態類型檢查,並透過在現實生活場景中的廣泛使用而得到驗證。
歡迎貢獻!請閱讀我們的貢獻指南以獲取更多資訊。
PokerKit 在 MIT 許可證下分發。
如果您在研究中使用 PokerKit,請引用我們的庫:
@ARTICLE { 10287546 ,
author = { Kim, Juho } ,
journal = { IEEE Transactions on Games } ,
title = { PokerKit: A Comprehensive Python Library for Fine-Grained Multi-Variant Poker Game Simulations } ,
year = { 2023 } ,
volume = { } ,
number = { } ,
pages = { 1-8 } ,
doi = { 10.1109/TG.2023.3325637 } }