Java 从头开始构建德州扑克玩 AI

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/506167/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 15:31:28  来源:igfitidea点击:

Building a Texas Hold'em playing AI..from scratch

javalispartificial-intelligencepokerjatha

提问by andandandand

I'm interested in building a Texas Hold 'Em AI engine in Java. This is a long term project, one in which I plan to invest at least two years. I'm still at college, haven't build anything ambitious yet and wanting to tackle a problem that will hold my interest in the long term. I'm new to the field of AI. From my data structures class at college, I know basic building blocks like BFS and DFS, backtracking, DP, trees, graphs, etc. I'm learning regex, studying for the SCJP and the SCJD and I'll shortly take a (dense) statistics course.

我对用 Java 构建德州扑克 AI 引擎很感兴趣。这是一个长期项目,我计划在其中投资至少两年。我还在上大学,还没有建立任何雄心勃勃的东西,想要解决一个能长期保持我兴趣的问题。我是人工智能领域的新手。从我大学的数据结构课上,我知道基本的构建块,如 BFS 和 DFS、回溯、DP、树、图等。我正在学习正则表达式,为 SCJP 和 SCJD 学习,我很快就会学习(密集) 统计课程。

Questions:

问题:

-Where do I get started? What books should I pick? What kind of AI do poker playing programs run on? What open source project can I take a page from? Any good AI resources in Java? I'm interested in learning Lisp as well, is Jatha good?

- 我从哪里开始?我应该选什么书?玩扑克的程序运行在什么样的人工智能上?我可以从哪个开源项目中获取页面?Java 中有什么好的 AI 资源吗?我也有兴趣学习 Lisp,Jatha 好吗?

回答by patros

Poker AI's are notoriously difficult to get right because humans bet unpredictably. It's usually broken into two parts.

众所周知,扑克 AI 很难正确,因为人类下注不可预测。它通常分为两部分。

1) Calculate the odds of your hand being the winner.

1) 计算你的手成为赢家的几率。

2) Formulate betting strategy based on 1.

2) 根据 1 制定投注策略。

I'd recommend starting with lots of statistics reading for part 1. It seems easy at first blush, but it's actually very complicated (and getting it wrong will doom your AI). Then move on to genetic algorithms for part 2. Betting strategies are mostly genetic algorithms. They adjust themselves based on past success and failures + some randomization so as not to become predictable.

我建议从第 1 部分的大量统计数据开始。乍一看似乎很容易,但实际上非常复杂(如果弄错了会毁了你的 AI)。然后转到第 2 部分的遗传算法。投注策略主要是遗传算法。他们根据过去的成功和失败+一些随机化来调整自己,以免变得可预测。

回答by Jonas K?lker

One interesting result I've heard is that if you restrict the betting options to fold, check and all-in, you can write an AI that wins one-on-ones with probability at least 49%, and 49.5% if it's (IIRC) notgoing first.

我听说过的一个有趣的结果是,如果你将下注选项限制为弃牌、过牌和全押,你可以编写一个人工智能,它以至少 49% 的概率赢得一对一,如果是(IIRC )先去。

I don't know that this AI is easier to write that one which knows how much to bet, but it's food for thought: choosing amounts to bet only accounts for 1.5% of the probability of winning.

我不知道这个AI更容易写一个知道下注多少的AI,但它值得深思:选择数量下注仅占获胜概率的1.5%。

回答by bowsie

I wrote a Hold'Em AI in my undergrad. It wasn't particularly advanced, I used a Q-Value machine that traversed a number of states and updated Q values for each state.

我在本科时写了一个 Hold'Em AI。它不是特别先进,我使用了一个 Q-Value 机器,它遍历多个状态并为每个状态更新 Q 值。

I found the University of Alberta's AI Poker project an invaluable source of info for avoiding pitfalls.

我发现阿尔伯塔大学的 AI 扑克项目是避免陷阱的宝贵信息来源。

As one poster above states, the first step is to nail in a couple of determinable poker rules - one-on-one poker can be developed programatically.

正如上面的一张海报所述,第一步是确定几个可确定的扑克规则 - 可以通过编程方式开发一对一扑克。

One pitfall I fell into was not building in reconfigurability early on. For instance being able to switch the grade of learning/playing.

我陷入的一个陷阱是没有在早期构建可重构性。例如能够切换学习/玩耍的等级。

I would be interested to hear how you get on drop me a mail stevekeogh at gmail.com

我很想听听您如何在 gmail.com 上给我发邮件 stevekeogh

回答by nhaa123

Also, letting genetic algorithm adjust the weights of neural network, which determines the decision logic. This approach is very suitable for poker AI.

另外,让遗传算法调整神经网络的权重,决定了决策逻辑。这种方法非常适合扑克AI。

I made my own AI like this. At first, I created ~1000 players, who didn't know how to play the game at all. Based on their initial luck during the hands, their fitness was weighted and new generation created. New "brains" were playing better than previous generation.

我像这样制作了自己的人工智能。起初,我创建了大约 1000 名玩家,他们根本不知道如何玩游戏。根据他们最初的运气,他们的健康被加权并创造了新一代。新的“大脑”比上一代玩得更好。

Eventually, the best individuals played very good.

最终,最好的人打得非常好。

回答by lokori

As already recommended, the book Theory of Pokeris a truly invaluable source of information for playing the game as well as for building an AI. You should probably buy it as it does not cost that much.

正如已经推荐的那样,《扑克理论》一书是玩游戏和构建 AI 的真正无价的信息来源。您可能应该购买它,因为它不会花费那么多。

University of Alberta resarch group does the state-of-the-art at the moment, though they have stiff competition emerging every now and then. (Not all poker bots and AI research in the field is public because of the temptation to use one's results in internet poker, though that's forbidden.)

