GithubHelp home page GithubHelp logo

deepbot-poker's Introduction

deepbot-poker

This repository implements a bot playing No Limit Texas Hold'em poker. It has been trained to play 6-handed sit-and-go as well as heads-up ring-games. The model is built on a neural network, trained with a genetic algorithm. It tracks the game as a whole as well as each opponent separately. LSTMs are used for memory, taking advantage of the sequential nature of poker. The detailed report and corresponding presentation can be found in the docs alongside other important files.

Below is an overview of the neural network used at the core of the decision making of the last iteration of DeepBot.

Six handed neural network overview

Getting started

Setting up

First clone the repository with the recursive argument. This is to include two necessary submodules (PyPokerEngine and OMPEval). Both are forks that have been altered for the purpose of this project.

git clone https://github.com/tamlhp/deepbot.poker.git --recursive

This code was developed and tested with python 3.5.6. All the required python libraries are in the requirements file and can be installed with

pip install -r requirements.txt

In order to perform trainings, it is also required to have redis installed.

Run default game

In order to verify that everything is set up correctly, it is appropriate to let a trained agent play and watch the trace of the game. To do so with the default options, simply move to the code folder and run the agent_play script.

python3 agent_play.py

Training a new agent

Redis server and workers

As a lot of games have to be played, redis is used to enable multi-threading and cloud computing. Go to ./code/redis, then run the redis server:

redis-server redis.conf

redis.conf binds the server to an address.

Then, start the workers:

sh run_workers.sh 70 127.0.0.1

The first argument (70) is the number of workers to start. This should be equal to the number of threads available on the machine, or the genetic algorithm population size if it is smaller. The second argument (127.0.0.1) is the ip address of the redis server, here it is local. If multiple machines are used for computation, the address should be changed both here and in redis.conf.

Starting the training

To train an agent from scratch, use the script train_agent.py. It is best to have a look at the many available arguments first:

python3 train_agent.py -h

At the very least it is adviserd to define a simulation id (--simul_id), to avoid overwritting past training traces.

python3 train_agent.py --simul_id 1

Training trace

The training process generates data for reproducibility, and the agents. It saves the decks used, the earnings obtained by the agents, and most importantly the agents in a lightweight format: a single list containing all the parameters of its neural network.

The default location of training data is ./data/trained_agents_and_data. As it takes a lot of storage, it is not included in the git repository.

A few agents are however available in ./data_trained_agents_git. There are (partial) traces of three trainings:

  • 6max_full: Plays 6 Handed Sit and Go against various opponent tables
  • 6max_single: Plays 6 Handed Sit and Go against one opponent, the Ruler (see report)
  • hu_second: Plays Heads Up Ring Game against various weak opponents

The best agent of each training instance is the first agent (best peformance) of the last generation (most trained).

Training performance example

Here is an example of the return on investments (ROI) obtained by agents over the training. It is for the '6max_full' network and environment. The maximum attainable ROI is 300%. Each curve is for a table with different type of opponents.

Average ROI over generations

Post training scripts

Make a trained agent play

To make a trained agent play a single game, one can use the agent_play script. Again, it is advised to look at the available arguments. For example to let the pre-trained 6max_full (git) agent play against a tight passive table, run:

python3 agent_play.py --network 6max_full --table_ind 2 --agent_file ../data/trained_agents_git/6max_full/gen_300/bots/1/bot_1_flat.pkl

This will print information about the actions taken and rewards given at each hand.

Validations

The scripts to perform the validation, be it quantitative or qualitative, are in ./code/validations.

GUI

As the various bots developed in this repository, including DeepBot, are compatible with PyPokerEngine, it is possible to play against them through a GUI. To do so use PyPokerGUI.

Contributor

  • Cyril van Schreven

Supervisors

  • Thanh Tam Nguyen, Karl Aberer

deepbot-poker's People

Contributors

schreven avatar tamlhp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

deepbot-poker's Issues

an error in train_agent.py

there is an error when run train_agent.py:
28, 52, 50, 27, 9, 44, 10, 6, 12, 41, 35, 43, 7, 15, 47, 5, 32, 23, 42, 19, 8, 14, 34, 39, 31, 51, 13, 26, 37, 48, 36, 17, 45, 49, 3, 21, 22, 38, 29, 4, 30, 16, 20, 11, 40, 1, 25, 33], deepbot=<bot_DeepBot.DeepBot object at 0x7f5377c65ac8>, ini_stack=20000, nb_hands=500, sb_amount=50, train_env='hu_cash_mixed') (c2f077f8-7c16-40a5-9f18-7f6e7ec74c49)
10:59:38 ValueError: Hole card is already set
Traceback (most recent call last):
File "/home/mm/wkq/anaconda3/envs/deepbot/lib/python3.6/site-packages/rq/worker.py", line 822, in perform_job
rv = job.perform()
File "/home/mm/wkq/anaconda3/envs/deepbot/lib/python3.6/site-packages/rq/job.py", line 605, in perform
self._result = self._execute()
File "/home/mm/wkq/anaconda3/envs/deepbot/lib/python3.6/site-packages/rq/job.py", line 611, in _execute
return self.func(*self.args, **self.kwargs)
File "../main_functions/u_training_games.py", line 82, in run_games
run_one_game_rebuys(deepbot=deepbot, ini_stack = ini_stack, sb_amount=sb_amount, nb_hands = nb_hands, cst_decks = cst_decks)
File "../main_functions/u_training_games.py", line 166, in run_one_game_rebuys
game_result_1 = start_poker(config, verbose=0, cheat = True, cst_deck_ids = cst_deck_match, return_last_two=False)
File "../PyPokerEngine/pypokerengine/api/game.py", line 14, in start_poker
result_message, last_two, deepbot_rank = dealer.start_game(config.max_round)
File "../PyPokerEngine/pypokerengine/engine/dealer.py", line 56, in start_game
table, action_history = self.play_round(round_count, sb_amount, ante, table)
File "../PyPokerEngine/pypokerengine/engine/dealer.py", line 64, in play_round
state, msgs = RoundManager.start_new_round(round_count, blind_amount, ante, table)
File "../PyPokerEngine/pypokerengine/engine/round_manager.py", line 23, in start_new_round
self.__deal_holecard(table.deck, table.seats.players)
File "../PyPokerEngine/pypokerengine/engine/round_manager.py", line 70, in __deal_holecard
player.add_holecard(deck.draw_cards(2))
File "../PyPokerEngine/pypokerengine/engine/player.py", line 26, in add_holecard
raise ValueError(self.__dup_hole_msg)
ValueError: Hole card is already set

Discussion on expanding research possibilities

Dear author:
It is really an excellent job on poker bot!!!

 Here I have one question for further research possibilities you may have considered:  whether or how can the training deepbot agent learn from more intelligent opponent AIs like DeepStack(we have recreated a 6-handed version and include muti-iterations children version), especially in 6-handed Nolimited Texas holdem games?


Thank you in advance!!!

Test your Poker Agents on pokerwars.io

Hi Guys,

just wanna let you know that there is a Free Poker Bot Platform to test your agents in a more heterogenous environment. I think the current bots are already pretty competitive although it would be nice to compete against more ml experts. There are around 20-40 bots online almost 24/7.

Jump to pokerwars leaderboard or check out several API languages on pokerwars github

Hope to see some of you there and exchange some insights.

Cheers,
Simon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.