Question 6 Deck Card Shuffling In Access (1 Viewer)

bcmarshall

Registered User.
Local time
Today, 10:48
Joined
Jul 17, 2010
Messages
92
I'm doing something not generally associated with Access. I'm writing an
analytical blackjack program. Anyone familiar with Access knows that it can be instructed to do the things involved, namely count the hand, stand or hit at a certain level, and anything else required to play the game. My problem is that I've been unable to come up with a practical and fast shuffling routine, but I have special requirements.

I want the shuffled decks stored in a table for several reasons. I want to
be able to compare two moves, say standing vs. hitting a 16 v 10. The only way that's possible is to be able to see what the next card would have been and then making a comparison of the results. Another reason is to be able to save really good or really poor decks so that they can be collected and strategies can be developed which are optimized to bad or good runs of cards.

Can anyone offer a means of shuffling 6 decks and storing the results in a
table? I have been able to do it, but the wait is interminable, and I know
there are much better ways out there. I just can't think of any!

Thanks for your help.
 

HiTechCoach

Well-known member
Local time
Today, 12:48
Joined
Mar 6, 2006
Messages
4,357
from one of the other 5 forums that this was posted:

bcmarshall said:
My current tables are simple. I have a table with one deck of cards in it, and a field on my play form for number of decks. The shuffle button (or automatically when the number of cards remaining drops below a set pont) runs a macro whose repeat count is equal to the number of decks. Said macro runs an append query to append to another table one deck 4, 5, 6, or any desired number of times.

Once that table contains the correct number of decks, I used a routine with the Rnd() feature. In the case of 6 decks, I had a field on a form set to [Decks]*52 as the shuffle opened, so the field would contain the number 312. I then would generate a random number between 1 and 312 cards, go to that record number in the table that has the unshuffled decks, and set it as the first card in the Shuffled table. The final step in the routine was to decrement the counting field by one. The macro runs 312 times.

Then for the second card I would generate a second random number between 1 and 311 (the count field decremented, and also the number of remaining cards in the unshuffled table), go to that record and move its value to the shuffled table. In this manner I was able to generate a "randomly" shuffled multi-deck group. It works, but the problem is that it takes 30-40 seconds to complete the routine, and that's impractical if I want to run tens of thousands of comparison hands.

There are no relationships between tables since I can see no need for it, as nothing is related for future reference or lookup, and the shuffle decrementer form runs completely on unbound controls.

I hope that explains what I've done up to now. As I said, it does work, but just not efficiently at all.

And yes, I posted this at about six different forums. I really want to get this solved so I can move on!

from HERE
 

Poppa Smurf

Registered User.
Local time
Tomorrow, 03:48
Joined
Mar 21, 2008
Messages
448
Please post your database, there maybe a way by using arrays.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 18:48
Joined
Sep 12, 2006
Messages
15,653
to have a 6 card deck, all you need is a random number between 1 and 312 surely

then just map this to the decks, in whatever way you like.

------------
the shuffling really turns into the effectiveness of the random number generator, surely.
 

bcmarshall

Registered User.
Local time
Today, 10:48
Joined
Jul 17, 2010
Messages
92
I apologize to all who answered. The email notification of the response was delivered to my spam folder and I didn't see it until now.

As HiTechCoach will probably point out, I did get my problem solved by a user in another forum. He came up with the following solution. http://www.mediafire.com/download.php?i6e3elm9a2hh71t It works in less than half a second and will allow me to move on to the reason for the request, which is the ability to analyze the game of blackjack in ways that it has not been analyzed before. Even without that ability I am able to win at an almost unheard of rate, currently 18 wins for 21 trips. I expect even better results once I can dissect the game and look inside it the way I want to.

I want to sincerely thank all who offered ideas, suggestions, and time to help me resolve this. It's good to know there are folks out there like you who are just interested in assisting others, and it is deeply appreciated.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 18:48
Joined
Sep 12, 2006
Messages
15,653
I thnik the "best outcome" prrinciples for playing blackjack are clearly established.

there is no way to win, other than by counting cards, and waiting for the decks to become "stacked" (watch the film 21) In a casino, if you count cards you will be ejected or worse.

i suspect that on line games dont work like this, and each deal is different, so you counting cards is not relevant anyway.

like all casino games, the house has a small % edge, and you will lose in the long run.
 

bcmarshall

Registered User.
Local time
Today, 10:48
Joined
Jul 17, 2010
Messages
92
Gemma, I understand that you are restating conventional wisdom, and I agree that there is indeed a built-in very small percentage house advantage (about 2%). Regardless, I have noticed and exploited something previously either unrecognized or underappreciated about the game which has allowed me to overcome that very small edge. Right now I'm 18 wins for 21 trips, or about 86%, without the benefit of the ability to computer analyze the game. That isn't luck.

