dh-blackjack
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

Black jack

Library to provide blackjack game logic in javascript.

Current features:

  • Player
  • Dealer
  • Bets
  • Bank / Creditsystem
  • Roundsimulation
  • Deck creation
  • Deck shuffling (early stage, currently only riffle | goal: simulate real dealers)
  • Card creation
  • Card calculation

Future ideas

  • Side-Bets
  • Splits (incl. multiple splits)
  • Game configs
  • GameClient in seperate project

Installation

$: npm install dh-blackjack

Usage

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]);

Create single cards

import { CardAce } from "dh-blackjack/lib/Game/Cards/CardAce";
const card = new CardAce('heart');

Simulate (WIP)

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();

Dealer Ki

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

Usage

DealerCardKi.calculate([card, ..]);

Run tests

$: npm run test

Readme

Keywords

Package Sidebar

Install

npm i dh-blackjack

Weekly Downloads

0

Version

1.1.1

License

MIT

Unpacked Size

62.1 kB

Total Files

82

Last publish

Collaborators

  • hormez