Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
card shuffler
#13
here's my take on it - it's not the fastest but it most closely simulates the act of shuffling a deck as it might be done by a professional type

Code:
int card[52], temp[52], i, shuffles, cutsplit, lefthand, righthand, whichhand;
for (i=0; i < 52; i++)
  card[i] = i; // reset the deck
for (shuffles=1; shuffles <= 7; shuffles++) // shuffle the deck 7 times
{
  for (i=0; i < 52; i++)
    temp[i] = card[i];
  cutsplit = rand() % 3 + 24; //  cut the deck, make it slightly uneven sometimes
  lefthand  = 0;
  righthand = cutsplit;
  whichhand = 1;
  for (i=0; i < 52; i++)
  {
    if (rand() % 3 == 0) whichhand = -whichhand; // the act of shuffling will typically alternate left to right but add a 33% randomizing factor.
    if      (whichhand == 1  && lefthand  >= cutsplit) whichhand = -whichhand; // if theres no card in the designated half, switch halves
    else if (whichhand == -1 && righthand >= 52)       whichhand = -whichhand;

    if      (whichhand == 1)  deck[i] = temp[lefthand++ ];
    else if (whichhand == -1) deck[i] = temp[righthand++];
    whichhand = -whichhand;
  }
}
ignatures suck
Reply


Messages In This Thread
card shuffler - by neuro - 05-22-2005, 06:40 AM
card shuffler - by Z!re - 05-22-2005, 07:16 AM
card shuffler - by neuro - 05-22-2005, 09:08 AM
card shuffler - by Mango - 05-22-2005, 02:11 PM
card shuffler - by relsoft - 05-22-2005, 04:01 PM
card shuffler - by Anonymous - 05-22-2005, 04:07 PM
card shuffler - by Z!re - 05-22-2005, 08:15 PM
card shuffler - by Anonymous - 05-23-2005, 09:53 AM
card shuffler - by Z!re - 05-23-2005, 08:08 PM
card shuffler - by neuro - 05-24-2005, 04:43 AM
card shuffler - by Z!re - 05-24-2005, 05:00 AM
card shuffler - by Pyrokid - 05-24-2005, 06:43 AM
card shuffler - by neuro - 05-24-2005, 07:13 AM
card shuffler - by Anonymous - 05-24-2005, 10:49 AM
card shuffler - by Pyrokid - 05-24-2005, 04:02 PM
card shuffler - by aetherfox - 05-24-2005, 04:57 PM
card shuffler - by shiftLynx - 05-24-2005, 09:05 PM
card shuffler - by Pyrokid - 05-24-2005, 09:56 PM
card shuffler - by phycowelder - 11-04-2005, 09:44 AM
card shuffler - by stylin - 11-04-2005, 12:07 PM
card shuffler - by Moneo - 11-05-2005, 07:08 AM
card shuffler - by Dr_Davenstein - 11-05-2005, 10:20 AM
card shuffler - by Torahteen - 11-05-2005, 10:22 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)