I have another question I'd like to pose to readers. This program has always been intended as an analytical tool, and nice pretty graphics were never a consideration. In fact, my original shuffle routine made no provision for suit, since for analytical purposes a six of diamonds or clubs is identical. However, the shuffle routine I now have does include suits, and it would be nice to utilize cards.dll to make it graphical if it's not too much extra effort.

Does anyone out there know how to call specific card graphics from within Access? I'd sure like to know if it's possible, and if so, how it is done.
 

HiTechCoach

Well-known member
Local time
Today, 12:48
Joined
Mar 6, 2006
Messages
4,357
For anyone following this thread, the following is from a dbForums post here

bcmarshall said:
The notice that there were responses was delivered to my spam folder so i didn't see it until now. Sorry. I was very fortunate in that someone offered me a fantastic, fast solution which does the shuffling within Access and stores the results in a table in less than half a second. If anyone is interested in reviewing it, it can be seen here. CardShuffle.mdb

Missinglinq, Access is no VW beetle! I agree that its primary purpose is a database, but that makes it very helpful for me to be able to store and analyze results. It's an extremely powerful program (do I need to tell you that?), and it can effortlessly do the tasks needed to play the game, even if that's not its primary purpose. I'll bet the shuffle routine offered by a poster at another forum is as fast as any in any other language. It works in less than half a second, and could even be faster than a dump truck! And I never complained that it's taking too many trips. I was simply asking for exactly what I got, a direct route to my destination instead of driving in circles to get there. Check it out and see if you don't agree.

Healdem, the idea of being able to replicate a deck via code is a great one, but now unnecessary because of the routine I have. I can easily store the info in a table and draw from there as needed, so while it would have been more efficient it's really not that much different. I do appreciate the suggestion, though.

Regarding cross-posting, my apologies if pbaldy or others are offended, but it did accomplish what I set out to accomplish, and no matter how it appears, the answer came from another forum. That's not meant to be a shot at this forum in any way. I sincerely appreciate all the thought and suggestions that people have offered on my behalf. Cross posting, which I freely admitted to, was used to get maximum exposure and the greatest number of minds considering the problem. Again, I apologize if that is considered poor etiquette.

Pkstormy, cool stuff you wrote. It just shows how versatile Access is.
 

vbaInet

AWF VIP
Local time
Today, 18:48
Joined
Jan 22, 2010
Messages
26,374
Looks like HiTechCoach has been double posting too (cross referencing) :D lol
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 12:48
Joined
Feb 28, 2001
Messages
27,175
FWIW, Casinos DO NOT eject counters in Blackjack. They eject those who count other than in their heads alone. I.e. multi-person counting teams or any folks with mechanical counting devices.

The casinos have a name for individual, non-mechanical counters. "Losers."
 

vbaInet

AWF VIP
Local time
Today, 18:48
Joined
Jan 22, 2010
Messages
26,374
Good job you're doing pointing them out :) That should be a good read for the OP. I think he's new to the whole "posting on technical forums" scene.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 18:48
Joined
Sep 12, 2006
Messages
15,653
Gemma, I understand that you are restating conventional wisdom, and I agree that there is indeed a built-in very small percentage house advantage (about 2%). Regardless, I have noticed and exploited something previously either unrecognized or underappreciated about the game which has allowed me to overcome that very small edge. Right now I'm 18 wins for 21 trips, or about 86%, without the benefit of the ability to computer analyze the game. That isn't luck.

I have another question I'd like to pose to readers. This program has always been intended as an analytical tool, and nice pretty graphics were never a consideration. In fact, my original shuffle routine made no provision for suit, since for analytical purposes a six of diamonds or clubs is identical. However, the shuffle routine I now have does include suits, and it would be nice to utilize cards.dll to make it graphical if it's not too much extra effort.

Does anyone out there know how to call specific card graphics from within Access? I'd sure like to know if it's possible, and if so, how it is done.

I still dont understand what a "shuffle" is supposed to be. Why is a true shuffle not the same as a random number generator.

[i will have a look at the example you provided to see what it does]

Having said that, in practice a real world shuffle may not be random. The cards are definitely packed together in a non-random way - and the technique of shuffling may or may not randomize the pack. eg Clusters of pre-sorted cards may not be affected by a manual shuffle.


I still struggle to see where a player's edge comes from.

The only thing I can see is when a player stands on a modest hand (ie in the range 12-15), in the expectation that the dealer will "bust" - which becomes far more likely when the percentage of high cards left in the deck is unusually high - hence the need to count cards.
 
Last edited:

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 18:48
Joined
Sep 12, 2006
Messages
15,653
FWIW, Casinos DO NOT eject counters in Blackjack. They eject those who count other than in their heads alone. I.e. multi-person counting teams or any folks with mechanical counting devices.

The casinos have a name for individual, non-mechanical counters. "Losers."

it was just a thought/observation - casinos will definitely pay serious attention to gamblers who consistently overcome the house edge.

in the same way as UK bookmakers will not accommodate bets from some backers.
 

bcmarshall

Registered User.
Local time
Today, 10:48
Joined
Jul 17, 2010
Messages
92
I have another question, which I have also posted at other forums.

