Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / randomize sprites

Author
Message
pokerman
15
Years of Service
User Offline
Joined: 20th May 2009
Location: Bournemouth, England
Posted: 21st Jul 2009 18:25
Hi i am trying to randomize a deck of cards (making a poker game) was wondering how to randomize them and show them at a certain location.

thanks in advance
Joe
jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 21st Jul 2009 18:40
create an array of objects, 52 of them, each object should have properties for suite and number. then just chose a random element from that array.

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 21st Jul 2009 20:10
I'll assume the cards are numbered 0 through 51. The suit is determined by the card number mod 13 and the pip value is the card number mod 4. That way you don't have to store two values for each card.



This walks through every element of the deck and swaps it with a random location, thus assuring that all elements are shuffled. In the past I've run this routine inside an outer loop, after the initial ordered number, as many as four times to really shuffle the deck. If you don't overwrite the elements of deck there's no need to re-do the ordered initialization.

If you use a struct'd datatype or a class object for the array you can still do the swap with the appropriate datatype as long as it has a copy constructor.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
pokerman
15
Years of Service
User Offline
Joined: 20th May 2009
Location: Bournemouth, England
Posted: 27th Jul 2009 12:11
Sorry for not getting back sooner thank you for the help.

Login to post a reply

Server time is: 2024-10-01 08:40:35
Your offset time is: 2024-10-01 08:40:35