English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have to write a program that requests five cards as input from the user, creates the related array, and passes the array to procedures to determine the type of the hand: (flush, straight, straight flush, four of a kind, full house, three of a kind, two pairs, one pair, or none of the above.)

I have the poker hand data stored in a two dimensional array by using the statement "dim hand(3,12) as integer" which gives me an array with 52 elements.

How do I take the inputted data and enter it into the hand() array? Then how do I determine what kind of hand the user has inputted?

Can anyone help??

2007-04-08 10:51:48 · 3 answers · asked by Garland R 2 in Computers & Internet Programming & Design

3 answers

Here are some ideas:

Consider how you can easily analyze a hand when it is sorted. Next is do you have to have such a large array to hold your hand? Why not use a smaller array sized to hold five cards? If you get tricky with strings you won't have to use a multidimensional array to keep tract of card value and suit type. Rather combine card value and suit into a single string.

Say 5C = five of clubs and 11D = Jack of diamonds

Realize that if you sort strings the CLUBS would sort out as

1C = Ace ( though you will probably want to make its value 14)
11C = Jack
12C = Queen
13C = King
2C = two
3C
You get the idea if you want to change the sort order so 1 to 13 are in order you would have to add leading place holder zeros to the strings.

You can easily extract a card value like 05H with a val function and determine it is a five and extract the last character to id the suit using a MID or RIGHT function.

Once a hand is sorted it would be easy to sequence through eact element and look for and count matching values

For a sorted hand:
5C,5D,5H,10C,10S

Since each hand could have 5 un paired cards like in a straight you will need a scond array to count the number of matching cards in each hand.

As the hans is sorted you merely ned to compare adjactent card values and if the same increment a counter if not record the existing counter to the current group count index, reset it and advance the index and test the next cards

For the above hand the count array would have the values
3,2,0,0,0 a full house

Some other types of card counts
4,1,0,0,0 = 4 of a kind or 1,4,0,0,0

So basically you can scan the count array and determine some valid hands. SO if one of the elements has a 4 you have a 4 of a kind
Then scan for a three if found you at least have a three of a kind and need to scan for a two to see if it is a full house.


a straight would have card group counts of
1,1,1,1,1 = 5 unpaired cards potential straight but need more testing. A valid straight would have the difference between adjacent sorted cards = 1 or =-1
4,5,6,7,8

4-5 = -1, 5-6 = -1, 6-7 =-1
if all adjacent subtractions have an absolute value of 1 then a straight is confirmed, You can then test for identical suit and test for face card
Consider totalizing card values to determine if a Royal flush is held, You now see why I would give an ACE the value of 14

2007-04-08 14:40:02 · answer #1 · answered by MarkG 7 · 0 0

Call Howard Lederer or Mike Caro.

2007-04-08 10:55:27 · answer #2 · answered by LadyLynn 7 · 0 2

i like to take the incredibly quite ones and place them factor area up alongside my walkway. I then shove the heads of undesirable visitors on them, ala Vlad the Impaler. It incredibly keeps babies and the religious out of the backyard.

2016-12-08 21:41:44 · answer #3 · answered by ? 4 · 0 1

fedest.com, questions and answers