Results 1 to 11 of 11
  1. #1
    Join Date
    Jul 2010
    Posts
    3

    Unanswered: 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
    Join Date
    May 2010
    Posts
    601
    Quote Originally Posted by bcmarshall View Post
    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.
    Welcome to dbForums!

    We will be glad to give you guidance as you create this.

    First step will be to get your tables set up correctly.

    Please describe your current tables, fields, indexes, a relationships.
    Last edited by HiTechCoach; 07-17-10 at 19:59.
    Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
    Microsoft MVP - Access Expert
    BPM/Accounting Systems/Inventory Control/CRM
    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  3. #3
    Join Date
    May 2010
    Posts
    601
    I see you have also posted this at UtterAccess
    Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
    Microsoft MVP - Access Expert
    BPM/Accounting Systems/Inventory Control/CRM
    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  4. #4
    Join Date
    Jul 2010
    Posts
    3

    6 Deck Card Shuffling in Access

    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!

  5. #5
    Join Date
    May 2010
    Posts
    601
    Yes, I have seen 5 of the 6.

    If anyone is curious to see if anyone else has already answered this, see:

    AWF

    Access Forums

    ASPfree
    Last edited by HiTechCoach; 07-19-10 at 00:54.
    Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
    Microsoft MVP - Access Expert
    BPM/Accounting Systems/Inventory Control/CRM
    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    if you use a random number with a same seed then you know the sequence will be the same. so if you set the seed and store it you know you can replicate the sequence

    the sort sequence itself can be realtively simple
    build the deck (I've used collections before)
    generate a random number that selects one of the cards in the collection (use the min/max to select the index of the card in the collection... note collections are zero based)
    then extract the card from the collection (remove it from the deck),add it to the shuffled deck
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Quote Originally Posted by bcmarshall View Post
    I really want to get this solved so I can move on!
    Perhaps a good first step towards "getting this solved" so that you can "move on" would be to select an appropriate programming environment for the job at hand!

    Using a database development program to write an app that is not a database, then complaining because it won't do the job as efficiently as you'd like it to, is simply absurd!

    It's like having to haul a ton of gravel, using the backseat of a VW Beetle, then complaining because it's taking so many trips, rather than using a dump truck!
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  8. #8
    Join Date
    Jul 2004
    Location
    South Dakota
    Posts
    267
    Aren't collections 1 based while arrays are 0 based (unless you changed the Option Base)?

    C

  9. #9
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Here's some games I designed in MSAccess. There are a couple of others in the code bank as well:

    http://www.dbforums.com/6274797-post25.html
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  10. #10
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Quote Originally Posted by HiTechCoach View Post
    Yes, I have seen 5 of the 6.

    If anyone is curious to see if anyone else has already ansered this, see:
    An FYI on why some of us don't like posting all over creation:

    A message to forum cross posters | Excelguru.ca
    Paul

  11. #11
    Join Date
    Jul 2010
    Posts
    3
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •