I am doing a small poker program and I want to determine how well a deck is shuffled. I have a List with 52 cards then I run my shuffling algorithm and I want to be able to determine how well the deck is shuffled on some scale. Does someone have an idea how to do this? Thanks
EDIT: Wow. A lot of responses. All good but not exactly what I was looking for. That is my fault for not specifying my question further. But I think Saran is closest to what I actually want. Let me specify.
I do NOT want a "perfect" shuffle straight away. I already read up on that and I implemented Fisher-Yates. That one is pretty good at giving "perfect" shuffle. What I AM trying to do is to simulate a real world situation where friends are playing texas hold-em and the dealer takes the deck and shuffles it using riffle shuffle mixed with other shuffles. In the end, what I want is a way to measure the difference between real world shuffles.
An example. Assume the deck is always fresh (ace to king suited, then next suit ace to king for all four suits). Joe takes the deck and does 2 riffle shuffles with one cut in between. Peter does 5 stripping shuffles. I want to find a way to see which one shuffles the deck "better".
The more I think about it the more I think it is very very veeery hard to determine.
Thanks again.
EDIT 23.10.2013
Here is the method I came up with, combining Sarans idea with mine:
public int checkShuffle(List<Card> cardDeckToCheck,int[] previousOrder)
{
// Higher is worse? Sure.
int score = 0;
for (int i = 0; i < cardDeckToCheck.Count; i++)
{
Card cardToCheck = cardDeckToCheck[i];
Card cardToLeft = null;
Card cardToRight = null;
// Should cost more since the card has not moved at all.
// For this I need an array that shows me the arangement of the deck before shuffling.
if(cardToCheck.index == previousOrder[i])
{
score += 3;
}
if (i == 0)
{
Console.WriteLine("i == 1");
cardToRight = cardDeckToCheck[i+1];
// if the card we are checking is one lower or one higher than the card to the right
if(Math.Abs(cardToCheck.index - cardToRight.index) == 1)
{
score++;
}
continue;
}
else if (i == cardDeckToCheck.Count-1)
{
Console.WriteLine("i == carddecktocheck.count-1");
cardToLeft = cardDeckToCheck[i - 1];
// if the card we are checking is one lower or one higher than
if (Math.Abs(cardToCheck.index - cardToLeft.index) == 1)
{
score++;
}
continue;
}
else
{
cardToLeft = cardDeckToCheck[i - 1];
cardToRight = cardDeckToCheck[i + 1];
// if the card we are checking is one lower or one higher than
if (Math.Abs(cardToCheck.index - cardToLeft.index) == 1)
{
score++;
}
if (Math.Abs(cardToCheck.index - cardToRight.index) == 1)
{
score++;
}
continue;
}
}
return score;
}
I first record how the deck looks like into an int array then I shuffle the deck and then I run this method with the shuffled deck and the previous order of the deck. Like so:
int[] previousOrder = getCurrentOrder(deck.getDeck());
deck.setDeck(riffleShuffle2(3));
textBoxShuffleness.Text = "" + checkShuffle(deck.getDeck(), previousOrder);
displayDeck(deck);
When I start with an unshuffled deck and run the riffle shuffle method 5 times I get 70,33,28,5,10. When I start with an unshuffled deck and run the Durstenfeld shuffle method 5 times I get 5,0,7,11,7.
Those results are very much what I would expect.
If someone can find something wrong with this method then I would appreciate if you would comment :) Thanks