I originally asked for, and received, a great routine that shuffles the cards very fast and stores the shuffle in a table. After posting it in this and other forums, the suggestion was made that a deck could be represented with a single number, something I had not considered before. Since one of my interests is to be able to store many given decks, I'm now realizing that it would be 312 times easier to store one number than a six-deck shuffle.

Does anyone know of a way to convert that shuffle into a single number, and then convert the number back into the shuffle?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 18:48
Joined
Sep 12, 2006
Messages
15,653
bc - I dont quite understand what "routine" you got to shuffle cards.

lets say you map cards

1-13 = 2 to A Spades
14-26 = 2 to A Hearts
27-39 = 2 to A Diamonds
40-52 = 2 to A Clubs

if you have more that 1 deck, then extend this mapping etc.

-------------
now, i still cant see that a shuffle is any more than a random number generator, which sorts the cards (1 to 52) in a random order.

so - either you use a repeatable RNG - so all you need to store is the starting seed, as you can reconstruct the deck just from this number.

or - run the RNG, and then store an array of the first few card values - depending how many you want. (which is what you are doing)

or just store this as a string of (say 3 char values) such as
- 004123086257, representing cards 4, 123, 86, 257

instead of storing card numbers you can store cards themselves
2H JH 3D 4S etc

If the deck matters then store this as well

2H1 JH4 3D2 4S1 etc
 

bcmarshall

Registered User.
Local time
Today, 10:48
Joined
Jul 17, 2010
Messages
92
I posted the shuffle routine I received here. Perhaps you didn't see it.
http://www.mediafire.com/download.php?i6e3elm9a2hh71t

Of course you're right that shuffle=RNG, except that the numbers are now associated with conventional card values. It seems that there are many seed numbers in that routine, each of which is randomly generated.

When one plays FreeCell, as an example, one can choose the game number or get a random one. Choosing the game number reproduces a specific deck. What I was hoping for is a way to convert the 312 cards in a specific shoe to one number for storage in a similar manner, instead of storing 312 individual records.

I see what you're saying about storing the seed number. I just don't don't know how to integrate it with what I have, or if it's integratable at all. The routine I've got is extremely fast and I'm very happy with it, and it does exactly what I wanted with storing the values in a table so I could "peek" forward into the deck to see what the next card(s) would have been without actually dealing them. It's just that when I've finished with that shoe and I want to put it away for later use it would be much easier to be able to store it as a single number.

How about this? Once my shoe is played through can I just use a separate routine that would do what you suggest and use a single seed number for storage? That would give the best of both worlds. I can use the existing very fast shuffle and table, and use a second routine (which I don't have yet) to create the seed number needed to reproduce it later.

The string idea doesn't seem to be practical since it would have 312*3 digits in it.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 18:48
Joined
Sep 12, 2006
Messages
15,653
i downloaded the reference, but i haven't looked at it.

it depends how they generate the sequence. if a given random number always produces the same random sequence, then all you need to store is the seed. if not you need to store everything

dont get hung up about storing a card itself. if your RNG generates a number in the range 1 to 312, then it is trivial to turn this into a card value. any routine will be quick. this isnt a very complex procedure, especially for your testing purposes.

the same first card wont always produce the same sequence. the seed will be a real number with many significant digits. these will/should variously produce a different sequence

ie lets say, any real number between 1 and 2 generates the A spades. But 1.01234 will generate a different second card, form 1.23456. etc. As long as 1.01234 always then generates the same sequence, then you only need to store the seed.


on line gambling sites (poker) DID (supposedly) have problems with the rng, because it was claimed that it was possible to pre-compute the rng sequence, and therefore for betters to anticipate the cards. even if this is possible in your case, this wont be an issue for research purposes.

with regared to storing the entire card sequence, a string of 1000 characters isnt so big. You get a 1000 sequences in 1Mb. A million in 1Gb. How many do you need? If you need to compare the card order in successive strings, then this may be the best solution.

As I said, you need to bear in mind that
a) I would think that online blackjack doesnt run down a shoe, but reshuffles each hand
b) real world shuffles may not be random.
 
Last edited:

bcmarshall

Registered User.
Local time
Today, 10:48
Joined
Jul 17, 2010
Messages
92
Thanks, Dave. As I think about it, there are only 52 cards, so there is no need to use three digits to store a card value. Using two digits creates a string 624 characters long. While a damn long number by human standards, it probably is a piece of cake for Access to handle.

I don't expect to be comparing the card order in successive strings. What I want to do is have a control for my experiments, the control being many shoes of cards that can be reproduced. I can run the shoes using one play or bet pattern, and then rerun the exact same card sequences using another pattern. In that way I can compare results obtained one way with what would have happened another way.

I can think of several ways to convert the 312 individual records in one shoe to a string, and then convert the string back to 312 individual records, but they don't seem particularly efficient. Do you have any suggestions as to the best way to accomplish that?
 

Users who are viewing this thread

Top Bottom