Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Blackjack WIP

Greenhorn
Posts: 1
I got some education in Java and everything you see in this program is something I was introduced to.
There is a linked list with 4 of each card from 1 to 10. Can someone show how I could add all hte face cards (valued at 10) and maybe even give me step by step instructions on how to exchange the 1 for an 11 and have the 11 turn into 1 when the hand goes over 21. If anyone could provide help I would very much appreciate it.

lowercase baba
Bartender
Posts: 12624
50
That's a lot of code to expect someone to go through, especially with such vague questions. I'll give it a shot, though...

Your lines 31-40 seem to count from 1 to 10, and then for each value, add it four times to the deck. So that would give you 40 cards. You now need to add 12 more cards, all valued at 10, right?

I'd just do another loop, and add them in.

If you want my HONEST opinion, i'd throw this out and start over. I'd make a 'card' class that hold (among possible other things) a rank, a suit, and perhaps a value.

I'd build a deck class that contains cards. I'd design the constructor to initialize the deck in a sorted order, and provide it a shuffle() method.

I'd design a 'hand' class that holds cards. It can return how many cards are in the hand, and also return the value of the hand. So it would compute the value. it would basically add up all the values, assuming each ace was worth "11". If the hand was over 21, and I had one or more aces, I'd then subtract 10 and see if the value was now 21 or under, looping for each ace in the hand...

Note - just typing that out implies I may need to keep track of how many aces are in the hand as well...

Marshal
Posts: 59124
180

fred rosenberger wrote:. . . keep track of how many aces are in the hand as well...

Are you allowed five?

And welcome to the Ranch

fred rosenberger
lowercase baba
Bartender
Posts: 12624
50

Campbell Ritchie wrote:

fred rosenberger wrote:. . . keep track of how many aces are in the hand as well...

Are you allowed five?

I meant how many aces are in each player's hand. For example, if I have

A A A 10 7

my original score computation would produce 11 + 11 + 11 + 10 + 7 = 50

That busts. But, If I know I have an ace, I can subtract 10 and get 40 (still bust). If I know I have three aces, I know I can subtract 10 two more times.

Of course, if you play with the "five card charlie" rule, you need to have a tally of how many cards the player has.

And if you go to the casino and they use a muti-deck shoe, you can have five aces...although a smart player would keep splitting.

 CAUTION! Do not touch the blades on your neck propeller while they are active. Tiny ad: Rocket Oven Kickstarter - from the trailboss https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss