Available game parameters
There are many possible configuration. We are implementing Standard and Custom options so that you can easily combine flags to create games according with your skill/needs.
- number of
decks, default is
standOnSoft17, turn On/Off the "Soft 17" rule, default
double, ability to double after deal, default
split, On/Off the possibility to split after deal, default
doubleAfterSplit, On/Off the possibility to double after split (split and double must be "on"), default
surrender, on/off the ability to surrender after deal, default
insurance, on/off the ability of ensuring a hand, default
If you are using npm, to get the last version:
yarn add blackjack-engine
npm install blackjack-engine
Once obtained the library just require
const blackjack = require('blackjack-engine') const actions = blackjack.actions const Game = blackjack.Game
At this point you can initialize a new game by calling the
Creating a new game
const game = new Game()
In this cases, no state is passed to the constructor:
- the default state is loaded into game
- game is ready to
dispatchactions to alter the state
Getting current state
At any moment we can require the current state of the game by calling the
The content of the state and its schema depends on the stage of the game. In this case we initialized the game without any precedent state, so we will receive something like this:
For the moment the only thing we should note is that the field
stage tells us "game is ready".
The only way to mutate the state of the game is to dispatch actions. Some actions are required by the "user", some other actions are dispatched by the engine to "complete" the game.
NOTE: 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.
// stage is "ready" console.log(game.getState().stage) // call an action to mutate the state game.dispatch(actions.deal()) // stage has changed console.log(game.getState().stage)
Based on Marco Casula's project.
Engine exposes actions, once invoked, the state of the game is changed. The following list represent the actions that can be dispatched by from the public API.
And, those are actions that are internally called in determinate stages by the engine itself.
The stage represent a moment in the game. The stage is directly related with the action allowed in that particular moment.
Current available stages for players are:
The game logic is implemented into
There is a specific design limitation currently in the code.
NOTE: If you are interested in the random components, check out the
Run tests by calling
yarn test or
Jest will care about the following tasks:
- create a new game
- initialize it by injecting
♠10 ♦1 ♥5 ♣6 ♠11 ♦10at the and of the deck
- run the desired
- return the current state
- compare if
stageis 'done' at the end
If you specify the
finalWin the test will compare the final winning.