Java 中的扑克手牌
有没有简单的方法来比较两手扑克牌?我的想法很天真,所以如果有人有这方面的经验,那可能会有所帮助。
Is there any easy method to compare two poker hands? I'm going about this pretty naively, so if anybody has experience doing this, it could be helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
没有一种简单(且高效)的方法可以做到这一点,特别是如果您想评估七张牌的五张牌子集,例如德州扑克。
您可能想查看 pokersource ,它有一些 Java 绑定。
编辑 - 另一个资源是pokerai 论坛。我在那里发现了很多 Java 算法。它们定期运行基准测试,并且通常伴随着蒙特卡罗模拟的枚举算法。 这似乎是主要帖子。
There isn't an easy (and performant) way to do this, especially if you want to evaluate five-card subsets of seven-card hands, like in Texas Hold 'em.
You might want to check out pokersource which has some Java bindings.
Edit - an additional resource is the pokerai forums. I found quite a few Java algorithms there. They are regularly run through benchmarks and are often accompanied by enumeration algorithms for Monte Carlo simulation. This appears to be the main post.
我发现这个看起来很有希望。
您也可以自己推出。
I found this which seems promising.
You can also roll your own.
您可以在此处 附有文档并在此处进一步解释。欢迎通过其中的电子邮件地址提供所有反馈。
An example of a ready made Texas Hold'em 7- and 5-card evaluator can be found here with documentation and further explained here. All feedback welcome at the e-mail address found therein.
看看来自阿尔伯塔大学的免费扑克 Java 库:
http://spaz.ca/poker/doc/ca /ualberta/cs/poker/package-summary.html
Look at this free poker java lib from Alberta university :
http://spaz.ca/poker/doc/ca/ualberta/cs/poker/package-summary.html
假设您已经拥有某种数据结构来确定玩家拥有的手牌类型,您可以为每种类型的手牌分配某种 int 值并进行比较。任何拥有更高价值的玩家都会获胜。如果值相等,您只需比较两手牌即可。即,如果双方都有对子,则只需比较卡片的数量,或者如果他们都有葫芦,则比较他们拥有 3 张卡片的价值。
编辑:如果他们有相同的手牌,只需检查他们手中的下一张最高的牌(踢球者)。
Assuming you already have some kind of data structure in place for determining the kind of hand that the player has, you could just assign some kind of int value to each type of hand and compare them. Whatever player has the higher value wins. If the values are equal, you'd just have to compare the hands against eachother. I.E if both have pairs, just compare the numbers of the card, or if they have a full house, compare the value of the card that they have 3 of.
EDIT: if they have the same hand, just check the next highest card in their hand (kicker).
我为 java 编写了一个扑克牌评估库,它正是您所寻找的。
这并不容易,但它很高效。我在 GitHub 上根据 GNU GPL 发布了它。
在此处获取源代码
I wrote a poker hand evaluation library for java, that does exactly what your looking for.
It wasn't easy but it is performant. I released it under the GNU GPL on GitHub.
get sourecode here
我写了这个,如果有帮助请告诉我。本质上,我将每张牌映射到黑桃 2 为 0,黑桃 A 为 12,红心 2 为 3 等等。
我希望在投入工作之前看到这个线程。
I wrote this, let me know if this helps. Essentially I map each card to a number 2 of spades being 0,and Ace of spades being a 12 and 2 of hearts a 3 etc etc.
I wish I saw this thread before I put in the work.