• Post Reply Bookmark Topic Watch Topic
  • New Topic
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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Blackjack program not good with random cards

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are two bugs in my Blackjack program. The first: it prints every card before the game starts. Buggery. The second: it draws the same card every time. Double buggery.

Ace of Hearts //first problem
King of Spades
Queen of Clubs
Jack of Diamonds
Ten of Hearts
Nine of Spades
Eight of Clubs
Seven of Diamonds
Six of Hearts
Five of Spades
Four of Clubs
Three of Diamonds
Two of Hearts
Ace of Spades
King of Clubs
Queen of Diamonds
Jack of Hearts
Ten of Spades
Nine of Clubs
Eight of Diamonds
Seven of Hearts
Six of Spades
Five of Clubs
Four of Diamonds
Three of Hearts
Two of Spades
Ace of Clubs
King of Diamonds
Queen of Hearts
Jack of Spades
Ten of Clubs
Nine of Diamonds
Eight of Hearts
Seven of Spades
Six of Clubs
Five of Diamonds
Four of Hearts
Three of Spades
Two of Clubs
Ace of Diamonds
King of Hearts
Queen of Spades
Jack of Clubs
Ten of Diamonds
Nine of Hearts
Eight of Spades
Seven of Clubs
Six of Diamonds
Five of Hearts
Four of Spades
Three of Clubs
Two of Diamonds
Player gets a Eight of Hearts //Look! It works!
Dealer gets a Eight of Hearts //Wait, no it doesn't.
Player gets a Eight of Hearts //BUGGERY.
Dealer gets a card.

Would you like to take a hit or stand? (H/S) //I would like this program to work!

I don't know what parts of the code are affecting what. This is my second large program, and the vastness of it all tends to give me a headache. So here's the code in its entirity:

 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

I would think that the line

System.out.println(deck[i].toString());

in the "shuffle()" loop would have something to do with problem 1, wouldn't you?

As far as dealing the same card every time: the card in the variable "temp" is the one that gets dealt; I don't see any code intended to change that, nor do I see any code which, even if different cards were being dealt, would prevent the same card from being dealt more than once (i.e., the deck always contains all the cards.)
 
Ricky Harline
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!


Not howdy? =(


I would think that the line

System.out.println(deck[i].toString());

in the "shuffle()" loop would have something to do with problem 1, wouldn't you?



I thought so as well. Here, let me show you.


Card@b162d5
Card@1cfb549
Card@186d4c1
Card@f9f9d8
Card@1820dda
Card@15b7986
Card@87816d
Card@422ede
Card@112f614
Card@1d9dc39
Card@93dcd
Card@b89838
Card@111a3ac
Card@110b053
Card@a83b8a
Card@dd20f6
Card@19efb05
Card@723d7c
Card@22c95b
Card@1d1acd3
Card@a981ca
Card@8814e9
Card@1503a3
Card@1a1c887
Card@743399
Card@e7b241
Card@167d940
Card@e83912
Card@1fae3c6
Card@7ffe01
Card@fd13b5
Card@118f375
Card@117a8bd
Card@471e30
Card@10ef90c
Card@a32b
Card@1d8957f
Card@3ee284
Card@8965fb
Card@867e89
Card@1dd7056
Card@fa3ac1
Card@276af2
Card@1de3f2d
Card@5d173
Card@1f9dc36
Card@e86da0
Card@1754ad2
Card@1833955
Card@291aff
Card@ab95e6
Card@fe64b9
Player gets a Card@1503a3
Dealer gets a Card@1503a3
Player gets a Card@1503a3
Dealer gets a card.



As far as dealing the same card every time: the card in the variable "temp" is the one that gets dealt; I don't see any code intended to change that,


Oh, geez. This is gonna take me while.

nor do I see any code which, even if different cards were being dealt, would prevent the same card from being dealt more than once (i.e., the deck always contains all the cards.)

Ah, crap. I'm sure Google will help me with that one. But first to tackle the first two.

Crap, I'm going to make another Shuffle thingy fot my getCard(), aren't I?

[ November 10, 2006: Message edited by: Ricky Harline ]

[ November 10, 2006: Message edited by: Ricky Harline ]
[ November 10, 2006: Message edited by: Ricky Harline ]
 
Ricky Harline
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The cards are shuffled, which means that I simply need to move on to the next card in the Array.

I have it in Array format:



That's how I figured this out... But I have no idea how to move on to the next card. GRRRR.

After many hours work, I was able to come up with the two lines of code required to make it move on to the next card. Wewt.
[ November 10, 2006: Message edited by: Ricky Harline ]
[ November 10, 2006: Message edited by: Ricky Harline ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic