I'm looking to create a bridge deal with four players, each receiving 13 randomized cards.
To start, I plan on declaring variables for the suits, creating a deck containing these suits, and assigning the players their hands:
var deal = function() {
var spades = ['A', 'K', 'Q', 'J', 'T', 9, 8, 7, 6, 5, 4, 3, 2];
var hearts = ['A', 'K', 'Q', 'J', 'T', 9, 8, 7, 6, 5, 4, 3, 2];
var diamonds = ['A', 'K', 'Q', 'J', 'T', 9, 8, 7, 6, 5, 4, 3, 2];
var clubs = ['A', 'K', 'Q', 'J', 'T', 9, 8, 7, 6, 5, 4, 3, 2];
var deck = [spades, hearts, diamonds, clubs];
//Next step: dealing 13 random cards to each player
var northHand = [ [], [], [], [] ];
var eastHand = [ [], [], [], [] ];
var southHand = [ [], [], [], [] ];
var westHand = [ [], [], [], [] ];
}
Later, I came across a shuffle function based on the Fisher-Yates algorithm:
function shuffle(array) {
var m = array.length, t, i;
// While there are elements left to shuffle...
while (m) {
// Choose a remaining element...
i = Math.floor(Math.random() * m--);
// Swap it with the current element.
t = array[m];
array[m] = array[i];
array[i] = t;
}
return array;
}
However, my skills in programming and logic are lacking when it comes to applying this algorithm to my situation involving multiple arrays.
Do you think this is a good starting point for solving my problem, or should I explore other approaches?