GithubHelp home page GithubHelp logo

rhalbersma / gym-blackjack-v1 Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 1.0 140 KB

OpenAI Gym blackjack environment (v1)

License: Boost Software License 1.0

Python 100.00%
openai-gym blackjack reinforcement-learning model-based-reinforcement-learning

gym-blackjack-v1's Introduction

OpenAI Gym blackjack environment (v1)

Language Standard License Lines of Code

Requirements

  • Python version 3.6 or higher

Installation

git clone https://github.com/rhalbersma/gym-blackjack-v1.git
cd gym-blackjack-v1
python3 -m venv .env
source .env/bin/activate
pip install --upgrade pip setuptools wheel
pip install -e .

Hello World

Let's simulate one millions blackjack hands using Sutton and Barto's blackjack rules and Thorp's basic strategy:

import gym
import gym_blackjack_v1 as bj
env = gym.make('Blackjack-v1')
agent = bj.BasicStrategyAgent(env)
stats = bj.simulate(agent, env)
dict(zip(stats.data, stats.weights / stats.sum_weights)), stats.mean, stats.tconfint_mean()

The above code will output the distribution of outcomes (win, loss, tie), the mean score per hand and its 95% confidence interval:

>>> import gym
>>> import gym_blackjack_v1 as bj
>>> env = gym.make('Blackjack-v1')
>>> agent = bj.BasicStrategyAgent(env)
>>> stats = bj.simulate(agent, env)
100%|██████████████████████████████| 1000000/1000000 [00:28<00:00, 35182.52it/s]
>>> dict(zip(stats.data, stats.weights / stats.sum_weights)), stats.mean, stats.tconfint_mean()
({0.0: 0.087323, -1.0: 0.479979, 1.0: 0.432698}, -0.047281, (-0.04915114318214309, -0.04541085681785691))

A player using the basic strategy will approximately lose 48.0%, win 43.3% and tie 8.7% of all hands, for a mean score per hand of -4.73%, give or take 0.19%.

Acknowledgement

Special thanks to Craig L. Zirbel for his illumunating blackjack paper.

License

Copyright Rein Halbersma 2020-2021.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

gym-blackjack-v1's People

Contributors

rhalbersma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

gonellcl1

gym-blackjack-v1's Issues

error when : >>> import gym_blackjack_v1 as bj

I got an error when i try to import gym_blackjack_v1

import gym_blackjack_v1 as bj

Traceback (most recent call last):

File "", line 1, in

File "/home/user/Dev/gym-blackjack-v1/src/gym_blackjack_v1/init.py", line 6, in

from . import envs

File "/home/user/Dev/gym-blackjack-v1/src/gym_blackjack_v1/envs/init.py", line 21, in

register(

File "/home/user/Dev/gym-blackjack-v1/src/gym_blackjack_v1/envs/init.py", line 10, in register

env_specs = gym.envs.registry.env_specs

AttributeError: 'dict' object has no attribute 'env_specs'

To solve this error try the command : pip install gym==0.17.3

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.