blackjack-dealer
v1.2.0
Published
This package provides utility functions to simulate a simple card-hand game. It allows you to draw random cards, display the hand's current state, and compute the dealer's hand based on the rules of a basic card game.
Readme
Blackjack Dealer
This package provides utility functions to simulate a simple card-hand game. It allows you to draw random cards, display the hand's current state, and compute the dealer's hand based on the rules of a basic card game.
Installation
Install the package via npm:
npm install blackjack-dealerUsage
Here is how you can use the package in your Node.js project:
const { draw, showCard, dealerHand } = require('blackjack-dealer');
// Draw the first card
const firstCard = draw();
console.log(`First card drawn: ${firstCard}`);
// Show the hand
let handValues = [];
showCard(firstCard, handValues);
console.log(`Current hand values: ${handValues}`);
// Compute the dealer's hand
const dealerHandValues = dealerHand(draw, showCard);
console.log(`Dealer's hand values: ${dealerHandValues}`);API
draw()
Returns a random integer between 1 and 10, representing a card drawn from the deck.
showCard(hand, handValues)
- hand (number): The current value of the hand.
- handValues (array): An array to store the progression of hand values.
Stores the current hand value in the handValues array.
dealerHand(firstCard, showCard)
- firstCard (function): A function that draws a random card.
- showCard (function): A function to display the hand.
Simulates the dealer's hand based on the following rules:
- The dealer starts with two random cards.
- Cards are drawn until the dealer's hand reaches or exceeds 17, or goes bust (>21).
- If the hand value equals 21, it is marked as "Blackjack!".
- If the hand value exceeds 21, it is marked as "Bust!".
Returns an array of hand values, including the final result (e.g., "Blackjack!" or "Bust!").
Example Output
First card drawn: 7
Current hand values: [7]
Dealer's hand values: [14, 19]License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Feel free to submit a pull request or open an issue if you find a bug or have a feature request.
