Last active
August 29, 2015 14:04
-
-
Save navio/9f47a5948b730b37a95b to your computer and use it in GitHub Desktop.
Deck Generator.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var deck = [], hand = [], hands = []; | |
"♠♡♢♣".split("").forEach(function (suit) { | |
"A 2 3 4 5 6 7 8 9 10 J Q K".split(" ").forEach(function (rank) { | |
deck.push(rank + suit); | |
}); | |
}); | |
for (var i = 0; i < 4; i += 1){ // Players | |
for (var i = 0; i < 5; i += 1){ // Cards | |
hand.push(deck.splice(Math.floor(Math.random() * deck.length), 1)); | |
hands.push(hand.join(" ")); | |
} | |
} | |
return hands; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var PockerDeck = (function(suits,levels){ | |
deck = []; | |
suits.forEach(function(suit){ | |
levels.forEach(function(level){ | |
deck.push(suit+level); | |
}) | |
}) | |
return deck; | |
})(['♠','♡','♢','♣'],['A','1','2','3','4','5','6','7','8','9','J','Q','K']); | |
PockerHand = function(deck, cards){ | |
var hand = []; | |
var i = 0 | |
while(cards > i){ | |
hand.push(deck.splice(Math.floor(Math.random() * deck.length), 1)); | |
++i; | |
} | |
return hand.join(" "); | |
} | |
console.log(PockerHand(PockerDeck, 5),PockerHand(PockerDeck, 5),PockerHand(PockerDeck, 5) ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.export = function(num_of_players,cards_per_Player){ | |
var hands = []; // Hands Array | |
var deck = (function GenerateDeck(suits,ranks){ // Deck Generator | |
deck = []; | |
suits.split("").forEach(function (suit) { | |
ranks.split(" ").forEach(function (rank) { | |
deck.push(rank + suit); | |
}); | |
}); | |
return deck; | |
})("♠♡♢♣","A 2 3 4 5 6 7 8 9 10 J Q K"); | |
function getHand(){ // Hand Generator | |
var hand = []; | |
for (var i = 0; i < cards_per_Player; i += 1) | |
hand.push(deck.splice(Math.floor(Math.random() * deck.length), 1)); | |
return hand; | |
} | |
for (var i = 0; i < num_of_players; i += 1) // Get Hands | |
hands.push(getHand()); | |
return hands; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment