Solved

Poker game in VB 2008

Posted on 2010-09-10
1,032 Views
Hi everyone,

I am planning to make a Texas Holdem Poker game in VB. I am looking forward to some basic application where five card are selected at random and displayed on the screen and then users will have their two card in their hand (physically). Then the application will ask the users to enter their cards in hand and then the system calculated if they have won or not.

I have some idea about the basics like I will need 2 classes one for cards and one for the deck and two methods, one for shuffle and one for deal.
I also have all the card images etc available.

But before starting I was wonder if I could look at some sample codes. I am not sure where to start from.

Any help to guide me in the right direction will be highly appreciated.

Thanks
0
Question by:justind39

LVL 39

Expert Comment

If you're going to do this right, you're going to want to have multiple classes.

Table:  holds people, public cards, etc.

People:  account info, username, private cards, etc

Deck - 52 cards.  shuffle will be a randomize function, put them on a stack or in a list randomly so that all 52 are contained.

Deal as per the rules, just taking off the front card and allocating it to the person.

If you are going to give them physical cards . . . what's to say I don't have aces all the time?  What's the finaly application?

0

LVL 20

Accepted Solution

alainbryden earned 500 total points
I was helping a friend create a texas holdem game the other day so I'll help you out. The included code should be incredibly easy to translate from java pseudocode to VBA:

• Define a deck of cards as a 4*13 2D boolean array, and a card object as a two integer pair.

• As you randomly generate a card (S=rand(1,4) for suit and  V=rand(2,14) for value), you mark the appropriate array index  Deck[S-1][V-2] = true, and on future random generations, ensure that the  card has not already been drawn)

• Have a function that sorts your hand as you did, and then checks for  hands from highest to lowest value based on flush, straight, pair  determinations. As soon as a winning is found, you can break and return  the appropriate multiplier.
• When you create a hand, you should sort it in ascending order. A hand can be easily defined using two 5 element arrays. One array of face values (where 2=2, 3=3, ..., Jack=11, Queen=12, King=13, Ace=14). The other array is the suits (which can just be a single character or a number from 0 to 3)
Based on the above infrastructure, the following segments of code can be used to computer a hand:
hasFlush:
bool flush = true;
for( int i = 0; i < 4, flush == true; i++)
if( suitArray[i] != suitArray[i+1] ) flush = false;
//We assume a flush until a test tells us otherwise.

hasStraight (requires valArray to be in ascending order):
bool straight = true;
for( int i = 0; i < 3, straight == true; i++)
if( (valArray[i]+1) != valArray[i+1] ) straight = false;
if( straight == true && (valArray[3]+1) != valArray[4] && (valArray[3]+9) != valArray[4]) straight = false;
//Because there's a special case for a wheel straight the final test is done after the loop.

Count pairs, 3 of a kinds, and 4 of a kinds (requires valArray to be in ascending order):
int pairCount = 0, matchCount = 0, maxMatch = 0, maxPair = 0;
for( int i = 0; i < 4; i++)
{
if( valArray[i] == valArray[i+1] )
{
if( matchCount == 0 ) pairCount++;
matchCount++;
maxMatch = matchCount > maxMatch ? matchCount : maxMatch;
maxPair = valArray[i] > maxPair ? valArray[i] : maxPair;
}
else
matchCount = 0;
}

Final Result:
if( straight == true && flush == true && valArray[0] == 10) //return Royal Flush
if( straight == true && flush == true) //return Straight Flush
if( maxMatch == 4) //return Four of a Kind
if( pairCount == 2 && maxMatch == 3) //return Full House
if( flush == true ) //return Flush
if( straight == true ) //return Straight
if( pairCount == 1 && maxMatch == 3) //return 3 of a Kind
if( pairCount == 2 && maxMatch == 2) //return 2 Pair
if( pairCount == 1 && maxMatch == 2 && maxPair >= 10) //return High Pair

Hope that's a solid start. Good Luck.

--
Alain
0

Featured Post

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…