StUnT10011
06-18-2004, 05:15 PM
Hey guys, I'm writing a BlackJack prog and I have the GUI setup and pretty much everything is done but I have one problem. I can't figure out a way to
keep track of the cards. For example, sometimes you will be dealt two Ace of Clubs. How can I make it so that each card is only used once per hand? I've heard an array might be helpful. Any ideas???
Iceplug
06-18-2004, 06:08 PM
Well, an array might be helpful, or you can use an ArrayList.
You can put numbers in the array list to represent the cards (or you can use your own type). To shuffle the arraylist, you can generate two random numbers: one to determine the card position that you draw from and the other to determine where you put the card in the array. :)
StUnT10011
06-19-2004, 01:41 PM
Well, an array might be helpful, or you can use an ArrayList.
You can put numbers in the array list to represent the cards (or you can use your own type). To shuffle the arraylist, you can generate two random numbers: one to determine the card position that you draw from and the other to determine where you put the card in the array. :)
Ummm.... when setting up the array, how would I have a number reprent a certain card???
Iceplug
06-20-2004, 07:03 AM
Well... you could just go down the list of cards:
0 = Ace of Spades, 1 = 2 Spades, 2 = 3 Spades, 3 = 4 Spades ...
11 = Queen Spades, 12 = King Spades
13 = Ace of Hearts, 14 = 2 Hearts
Then, you extract the card value using Mod
V = Card Mod 13 (mod returns the remainder of division)
You can get the suit by using the integer division (backwards slash)
V = Card \ 13
:)
You may also use a card Structure or Class and store the Suit and Value in different properties of the card.