Skip to main content

treys 是一个纯 Python 扑克手评估库

项目描述

一个纯 Python 扑克手评估库

[ 3 ❤ ] , [ 3 ♠ ]

安装

$ pip install treys

实施说明

Treys 是 Deuces的 Python 3 端口,基于 msaindon 的fork 中的初始工作。Deuces 由Will Drevo为 MIT Pokerbots 比赛编写。

Treys 轻巧且快速。所有查找都是通过位算术和字典查找完成的。也就是说,Treys 不会击败 C 实现(约 250k eval/s),但它对于需要 Python 或为机器人分配合理思考时间(人类时间尺度)的情况很有用。

Treys 处理 5、6 和 7 手牌查找。6 和 7 卡查找是通过组合评估 5 卡选择来完成的。

用法

Treys 易于设置和使用。

>>> from treys import Card
>>> card = Card.new('Qh')

Card 对象被表示为整数,以保持 Trey 的高性能和轻量级。

现在让我们创建棋盘和示例德州扑克牌:

>>> board = [
>>>     Card.new('Ah'),
>>>     Card.new('Kd'),
>>>     Card.new('Jc')
>>> ]
>>> hand = [
>>>    Card.new('Qs'),
>>>    Card.new('Th')
>>> ]

漂亮的打印卡片整数到终端:

>>> Card.print_pretty_cards(board + hand)
  [ A ❤ ] , [ K ♦ ] , [ J ♣ ] , [ Q ♠ ] , [ T ❤ ]

如果您安装了termcolor ,它们也会被着色。

否则直接评估您的手部力量:

>>> from treys import Evaluator
>>> evaluator = Evaluator()
>>> print(evaluator.evaluate(board, hand))
1600

牌力按 1 到 7462 的等级衡量,其中 1 是同花大顺,7462 是同花顺 7-5-4-3-2,因为扑克中只有 7642 手明显排名。

如果你想从一副牌中随机发牌,你也可以用 Treys 做到这一点:

>>> from treys import Deck
>>> deck = Deck()
>>> board = deck.draw(5)
>>> player1_hand = deck.draw(2)
>>> player2_hand = deck.draw(2)

并打印它们:

>>> Card.print_pretty_cards(board)
  [ 4 ♣ ] , [ A ♠ ] , [ 5 ♦ ] , [ K ♣ ] , [ 2 ♠ ]
>>> Card.print_pretty_cards(player1_hand)
  [ 6 ♣ ] , [ 7 ❤ ]
>>> Card.print_pretty_cards(player2_hand)
  [ A ♣ ] , [ 3 ❤ ]

让我们评估双手的强度,然后将它们分类,每种手型(高牌、对子等)一个

>>> p1_score = evaluator.evaluate(board, player1_hand)
>>> p2_score = evaluator.evaluate(board, player2_hand)
>>> p1_class = evaluator.get_rank_class(p1_score)
>>> p2_class = evaluator.get_rank_class(p2_score)

或者得到一个人性化的字符串来描述分数,

>>> print("Player 1 hand rank = %d (%s)\n" % (p1_score, evaluator.class_to_string(p1_class)))
Player 1 hand rank = 6330 (High Card)

>>> print("Player 2 hand rank = %d (%s)\n" % (p2_score, evaluator.class_to_string(p2_class)))
Player 2 hand rank = 1609 (Straight)

或者,最酷的是,对与手部力量相关的游戏阶段进行逐个分析:

>>> hands = [player1_hand, player2_hand]
>>> evaluator.hand_summary(board, hands)

========== FLOP ==========
Player 1 hand = High Card, percentage rank among all hands = 0.893192
Player 2 hand = Pair, percentage rank among all hands = 0.474672
Player 2 hand is currently winning.

========== TURN ==========
Player 1 hand = High Card, percentage rank among all hands = 0.848298
Player 2 hand = Pair, percentage rank among all hands = 0.452292
Player 2 hand is currently winning.

========== RIVER ==========
Player 1 hand = High Card, percentage rank among all hands = 0.848298
Player 2 hand = Straight, percentage rank among all hands = 0.215626

========== HAND OVER ==========
Player 2 is the winner with a Straight

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

treys-0.1.8.tar.gz (12.1 kB 查看哈希

已上传 source

内置分布

treys-0.1.8-py3-none-any.whl (11.9 kB 查看哈希

已上传 py3