{"id":15551663,"url":"https://github.com/hhoppe/blackjack","last_synced_at":"2025-08-11T21:17:34.981Z","repository":{"id":42529322,"uuid":"467760354","full_name":"hhoppe/blackjack","owner":"hhoppe","description":"Blackjack Notebook (bjnb): Probabilistic analysis and simulation","archived":false,"fork":false,"pushed_at":"2025-05-08T04:47:21.000Z","size":10218,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-08T05:28:58.058Z","etag":null,"topics":["blackjack","blackjack-game","monte-carlo-simulation","probabilistic-modeling"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hhoppe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-03-09T03:15:25.000Z","updated_at":"2025-05-08T04:47:24.000Z","dependencies_parsed_at":"2023-11-09T22:45:45.869Z","dependency_job_id":"e6cd3add-daab-4236-9d2e-8f864d2440b3","html_url":"https://github.com/hhoppe/blackjack","commit_stats":{"total_commits":50,"total_committers":2,"mean_commits":25.0,"dds":0.06000000000000005,"last_synced_commit":"a0565d978e58ccf67d2dff237c5491fc9781d813"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hhoppe/blackjack","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhoppe%2Fblackjack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhoppe%2Fblackjack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhoppe%2Fblackjack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhoppe%2Fblackjack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hhoppe","download_url":"https://codeload.github.com/hhoppe/blackjack/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhoppe%2Fblackjack/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269958647,"owners_count":24503601,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-11T02:00:10.019Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blackjack","blackjack-game","monte-carlo-simulation","probabilistic-modeling"],"created_at":"2024-10-02T14:06:10.703Z","updated_at":"2025-08-11T21:17:34.935Z","avatar_url":"https://github.com/hhoppe.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bjnb: Blackjack Notebook\n\n[Hugues Hoppe](https://hhoppe.com/)\n\u0026nbsp;\u0026nbsp;\u0026mdash;\u0026nbsp;\n\u0026nbsp; [**[Open in Colab]**](https://colab.research.google.com/github/hhoppe/blackjack/blob/main/blackjack.ipynb)\n\u0026nbsp; [**[in Kaggle]**](https://www.kaggle.com/notebooks/welcome?src=https://github.com/hhoppe/blackjack/blob/main/blackjack.ipynb)\n\u0026nbsp; [**[in MyBinder]**](https://mybinder.org/v2/gh/hhoppe/blackjack/main?filepath=blackjack.ipynb)\n\u0026nbsp; [**[in Deepnote]**](https://deepnote.com/launch?url=https%3A%2F%2Fgithub.com%2Fhhoppe%2Fblackjack%2Fblob%2Fmain%2Fblackjack.ipynb)\n\u0026nbsp; [**[GitHub source]**](https://github.com/hhoppe/blackjack/blob/main/blackjack.ipynb)\n\nBlackjack \u0026mdash; *\"the most widely played casino banking game in the world\"*.\n\n\n**Goals**:\n\n- Solution methods for both:\n\n  1. [Probabilistic analysis](https://colab.research.google.com/github/hhoppe/blackjack/blob/main/blackjack.ipynb#Probabilistic-analysis)\n     of blackjack actions and outcomes under many strategies, and\n\n  2. [Monte Carlo simulation](https://colab.research.google.com/github/hhoppe/blackjack/blob/main/blackjack.ipynb#Monte-Carlo-simulation)\n     for cut-card effects and precise split-hand rewards.\n\n- Support for many [rule variations](https://colab.research.google.com/github/hhoppe/blackjack/blob/main/blackjack.ipynb#Define-Rules)\n  (12 parameters including #decks, dealer hit soft17, cut-card, ...)\n\n- Optimal [action tables](https://colab.research.google.com/github/hhoppe/blackjack/blob/main/blackjack.ipynb#Tables-for-basic-strategy) for\n  [basic strategy](https://colab.research.google.com/github/hhoppe/blackjack/blob/main/blackjack.ipynb#Define-Actions-and-Strategy)\n  under any rules, reproducing\n  [Wikipedia](https://en.wikipedia.org/wiki/Blackjack#Basic_strategy) and\n  [WizardOfOdds](https://wizardofodds.com/games/blackjack/strategy/calculator/) results.\n\n- Six separate [composition-dependent strategies](https://colab.research.google.com/github/hhoppe/blackjack/blob/main/blackjack.ipynb#Define-Actions-and-Strategy)\n  based on different levels of *attention*.\n  \u003c!--(initial cards, all hand cards, cards in *prior split hands*, ...).--\u003e\n\n- Computation of\n  [house edge](https://colab.research.google.com/github/hhoppe/blackjack/blob/main/blackjack.ipynb#House-edge-results)\n  under any rules, with either basic or composition-dependent strategies.\n\n- Comparisons with online\n  [hand calculator](https://colab.research.google.com/github/hhoppe/blackjack/blob/main/blackjack.ipynb#Hand-calculator-results) and\n  [house edge calculator](https://colab.research.google.com/github/hhoppe/blackjack/blob/main/blackjack.ipynb#House-edge-results) results.\n\n- Novel analysis and visualization of the\n  [*cut-card effect*](https://colab.research.google.com/github/hhoppe/blackjack/blob/main/blackjack.ipynb#Effect-of-using-a-cut-card)\n  and its [surprising oscillations](https://colab.research.google.com/github/hhoppe/blackjack/blob/main/blackjack.ipynb#cut-card-graph).\n\n- Open-source Python, sped up with jitting (\\~30x) and multiprocessing (\\~10x),\n  simulating \\~$10^{8}$ hands/s.\n  \n- GPU implementation using `numba.cuda`, simulating \\~$10^{10}$ hands/s.\n\n\n**Versions**:\n\n- 1.0 (March 2022): use probabilistic analysis for basic strategy tables and\n  approximate house edge.\n- 2.0 (July 2022): add Monte Carlo simulation, hand analysis,\n  and cut-card analysis.\n- 3.0 (January 2025): add CUDA implementation of simulation.\n\n\n**Running this Jupyter notebook**:\n\n- The notebook requires Python 3.10 or later.\n- We recommend starting a Jupyter server on a local machine with a fast multi-core CPU. \u003cbr/\u003e\n  (The notebook can also be executed on a\n  [Colab server](\n   https://colab.research.google.com/github/hhoppe/blackjack/blob/main/blackjack.ipynb),\n  where it greatly benefits from a CUDA GPU.)\n- Within a Linux environment (e.g.,\n  [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install)):\n\n```bash\n    sudo apt install python3-pip\n    python3 -m pip install --upgrade pip\n    pip install jupyterlab jupytext matplotlib numba tqdm\n    jupyter lab --no-browser\n```\n\n- Open the URL (output by `jupyter lab`) using a web browser (e.g., Google Chrome on Windows).\n- Load the notebook (`*.ipynb` file).\n- Evaluate all cells in `Code library` and then selectively evaluate `Results`.\n- Adjust the `EFFORT` global variable to trade off speed and accuracy.\n\n\n**References**:\n\n- https://en.wikipedia.org/wiki/Blackjack\n- https://wizardofodds.com/games/blackjack/basics/#rules\n- https://www.casinoguardian.co.uk/blackjack/ -- rich; explore more?\n- https://wizardofvegas.com/guides/blackjack-survey/\n- https://www.blackjackinfo.com/ -- created by Ken Smith; explore?\n- https://www.onlinegambling.com/blackjack/odds/\n- https://www.onlineunitedstatescasinos.com/las-vegas/blackjack/\n- https://en.wikipedia.org/wiki/Gambling_mathematics\n- https://www.gamingtheodds.com/blackjack/house-edge/ -- looks like truncated results of\n  WizardOfOdds assuming no late surrender.\n- https://github.com/johntelforduk/blackjack\n  -- Python simulator to evaluate house edge for various strategies.\n- [First reddit post](\n https://www.reddit.com/r/blackjack/comments/t9ygkm/python_notebook_to_analyze_blackjack_optimal/)\n\n(See also references in\n [Tables for basic strategy](https://colab.research.google.com/github/hhoppe/blackjack/blob/main/blackjack.ipynb#Tables-for-basic-strategy),\n [Hand calculators](https://colab.research.google.com/github/hhoppe/blackjack/blob/main/blackjack.ipynb#Hand-calculators), and\n [House edge calculators](https://colab.research.google.com/github/hhoppe/blackjack/blob/main/blackjack.ipynb#House-edge-calculators).)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhhoppe%2Fblackjack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhhoppe%2Fblackjack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhhoppe%2Fblackjack/lists"}