4 Replies Latest reply on Jul 20, 2006 8:34 AM by fergal.mccann

# Card Game

I am working on a card game and I have to be able to number the cards from 1 to 53. After each game the cards get reshuffled so i have to somehow enable numbering without it sticking to the same card time and time again.

Thanks in advanced for any help.
• ###### 2. Re: Card Game
I've done it for a mah jong game, and while it's probably not the most efficient algorithm (I'm not a trained programmer) it's fairly easy to do:

Set up two arrays - one for the stock of cards, and one for the shuffled cards. Put all values into the stock array, so [0] would equal 1, and [52] would equal 53.

Then just generate a random number limited by the length of the stock array. Copy the value from that index of the stock array to the next available index in the 'shuffled array' and replace the value in the stock array with something high, like 500.

Then just reorder the stock array and pop the 'used' value.

Do this 53 times and you've moved all the cards from the stock array to the shuffled array, but in a random order. Use the shuffled array for your deal.

Does this make sense? Hope so.
• ###### 3. Re: Card Game
I am sort of lost here. I'm still learning the basics of action scripting. I think I understand parts of it but im not 100% sure. If it not too much of a problem could you possible show me.

I would be most greatful.

Kind regards

Fergal
• ###### 4. Re: Card Game
I am sort of lost here. I'm still learning the basics of action scripting. I think I understand parts of it but im not 100% sure. If it not too much of a problem could you possible show me.

I would be most greatful.

Kind regards

Fergal