阿尔伯塔大学研究小组目前是最先进的,尽管他们时不时会出现激烈的竞争。(并非该领域的所有扑克机器人和人工智能研究都是公开的,因为在互联网扑克中使用自己的结果的诱惑,尽管这是被禁止的。)

First you should decide what sort of poker are you going to tackle first. two player hold'em is pretty much solved, though the best humans still put up a real fight with the best AI's available. The AI has the main advantages over humans by having an unlimited flawless memory of past hands, flawless analysis of the patterns based on that and as they are machines, they don't tilt like almost all humans occasionally do.

首先,您应该决定首先要玩哪种扑克。两人德州扑克几乎已经解决了,尽管最好的人类仍然与最好的 AI 进行真正的战斗。与人类相比,人工智能的主要优势在于对过去的手有无限完美的记忆,基于此对模式进行完美的分析,而且由于它们是机器,它们不会像几乎所有人类偶尔那样倾斜。

Fixed Hold'em is probably the easiest to crack, so you might want to start with 1-1 fixed hold'em and then decide what you want to do next.

固定德州扑克可能是最容易破解的,因此您可能希望从 1-1 固定德州扑克开始,然后决定下一步要做什么。

Here are some aspects which change the correct strategy (and your AI):

以下是改变正确策略(和您的 AI)的一些方面:

  • A cash game is different from a tournament -The number of players makes the decisions different.
  • Hold'em is not the only poker. Omaha, Stud and others exist and are widely played.
  • Fixed Limit is different from Pot Limit, which is different from No Limit.
  • To beat the best you need to cover a lot of very subtle things the best players think about when they play. To beat a low-stakes amateur game, none of these things count.
  • 现金游戏与锦标赛不同 - 玩家的数量做出不同的决定。
  • 德州扑克并不是唯一的扑克。奥马哈、梭哈等存在并被广泛使用。
  • Fixed Limit 与 Pot Limit 不同,Pot Limit 与 No Limit 不同。
  • 要击败最好的球员,您需要涵盖最好的球员在比赛时会考虑的许多非常微妙的事情。要击败低风险的业余游戏,这些都不算数。

If you decide to go for No Limit Hold'em, you might want to check out three-book series Harrington on Hold'emand a book No Limit Poker - Theory and Practice. Having read quite a many books on poker, I can say these books combined with the Theory of Poker are quite enough.

如果您决定参加无限注德州扑克,您可能需要查看三本书的哈灵顿德州扑克系列和一本书无限注扑克 - 理论与实践。看了很多扑克书籍,我可以说这些书籍结合扑克理论已经足够了。

回答by Pablo Cantero

I wrote a Texas Hold'em Video Poker engine in Java

我用 Java 编写了德州扑克视频扑克引擎

This code is a core engine for Texas Hold'em without views and others

此代码是德州扑克的核心引擎,没有视图和其他

http://github.com/phstc/javapokertexasholdem

http://github.com/phstc/javapokertexasholdem

回答by zubinmehta

Just to add to the links above, one of the important things to implement would be http://en.wikipedia.org/wiki/Kelly_criterionwhich will help figure out the optimal size of bets given the expected odds in a series of bets. With humans there could be errors in judgement of odds, but if your AI program can spit the some expected normalized odds based on whatever the algorithm then this bet-sizing technique which balances both risk and reward for the advantage gambler would be a good cheap solution.

只是为了添加到上面的链接,要实现的重要事情之一是http://en.wikipedia.org/wiki/Kelly_criterion,这将有助于根据一系列投注的预期赔率确定最佳投注规模。对于人类来说,在判断赔率时可能会出现错误,但是如果您的 AI 程序可以基于任何算法吐出一些预期的归一化赔率,那么这种平衡优势赌徒的风险和回报的下注规模技术将是一个很好的廉价解决方案.

回答by Andrew Prock

I'm not sure which exact game you are interested in, but the typical approach is to create a much smaller abstract version of the game, solving that smaller game, and then mapping real game situations back to the abstract game to generate advice. Most of the academic papers skip over the details of this process in favor of presenting results about convergence, exploitation, and competition results.

我不确定您对哪个游戏感兴趣,但典型的方法是创建一个更小的抽象版本的游戏,解决那个更小的游戏,然后将真实的游戏情况映射回抽象游戏以生成建议。大多数学术论文都跳过了这个过程的细节,而倾向于呈现关于收敛、开发和竞争结果的结果。

However, there are some publicly available code bases which present a complete implementation. One of the best ones is Fell Omen:

但是,有一些公开可用的代码库提供了完整的实现。最好的之一是Fell Omen:

http://www.deducer.org/pmwiki/pmwiki.php?n=Main.ArtificialIntelligencePoker

http://www.deducer.org/pmwiki/pmwiki.php?n=Main.ArtificialIntelligencePoker

This is a basic complete strategy bot that uses fictitious play to optimize the strategy for the abstract game. It's a good starting point because it is fairly straightforward, complete, and represents a good presentation of the abstract game approach.

这是一个基本的完整策略机器人,它使用虚拟游戏来优化抽象游戏的策略。这是一个很好的起点,因为它相当简单、完整,并且很好地展示了抽象游戏方法。

If you are interested in developing poker AI, I would suggest reading everything from 2007 and on from the UA poker group and Tuomas Sandholm's students:

如果您对开发扑克 AI 感兴趣,我建议您阅读 2007 年及以后 UA 扑克组和 Tuomas Sandholm 学生的所有内容:

http://www.cs.cmu.edu/~sandholm/

http://www.cs.cmu.edu/~sandholm/

http://poker.cs.ualberta.ca/publications.html

http://poker.cs.ualberta.ca/publications.html