npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

blackjack-game-server

v1.0.2

Published

Blackjack Game Server

Downloads

5

Readme

blackjack-game-server

Node application for a blackjack game that offers advice for different rule sets The service returns JSON objects representing the state of the game and accepts POST requests to perform actions or return recommended player actions You can use in conjunction with the angular-powered HTML file provided in html\index.htm to play a full game in your browser

Usage

You will need to run a redis server and update config.redisHost in src\config.js to point to the endpoint. The server maintains all of the game state, allowing the client to simply render the returned JSON game and further the game by allowing the player to post an action back to the server. The format of the JSON that is returned is as follows:

gameState = {
    "userID":string,                 // Represents the ID of the game; pass this in with subsequent POSTs
    "activePlayer":string,           // The active player - none, player, or dealer
    "currentPlayerHand":integer,     // 0-based index of the player hand currently in play
    "bankroll":integer,              // The player's bankroll
    "possibleActions":string[],      // An array of strings representing possible actions the player can take:
                                     //   insurance, noinsurance, surrender, double, split, hit, stand,
                                     //   bet, shuffle, or resetbankroll (after the player runs out of money)
    "dealerHand":{
            outcome:string,          // The outcome after the dealer peeked at their hole card for a blackjack:
                                     //   dealerblackjack, nodealerplayerjack, or playing
            cards:[
                {rank: integer,      // Rank of the card from 1 (Ace) - 13 (King)
                 suit: string}       // Suit: clubs, diamonds, hearts, or spades
            ]
        },
    "playerHands":[
            outcome:string,          // The outcome of the player's hand:
                                     //    playing, surrender, blackjack, win, loss, push
            bet:integer,             // The amount bet on this hand
            busted:boolean,          // Whether the player busted this hand
            cards:[
                {rank: integer,      // Rank of the card from 1 (Ace) - 13 (King)
                 suit: string}       // Suit: clubs, diamonds, hearts, or spades
        ],
    "lastBet":integer,               // The player's initial bet on the previous hand
    "houseRules": {
            hitSoft17:boolean,        // Does dealer hit soft 17
            surrender:string,         // Surrender offered - none, late, or early
            double:string,            // Double rules - none, 10or11, 9or10or11, any
            doubleaftersplit:boolean, // Can double after split
            resplitAces:boolean,      // Can you resplit aces
            blackjackBonus:decimal,   // Bonus for player blackjack, usually 0.5 or 0.2
            numberOfDecks:1,          // Number of decks in play
            minBet:5,                 // The minimum bet - not configurable
            maxBet:1000,              // The maximum bet - not configurable
            maxSplitHands:4           // Maximum number of hands you can have due to splits
        }
};

After retrieving the gameState, the client communicates with the server by issuing a POST command. Each of these commands expects a payload key/value pair containing the userID field from the JSON object retrieved from the previous GET command. The first list of commands can only be accepted if set in the possibleActions array. The return value for all of these is a JSON object representing the new game state after taking this action:

  • hit - The player will take another card
  • stand - The player will stay on this hand
  • split - The player will split a pair to create an additional hand
  • double - The bet on this hand will be doubled and one additional card will be drawn
  • surrender - The player will surrender this hand
  • insurance - The player wants to take insurance
  • noinsurance - The player doesn't want to take insurance
  • bet - Deal a new hand (this option will take an additional key/value pair of the form "value=X" where X is the amount of the bet)

In addition, you can post the following commands:

  • suggest - Make a suggestion of what the user should do for this hand; return value is a JSON object with field "suggestion" set to one of the possibleAction values, and "error" set to an error string if applicable
  • setrules - Change the rules in play. The payload will be an ampersand-delimited string of key/value pairs corresponding to the houseRules field listed above. Changing the rules forces a shuffle; the return value is a JSON object with the new gameState (noting the shuffle)

Contributing - bug fixes

Contributions are welcome! Please feel free to fork this code and submit pull requests, for bug fixes or feature enhancements.

  1. Fork it!
  2. Create your featured branch: git checkout -b my-feature
  3. Commit your changes: git commit -m 'add some feature'
  4. Push to the branch: git push origin my-feature
  5. Submit a pull request

Many Thanks!