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 } }