I am in the end part of a Python Gui game build; it is going quite well but I am finding that I underestimated one area of the logic, incorrectly coding it: The game is blackjack.
One area that, although it seemed simple on the surface (and in fact it probably is not as difficult as I am making it) is to monitor Aces that may be in one hand of the game. I will not go into the details of the game of blackjack but I will explain the basics concerning Aces.
- They have a value of "1" by default
- Aces can be played as either as "1" or "11" depending on which suits the player better without going over "21"-- that is, they can and do switch value from each card dealt depending on the other cards
I am writing code that first determines if a card is specifically an Ace. I then need to have the program decide whether or not to make the Ace a "1" or an "11". This is simple when dealing with one Ace but if you have more than one Ace it gets trickier. You must, of course, determine how many Aces you have and what their value should be depending on every other card. At this point, I check for an Ace after each new card is dealt then I try to determine its proper value, whatever creates the best hand without going over 21.
I have written a lot of code (I will not post any at this point because it is a mess and it only works in part, that is if you have only two cards dealt, it can sometimes know what to do if one card is a "5" and one card is an Ace: the total at that point would and should be "16" (11 + 5). Add a new Ace,(dealt card 3) and it may or may not react correctly.
I realize the algo for this must be somewhat simple, but I am going in circles at this point. I seemed to have it working well earlier (I am only coding and testing for the first 3 dealt cards at this point seeing that I can simply clone and update this code for the next, dealt cards); I took just this Ace section out of the program code, created a simplified file without the GUI\animation and ran it all night. This worked until I placed it back into the real program then... instant bugs concerning Ace recognition and value manipulation.
Has anyone ever dealt with this sort of thing. I know I will figure out it alone but I could use some help.
Thank you in advance,