1.0.1 • Published 6 years ago

robot-cards v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

robot-cards

Robots and Pencils Cards programming challenge

Installation

npm install robot-cards

Usage

Start by importing the Robot Cards libary (pick and choose which components you will need to import):

const {Deck, Card, Hand, getStandardPlayingCards, SHUFFLE_METHODS}  = require('robot-cards'); 

Robot Cards can be used with most style cards. Simple provide an array of cards to the deck. For sake of ease, you can get a standard deck of cards by calling:

const standardPlayingCards = getStandardPlayingCards(); 

Once this is done, you can initialize your deck:

const deck = new Deck(standardPlayingCards); 

The deck constructor also takes a second optional parameter to change the method for shuffling the deck. The shuffle methods are:

SHUFFLE_METHODS.SIMPLE // default
SHUFFLE_METHODS.MAP
SHUFFLE_METHODS.FISHER_YATES

With the deck initialized, you can now shuffle your cards and distribute your hands.

deck.shuffle(); 

const numberOfHandsToDeal = 2;
const numberOfCardsPerHand = 3; 

const [handA, handB] = deck.dealHands(numberOfHandsToDeal, numberOfCardsPerHand); 

Optionally, you can also deal one card at a time:

const myHand = new Hand(); 
cosnt topCard = deck.deal(); 

myHand.addCard(topCard); 

Lastly, you can also add cards to a discard pile and, on your choosing reshuffle and add discarded cards;

for(let numberToDiscard = 0; numberToDiscard <= 5; numberToDiscard++) {
    deck.discard(deck.deal()); 
}

deck.shuffleDiscarded(); 

Contributing

  • Clone the repo
  • run npm install
  • run gulp

That's it!

1.0.1

6 years ago

1.0.0

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago