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

mr-squishy-cardmaster

v0.0.1

Published

Keep track of card games with players and current hands.

Downloads

13

Readme

mr-squishy-cardmaster

Travis

Keep track of card games with players and current hands.

installation

node:

$ npm install mr-squishy-cardmaster

component:

$ component install kitto1/mr-squishy-cardmaster

usage

You pass mr-squishy an array of 'hands'.

Each hand represents a player in the card game and is an array of cards in the hand.

mr-squishy keeps track of the hands so you can:

  • get the next card from the top of a players hand
  • put a card onto the bottom of a players hand
  • ask how many cards are in a players hand

Each card is an object with any properties you want - mr-squishy just looks after the dealing.

creating hands

First - lets create some hands using decked and scruffy-shuffle

var decked = require('decked')
var scruffyShuffle = require('scruffy-shuffle')
var cardmaster = require('mr-squishy-cardmaster')

// get a deck of cards with aces low
var deck = decked({
  ace:'low'
})

// get cards that exclude face cards
var cards = deck(function(card){
  return card.number<=10
})

// split the deck into 2 players
var hands = scruffyShuffle(cards, {
  valueField:'number',
  players:[1,1]
})

running games

Now we have an array of player hands (each hand being an array of objects) - we can create a dealer using mr-squishy.

We could play a round of a game where one player 'wins' 2 cards from the other. This would result in putting 4 cards on the bottom of the winning players hand:

var game = cardmaster(hands)
var player1 = game.player(0)
var player2 = game.player(1)

// deal 2 cards from the top of player 1's hand into a new array
var player1Cards = player1.takeCards(2)

// deal 2 cards from the top of player 2's hand into a new array
var player2Cards = player2.takeCards(2)

// decide that player 2 wins all 4 cards
// and put them back onto the bottom of player 2's hand
player2.putCards(player1Cards.concat(player2Cards))

api

var game = cardmaster(hands)

Create a new game with the given hands of cards.

hands is an 2d array - each top level is a player and each element in the player array is a card in their hand.

// hands for 2 players - each player has 2 cards
var hands = [[{
  name:'jack',
  number:11,
  suit:'diamond'
},{
  name:'jack',
  number:11,
  suit:'spade'
}],[{
  name:'jack',
  number:11,
  suit:'club'
},{
  name:'jack',
  number:11,
  suit:'heart'
}]]

var game = cardmaster(hands)

var player = game.player(index)

Get a reference to a players individual hand - index is zero-based so pass 0 for player1

var game = cardmaster(hands)
var player1 = game.player(0)
var player2 = game.player(1)

var cards = player.hand()

Return the full list of cards in the players hand

var card = player.takeCard(position)

Take a single card from a players hand

Position can be 'top' or 'bottom' (top is default).

player.putCard(card, position)

Return a single card to a players hand

Position can be 'top' or 'bottom' (bottom is default).

var cards = player.takeCards(number, position)

Take some cards from a players hand - this alters the count for that hand (because it removes the cards from the hand)

Count is the number of cards to return in the array.

Position can be 'top' or 'bottom' (top is default).

player.putCards(cards, position)

Insert some cards back into a players hand - cards is an array of the card objects.

Position can be 'top' or 'bottom' (bottom is default)

var count = player.count()

Return a number representing how many cards a player has in their hand.

license

MIT