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

treys的Python项目详细描述


纯python扑克手评估库

[ 3 ❤ ] , [ 3 ♠ ]

安装

$ pip install treys

实施说明

treys是python 3的一个端口 Deuces。大部分的工作都要做 从msaindon’s叉。

treys(最初是deuces)是由Will Drevo为麻省理工学院扑克机器人竞赛编写的。它 重量轻,速度快。所有的查找都是用位运算和 查字典。也就是说,treys不会超过c实现(~250k eval/s),但对于需要使用python或 机器人被分配合理的思考时间(人类时间尺度)。

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

用法

treys易于设置和使用。

>>>fromtreysimportCard>>>card=Card.new('Qh')

card对象被表示为整数,以保持treys的性能和 很轻。

现在,让我们创建一个板和一个示例得克萨斯手持:

>>>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 安装后,它们也将着色。

否则,直接评估手的力量:

>>>fromtreysimportEvaluator>>>evaluator=Evaluator()>>>print(evaluator.evaluate(board,hand))1600

手的力量按1到7462的比例计算,其中1是皇家的 齐平和7462不适合7-5-4-3-2,因为只有7642 在扑克中排名第一的手。再次,请参阅我的博客文章了解更多 数学上完全解释了为什么会这样。

如果你想从一副牌中随机出牌,你也可以这样做 使用treys:

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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java OnResizeListener或OnDrawListener或类似的东西   java Orika映射嵌套子列表   保存时java Heroku请求超时代码H12   数据库在Java中出现socket读取超时异常的原因是什么?   java如何更改来自Sqlite数据库的特定数据在Listview中的行颜色   java JAXB解组器无法正确处理XML中的列表   java Android日期时区让我抓狂   java不透明属性在Swing中如何工作?   eclipse从JavaEE代码生成流程图   java如何在Hibernate中从相关表中获取计数   java Glassfish部署了项目的依赖项库   java使内容适合JavaFx中的WebView   java不满意的链接错误libcrypto。所以1.0.0   循环中java数组的使用   java找出哪个包调用服务