# AnsweredNeed help with problem solving

#### Foxster

##### New member
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
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
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.
Ok. But it would be very long, because everything is intgrated with everything, so here's a link to a GitHub repository instead.

#### Foxster

##### New member
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
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
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.

#### Foxster

##### New member
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.
Thanks!