1) I set up an array for the cards simulating a deck of 52, and I initialize the values with a 0

DIM deck[52]

for t = 1 to 52

deck[t] = 0

next t

2) Then I pick a random number between 1 and 52 using a label to loop back here if need be

pick_a_random_card:

pick_a_card = random(1,52)

3) Then I check the deck with a for loop to make sure that the random number is not already there in the deck

for r = 1 to 52

if pick_a_card = deck[r]

goto pick_a_random_card

endif

next r

if the random card matches one already in the deck then I am going back to pick a new random number

4)if the random card does not match any in the deck then we go on to find an empty slot for the random number

for s= 1 to 52

if deck[s] = 0

deck[s] = pick_a_card

goto pick_a_random_card

endif

next s

notice I am jumping out of that for loop with a goto so we only assign the value of the random card in the first open slot of the deck and not all of the slots that = 0

5) we end it off by checking to see if the deck is full, and we can stick that in several places to effectively leave this cycle

if deck[52] <> 0

goto deal_the_cards

endif

we only have to check the last slot for being empty since we fill the deck one card at a time

just remember to reset the values to zero at the beginning of the shuffle on reshuffles

for t = 1 to 52

deck[t] = 0

next t

In short, this fills the array

*deck[52]* with values between 1 and 52 without duplicates

Now we can deal these cards by cycling through the deck array starting at the first slot and incrementing each time

Instead of assigning the face value and suits for all 52 cards in the deck, I opt to do that one card at a time as I deal them

So I keep a separate multidimensional array for the cards

That way the multidimensional one is smaller.

DIM cards[5,3]

whereas if we start at 1 being Ace of clubs, and 2 being 2 of clubs through 13 being King of clubs, then

a card value of 14 would be the Ace of diamonds, and 15 the 2 of diamonds, etc.

so if the card in the 32 slot of the deck was a 23 then that is the 10 of diamonds, because the 23 represents the 10 of diamonds

so if that 32 card was the first card in our hand, then the cards array for that slot would be...

cards[1,1] = 23

cards[1,2] = 10

cards[1,3] = 2

note I use all numbers for everything then convert it, because that makes it easier when doing comparisons on the cards

you only need to convert that when displaying the card to show that suit value of 2 to equal diamonds, or whatever suit you have as your second suit

Anyway, this is not the best way to do this I am sure, but it does work without a hitch as you can see in my game.

Filling that deck array with no duplicates is just like having a real deck sitting there, shuffled and ready to be dealt.

I just keep a card counter to keep my place in knowing which card I am choosing...

cards[1,1] = deck[current_card]

current_card = current_card + 1

...note that I increment the current_card every time I use it so I am ready for drawing the next card.

You will need to reset this variable to 1 when shuffling, so you will start dealing at the beginning of the fresh deck

You will also need to know when to shuffle.

I do this check on the deal...

if current_card > 42

goto shuffle

endif

...in my case it is 5 card draw, so I need at least 10 cards left in the deck to deal a new hand. (dealt 5 and draw 5)

That way we do not have to check the cards in the players hand for duplicates when shuffling, just the deck.

You could run up to the last card if you wanted to, just remember to assign the first cards in the deck array with the values of the cards' first elements after resetting the array to 0's and before picking a random card, and also set the current_card accordingly so you would start dealing in the slot after the cards the player is holding

Sorry about the goto statements, but I use them.

This program is linear with labels. (no functions, just labeled routines)

Hope this helps

Using AppGameKit V1 Tier 1