Well I could not sleep so I spent some time working on this and came up with a solution that seems to do the trick.
sync on
sync rate 30
`array of 52 cards in a deck
global DIM drawn(4,13)
global DIM deck(4,13)
`spades
deck(1,1) = 1 `ace
deck(1,2) = 2
deck(1,3) = 3
deck(1,4) = 4
deck(1,5) = 5
deck(1,6) = 6
deck(1,7) = 7
deck(1,8) = 8
deck(1,9) = 9
deck(1,10) = 10
deck(1,11) = 11 `jack
deck(1,12) = 12 `queen
deck(1,13) = 13 `king
`hearts
deck(2,1) = 1 `ace
deck(2,2) = 2
deck(2,3) = 3
deck(2,4) = 4
deck(2,5) = 5
deck(2,6) = 6
deck(2,7) = 7
deck(2,8) = 8
deck(2,9) = 9
deck(2,10) = 10
deck(2,11) = 11 `jack
deck(2,12) = 12 `queen
deck(2,13) = 13 `king
`diamonds
deck(3,1) = 1 `ace
deck(3,2) = 2
deck(3,3) = 3
deck(3,4) = 4
deck(3,5) = 5
deck(3,6) = 6
deck(3,7) = 7
deck(3,8) = 8
deck(3,9) = 9
deck(3,10) = 10
deck(3,11) = 11 `jack
deck(3,12) = 12 `queen
deck(3,13) = 13 `king
`clubs
deck(4,1) = 1 `ace
deck(4,2) = 2
deck(4,3) = 3
deck(4,4) = 4
deck(4,5) = 5
deck(4,6) = 6
deck(4,7) = 7
deck(4,8) = 8
deck(4,9) = 9
deck(4,10) = 10
deck(4,11) = 11 `jack
deck(4,12) = 12 `queen
deck(4,13) = 13 `king
`keep track of the # of cards drawn since last shuffle
global cnt as integer = 0
`main loiop
do
` press SPACE to draw a card
if spacekey() = 1
DrawCard()
print "cards used: ", cnt
print "--------------------"
sleep 100
endif
`press RETURN to shuffle deck
if returnkey() = 1
ShuffleDeck()
print "the deck has been shuffled!"
print "--------------------"
sleep 100
endif
sync
loop
`draw a random card
function DrawCard()
if cnt = 52
print "no more cards left!"
result = 0
else
suit = RND(3)+1
card = RND(12)+1
while drawn(suit,card) = 1
suit = RND(3)+1
card = RND(12)+1
endwhile
`mark card as drawn
drawn(suit,card) = 1
print "suit: ", suit
print "card: ", card
if suit = 1 then print "Spade, index of ", deck(suit,card)
if suit = 2 then print "Heart, index of ", deck(suit,card)
if suit = 3 then print "Diamond, index of ", deck(suit,card)
if suit = 4 then print "Club, index of ", deck(suit,card)
cnt = cnt+1
result = 1
endif
endfunction result
`shuffle the deck and make all cards available again
function ShuffleDeck()
`reset counter
cnt = 0
`remove all drawn cards from array
drawn(1,1) = 0 `ace
drawn(1,2) = 0
drawn(1,3) = 0
drawn(1,4) = 0
drawn(1,5) = 0
drawn(1,6) = 0
drawn(1,7) = 0
drawn(1,8) = 0
drawn(1,9) = 0
drawn(1,10) = 0
drawn(1,11) = 0 `jack
drawn(1,12) = 0 `queen
drawn(1,13) = 0 `king
`hearts
drawn(2,1) = 0 `ace
drawn(2,2) = 0
drawn(2,3) = 0
drawn(2,4) = 0
drawn(2,5) = 0
drawn(2,6) = 0
drawn(2,7) = 0
drawn(2,8) = 0
drawn(2,9) = 0
drawn(2,10) = 0
drawn(2,11) = 0 `jack
drawn(2,12) = 0 `queen
drawn(2,13) = 0 `king
`diamonds
drawn(3,1) = 0 `ace
drawn(3,2) = 0
drawn(3,3) = 0
drawn(3,4) = 0
drawn(3,5) = 0
drawn(3,6) = 0
drawn(3,7) = 0
drawn(3,8) = 0
drawn(3,9) = 0
drawn(3,10) = 0
drawn(3,11) = 0 `jack
drawn(3,12) = 0 `queen
drawn(3,13) = 0 `king
`clubs
drawn(4,1) = 0 `ace
drawn(4,2) = 0
drawn(4,3) = 0
drawn(4,4) = 0
drawn(4,5) = 0
drawn(4,6) = 0
drawn(4,7) = 0
drawn(4,8) = 0
drawn(4,9) = 0
drawn(4,10) = 0
drawn(4,11) = 0 `jack
drawn(4,12) = 0 `queen
drawn(4,13) = 0 `king
endfunction
Any suggestions on tweaking this would be welcomed. Is there a better way for me to reset the drawn() array to all 0's? Setting each value individually looks so ugly, but it's the only way I knew.
badrock