{"id":16484350,"url":"https://github.com/nugaon/blackjack-engine","last_synced_at":"2025-03-23T12:32:40.419Z","repository":{"id":42875457,"uuid":"257214039","full_name":"nugaon/blackjack-engine","owner":"nugaon","description":"BlackJack engine with multiplayer/multihand functionality","archived":false,"fork":false,"pushed_at":"2023-01-07T17:17:59.000Z","size":751,"stargazers_count":3,"open_issues_count":12,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-12T13:16:51.395Z","etag":null,"topics":["blackjack","card-game","cards","games","nodejs"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nugaon.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}},"created_at":"2020-04-20T08:11:06.000Z","updated_at":"2024-04-27T19:20:19.000Z","dependencies_parsed_at":"2023-02-07T17:46:10.348Z","dependency_job_id":null,"html_url":"https://github.com/nugaon/blackjack-engine","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nugaon%2Fblackjack-engine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nugaon%2Fblackjack-engine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nugaon%2Fblackjack-engine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nugaon%2Fblackjack-engine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nugaon","download_url":"https://codeload.github.com/nugaon/blackjack-engine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221850582,"owners_count":16891653,"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","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","card-game","cards","games","nodejs"],"created_at":"2024-10-11T13:16:49.982Z","updated_at":"2024-10-28T15:47:45.220Z","avatar_url":"https://github.com/nugaon.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Available game parameters\n\nThere are many possible configuration. We are implementing _Standard_ and _Custom_ options\nso that you can easily _combine flags_ to create games according with your skill/needs.\n\n### Standard variations\n\n * number of `decks`, default is `1`\n * `standOnSoft17`, turn On/Off the \"Soft 17\" rule, default `true`\n * `double`, ability to double after deal, default `any`\n    * `none` not allowed\n    * `any` any allowed\n    * `9or10`\n    * `9or10or11`\n    * `9thru15`\n * `split`, On/Off the possibility to split after deal, default `true`\n * `doubleAfterSplit`, On/Off the possibility to double after split (_split_ and _double_ must be \"on\"), default `true`\n * `surrender`, on/off the ability to surrender after deal, default `true`\n * `insurance`, on/off the ability of ensuring a hand, default `true`\n\n## Install\n\nIf you are using [npm](https://www.npmjs.com/), to get the last version:\n\n * `yarn add blackjack-engine`\n * `npm install blackjack-engine`\n\n## Quick Start\n\nOnce obtained the library just _require_ `Game` and `actions`.\n\n```\nconst blackjack = require('blackjack-engine')\nconst actions = blackjack.actions\nconst Game = blackjack.Game\n```\n\nAt this point you can initialize a _new game_ by calling the `Game constructor`.\n\n### Creating a new game\n\n```\nconst game = new Game()\n```\n\nIn this cases, no state is passed to the constructor:\n\n 1. the _default_ state is loaded into _game_\n 2. _game_ is ready to _`dispatch` actions_ to alter the state\n\n### Getting current state\n\nAt any moment we can require the current state of the _game_ by calling the `getState()`.\n\n```\nconsole.dir(game.getState())\n```\n\nThe content of the state and its _schema_ depends on the _stage_ of the game. In this case\nwe initialized the game without any precedent state, so we will receive something like this:\n\nFor the moment the only thing we should note is that the _field_ `stage` tells us \"game is ready\".\n\n### Dispatching actions\n\nThe only way *to mutate the state of the game* is to dispatch actions. Some actions are required by the \"user\",\nsome other actions are dispatched by the engine to \"complete\" the game.\n\nNOTE: In a real game, players and dealer are allowed to \"do actions\". The engine will \"impersonate the dealer\" at some point, depending on the _last action_ and the _state_.\n\n```\n// stage is \"ready\"\nconsole.log(game.getState().stage)\n\n// call an action to mutate the state\ngame.dispatch(actions.deal())\n\n// stage has changed\nconsole.log(game.getState().stage)\n```\n\n## Project Structure\n\nBased on [Marco Casula's project](https://github.com/kedoska/engine-blackjack/).\n\n### Actions\n\nsee the `/src/actions.js`\n\nEngine exposes _actions_, once invoked, the state of the game is changed.\nThe following list represent the _actions_ that can be _dispatched_ by from the public API.\n\n * bet\n * insurance\n * double\n * split\n * hit\n * stand\n * surrender\n\nAnd, those are _actions_ that are internally called in determinate _stages_ by the engine itself.\n\n * deal-cards\n * showdown\n * dealerHit\n * invalid\n\n### Stages\n\nSee the `/src/game.ts`\n\nThe stage represent a moment in the game. The stage is directly related with the action allowed in that particular moment.\n\nCurrent available stages for players are:\n\n * ready\n * insurance\n * players-turn\n * showdown\n * dealer-turn\n * done\n\n### Logic\n\nThe game logic is implemented into `/src/engine.ts`.\nThere is a specific design limitation currently in the code.\n\nNOTE: If you are interested in the random components, check out the `shuffle()` function.\n\n## Test\n\nRun tests by calling `yarn test ` or `npm test`\n\n[Jest](https://facebook.github.io/jest/) will care about the following tasks:\n - create a new game\n - initialize it by injecting `♠10 ♦1 ♥5 ♣6 ♠11 ♦10` at the and of the _deck_\n - run the desired `restore`, `deal`, `split`, `insurance` and finally `stand`\n - return the current state\n - compare if `stage` is 'done' at the end\n\nIf you specify the `finalWin` the test will compare the final winning.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnugaon%2Fblackjack-engine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnugaon%2Fblackjack-engine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnugaon%2Fblackjack-engine/lists"}