Library to provide blackjack game logic in javascript.
- Player
- Dealer
- Bets
- Bank / Creditsystem
- Roundsimulation
- Deck creation
- Deck shuffling (early stage, currently only riffle | goal: simulate real dealers)
- Card creation
- Card calculation
- Side-Bets
- Splits (incl. multiple splits)
- Game configs
- GameClient in seperate project
$: npm install dh-blackjack
import {
Card,
CardCalculator,
Dealer,
DealerCardKi,
Deck,
DeckCollection,
DeckGenerator,
DeckShuffler,
Player,
PlayerAction,
PlayerActionDoubleDown,
PlayerActionHit,
PlayerActionSplit,
PlayerActionStand,
PlayerBank,
Table,
TableRound,
} from 'dh-blackjack';
const deck = DeckGenerator.generate();
const shuffler = new DeckShuffler();
// single
shuffler.riffle(deck);
// or multiple decks
shuffler.shuffle([deck, ..]);
// ex.: Ace
const card1 = deck.getCard();
// ex.: Eight
const card2 = deck.getCard();
// ex.: { value: 9, sub: 19 }
const value = CardCalculator.calculate([card1, card2]);
import { CardAce } from "dh-blackjack/lib/Game/Cards/CardAce";
const card = new CardAce('heart');
player.placeBet(10);
// first 2 cards
table.start();
player.action = PlayerActionFactory.create(PlayerAction.HIT);
table.startPlayerRound();
player.action = PlayerActionFactory.create(PlayerAction.HIT);
table.startPlayerRound();
// Gives dealer one card, if below 17 and not above 21
table.startDealerRound();
table.closeRound();
The Dealer Ki is in use of the CardCalculator, but instead of just calculate the values it always returns the highest possible number. If there is a higher sub value, it would return it. The calculation based on min. 17 and max. 21.
ex.: Ace + 7 = 8 // returns sub 18, instead of 8
ex.: Ace + 7 + Ace = 9 // returns 19
ex.: Ace + Ace = 12 // returns 12, because dealer would bust
ex.: 10 + 6 // returns 16
DealerCardKi.calculate([card, ..]);
$: npm run test