Answered Need help with problem solving

Foxster

New member
Joined
Nov 3, 2020
Messages
4
Programming Experience
3-5
I made a simple BlackJack game, text only, betting is done IRL, no doubling, splitting or stuff like that. It's working nicely and i'm kinda proud, but there's one function that I don't know how to implement.
In BlackJack, the aces are worth 11, unless you would get bust, then they're worth only 1. I didn't think of this in the beginning, and now I don't know how to implement it without having to remake the whole thing.

Does anyone have an idea on how to solve this? Feel free to play around with the code.


Disclaimer: The code might be a bit messy and long, and my questionable commentary doesn't make it better. Please read at your own risk.
 

Attachments

  • BlackJack.zip
    5.5 KB · Views: 14
Last edited:

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
4,431
Location
Chesapeake, VA
Programming Experience
10+
Post the relevant code here in code tags instead of attaching a .ZIP file. Not everyone will want to download a random .ZIP file off the Internet.

Without seeing your code, it seems that if you make a method that computes the value of a hand, and that method takes a parameter that tells the method whether to treat the Aces as 1 or 11, that would get you part way there. The other part that is harder to handle is when you have two or more Aces, and you need to treat one Ace as an 11, and the other Aces as 1's. To be able to do that, you will have to take a slightly different approach of iteratively demoting 11's to 1's until the user does not bust anymore.
 

Foxster

New member
Joined
Nov 3, 2020
Messages
4
Programming Experience
3-5
Without seeing your code, it seems that if you make a method that computes the value of a hand, and that method takes a parameter that tells the method whether to treat the Aces as 1 or 11, that would get you part way there. The other part that is harder to handle is when you have two or more Aces, and you need to treat one Ace as an 11, and the other Aces as 1's. To be able to do that, you will have to take a slightly different approach of iteratively demoting 11's to 1's until the user does not bust anymore.
Yes, thats about what I would've come up with if I took this function in thought from the beginning, but I didn't, and I don't want to remake everthing now.
 

JohnH

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
1,362
Location
Norway
Programming Experience
10+
Change ToValue to return 1 for Ace, then in TotalValue if a 1 is found take note with a boolean variable that 10 can be added. If 10 can be added, and without bust, return that (result+10), else return result.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
4,249
Location
Sydney, Australia
Programming Experience
10+
Ok. But it would be very long, because everything is intgrated with everything, so here's a link to a GitHub repository instead.
Then you need to do a better job of isolating what your issue is and what code is relevant to that. It probably suggests that your code could be better structured too. If you can't ask for help with a specific issue without providing all your code then either or both of those things is an issue.
 
Top Bottom