Big Moose Saloon
 Search | Java FAQ | Recent Topics Register / Login Win a copy of The Mikado Method this week in the Agile and other Processes forum!

# Blackjack WIP

Steven Jacobsen
Greenhorn

Joined: Jul 25, 2012
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.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9946

6

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...

Never ascribe to malice that which can be adequately explained by stupidity.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32654

4
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

Joined: Oct 02, 2003
Posts: 9946

6

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.

I agree. Here's the link: http://aspose.com/file-tools

subject: Blackjack WIP