Page 1 of 3 123 LastLast
Results 1 to 15 of 43
  1. #1
    bcmarshall is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jul 2010
    Posts
    95

    6 Deck Card Shuffling In Access

    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.

  2. #2
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    a strange request; what you want is simple. a random order of a table list of 6x52 values. but databases are intended to sort & order - not randomize.

  3. #3
    bcmarshall is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jul 2010
    Posts
    95

    6 Deck Card Shuffling in Access

    I absolutely agree with you. I know this is a very strange request, not at all the common, garden-variety macro/query/table/relationship, etc. question that is posted most of the time, but it is a serious request nonetheless. I have been able to make it work using the Rnd() function, but what I have is very slow, awkward, and impractical for my purposes. If anyone has any ideas how to accomplish it I would be grateful.

  4. #4
    DaveT is offline Access Developer
    Windows 7 Access 2010 (version 14.0)
    Join Date
    May 2010
    Location
    Texas
    Posts
    69
    Lots of ways to do this especially if you are comfortable programming in VBA.

    One way would be to set up a table with 312 rows. The table would have a card field (long int) and you fill that with 1 - 13, 1-13, ... six times.

    Have an autonumber field (say RecID) and set it as PrimaryKey.

    Have a thrid field called SortOrder (long int, indexed unique)

    In its setup configuration, the SortOrder field would be null.

    Then you run a VBA procedure that steps through the table in RecID order.

    For each record, you use rnd to pull a number between 1 and 312. Try to write the value to SortOrder. If you do not get an error, move to the next record.

    When you get to EOF (the end of the table), you are through.

    Note that for an individual record if you pull a random number (1-312) that has already been used in the table, DAO will throw an error (can't add the record because it would violate unique index on SortOrder).

    This just says, pull another random number and try again.

    Not sure how long it would take this to run, but I wouldn't think that long ...

    To reset the process, run a query that sets SortOrder to null in your table.

    To use the finished result, pull values from the table sorted by (wait for it ...) SortOrder.

  5. #5
    Join Date
    Jun 2010
    Posts
    12
    I can't help you with the Access part necessarily. But as a former counter of cards, if you are doing a study of whether you made the correct decision to stand on 16, your study is useless. Always hit 16 vs. a 10, the mathmatics and statistics will agree in the long run.

  6. #6
    bcmarshall is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jul 2010
    Posts
    95

    6 Deck Card Shuffling in Access

    Oh, that is absolutely not what I'm trying to accomplish. I only used that as an example, but there is much, much more that I want to look at. I can tell you that I'm very successful now, having won 18 of the last 21 trips to a casino in live play without counting, but there are dozens of things that I want to look at in ways that only a computer analysis can provide. I have already written the play program, and I know how to tell Access to isolate and compute the things I want to look at. I just need to find a practical shuffle routine, which is fundamental to anything else that I do.

  7. #7
    Ted C is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    66
    For shuffling, I would have a "SortOrder" column in the table of cards for a deck. Have an update query assign a random number to the SortOrder for each card in the deck, then sort the deck by the SortOrder.

  8. #8
    bcmarshall is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jul 2010
    Posts
    95
    Dave, thanks for your response. I posted this question on several forums in order to get maximum exposure for it (I really want to get past this roadblock), and I received the following from someone.

    SELECT INTO randCards FROM sixdeck ORDER BY Rnd(<some_numeric_field>)

    It seems to do everything within a query, but the poster did not provide a description of what randCards, sixdeck, and the <some_numeric_field> refer to. Can you or someone else explain? Is randCards a table name? Would sixdeck be a field? I feel this is an extremely simple and fast solution, but I just don't know how to harness it, and perhaps someone else can look at it and provide the missing pieces.

  9. #9
    bcmarshall is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jul 2010
    Posts
    95
    Ted, your suggestion is not too far afield from what I've done. The problem is that the random number I need must be between 1-312 and can not repeat. The only way I've been able to do that is to look up the random number that's generated to see if it has already been used, and if it has run the random again until an unused number within that group is generated. It goes fast at the beginning, but as the number of possible remaining numbers diminishes it takes a very long time.

    Do you have another idea in generating that random number in the update query that would eliminate the problem?

  10. #10
    Ted C is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    66
    Quote Originally Posted by bcmarshall View Post
    SELECT INTO randCards FROM sixdeck ORDER BY Rnd(<some_numeric_field>)

    It seems to do everything within a query, but the poster did not provide a description of what randCards, sixdeck, and the <some_numeric_field> refer to. Can you or someone else explain? Is randCards a table name? Would sixdeck be a field? I feel this is an extremely simple and fast solution, but I just don't know how to harness it, and perhaps someone else can look at it and provide the missing pieces.
    It looks like "randCards" and "sixdeck" are tables that have identical columns (such as Suit, Name, Value, etc.).

    Rnd is a random value used to sort the rows as they're pulled by an append query from the original "sixdeck" table. Instead of building the list of cards and then randomizing it, this query sucks cards into a new table (randCards) in a random order.

  11. #11
    Join Date
    Jun 2010
    Posts
    12
    This is just side comments, I hope your analysis goes well and you find the right shuffling code. But realize if you are not counting, and you won 18 out of the last 21 trips(if that is accurate), you have been on an incredibly lucky run. You are working with a House Edge of 2% or greater depending how you play. The game can only be beaten when there is patience and counting involved. If you keep going back, that edge is going to bite into your winnings and the casino is going to enjoy every second you think you have the game figured out. No one can consistantly beat the game without counting

  12. #12
    bcmarshall is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jul 2010
    Posts
    95

    6 Deck Card Shuffling in Access

    Img, the 18 of 21 trips is quite accurate, and I am neither counting nor am I incredibly lucky. I have been studying this game intensely for 35 years and I found something previously either overlooked or underappreciated which I have been working to perfect. That's why I want this program running. I believe that my record of 18 for 21 would have been even higher except that on those losing trips I was with my daughter who had to leave early, and I was unable to stay at the table long enough to do what I've done on all the other trips. BTW, the total losses on the three losing trips amounted to less than $300, so while they were technically and fairly called losses, they were not big at all.

    Also, in the interest of total disclosure, one of my "wins" was only $15, so though it was nothing to brag about, it was still technically and fairly a win. My average win is between $100-$400 at the $5 table. I won $225 yesterday in about 6 hours, even though at one point I was -$280, and I was playing at the $10 table.

    Ted, thank you for your explanation of the code. I was unsure of how to apply it, but I will give it a go shortly to see what happens.

  13. #13
    Ted C is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    66
    Quote Originally Posted by bcmarshall View Post
    Ted, your suggestion is not too far afield from what I've done. The problem is that the random number I need must be between 1-312 and can not repeat. The only way I've been able to do that is to look up the random number that's generated to see if it has already been used, and if it has run the random again until an unused number within that group is generated. It goes fast at the beginning, but as the number of possible remaining numbers diminishes it takes a very long time.

    Do you have another idea in generating that random number in the update query that would eliminate the problem?
    When I wrote a card shuffling function in C#, I used a similar method to what I described. The random numbers don't have to fall within a specific range; since they're not equal, anything that you sort by them will fall in a random order.

    You might want to run a routine that actually shuffles six 52-card decks and then "loads the shoe" with the shuffled decks in a random order. Seems like that would be more authentic.

  14. #14
    bcmarshall is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jul 2010
    Posts
    95
    Ahh, I see, said the blind man, as he picked up his hammer and saw...

    The Access Rnd() function requires a numerical parameter, so if I follow correctly you're saying I could use any number, say 1,000 or 10,000, but when sorted they will still randomize. What happens if the same number is generated twice or three times?

  15. #15
    Ted C is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    66
    Quote Originally Posted by bcmarshall View Post
    Ahh, I see, said the blind man, as he picked up his hammer and saw...

    The Access Rnd() function requires a numerical parameter, so if I follow correctly you're saying I could use any number, say 1,000 or 10,000, but when sorted they will still randomize. What happens if the same number is generated twice or three times?
    In the unlikely event that the same number came up more than once in a large sequence, the cards with those numbers would end up right next to each other in the final shuffle, with which ever one was earliest before still earliest in the new sequence.

    Say you've got cards...
    AKQJT
    ...and they get assigned random numbers...
    15865
    ...they should sort to...
    AKTJQ

    The King and Ten both got assigned a 5, so they jump to where 5 belongs in the sorted list. Since the King was before the Ten originally, it's still before the Ten after the sort. If you use a large range for the sort, though, that's not likely to happen.

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Credit Card Info, Where?
    By mastromb in forum Access
    Replies: 3
    Last Post: 05-26-2010, 12:37 AM
  2. Import with a wild card
    By ukgooner in forum Import/Export Data
    Replies: 3
    Last Post: 09-09-2009, 08:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums